1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
diff -up ./esc/src/app/opensc.esc.conf.fix6 ./esc/src/app/opensc.esc.conf
--- ./esc/src/app/opensc.esc.conf.fix6 2019-11-14 18:19:13.343923930 -0800
+++ ./esc/src/app/opensc.esc.conf 2019-11-15 11:30:01.967034720 -0800
@@ -26,6 +26,11 @@ app default {
# Default: stderr
#
#debug_file = /tmp/opensc.log;
+ # sc650 scp01 (older version)
+ card_atr
+ 3B:FF:14:00:FF:81:31:FE:45:80:25:A0:00:00:00:56:57:53:43:36:35:30:03:02:39 {
+ pkcs11_enable_InitToken = yes;
+ }
card_atr
3B:FF:14:00:FF:81:31:FE:45:80:25:A0:00:00:00:56:57:53:43:36:35:30:03:03:38 {
@@ -52,12 +57,31 @@ app default {
pkcs11_enable_InitToken = yes;
}
+ card_atr
+ 3B:95:95:40:FF:AE:01:03:00:00 {
+ pkcs11_enable_InitToken = yes;
+ }
+
+
+ #g&d 6.0 smart cafe scp03
card_atr
3B:FE:18:00:00:80:31:FE:45:53:43:45:36:30:2D:43:44:30:38:31:2D:6E:46:A9 {
pkcs11_enable_InitToken = yes;
}
+ #g&d 7.0 smart cafe scp03
+ card_atr
+ 3B:F9:96:00:00:80:31:FE:45:53:43:45:37:20:03:00:20:46:42 {
+ pkcs11_enable_InitToken = yes;
+ }
+
+ #sc650 scp03
+
+ card_atr
+ 3B:FF:14:00:FF:81:31:FE:45:80:25:A0:00:00:00:56:57:53:43:36:35:30:04:02:3E {
+ pkcs11_enable_InitToken = yes;
+ }
reader_driver ctapi {
}
diff -up ./esc/src/lib/coolkey/CoolKey.cpp.fix6 ./esc/src/lib/coolkey/CoolKey.cpp
--- ./esc/src/lib/coolkey/CoolKey.cpp.fix6 2019-11-13 18:30:45.454938214 -0800
+++ ./esc/src/lib/coolkey/CoolKey.cpp 2019-11-14 18:16:49.078377331 -0800
@@ -542,6 +542,67 @@ done:
}
+/* Return the full reader name since nss can't seem to give us the whole name
+ * when the length is longer than 65 chars.
+ * Caller has to free the returned string.
+ */
+char *CoolKeyGetFullReaderName(const char *nssReaderName)
+{
+ char* fullReaderName = NULL;
+ CKYReaderNameList readerNames;
+ CKYCardContext *cardCtxt = NULL;
+ CKYStatus ret = CKYSCARDERR;
+ int readerCount = 0;
+ char tBuff[56];
+ PR_LOG( coolKeyLog, PR_LOG_DEBUG, ("%s CoolKeyGetFullReaderName entering:\n",GetTStamp(tBuff,56)));
+
+ if(nssReaderName == NULL) {
+ goto done;
+ }
+
+ cardCtxt = CKYCardContext_Create(SCARD_SCOPE_USER);
+ if (!cardCtxt) {
+ goto done;
+ }
+
+ ret = CKYCardContext_ListReaders(cardCtxt, &readerNames);
+ if (ret != CKYSUCCESS) {
+ goto done;
+ }
+
+ readerCount = CKYReaderNameList_GetCount(readerNames);
+
+ /* none found, return success */
+ if (readerCount == 0) {
+ goto done;
+ }
+
+ /* step through reader list to match to our possible partial reader name from nss. */
+ for (int i=0; i < readerCount ; i++) {
+ const char *thisReader = CKYReaderNameList_GetValue(readerNames, i);
+
+ const char *match = strstr(thisReader, nssReaderName );
+ if(match == NULL) {
+ PR_LOG( coolKeyLog, PR_LOG_DEBUG, ("%s CoolKeyGetFullReaderName reader: %s not the one. \n",thisReader,GetTStamp(tBuff,56)));
+
+ } else {
+ fullReaderName = strdup(thisReader);
+ PR_LOG( coolKeyLog, PR_LOG_DEBUG, ("%s CoolKeyGetFullReaderName correct full name: %s \n",fullReaderName,GetTStamp(tBuff,56)));
+ }
+ }
+
+done:
+
+ if (cardCtxt) {
+ CKYCardContext_Destroy(cardCtxt);
+ }
+
+ if(readerNames) {
+ CKYReaderNameList_Destroy(readerNames);
+ }
+ return fullReaderName;
+
+}
HRESULT CoolKeyGetATRDirectly(char *aBuff, int aBuffLen,const char *readerName) {
diff -up ./esc/src/lib/coolkey/CoolKeyHandler.cpp.fix6 ./esc/src/lib/coolkey/CoolKeyHandler.cpp
--- ./esc/src/lib/coolkey/CoolKeyHandler.cpp.fix6 2019-11-13 18:30:59.934918507 -0800
+++ ./esc/src/lib/coolkey/CoolKeyHandler.cpp 2019-11-14 17:16:03.946077277 -0800
@@ -2209,10 +2209,10 @@ CKHGetCoolKeyInfo(PK11SlotInfo *aSlot,Co
SECStatus status;
HRESULT hres,atrRes,cuidRes,cycleRes;
- CKYBuffer cardATR;
- CKYBuffer_InitEmpty(&cardATR);
char *readerName = PK11_GetSlotName(aSlot);
-
+
+ char *actualReaderName = CoolKeyGetFullReaderName(readerName);
+
memset((void *) &tokenInfo,0,sizeof(tokenInfo));
ATR.data = NULL; // initialize for error processing
label.data = NULL; // initialize for error processing
@@ -2233,6 +2233,11 @@ CKHGetCoolKeyInfo(PK11SlotInfo *aSlot,Co
char cuidChar[100];
memset((void*) cuidChar,0 ,sizeof(cuidChar));
+ if(actualReaderName == NULL) {
+ goto failed;
+ }
+
+
// get the CUID/Serial number (we *WILL* continue to need it )
status = PK11_GetTokenInfo(aSlot,&tokenInfo);
if (status != SECSuccess) {
@@ -2242,7 +2247,7 @@ CKHGetCoolKeyInfo(PK11SlotInfo *aSlot,Co
tokenInfo.flags=0; //Ignore what opensc says, get the info ourselves later.
//Get the life cycle state:
- cycleRes = CoolKeyGetLifeCycleDirectly(&lifeCycle,readerName);
+ cycleRes = CoolKeyGetLifeCycleDirectly(&lifeCycle,actualReaderName);
if(lifeCycle == 0x7) { // applet only
hasApplet = 1;
@@ -2255,7 +2260,7 @@ CKHGetCoolKeyInfo(PK11SlotInfo *aSlot,Co
//Let's see if we can get the ATR by force explicitly
- atrRes = CoolKeyGetATRDirectly(atrChar,100,readerName);
+ atrRes = CoolKeyGetATRDirectly(atrChar,100,actualReaderName);
if(atrRes == E_FAIL) {
goto failed;
@@ -2310,7 +2315,7 @@ CKHGetCoolKeyInfo(PK11SlotInfo *aSlot,Co
info->mInfoFlags = MapGetFlags(&tokenInfo);
- info->mReaderName = strdup(readerName);
+ info->mReaderName = strdup(actualReaderName);
info->mCUID = (char *)malloc(35); /* should be a define ! */
@@ -2361,6 +2366,9 @@ CKHGetCoolKeyInfo(PK11SlotInfo *aSlot,Co
SECITEM_FreeItem(&label,PR_FALSE);
+ if(actualReaderName) {
+ free(actualReaderName);
+ }
info->mSlot = PK11_ReferenceSlot(aSlot);
info->mSeries = PK11_GetSlotSeries(aSlot);
return info;
@@ -2372,7 +2380,9 @@ failed:
if (info) {
delete info;
}
-
- CKYBuffer_FreeData(&cardATR);
+ if (actualReaderName) {
+ free(actualReaderName);
+ }
+
return NULL;
}
diff -up ./esc/src/lib/coolkey/CoolKey.h.fix6 ./esc/src/lib/coolkey/CoolKey.h
--- ./esc/src/lib/coolkey/CoolKey.h.fix6 2019-11-13 18:30:37.263949374 -0800
+++ ./esc/src/lib/coolkey/CoolKey.h 2019-11-14 17:15:23.216143691 -0800
@@ -300,6 +300,7 @@ HRESULT CoolKeyGetATRDirectly(char *aBuf
HRESULT CoolKeyGetCUIDDirectly(char *aBuff, int aBuffLen, const char *readerName);
HRESULT CoolKeyGetCPLCDataDirectly(CKYAppletRespGetCPLCData *cplc,const char *readerName);
HRESULT CoolKeyGetLifeCycleDirectly(CKYByte *personalized,const char *readerName);
+char *CoolKeyGetFullReaderName(const char *nssReaderName);
}
diff -up ./esc/src/lib/coolkey/NSSManager.cpp.fix6 ./esc/src/lib/coolkey/NSSManager.cpp
--- ./esc/src/lib/coolkey/NSSManager.cpp.fix6 2019-11-14 17:21:14.596622085 -0800
+++ ./esc/src/lib/coolkey/NSSManager.cpp 2019-11-14 18:24:25.461109006 -0800
@@ -402,7 +402,8 @@ HRESULT NSSManager::GetKeyIssuer(const C
if(cert)
{
- if(cert->slot == slot)
+ int not_equal = strncmp(PK11_GetSlotName(slot), PK11_GetSlotName(cert->slot),65);
+ if(not_equal == 0)
{
if(IsCACert(cert))
{
@@ -478,7 +479,8 @@ HRESULT NSSManager::GetKeyUID(const Cool
if(cert)
{
- if(cert->slot == slot)
+ int not_equal = strncmp(PK11_GetSlotName(slot), PK11_GetSlotName(cert->slot),65);
+ if(not_equal == 0)
{
if(IsCACert(cert))
{
@@ -557,7 +559,8 @@ HRESULT NSSManager::GetKeyIssuedTo(const
if(cert)
{
- if(cert->slot == slot)
+ int not_equal = strncmp(PK11_GetSlotName(slot), PK11_GetSlotName(cert->slot),65);
+ if(not_equal == 0)
{
if(IsCACert(cert))
{
@@ -643,7 +646,8 @@ HRESULT NSSManager::GetKeyCertInfo(const
CERTCertificate *cert = node->cert;
if(cert)
{
- if(cert->slot == slot)
+ int not_equal = strncmp(PK11_GetSlotName(slot), PK11_GetSlotName(cert->slot),65);
+ if(not_equal == 0)
{
if(!strcmp(cert->nickname,aCertNickname))
{
|