#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 example6: failed C_Initialize (error:%lx)", rv );
return -1;
}
{
printf( "PKCS11 example6: memory allocation failed" );
return -2;
}
if (
CKR_OK == (rv = C_GetSlotList(
CK_FALSE, pSlotList, &ulSlotCount )))
{
for( i=0; i < ulSlotCount; i++ )
{
match = -1;
match = strncmp( (
const char*)oneSlot.
slotDescription, (
const char*)
"TCP:3001@10.123.123.6 - SLOT_0001 ", 64 );
if (0 == match)
{
if (
CKR_OK == (rv = C_OpenSession( pSlotList[i], flags, NULL, NULL, &hSession )))
{
pADMIN = (
CK_UTF8CHAR_PTR)
"ADMIN,E:\\Utimaco\\SafeGuardCryptoServer\\Administration\\ADMIN.key";
ulPinLen = (
CK_ULONG)strlen((
const char*) pADMIN );
{
if (
CKR_OK != (rv = C_InitToken( pSlotList[i], pSOPin, 6, pLabel ))) {
printf( "PKCS11 example6: slot %ld C_InitToken failed (error:%lx)", pSlotList[i], rv );
}
if (
CKR_OK != (rv = C_Logout( hSession ))) {
printf( "PKCS11 example6: slot %ld C_Logout failed (error:%lx)", pSlotList[i], rv );
}
}
if (
CKR_OK == (rv = C_Login( hSession,
CKU_SO, pSOPin, 6 )))
{
if (
CKR_OK != (rv = C_InitPIN( hSession, pUserPin, 12 ))) {
printf( "PKCS11 example6: slot %ld C_InitPIN for a new user failed (error:%lx)", pSlotList[i], rv );
}
if (
CKR_OK == (rv = C_Logout( hSession )))
{
if (
CKR_OK != (rv = C_SetPIN( hSession, pUserPin, 12, pNewPin, 10 ))) {
printf( "PKCS11 example6: slot %ld C_SetPIN for a new user failed (error:%lx)", pSlotList[i], rv );
}
}
}
{
match = -1;
match = strncmp( (
const char*)oneToken.
label, (
const char*)
"01234567890123456789012345678901", 32 );
if (0 != match) printf(
"PKCS11 example6: slot %ld, token label mismatch [%s]", pSlotList[i], (
const char*)oneToken.
label );
match = -1;
match = strncmp( (
const char*)oneToken.
serialNumber, (
const char*)
"UTIMACO CS000000", 16 );
if (0 != match) printf(
"PKCS11 example6: slot %ld, token serial number mismatch [%s]", pSlotList[i], (
const char*)oneToken.
serialNumber );
match = -1;
match = strncmp( (
const char*)oneToken.
model, (
const char*)
"CryptoServer ", 16 );
if (0 != match) printf(
"PKCS11 example6: slot %ld, token model mismatch [%s]", pSlotList[i], (
const char*)oneToken.
model );
match = -1;
match = strncmp( (
const char*)oneToken.
manufacturerID, (
const char*)
"Utimaco IS GmbH ", 32 );
if (0 != match) printf(
"PKCS11 example6: slot %ld, token manufacturer Id mismatch [%s]", pSlotList[i], (
const char*)oneToken.
manufacturerID );
printf(
"PKCS11 example6: slot %ld, token flags mismatch [%d]", pSlotList[i], (
int)oneToken.
flags );
}
printf(
"PKCS11 example6: slot %ld, token max session count mismatch [%ld]", pSlotList[i], oneToken.
ulMaxSessionCount );
}
printf(
"PKCS11 example6: slot %ld, token session count mismatch [%ld]", pSlotList[i], oneToken.
ulSessionCount );
}
printf(
"PKCS11 example6: slot %ld, token max RW session count mismatch [%ld]", pSlotList[i], oneToken.
ulMaxRwSessionCount );
}
printf(
"PKCS11 example6: slot %ld, token RW session count mismatch [%ld]", pSlotList[i], oneToken.
ulRwSessionCount );
}
printf(
"PKCS11 example6: slot %ld, token max PIN length mismatch [%ld]", pSlotList[i], oneToken.
ulMaxPinLen );
}
printf(
"PKCS11 example6: slot %ld, token min PIN length mismatch [%ld]", pSlotList[i], oneToken.
ulMinPinLen );
}
}
if (
CKR_OK != (rv = C_CloseSession( hSession ))) {
printf( "PKCS11 example6: failed C_CloseSession %lx", rv );
}
}
}
}
}
}
if (
NULL_PTR != pSlotList) free( pSlotList );
printf( "PKCS11 example6: failed C_Finalize %lx", rv );
return -3;
}
return 0;
}