#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <memory.h>
int main(int argc,char *argv[])
{
CK_OBJECT_CLASS objClass = 0;
CK_KEY_TYPE keyType = 0;
CK_ULONG ulSlotCount = 0;
CK_ULONG i = 0;
CK_ULONG j = 0;
int match = 0;
if (
CKR_OK != (rv = C_Initialize( &initArgs ))) {
printf( "PKCS11 example2: failed C_Initialize (error:%lx)", rv );
return -1;
}
{
printf( "PKCS11 example2: memory allocation failed" );
return -2;
}
if (
CKR_OK == (rv = C_GetSlotList(
CK_FALSE, pSlotList, &ulSlotCount )))
{
for( i=0; i < ulSlotCount; i++ )
{
{
match = strncmp( (const char*)oneSlot.slotDescription, "KMIP SLOT1 ", 64 );
if (0 == match)
{
if (
CKR_OK != (rv = C_OpenSession( pSlotList[i], flags, NULL, NULL, &hSession ))) {
printf( "PKCS11 example2: slot %ld failed to open a session (error:%lx)", pSlotList[i], rv );
break;
}
{
CK_ULONG keySizeInBytes = 32;
for( j=0; j < 32; j++ ) keyBytes[j] = (
CK_BYTE)j+15;
strncpy( (char*) label, "An AES secret key object", 24 );
keyTemplate[0].
pValue = &objClass;
keyTemplate[1].
pValue = &keyType;
keyTemplate[2].
pValue = &bTFlag;
keyTemplate[3].
pValue = &label;
keyTemplate[4].
pValue = &bTFlag;
keyTemplate[5].
pValue = &bTFlag;
{
printf( "PKCS11 example2: slot %ld failed to store key on token (error:%lx)", pSlotList[i], rv );
}
else
{
start.
year[0] =
'2'; start.
year[1] =
'0'; start.
year[2] =
'1'; start.
year[3] =
'5';
start.
day[0] =
'1'; start.
day[1] =
'6';
end.
day[0] =
'0'; end.
day[1] =
'2';
strncpy( (char*)label2, "An updated AES secret key object on token", 41 );
changeTemplate[0].
pValue = &start;
changeTemplate[1].
pValue = &end;
changeTemplate[2].
pValue = label2;
printf( "PKCS11 example2: slot %ld failed to update key on token (error:%lx)", pSlotList[i], rv );
}
}
if (
CKR_OK != (rv = C_Logout( hSession ))) {
printf( "PKCS11 example2: slot %ld failed to logout of token (error:%lx)", pSlotList[i], rv );
}
}
if (
CKR_OK != (rv = C_CloseSession( hSession ))) {
printf( "PKCS11 example2: slot %ld failed to close an active token session (error:%lx)", pSlotList[i], rv );
break;
}
}
else {
printf( "PKCS11 example2: slot %ld failed to log user into token (error:%lx)", pSlotList[i], rv );
}
}
}
}
}
if (
NULL_PTR != pSlotList) free( pSlotList );
printf( "PKCS11 example2: failed C_Finalize %lx", rv );
return -3;
}
return 0;
}