|
| 1 | +From 0aa6d8653f60c4ed418f7e20bafbeea778666474 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Luca Magrone <luca@magrone.cc> |
| 3 | +Date: Fri, 25 Oct 2024 21:20:51 +0200 |
| 4 | +Subject: [PATCH] cie-pkcs11: hack: Do not report slots that have a non-CIE |
| 5 | + token present |
| 6 | + |
| 7 | +Ignore slots with unrecognised tokens since the library can only |
| 8 | +interface with CIE token anyway. |
| 9 | +Don't log errors about unrecognised tokens because are ignored. |
| 10 | + |
| 11 | +Signed-off-by: Luca Magrone <luca@magrone.cc> |
| 12 | +--- |
| 13 | + cie-pkcs11/PKCS11/PKCS11Functions.cpp | 17 +++++++++++------ |
| 14 | + cie-pkcs11/PKCS11/Slot.cpp | 17 +++++++++++++++++ |
| 15 | + cie-pkcs11/PKCS11/Slot.h | 1 + |
| 16 | + 3 files changed, 29 insertions(+), 6 deletions(-) |
| 17 | + |
| 18 | +diff --git a/cie-pkcs11/PKCS11/PKCS11Functions.cpp b/cie-pkcs11/PKCS11/PKCS11Functions.cpp |
| 19 | +index 93eef49..aa7d43f 100755 |
| 20 | +--- a/cie-pkcs11/PKCS11/PKCS11Functions.cpp |
| 21 | ++++ b/cie-pkcs11/PKCS11/PKCS11Functions.cpp |
| 22 | +@@ -276,7 +276,7 @@ CK_RV CK_ENTRY C_GetSlotList(CK_BBOOL tokenPresent, CK_SLOT_ID_PTR pSlotList, CK |
| 23 | + it--; |
| 24 | + std::shared_ptr<CSlot> pSlot=it->second; |
| 25 | + |
| 26 | +- if (pSlot->IsTokenPresent()) { |
| 27 | ++ if (pSlot->IsTokenPresent() && pSlot->IsTokenRecognised()) { |
| 28 | + if (pSlotList) { |
| 29 | + if (iCnt<*pulCount) |
| 30 | + pSlotList[iCnt]=pSlot->hSlot; |
| 31 | +@@ -299,11 +299,16 @@ CK_RV CK_ENTRY C_GetSlotList(CK_BBOOL tokenPresent, CK_SLOT_ID_PTR pSlotList, CK |
| 32 | + while (it!=CSlot::g_mSlots.begin()) |
| 33 | + { |
| 34 | + it--; |
| 35 | +- if (iCnt<*pulCount) |
| 36 | +- pSlotList[iCnt]=it->first; |
| 37 | +- else |
| 38 | +- bOver=true; |
| 39 | +- iCnt++; |
| 40 | ++ std::shared_ptr<CSlot> pSlot=it->second; |
| 41 | ++ |
| 42 | ++ if (!pSlot->IsTokenPresent() || pSlot->IsTokenRecognised()) |
| 43 | ++ { |
| 44 | ++ if (iCnt<*pulCount) |
| 45 | ++ pSlotList[iCnt]=it->first; |
| 46 | ++ else |
| 47 | ++ bOver=true; |
| 48 | ++ iCnt++; |
| 49 | ++ } |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | +diff --git a/cie-pkcs11/PKCS11/Slot.cpp b/cie-pkcs11/PKCS11/Slot.cpp |
| 54 | +index 107ba8a..339dd7f 100755 |
| 55 | +--- a/cie-pkcs11/PKCS11/Slot.cpp |
| 56 | ++++ b/cie-pkcs11/PKCS11/Slot.cpp |
| 57 | +@@ -362,6 +362,23 @@ namespace p11 { |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | ++ bool CSlot::IsTokenRecognised() |
| 62 | ++ { |
| 63 | ++ init_func |
| 64 | ++ |
| 65 | ++ if (pTemplate == nullptr) |
| 66 | ++ pTemplate = CCardTemplate::GetTemplate(*this); |
| 67 | ++ |
| 68 | ++ if (pTemplate == nullptr) |
| 69 | ++ return false; |
| 70 | ++ |
| 71 | ++ std::vector<uint8_t> atr_vector(baATR.data(), baATR.data() + baATR.size()); |
| 72 | ++ if (get_type(atr_vector) == CIE_Type::CIE_Unknown) |
| 73 | ++ return false; |
| 74 | ++ |
| 75 | ++ return true; |
| 76 | ++ } |
| 77 | ++ |
| 78 | + void CSlot::GetInfo(CK_SLOT_INFO_PTR pInfo) |
| 79 | + { |
| 80 | + init_func |
| 81 | +diff --git a/cie-pkcs11/PKCS11/Slot.h b/cie-pkcs11/PKCS11/Slot.h |
| 82 | +index 60ec96a..3b279f9 100755 |
| 83 | +--- a/cie-pkcs11/PKCS11/Slot.h |
| 84 | ++++ b/cie-pkcs11/PKCS11/Slot.h |
| 85 | +@@ -96,6 +96,7 @@ public: |
| 86 | + void DelP11Object(const std::shared_ptr<CP11Object>& pObject); |
| 87 | + void ClearP11Objects(); |
| 88 | + bool IsTokenPresent(); |
| 89 | ++ bool IsTokenRecognised(); |
| 90 | + |
| 91 | + P11ObjectVector P11Objects; // vettore degli oggetti |
| 92 | + |
| 93 | +-- |
| 94 | +2.43.5 |
| 95 | + |
0 commit comments