I face some troubles about PKCS#11 library. I create 2 projects:
- Project 1: macOS Application (GUI - with Objective-C)
- Project 2: Command line tool (Console - with C++)
unsigned long GetTokenInfos(CK_TOKEN_INFO_PTR pTokenInfo)
{
CK_RV rv = CKR_OK;
CK_ULONG ulCount = 0;
CK_SLOT_ID_PTR pSlotList = NULL_PTR;
rv = m_pToken->C_GetSlotList(TRUE, NULL_PTR, &ulCount);
if(rv != CKR_OK){
return rv;
}
if(ulCount <= 0){
return CKR_TOKEN_NOT_PRESENT;
}
pSlotList = (CK_SLOT_ID_PTR)new CK_SLOT_ID [ulCount];
rv = m_pToken->C_GetSlotList(TRUE, pSlotList, &ulCount);
if((rv != CKR_OK) || (ulCount <= 0))
{
delete [] pSlotList;
pSlotList = NULL_PTR;
return CKR_TOKEN_NOT_PRESENT;
}
/*Get slot information for the first token*/
for (unsigned int i = 0; i < ulCount; ++i)
{
rv = m_pToken->C_GetTokenInfo(pSlotList[i], pTokenInfo);
if(rv != CKR_OK)
{
delete [] pSlotList;
pSlotList = NULL_PTR;
return rv;
}
//ShowTokenInfo(pTokenInfo);
}
delete [] pSlotList;
pSlotList = NULL_PTR;
return CKR_OK;
}
Both of them follow the same logic and flow of coding; build and run on a computer. But I got a strange thing: **Project macOS Application always return zero slot with HSM Token presented, on other side, project Command Line Tool always return one slot with token represented. **
I have no idea about the problem. I guess the macOS application project need some permissions or some things like that, in order to interact with hardware like HSM Token/ Smart Card...
Anyone had experience about the situation? Please give me some advice! Thank you all!