📄 enumobjdlg.cpp
字号:
dlg.DoModal();
if("" == g_strUserPIN)
{
ShowMsg(NEWLINE"To enum all objects, you must input User PIN!"NEWLINE);
return;
}
CK_ULONG ulPIN = g_strUserPIN.GetLength();
CK_BYTE_PTR pPIN = (CK_BYTE_PTR)g_strUserPIN.GetBuffer(ulPIN);
::SetCursor(::LoadCursor(NULL, IDC_WAIT));
rv = C_Login(m_hSession, CKU_USER, pPIN, ulPIN);
if(CKR_OK != rv)
{
ShowErr(NEWLINE"Can't login to token, ErrorCode: 0x%08X."NEWLINE, rv);
if(rv==CKR_USER_ALREADY_LOGGED_IN)
ShowErr(NEWLINE"You have already logged in!",NULL);
return;
}
else
ShowMsg(NEWLINE"Login to Token Successfully!"NEWLINE);
m_btnEnum.EnableWindow(TRUE);
m_btnData.EnableWindow(TRUE);
m_btnPublic.EnableWindow(TRUE);
m_btnPrivate.EnableWindow(TRUE);
m_btnSecret.EnableWindow(TRUE);
}
void CEnumObjDlg::OnBtnData()
{
// TODO: Add your control notification handler code here
CK_OBJECT_CLASS dataClass = CKO_DATA;
BOOL IsToken=true;
CK_ATTRIBUTE pTempl[] =
{
{CKA_CLASS, &dataClass, sizeof(CKO_DATA)},
{CKA_TOKEN, &IsToken, sizeof(true)}
};
C_FindObjectsInit(m_hSession, pTempl, 2);
CK_OBJECT_HANDLE hCKObj;
CK_ULONG ulRetCount = 0;
CK_RV ckrv = 0;
int numObj=0;
do
{
ckrv = C_FindObjects(m_hSession, &hCKObj, 1, &ulRetCount);
if(CKR_OK != ckrv)
{
break;
}
if(1 != ulRetCount)
break;
CK_ATTRIBUTE pAttrTemp[] =
{
{CKA_CLASS, NULL, 0},
{CKA_LABEL, NULL, 0},
{CKA_APPLICATION, NULL, 0},
{CKA_VALUE, NULL,0},
};
ckrv = C_GetAttributeValue(m_hSession, hCKObj, pAttrTemp, 4);
if(ckrv != CKR_OK)
{
break;
}
pAttrTemp[0].pValue = new char[pAttrTemp[0].ulValueLen];
pAttrTemp[1].pValue = new char[pAttrTemp[1].ulValueLen + 1];
pAttrTemp[2].pValue = new char[pAttrTemp[2].ulValueLen + 1];
pAttrTemp[3].pValue = new char[pAttrTemp[3].ulValueLen];
ZeroMemory(pAttrTemp[0].pValue, pAttrTemp[0].ulValueLen);
ZeroMemory(pAttrTemp[1].pValue, pAttrTemp[1].ulValueLen + 1);
ZeroMemory(pAttrTemp[2].pValue, pAttrTemp[2].ulValueLen + 1);
ZeroMemory(pAttrTemp[3].pValue, pAttrTemp[3].ulValueLen );
ckrv = C_GetAttributeValue(m_hSession, hCKObj, pAttrTemp, 4);
if(ckrv != CKR_OK)
{
delete[] pAttrTemp[0].pValue;
delete[] pAttrTemp[1].pValue;
delete[] pAttrTemp[2].pValue;
delete[] pAttrTemp[3].pValue;
break;
}
numObj++;
int nClassTemp = *((int*)pAttrTemp[0].pValue);
CString strvale = (char*)pAttrTemp[1].pValue;
CString strApp= (char*)pAttrTemp[2].pValue;
ShowMsg(NEWLINE);
StartOP();
CString strShow;
parse_object(pAttrTemp, 10, strShow);
ShowMsg(strShow);
delete[] pAttrTemp[0].pValue;
delete[] pAttrTemp[1].pValue;
delete[] pAttrTemp[2].pValue;
delete[] pAttrTemp[3].pValue;
}while(true);
if(numObj==0)
{
StartOP();
ShowMsg(NEWLINE"No data object."NEWLINE);
}
else
{
StartOP();
CHAR strNumObj[4];
wsprintf(strNumObj,"%d",numObj);
ShowMsg(NEWLINE);
ShowMsg(strNumObj);
ShowMsg(" data object(s) was found."NEWLINE);
}
}
void CEnumObjDlg::OnBtnPublic()
{
CK_OBJECT_CLASS dataClass = CKO_PUBLIC_KEY;
BOOL IsToken=true;
CK_ATTRIBUTE pTempl[] =
{
{CKA_CLASS, &dataClass, sizeof(CKO_PUBLIC_KEY)},
{CKA_TOKEN, &IsToken, sizeof(true)}
};
C_FindObjectsInit(m_hSession, pTempl, 2);
CK_OBJECT_HANDLE hCKObj;
CK_ULONG ulRetCount = 0;
CK_RV ckrv = 0;
int numObj=0;
do
{
ckrv = C_FindObjects(m_hSession, &hCKObj, 1, &ulRetCount);
if(CKR_OK != ckrv)
{
break;
}
if(1 != ulRetCount)
break;
CK_ATTRIBUTE pAttrTemp[] =
{
{CKA_CLASS, NULL, 0},
{CKA_KEY_TYPE,NULL,0},
{CKA_LABEL, NULL, 0},
{CKA_WRAP,NULL,0},
{CKA_ENCRYPT,NULL,0},
{CKA_MODULUS,NULL,0},
{CKA_PUBLIC_EXPONENT,NULL,0},
};
ckrv = C_GetAttributeValue(m_hSession, hCKObj, pAttrTemp, 7);
if(ckrv != CKR_OK)
{
break;
}
pAttrTemp[0].pValue = new char[pAttrTemp[0].ulValueLen];
pAttrTemp[1].pValue = new char[pAttrTemp[1].ulValueLen];
pAttrTemp[2].pValue = new char[pAttrTemp[2].ulValueLen+1];
pAttrTemp[3].pValue = new char[pAttrTemp[3].ulValueLen];
pAttrTemp[4].pValue = new char[pAttrTemp[4].ulValueLen];
pAttrTemp[5].pValue = new char[pAttrTemp[5].ulValueLen];
pAttrTemp[6].pValue = new char[pAttrTemp[6].ulValueLen];
ZeroMemory(pAttrTemp[0].pValue, pAttrTemp[0].ulValueLen);
ZeroMemory(pAttrTemp[1].pValue, pAttrTemp[1].ulValueLen);
ZeroMemory(pAttrTemp[2].pValue, pAttrTemp[2].ulValueLen+1);
ZeroMemory(pAttrTemp[3].pValue, pAttrTemp[3].ulValueLen);
ZeroMemory(pAttrTemp[4].pValue, pAttrTemp[4].ulValueLen);
ZeroMemory(pAttrTemp[5].pValue, pAttrTemp[5].ulValueLen);
ZeroMemory(pAttrTemp[6].pValue, pAttrTemp[6].ulValueLen);
ckrv = C_GetAttributeValue(m_hSession, hCKObj, pAttrTemp, 7);
if(ckrv != CKR_OK)
{
delete[] pAttrTemp[0].pValue;
delete[] pAttrTemp[1].pValue;
delete[] pAttrTemp[2].pValue;
delete[] pAttrTemp[3].pValue;
delete[] pAttrTemp[4].pValue;
delete[] pAttrTemp[5].pValue;
delete[] pAttrTemp[6].pValue;
break;
}
numObj++;
ShowMsg(NEWLINE);
StartOP();
CString strShow;
parse_object(pAttrTemp, 7, strShow);
ShowMsg(strShow);
delete[] pAttrTemp[0].pValue;
delete[] pAttrTemp[1].pValue;
delete[] pAttrTemp[2].pValue;
delete[] pAttrTemp[3].pValue;
delete[] pAttrTemp[4].pValue;
delete[] pAttrTemp[5].pValue;
delete[] pAttrTemp[6].pValue;
}while(true);
if(numObj==0)
{
StartOP();
ShowMsg(NEWLINE"No public key object."NEWLINE);
}
else
{
StartOP();
CHAR strNumObj[4];
wsprintf(strNumObj,"%d",numObj);
ShowMsg(NEWLINE);
ShowMsg(strNumObj);
ShowMsg(" public key object(s) was found."NEWLINE);
}
}
void CEnumObjDlg::OnBtnPrivate()
{
// TODO: Add your control notification handler code here
CK_OBJECT_CLASS dataClass = CKO_PRIVATE_KEY;
BOOL IsToken=true;
CK_ATTRIBUTE pTempl[] =
{
{CKA_CLASS, &dataClass, sizeof(CKO_PRIVATE_KEY)},
{CKA_TOKEN, &IsToken, sizeof(true)}
};
C_FindObjectsInit(m_hSession, pTempl, 2);
CK_OBJECT_HANDLE hCKObj;
CK_ULONG ulRetCount = 0;
CK_RV ckrv = 0;
int numObj=0;
do
{
ckrv = C_FindObjects(m_hSession, &hCKObj, 1, &ulRetCount);
if(CKR_OK != ckrv)
{
break;
}
if(1 != ulRetCount)
break;
CK_ATTRIBUTE pAttrTemp[] =
{
{CKA_CLASS, NULL, 0},
{CKA_KEY_TYPE,NULL,0},
{CKA_LABEL, NULL, 0},
{CKA_SUBJECT,NULL,0},
{CKA_ID,NULL,0},
{CKA_SENSITIVE,NULL,0},
{CKA_DECRYPT,NULL,0},
{CKA_SIGN,NULL,0},
{CKA_MODULUS,NULL,0},
{CKA_PUBLIC_EXPONENT,NULL,0},
};
ckrv = C_GetAttributeValue(m_hSession, hCKObj, pAttrTemp, 10);
if(ckrv != CKR_OK)
{
break;
}
pAttrTemp[0].pValue = new char[pAttrTemp[0].ulValueLen];
pAttrTemp[1].pValue = new char[pAttrTemp[1].ulValueLen];
pAttrTemp[2].pValue = new char[pAttrTemp[2].ulValueLen+1];
pAttrTemp[3].pValue = new char[pAttrTemp[3].ulValueLen+1];
pAttrTemp[4].pValue = new char[pAttrTemp[4].ulValueLen+1];
pAttrTemp[5].pValue = new char[pAttrTemp[5].ulValueLen];
pAttrTemp[6].pValue = new char[pAttrTemp[6].ulValueLen];
pAttrTemp[7].pValue = new char[pAttrTemp[7].ulValueLen];
pAttrTemp[8].pValue = new char[pAttrTemp[8].ulValueLen];
pAttrTemp[9].pValue = new char[pAttrTemp[9].ulValueLen];
ZeroMemory(pAttrTemp[0].pValue, pAttrTemp[0].ulValueLen);
ZeroMemory(pAttrTemp[1].pValue, pAttrTemp[1].ulValueLen);
ZeroMemory(pAttrTemp[2].pValue, pAttrTemp[2].ulValueLen+1);
ZeroMemory(pAttrTemp[3].pValue, pAttrTemp[3].ulValueLen+1);
ZeroMemory(pAttrTemp[4].pValue, pAttrTemp[4].ulValueLen+1);
ZeroMemory(pAttrTemp[5].pValue, pAttrTemp[5].ulValueLen);
ZeroMemory(pAttrTemp[6].pValue, pAttrTemp[6].ulValueLen);
ZeroMemory(pAttrTemp[7].pValue, pAttrTemp[7].ulValueLen);
ZeroMemory(pAttrTemp[8].pValue, pAttrTemp[8].ulValueLen);
ZeroMemory(pAttrTemp[9].pValue, pAttrTemp[9].ulValueLen);
ckrv = C_GetAttributeValue(m_hSession, hCKObj, pAttrTemp, 10);
if(ckrv != CKR_OK)
{
delete[] pAttrTemp[0].pValue;
delete[] pAttrTemp[1].pValue;
delete[] pAttrTemp[2].pValue;
delete[] pAttrTemp[3].pValue;
delete[] pAttrTemp[4].pValue;
delete[] pAttrTemp[5].pValue;
delete[] pAttrTemp[6].pValue;
delete[] pAttrTemp[7].pValue;
delete[] pAttrTemp[8].pValue;
delete[] pAttrTemp[9].pValue;
break;
}
numObj++;
CString strvale = (char*)pAttrTemp[2].pValue;
CString strsubject=(char*)pAttrTemp[3].pValue;
CString strckaid=(char*)pAttrTemp[4].pValue;
ShowMsg(NEWLINE);
StartOP();
CString strShow;
parse_object(pAttrTemp, 10, strShow);
ShowMsg(strShow);
delete[] pAttrTemp[0].pValue;
delete[] pAttrTemp[1].pValue;
delete[] pAttrTemp[2].pValue;
delete[] pAttrTemp[3].pValue;
delete[] pAttrTemp[4].pValue;
delete[] pAttrTemp[5].pValue;
delete[] pAttrTemp[6].pValue;
delete[] pAttrTemp[7].pValue;
delete[] pAttrTemp[8].pValue;
delete[] pAttrTemp[9].pValue;
}while(true);
if(numObj==0)
{
StartOP();
ShowMsg(NEWLINE"Can's find private key Obj"NEWLINE);
}
else
{
StartOP();
CHAR strNumObj[4];
wsprintf(strNumObj,"%d",numObj);
ShowMsg(NEWLINE);
ShowMsg(strNumObj);
ShowMsg(" private key object(s) was found."NEWLINE);
}
}
void CEnumObjDlg::OnBtnSecret()
{
// TODO: Add your control notification handler code here
CK_OBJECT_CLASS dataClass = CKO_SECRET_KEY;
BOOL IsToken=true;
CK_ATTRIBUTE pTempl[] =
{
{CKA_CLASS, &dataClass, sizeof(CKO_PUBLIC_KEY)},
{CKA_TOKEN, &IsToken, sizeof(true)}
};
C_FindObjectsInit(m_hSession, pTempl, 2);
CK_OBJECT_HANDLE hCKObj;
CK_ULONG ulRetCount = 0;
CK_RV ckrv = 0;
int numObj=0;
do
{
ckrv = C_FindObjects(m_hSession, &hCKObj, 1, &ulRetCount);
if(CKR_OK != ckrv)
{
break;
}
if(1 != ulRetCount)
break;
CK_ATTRIBUTE pAttrTemp[] =
{
{CKA_CLASS, NULL, 0},
{CKA_KEY_TYPE,NULL,0},
{CKA_LABEL, NULL, 0},
{CKA_DERIVE,NULL,0},
{CKA_VALUE,NULL,0},
};
ckrv = C_GetAttributeValue(m_hSession, hCKObj, pAttrTemp, 5);
if(ckrv != CKR_OK)
{
break;
}
pAttrTemp[0].pValue = new char[pAttrTemp[0].ulValueLen];
pAttrTemp[1].pValue = new char[pAttrTemp[1].ulValueLen];
pAttrTemp[2].pValue = new char[pAttrTemp[2].ulValueLen+1];
pAttrTemp[3].pValue = new char[pAttrTemp[3].ulValueLen];
pAttrTemp[4].pValue = new char[pAttrTemp[4].ulValueLen];
ZeroMemory(pAttrTemp[0].pValue, pAttrTemp[0].ulValueLen);
ZeroMemory(pAttrTemp[1].pValue, pAttrTemp[1].ulValueLen);
ZeroMemory(pAttrTemp[2].pValue, pAttrTemp[2].ulValueLen+1);
ZeroMemory(pAttrTemp[3].pValue, pAttrTemp[3].ulValueLen);
ZeroMemory(pAttrTemp[4].pValue, pAttrTemp[4].ulValueLen);
ckrv = C_GetAttributeValue(m_hSession, hCKObj, pAttrTemp, 5);
if(ckrv != CKR_OK)
{
delete[] pAttrTemp[0].pValue;
delete[] pAttrTemp[1].pValue;
delete[] pAttrTemp[2].pValue;
delete[] pAttrTemp[3].pValue;
delete[] pAttrTemp[4].pValue;
break;
}
numObj++;
ShowMsg(NEWLINE);
StartOP();
CString strShow;
parse_object(pAttrTemp, 5, strShow);
ShowMsg(strShow);
delete[] pAttrTemp[0].pValue;
delete[] pAttrTemp[1].pValue;
delete[] pAttrTemp[2].pValue;
delete[] pAttrTemp[3].pValue;
delete[] pAttrTemp[4].pValue;
}while(true);
if(numObj==0)
{
StartOP();
ShowMsg(NEWLINE"No secret key."NEWLINE);
}
else
{
StartOP();
CHAR strNumObj[4];
wsprintf(strNumObj,"%d",numObj);
ShowMsg(NEWLINE);
ShowMsg(strNumObj);
ShowMsg(" secret key object(s) was found."NEWLINE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -