Skip to content

Commit

Permalink
Correctly use C_GetSlotList() git PKCS#11 2.40
Browse files Browse the repository at this point in the history
Use a double call to C_GetSlotList() so that the module list is
correctly initialized.

Fix "trouble using PyKCS11 with libbeidpkcs11 #73"
#73
  • Loading branch information
LudovicRousseau committed Jul 29, 2020
1 parent faf137e commit 7d83685
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/pkcs11lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,19 @@ CK_RV CPKCS11Lib::C_GetSlotList(

CK_ULONG i;
slotList.clear();
CK_SLOT_ID ck_slotList[1024];
CK_ULONG ulSlotCount = sizeof(ck_slotList)/sizeof(ck_slotList[0]);
rv = m_pFunc->C_GetSlotList(tokenPresent, ck_slotList, &ulSlotCount);
CK_ULONG ulSlotCount;
rv = m_pFunc->C_GetSlotList(tokenPresent, NULL, &ulSlotCount);
if (CKR_OK == rv)
for(i=0; i<ulSlotCount; i++)
slotList.push_back(ck_slotList[i]);
{
CK_SLOT_ID_PTR ck_slotList;
ck_slotList = (CK_SLOT_ID_PTR)malloc(ulSlotCount * sizeof(CK_SLOT_ID));
rv = m_pFunc->C_GetSlotList(tokenPresent, ck_slotList, &ulSlotCount);
if (CKR_OK == rv)
for(i=0; i<ulSlotCount; i++)
slotList.push_back(ck_slotList[i]);

free(ck_slotList);
}

CPKCS11LIB_EPILOGUE;
return rv;
Expand Down

0 comments on commit 7d83685

Please sign in to comment.