Skip to content

Commit

Permalink
Close #496: PKCS11 access to AWS CloudHSM failed
Browse files Browse the repository at this point in the history
It results in CKR_SLOT_ID_INVALID error.

Use CK_SLOT_ID definition (unsigned long)
consistently. It is 64 bit on Linux.

Especially don't mangle it through an 'int'
in line 226 of lib/pkcs11_lib.cpp
  • Loading branch information
chris2511 committed Feb 29, 2024
1 parent 4b37902 commit 0600970
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
7 changes: 4 additions & 3 deletions lib/pkcs11_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ QList<unsigned long> pkcs11_lib::getSlotList()
{
CK_RV rv;
CK_SLOT_ID *p11_slots = NULL;
QList<unsigned long> sl;
QList<CK_SLOT_ID> sl;
unsigned long i, num_slots = 0;

if (!isLoaded())
return sl;

qDebug() << "sizeof CK_SLOT_ID" << sizeof(CK_SLOT_ID) << sizeof(unsigned long);
/* This one helps to avoid errors.
* Fist time it fails, 2nd time it works */
CALL_P11_C(this, C_GetSlotList, CK_TRUE, p11_slots, &num_slots);
Expand Down Expand Up @@ -221,9 +222,9 @@ slotidList pkcs11_lib_list::getSlotList() const
if (!l->isLoaded())
continue;
try {
QList<unsigned long> realids;
QList<CK_SLOT_ID> realids;
realids = l->getSlotList();
foreach(int id, realids)
for (CK_SLOT_ID id : realids)
list << slotid(l, id);
success = true;
} catch (errorEx &e) {
Expand Down
12 changes: 4 additions & 8 deletions lib/pkcs11_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class pkcs11_lib : public QLibrary
pkcs11_lib() = delete;
~pkcs11_lib();

QList<unsigned long> getSlotList();
QList<CK_SLOT_ID> getSlotList();
QString driverInfo() const;
QString filename() const
{
Expand Down Expand Up @@ -71,15 +71,11 @@ class pkcs11_lib : public QLibrary

class slotid
{
public:
CK_ULONG id;
public:
pkcs11_lib *lib;
CK_SLOT_ID id;
slotid() = default;
slotid(pkcs11_lib *l, CK_ULONG i)
{
lib = l;
id = i;
}
slotid(pkcs11_lib *l, CK_SLOT_ID i) : lib(l), id(i) { }
void isValid() const
{
if (!lib)
Expand Down

0 comments on commit 0600970

Please sign in to comment.