|
| 1 | +diff --git a/cie-pkcs11/CSP/FirmaConCIE.cpp b/cie-pkcs11/CSP/FirmaConCIE.cpp |
| 2 | +index 050d282..9f5bf6b 100644 |
| 3 | +--- a/cie-pkcs11/CSP/FirmaConCIE.cpp |
| 4 | ++++ b/cie-pkcs11/CSP/FirmaConCIE.cpp |
| 5 | +@@ -10,6 +10,7 @@ |
| 6 | + #include "../PKCS11/PKCS11Functions.h" |
| 7 | + #include "../PKCS11/Slot.h" |
| 8 | + #include "../Util/ModuleInfo.h" |
| 9 | ++#include "../Util/UtilException.h" |
| 10 | + #include "../PCSC/PCSC.h" |
| 11 | + #include "../Crypto/ASNParser.h" |
| 12 | + #include "../Sign/CIESign.h" |
| 13 | +@@ -34,6 +35,7 @@ CK_RV CK_ENTRY firmaConCIE(const char* inFilePath, const char* type, const char* |
| 14 | + |
| 15 | + char* readers = NULL; |
| 16 | + char* ATR = NULL; |
| 17 | ++ bool panMismatch = false; |
| 18 | + try |
| 19 | + { |
| 20 | + std::map<uint8_t, ByteDynArray> hashSet; |
| 21 | +@@ -96,12 +98,21 @@ CK_RV CK_ENTRY firmaConCIE(const char* inFilePath, const char* type, const char* |
| 22 | + IAS* ias = new IAS((CToken::TokenTransmitCallback)TokenTransmitCallback, atrBa); |
| 23 | + ias->SetCardContext(&conn); |
| 24 | + |
| 25 | +- foundCIE = false; |
| 26 | + ias->token.Reset(); |
| 27 | +- ias->SelectAID_IAS(); |
| 28 | ++ // Continue looking for a CIE if the token is unrecognised |
| 29 | ++ try |
| 30 | ++ { |
| 31 | ++ ias->SelectAID_IAS(); |
| 32 | ++ } |
| 33 | ++ catch(logged_error &err) |
| 34 | ++ { |
| 35 | ++ delete ias; |
| 36 | ++ continue; |
| 37 | ++ } |
| 38 | + ias->ReadPAN(); |
| 39 | + |
| 40 | +- foundCIE = true; |
| 41 | ++ if (!foundCIE) |
| 42 | ++ foundCIE = true; |
| 43 | + ByteDynArray IntAuth; |
| 44 | + ias->SelectAID_CIE(); |
| 45 | + ias->ReadDappPubKey(IntAuth); |
| 46 | +@@ -112,9 +123,12 @@ CK_RV CK_ENTRY firmaConCIE(const char* inFilePath, const char* type, const char* |
| 47 | + ias->ReadIdServizi(IdServizi); |
| 48 | + ByteArray baPan = ByteArray((uint8_t*)pan, strlen(pan)); |
| 49 | + |
| 50 | ++ // Check for pan mismatch and continue search in such case |
| 51 | + if (memcmp(baPan.data(), IdServizi.data(), IdServizi.size()) != 0) |
| 52 | + { |
| 53 | +- return CARD_PAN_MISMATCH; |
| 54 | ++ panMismatch = true; |
| 55 | ++ delete ias; |
| 56 | ++ continue; |
| 57 | + } |
| 58 | + |
| 59 | + ByteDynArray FullPIN; |
| 60 | +@@ -134,9 +148,13 @@ CK_RV CK_ENTRY firmaConCIE(const char* inFilePath, const char* type, const char* |
| 61 | + uint16_t ret = cieSign->sign(inFilePath, type, fullPinCStr, page, x, y, w, h, imagePathFile, outFilePath); |
| 62 | + if((ret & (0x63C0)) == 0x63C0) |
| 63 | + { |
| 64 | ++ delete ias; |
| 65 | ++ delete cieSign; |
| 66 | + return CKR_PIN_INCORRECT; |
| 67 | + }else if (ret == 0x6983) |
| 68 | + { |
| 69 | ++ delete ias; |
| 70 | ++ delete cieSign; |
| 71 | + return CKR_PIN_LOCKED; |
| 72 | + } |
| 73 | + |
| 74 | +@@ -148,7 +166,14 @@ CK_RV CK_ENTRY firmaConCIE(const char* inFilePath, const char* type, const char* |
| 75 | + delete ias; |
| 76 | + delete cieSign; |
| 77 | + |
| 78 | ++ // At this point if there has been a pan mismatch doesn't matter |
| 79 | ++ if (panMismatch) |
| 80 | ++ panMismatch = false; |
| 81 | ++ |
| 82 | + completedCallBack(ret); |
| 83 | ++ |
| 84 | ++ // A this point a CIE has been found, stop looking for it |
| 85 | ++ break; |
| 86 | + } |
| 87 | + |
| 88 | + if (!foundCIE) { |
| 89 | +@@ -174,5 +199,9 @@ CK_RV CK_ENTRY firmaConCIE(const char* inFilePath, const char* type, const char* |
| 90 | + free(ATR); |
| 91 | + |
| 92 | + free(readers); |
| 93 | ++ |
| 94 | ++ if (panMismatch) |
| 95 | ++ return CARD_PAN_MISMATCH; |
| 96 | ++ |
| 97 | + return SCARD_S_SUCCESS; |
| 98 | + } |
0 commit comments