Skip to content

Commit 108aafa

Browse files
committed
Fix error path in firmaConCIE
- Make progress bar of the signature more uniform Signed-off-by: Luca Magrone <luca@magrone.cc>
1 parent d9c0c93 commit 108aafa

3 files changed

Lines changed: 158 additions & 0 deletions
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
From 5a32e804c99655dc0c9a8c303e6597fac7014424 Mon Sep 17 00:00:00 2001
2+
From: Luca Magrone <luca@magrone.cc>
3+
Date: Sat, 26 Oct 2024 19:11:40 +0200
4+
Subject: [PATCH] CSP: firmaConCIE: make progress bar more uniform
5+
6+
Divide the progress of the progress bar into 4 chunks. Each one
7+
corresponding to 25% of the total progress.
8+
9+
Signed-off-by: Luca Magrone <luca@magrone.cc>
10+
---
11+
cie-pkcs11/CSP/FirmaConCIE.cpp | 11 +++++++----
12+
1 file changed, 7 insertions(+), 4 deletions(-)
13+
14+
diff --git a/cie-pkcs11/CSP/FirmaConCIE.cpp b/cie-pkcs11/CSP/FirmaConCIE.cpp
15+
index 9f5bf6b..c044c5f 100644
16+
--- a/cie-pkcs11/CSP/FirmaConCIE.cpp
17+
+++ b/cie-pkcs11/CSP/FirmaConCIE.cpp
18+
@@ -71,6 +71,9 @@ CK_RV CK_ENTRY firmaConCIE(const char* inFilePath, const char* type, const char*
19+
20+
char *curreader = readers;
21+
bool foundCIE = false;
22+
+
23+
+ progressCallBack(25, "Looking for CIE...");
24+
+
25+
for (; curreader[0] != 0; curreader += strnlen(curreader, len) + 1)
26+
{
27+
safeConnection conn(hSC, curreader, SCARD_SHARE_SHARED);
28+
@@ -93,8 +96,6 @@ CK_RV CK_ENTRY firmaConCIE(const char* inFilePath, const char* type, const char*
29+
30+
ByteArray atrBa((BYTE*)ATR, atrLen);
31+
32+
- progressCallBack(20, "Getting certificate from CIE...");
33+
-
34+
IAS* ias = new IAS((CToken::TokenTransmitCallback)TokenTransmitCallback, atrBa);
35+
ias->SetCardContext(&conn);
36+
37+
@@ -130,14 +131,16 @@ CK_RV CK_ENTRY firmaConCIE(const char* inFilePath, const char* type, const char*
38+
delete ias;
39+
continue;
40+
}
41+
-
42+
+
43+
+ progressCallBack(50, "Getting certificate from CIE...");
44+
+
45+
ByteDynArray FullPIN;
46+
ByteArray LastPIN = ByteArray((uint8_t*)pin, strlen(pin));
47+
ias->GetFirstPIN(FullPIN);
48+
FullPIN.append(LastPIN);
49+
ias->token.Reset();
50+
51+
- progressCallBack(40, "Starting signature...");
52+
+ progressCallBack(75, "Starting signature...");
53+
54+
char fullPinCStr[9];
55+
memcpy(fullPinCStr, FullPIN.data(), 8);
56+
--
57+
2.43.5
58+
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
}

cie-middleware.spec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Patch15: cie-middleware-improve-graphical-signature.patch
3232
Patch16: cie-middleware-fix-deallocation-mismatch.patch
3333
Patch17: cie-middleware-generate-transparent-signature.patch
3434
Patch18: cie-middleware-ignore-unrecognised-tokens.patch
35+
Patch19: cie-middleware-fix-FirmaConCIE-error-on-multiple-tokens.patch
36+
Patch20: cie-middleware-FirmaConCIE-make-progress-more-uniform.patch
3537

3638
%if 0%{?fedora} < 40 || (0%{?rhel} && 0%{?rhel} < 10)
3739
BuildRequires: maven-local-openjdk11

0 commit comments

Comments
 (0)