#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <memory.h>
int main(int argc,char *argv[])
{
CK_ULONG ulSlotCount = 0;
CK_ULONG i = 0;
int match = 0;
if (
CKR_OK != (rv = C_Initialize( &initArgs ))) {
printf( "PKCS11 example1: failed C_Initialize (error:%x)", (unsigned int) rv );
return -1;
}
{
printf( "PKCS11 example1: 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_InitToken( pSlotList[i], pPin, 8, pLabel ))) {
printf( "PKCS11 example1: slot %d failed to init SO account (error:%x)", (int) pSlotList[i], (unsigned int) rv );
break;
}
if (
CKR_OK != (rv = C_OpenSession( pSlotList[i], flags, NULL, NULL, &hSession ))) {
printf( "PKCS11 example1: slot %ld failed to open a session (error:%lx)", pSlotList[i], rv );
break;
}
{
if (
CKR_OK != (rv = C_InitPIN( hSession, pUserPin, 12 ))) {
printf( "PKCS11 example1: slot %ld failed to initialize user account (error:%lx)", pSlotList[i], rv );
}
if (
CKR_OK != (rv = C_Logout( hSession ))) {
printf( "PKCS11 example1: slot %ld failed to logout of token (error:%lx)", pSlotList[i], rv );
}
}
if (
CKR_OK != (rv = C_CloseSession( hSession ))) {
printf( "PKCS11 example1: slot %ld failed to close an active token session (error:%lx)", pSlotList[i], rv );
break;
}
}
}
}
}
}
if (
NULL_PTR != pSlotList) free( pSlotList );
printf( "PKCS11 example1: failed C_Finalize %lx", rv );
return -3;
}
return 0;
}