📄 pkiinit.cpp
字号:
// PKIInit.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "init_header.h"
typedef CK_RV (* C_GETFUNCTIONLISTPROC)(CK_FUNCTION_LIST_PTR_PTR);
typedef CK_RV (* PRIINIT)(CK_SLOT_ID, INIT_TOKEN_PRARM_PTR);
typedef CK_RV (* PKIINIT)(CK_SLOT_ID);
typedef CK_RV (* SetIsSupportSSF33)(CK_BBOOL);
typedef CK_RV (* SetIsSupportSCB2)(CK_BBOOL);
static SetIsSupportSSF33 pSetIsSupportSSF33;
static SetIsSupportSCB2 pSetIsSupportSCB2;
static C_GETFUNCTIONLISTPROC pC_GetFunctionList;
static PRIINIT pPriInit;
static PKIINIT pPkiInit;
static CK_FUNCTION_LIST_PTR ePass = NULL;
HINSTANCE m_hLibP11;
HINSTANCE m_hLibInit;
void ShowMainCmdMenu()
{
printf("\n\nMain Menu:\n");
printf("------------------------------------\n");
printf("Press any key to init the token,or ESC to exit......\n");
printf("\n");
printf("Please select your operation.\n");
}
unsigned long Do_Init()
{
CK_RV ck_rv = 0;
CK_ULONG ulTokenCount = 0;
CK_SLOT_ID_PTR pSlotID = NULL;
INIT_TOKEN_PARAM initParam={0};
DWORD dwPri=0, dwPub=0;
ck_rv = ePass->C_Initialize(NULL_PTR);
if(ck_rv != CKR_OK && ck_rv != CKR_CRYPTOKI_ALREADY_INITIALIZED)
{
printf("C_Initialize Error: %08x", ck_rv);
}
ck_rv = ePass->C_GetSlotList(TRUE, NULL_PTR, &ulTokenCount);
if(ck_rv != CKR_OK)
{
printf("C_GetSlotList 1 Error: %08x", ck_rv);
}
if(ulTokenCount == 0)
{
printf("No Found Slot!");
goto InitClean;
}
pSlotID = new CK_SLOT_ID[ulTokenCount*sizeof(CK_SLOT_ID)];
ck_rv = ePass->C_GetSlotList(TRUE,pSlotID,&ulTokenCount);
if(ck_rv != CKR_OK)
{
printf("C_GetSlotList 2 Error: %08x", ck_rv);
goto InitClean;
}
CK_BBOOL IsSupportSSF33;
/*
if you sure your key support SSF33,
you must set the IsSupportSSF33 = TRUE.
*/
IsSupportSSF33 = false;
char szSSF33[10], szSCB2[10];
printf("Are you sure this key support SSF33?\nY/N:");
scanf("%s", szSSF33);
if( 0 == strcmp("Y", szSSF33) || 0 == strcmp("y", szSSF33))
IsSupportSSF33 = TRUE;
else if( 0 == strcmp("N", szSSF33) || 0 == strcmp("n", szSSF33))
IsSupportSSF33 = FALSE;
else
{
printf("You have input wrong choose about SSF33.");
goto InitClean;
}
ck_rv = pSetIsSupportSSF33(IsSupportSSF33);
if(ck_rv != CKR_OK)
{
printf("pSetIsSupportSSF33 Error: %08x", ck_rv);
goto InitClean;
}
CK_BBOOL IsSupportSCB2;
/*
if you sure your key support SCB2,
you must set the IsSupportSCB2 = TRUE.
*/
IsSupportSCB2 = TRUE;
printf("Are you sure this key support SCB2?\nY/N:");
scanf("%s", szSCB2);
if( 0 == strcmp("Y", szSCB2) || 0 == strcmp("y", szSCB2))
IsSupportSCB2 = TRUE;
else if( 0 == strcmp("N", szSCB2) || 0 == strcmp("n", szSCB2))
IsSupportSCB2 = FALSE;
else
{
printf("You have input wrong choose about SCB2.");
goto InitClean;
}
ck_rv = pSetIsSupportSCB2(IsSupportSCB2);
if(ck_rv != CKR_OK)
{
printf("pSetIsSupportSCB2 Error: %08x", ck_rv);
goto InitClean;
}
if(IsSupportSCB2)
{
initParam.InitType = 3;
initParam.ulPrvSize = 16000;
initParam.ulPubSize = 15000;
initParam.SoPinEC = 6;
initParam.userPinEC = 6;
}
else
{
initParam.InitType = 3;
initParam.ulPrvSize = 16165;
initParam.ulPubSize = 30000;
initParam.SoPinEC = 6;
initParam.userPinEC = 6;
}
ck_rv = pPriInit(pSlotID[0],&initParam);
if(ck_rv != CKR_OK)
{
printf("pPriInit Error: %08x", ck_rv);
goto InitClean;
}
ck_rv = pPkiInit(pSlotID[0]);
if(ck_rv != CKR_OK)
{
printf("pPkiInit Error: %08x", ck_rv);
goto InitClean;
}
printf("Success!\n");
InitClean:
ck_rv = ePass->C_Finalize(NULL_PTR);
if(ck_rv != CKR_OK)
{
printf("C_Initialize Error: %08x", ck_rv);
}
if(pSlotID != NULL)
{
delete [] pSlotID;
pSlotID = NULL;
}
return CKR_OK;
}
int main(int argc, char* argv[])
{
m_hLibP11 = LoadLibrary("ngp11v211.dll");
if(!m_hLibP11)
{
printf("Load ngp11v211.dll Error!");
return FALSE;
}
m_hLibInit = LoadLibrary("..\\..\\..\\..\\..\\lib\\init_fteps3k_hid.dll");
if(!m_hLibInit)
{
printf("Load init_fteps3k_hid.dll Error!");
return FALSE;
}
pC_GetFunctionList = (C_GETFUNCTIONLISTPROC)GetProcAddress(m_hLibP11,"C_GetFunctionList");
pPriInit = (PRIINIT)GetProcAddress(m_hLibInit,"Init_DoPrvInit");
pPkiInit = (PKIINIT)GetProcAddress(m_hLibInit,"Init_DoPKInit");
pSetIsSupportSSF33 = (SetIsSupportSSF33)GetProcAddress(m_hLibInit,"Init_SetIsSupportSSF33");
pSetIsSupportSCB2 = (SetIsSupportSSF33)GetProcAddress(m_hLibInit,"Init_SetIsSupportSCB2");
pC_GetFunctionList(&ePass);
//
while(true)
{
ShowMainCmdMenu();
char ch = getch();
if(ch != 0x1b)
Do_Init();
else
{
if(m_hLibP11)
{
FreeLibrary(m_hLibP11);
m_hLibP11 = NULL;
}
if(m_hLibInit)
{
FreeLibrary(m_hLibInit);
m_hLibInit = NULL;
}
return 0;
}
}
if(m_hLibP11)
FreeLibrary(m_hLibP11);
if(m_hLibInit)
FreeLibrary(m_hLibInit);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -