From 06009705bb4348e99b646b809584f0634d46ca88 Mon Sep 17 00:00:00 2001 From: Christian Hohnstaedt Date: Thu, 29 Feb 2024 16:42:32 +0100 Subject: [PATCH] Close #496: PKCS11 access to AWS CloudHSM failed 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 --- lib/pkcs11_lib.cpp | 7 ++++--- lib/pkcs11_lib.h | 12 ++++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/pkcs11_lib.cpp b/lib/pkcs11_lib.cpp index 23ec7b71..6d5fbc90 100644 --- a/lib/pkcs11_lib.cpp +++ b/lib/pkcs11_lib.cpp @@ -77,12 +77,13 @@ QList pkcs11_lib::getSlotList() { CK_RV rv; CK_SLOT_ID *p11_slots = NULL; - QList sl; + QList 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); @@ -221,9 +222,9 @@ slotidList pkcs11_lib_list::getSlotList() const if (!l->isLoaded()) continue; try { - QList realids; + QList realids; realids = l->getSlotList(); - foreach(int id, realids) + for (CK_SLOT_ID id : realids) list << slotid(l, id); success = true; } catch (errorEx &e) { diff --git a/lib/pkcs11_lib.h b/lib/pkcs11_lib.h index 7d341cb5..fac645ec 100644 --- a/lib/pkcs11_lib.h +++ b/lib/pkcs11_lib.h @@ -31,7 +31,7 @@ class pkcs11_lib : public QLibrary pkcs11_lib() = delete; ~pkcs11_lib(); - QList getSlotList(); + QList getSlotList(); QString driverInfo() const; QString filename() const { @@ -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)