Example: ILE C program for listing retained keys
Change this IBM i program example to suit your needs for listing retained keys.
Note: Read the Code license and disclaimer information for important legal
information.
/*-------------------------------------------------------------------*/
/* List the names of the RSA private keys retained. */
/* */
/* */
/* */
/* COPYRIGHT 5769-SS1 (C) IBM CORP. 2000, 2007 */
/* */
/* 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: Input format is more fully described in Chapter 2 of */
/* IBM CCA Basic Services Reference and Guide */
/* (SC31-8609) publication. */
/* */
/* Parameters: */
/* none. */
/* */
/* Example: */
/* CALL PGM(LISTRETAIN) */
/* */
/* */
/* 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. */
/* */
/* The Common Cryptographic Architecture (CCA) verb used is */
/* Access_Control_Initialization (CSUAACI). */
/* */
/* Use these commands to compile this program on the system: */
/* ADDLIBLE LIB(QCCA) */
/* CRTCMOD MODULE(LISTRETAIN) SRCFILE(SAMPLE) */
/* CRTPGM PGM(LISTRETAIN) MODULE(LISTRETAIN) */
/* BNDSRVPGM(QCCA/CSNDRKL) */
/* */
/* Note: Authority to the CSNDRKL service program in the */
/* QCCA library is assumed. */
/* */
/* The Common Cryptographic Architecture (CCA) verb used is */
/* Retained_Key_List (CSNDRKL). */
/* */
/*-------------------------------------------------------------------*/
#include <string.h>
#include <stdio.h>
#include "csucincl.h"
void main(void)
{
/*-----------------------------------------------------------------*/
/* standard CCA parameters */
/*-----------------------------------------------------------------*/
long return_code;
long reason_code;
long exit_data_length;
unsigned char exit_data[2];
long rule_array_count;
unsigned char rule_array[2][8];
/*-----------------------------------------------------------------*/
/* CCA parameters unique to CSNDRKL */
/*-----------------------------------------------------------------*/
unsigned char key_label_mask[64];
unsigned char key_label[500][64];
long retain_key_count;
long key_label_count = 500;
int k;
/*-----------------------------------------------------------------*/
/* Set up label mask, ie. which key name to retrieve. */
/* *.*.*.*.*.*.* is a wildcard for all keys. */
/*-----------------------------------------------------------------*/
memset(key_label, 0x00, sizeof(key_label) );
memset(key_label_mask, ' ', sizeof(key_label_mask));
memcpy(key_label_mask,"*.*.*.*.*.*.*",13);
rule_array_count = 0;
/*-----------------------------------------------------------------*/
/* Invoke the verb to get the list of the retained keys. */
/*-----------------------------------------------------------------*/
CSNDRKL(&return_code,
&reason_code,
&exit_data_length,
exit_data,
&rule_array_count,
(unsigned char*)rule_array,
key_label_mask,
&retain_key_count,
&key_label_count,
(unsigned char*)key_label);
/*-----------------------------------------------------------------*/
/* Check the results */
/*-----------------------------------------------------------------*/
if (return_code != 0)
{
printf("Retained Key List failed with return/reason %d/%d \n",
return_code, reason_code);
return;
}
else
{
/*---------------------------------------------------------------*/
/* Display number of keys retained/returned. */
/*---------------------------------------------------------------*/
printf("Retained key count [%d]\n",retain_key_count);
printf( "No. of key labels returned [%d]\n",key_label_count);
if (key_label_count > 0)
{
/*------------------------------------------------------------*/
/* Display the names of each key returned. */
/*------------------------------------------------------------*/
printf("Retain list = \n" );
for (k = 0 ;k < key_label_count; k++)
{
printf( "[%.64s]\n",key_label[k]);
}
}
}
}