Example: ILE C program for logging on to your Cryptographic Coprocessor

Change this program example to suit your needs for logging on to your Cryptographic Coprocessor.

Note: Read the Code license and disclaimer information for important legal information.

If you choose to use this program example, change it to suit your specific needs. For security reasons, IBM® recommends that you individualize these program examples rather than using the default values provided.

/*-------------------------------------------------------------------*/
/* Log on to the  card using your profile and passphrase.        */
/*                                                                   */
/*                                                                   */
/*  COPYRIGHT 5769-SS1, 5722-SS1 (C) IBM CORP. 1999, 2000            */
/*                                                                   */
/*  This material contains programming source code for your          */
/*  consideration.  These examples have not been thoroughly          */
/*  tested under all conditions.  IBM, therefore, cannot             */
/*  guarantee or imply reliability, serviceability, or function      */
/*  of these program.  All programs contained herein are             */
/*  provided to you "AS IS".  THE IMPLIED WARRANTIES OF              */
/*  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE         */
/*  ARE EXPRESSLY DISCLAIMED.  IBM provides no program services for  */
/*  these programs and files.                                        */
/*                                                                   */
/*                                                                   */
/* Note: This verb is more fully described in Chapter 2 of           */
/*       IBM  CCA Basic Services Reference and Guide             */
/*       (SC31-8609) publication.                                    */
/*                                                                   */
/* Parameters:                                                       */
/*   none.                                                           */
/*                                                                   */
/* Example:                                                          */
/*   CALL PGM(LOGON)                                                 */
/*                                                                   */
/*                                                                   */
/* Note: This program assumes the card with the profile is           */
/*       already identified either by defaulting to the CRP01        */
/*       device or by being explicitly named using the               */
/*       Cryptographic_Resource_Allocate verb. Also this             */
/*       device must be varied on and you must be authorized         */
/*       to use this device description.                             */
/*                                                                   */
/*                                                                   */
/* Use these commands to compile this program on the system:         */
/* ADDLIBLE LIB(QCCA)                                                */
/* CRTCMOD MODULE(LOGON) SRCFILE(SAMPLE)                             */
/* CRTPGM  PGM(LOGON) MODULE(LOGON) BNDSRVPGM(QCCA/CSUALCT)          */
/*                                                                   */
/* Note: Authority to the CSUALCT service program in the             */
/*       QCCA library is assumed.                                    */
/*                                                                   */
/* The Common Cryptographic Architecture (CCA) verb used is          */
/* Logon_Control (CSUALCT).                                          */
/*                                                                   */
/*-------------------------------------------------------------------*/


#include "csucincl.h"      /* header file for CCA Cryptographic      */
                           /* Service Provider                       */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

/*-------------------------------------------------------------------*/
/* standard return codes                                             */
/*-------------------------------------------------------------------*/

#define ERROR    -1
#define OK        0
#define WARNING   4


int main(int argc, char *argv[])

{
    /*-------------------------------------------------------------------*/
    /* standard CCA parameters                                           */
    /*-------------------------------------------------------------------*/

    long return_code = 0;
    long reason_code = 0;
    long exit_data_length = 2;
    char exit_data[4];
    char rule_array[2][8];
    long rule_array_count = 2;

    /*-------------------------------------------------------------------*/
    /* fields unique to this sample program                              */
    /*-------------------------------------------------------------------*/

    char profile[8];
    long auth_parm_length;
    char auth_parm[4];
    long auth_data_length;
    char auth_data[256];

    /* set rule array keywords                                           */
    memcpy(rule_array,"LOGON   PPHRASE ", 16);

    /* Check for correct number of parameters                            */
    if (argc < 3)
      {
       printf("Usage:  CALL LOGON ( profile 'pass phrase')\n");
       return(ERROR);
      }

    /* Set profile and pad out with blanks                               */
    memset(profile, ' ', 8);
    if (strlen(argv[1]) > 8)
      {
       printf("Profile is limited to 8 characters.\n");
       return(ERROR);
      }
    memcpy(profile, argv[1], strlen(argv[1]));

    /* Authentication parm length must be 0 for logon                    */
    auth_parm_length = 0;

    /* Authentication data length is length of the pass-phrase           */
    auth_data_length = strlen(argv[2]);


    /* invoke verb to log on to the  card                            */

    CSUALCT( &return_code,
	     &reason_code,
	     &exit_data_length,
	     exit_data,
	     &rule_array_count,
	     (char *)rule_array,
	     profile,
	     &auth_parm_length,
	     auth_parm,
	     &auth_data_length,
	     argv[2]);

    if (return_code != OK)
    {
    	printf("Log on failed with return/reason codes %ld/%ld\n\n",
	           return_code, reason_code);
    }
    else
      printf("Logon was successful\n");
}