Blame SOURCES/esc-1.1.2-fix6.patch

f477a5
diff -up ./esc/src/app/opensc.esc.conf.fix6 ./esc/src/app/opensc.esc.conf
f477a5
--- ./esc/src/app/opensc.esc.conf.fix6	2019-11-14 18:19:13.343923930 -0800
f477a5
+++ ./esc/src/app/opensc.esc.conf	2019-11-15 11:30:01.967034720 -0800
f477a5
@@ -26,6 +26,11 @@ app default {
f477a5
         # Default: stderr
f477a5
         #
f477a5
     #debug_file = /tmp/opensc.log;
f477a5
+    # sc650 scp01 (older version)
f477a5
+    card_atr
f477a5
+      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 {
f477a5
+                pkcs11_enable_InitToken = yes;
f477a5
+        }
f477a5
 
f477a5
     card_atr
f477a5
       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 {
f477a5
@@ -52,12 +57,31 @@ app default {
f477a5
                 pkcs11_enable_InitToken = yes;
f477a5
     }
f477a5
 
f477a5
+    card_atr
f477a5
+      3B:95:95:40:FF:AE:01:03:00:00 {
f477a5
+                pkcs11_enable_InitToken = yes;
f477a5
+    }
f477a5
+
f477a5
+
f477a5
+   #g&d 6.0 smart cafe scp03
f477a5
 
f477a5
     card_atr
f477a5
       3B:FE:18:00:00:80:31:FE:45:53:43:45:36:30:2D:43:44:30:38:31:2D:6E:46:A9 {
f477a5
                pkcs11_enable_InitToken = yes;
f477a5
     }
f477a5
 
f477a5
+    #g&d 7.0 smart cafe scp03
f477a5
+    card_atr
f477a5
+      3B:F9:96:00:00:80:31:FE:45:53:43:45:37:20:03:00:20:46:42 {
f477a5
+                pkcs11_enable_InitToken = yes;
f477a5
+    }
f477a5
+
f477a5
+    #sc650 scp03
f477a5
+
f477a5
+    card_atr 
f477a5
+      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 {
f477a5
+                pkcs11_enable_InitToken = yes;
f477a5
+    }
f477a5
 
f477a5
     reader_driver ctapi {
f477a5
     }
f477a5
diff -up ./esc/src/lib/coolkey/CoolKey.cpp.fix6 ./esc/src/lib/coolkey/CoolKey.cpp
f477a5
--- ./esc/src/lib/coolkey/CoolKey.cpp.fix6	2019-11-13 18:30:45.454938214 -0800
f477a5
+++ ./esc/src/lib/coolkey/CoolKey.cpp	2019-11-14 18:16:49.078377331 -0800
f477a5
@@ -542,6 +542,67 @@ done:
f477a5
 
f477a5
 
f477a5
 }
f477a5
+/* Return the full reader name since nss can't seem to give us the whole name
f477a5
+ * when the length is longer than 65 chars.
f477a5
+ * Caller has to free the returned string.
f477a5
+ */
f477a5
+char *CoolKeyGetFullReaderName(const char *nssReaderName)
f477a5
+{
f477a5
+    char* fullReaderName = NULL;
f477a5
+    CKYReaderNameList readerNames;
f477a5
+    CKYCardContext *cardCtxt = NULL;
f477a5
+    CKYStatus ret = CKYSCARDERR;
f477a5
+    int readerCount = 0;
f477a5
+    char tBuff[56];
f477a5
+    PR_LOG( coolKeyLog, PR_LOG_DEBUG, ("%s CoolKeyGetFullReaderName entering:\n",GetTStamp(tBuff,56)));
f477a5
+
f477a5
+    if(nssReaderName == NULL) {
f477a5
+       goto done;
f477a5
+    }
f477a5
+
f477a5
+    cardCtxt = CKYCardContext_Create(SCARD_SCOPE_USER);
f477a5
+    if (!cardCtxt) {
f477a5
+         goto done;
f477a5
+    }
f477a5
+
f477a5
+    ret = CKYCardContext_ListReaders(cardCtxt, &readerNames);
f477a5
+    if (ret != CKYSUCCESS) {
f477a5
+         goto done;
f477a5
+    }
f477a5
+
f477a5
+    readerCount = CKYReaderNameList_GetCount(readerNames);
f477a5
+
f477a5
+    /* none found, return success */
f477a5
+    if (readerCount == 0) {
f477a5
+        goto done;
f477a5
+    }
f477a5
+
f477a5
+    /* step through reader list to match to our possible partial reader name from nss. */
f477a5
+    for (int i=0; i < readerCount ; i++) {
f477a5
+        const char *thisReader = CKYReaderNameList_GetValue(readerNames, i);
f477a5
+
f477a5
+        const char *match = strstr(thisReader, nssReaderName );
f477a5
+	if(match == NULL) {
f477a5
+            PR_LOG( coolKeyLog, PR_LOG_DEBUG, ("%s CoolKeyGetFullReaderName reader: %s not the one. \n",thisReader,GetTStamp(tBuff,56)));
f477a5
+
f477a5
+	} else {
f477a5
+            fullReaderName = strdup(thisReader);
f477a5
+            PR_LOG( coolKeyLog, PR_LOG_DEBUG, ("%s CoolKeyGetFullReaderName correct full name:  %s \n",fullReaderName,GetTStamp(tBuff,56)));
f477a5
+        }
f477a5
+    }
f477a5
+
f477a5
+done:
f477a5
+
f477a5
+    if (cardCtxt) {
f477a5
+        CKYCardContext_Destroy(cardCtxt);
f477a5
+    }
f477a5
+
f477a5
+    if(readerNames) {
f477a5
+        CKYReaderNameList_Destroy(readerNames);
f477a5
+    }
f477a5
+    return fullReaderName;
f477a5
+
f477a5
+}
f477a5
 
f477a5
 HRESULT CoolKeyGetATRDirectly(char *aBuff, int aBuffLen,const char *readerName) {
f477a5
 
f477a5
diff -up ./esc/src/lib/coolkey/CoolKeyHandler.cpp.fix6 ./esc/src/lib/coolkey/CoolKeyHandler.cpp
f477a5
--- ./esc/src/lib/coolkey/CoolKeyHandler.cpp.fix6	2019-11-13 18:30:59.934918507 -0800
f477a5
+++ ./esc/src/lib/coolkey/CoolKeyHandler.cpp	2019-11-14 17:16:03.946077277 -0800
f477a5
@@ -2209,10 +2209,10 @@ CKHGetCoolKeyInfo(PK11SlotInfo *aSlot,Co
f477a5
     SECStatus status;
f477a5
     HRESULT hres,atrRes,cuidRes,cycleRes;
f477a5
 
f477a5
-    CKYBuffer cardATR;
f477a5
-    CKYBuffer_InitEmpty(&cardATR);
f477a5
     char *readerName =  PK11_GetSlotName(aSlot);
f477a5
-    
f477a5
+
f477a5
+    char *actualReaderName = CoolKeyGetFullReaderName(readerName);
f477a5
+
f477a5
     memset((void *) &tokenInfo,0,sizeof(tokenInfo));
f477a5
     ATR.data = NULL; // initialize for error processing
f477a5
     label.data = NULL; // initialize for error processing
f477a5
@@ -2233,6 +2233,11 @@ CKHGetCoolKeyInfo(PK11SlotInfo *aSlot,Co
f477a5
     char cuidChar[100];
f477a5
     memset((void*) cuidChar,0 ,sizeof(cuidChar));
f477a5
 
f477a5
+    if(actualReaderName == NULL) {
f477a5
+        goto failed;
f477a5
+    }
f477a5
+
f477a5
+
f477a5
   // get the CUID/Serial number (we *WILL* continue to need it )
f477a5
     status = PK11_GetTokenInfo(aSlot,&tokenInfo);
f477a5
     if (status != SECSuccess) {
f477a5
@@ -2242,7 +2247,7 @@ CKHGetCoolKeyInfo(PK11SlotInfo *aSlot,Co
f477a5
     tokenInfo.flags=0; //Ignore what opensc says, get the info ourselves later.
f477a5
     //Get the life cycle state:
f477a5
 
f477a5
-    cycleRes = CoolKeyGetLifeCycleDirectly(&lifeCycle,readerName);
f477a5
+    cycleRes = CoolKeyGetLifeCycleDirectly(&lifeCycle,actualReaderName);
f477a5
 
f477a5
     if(lifeCycle == 0x7) { // applet only
f477a5
        hasApplet = 1; 
f477a5
@@ -2255,7 +2260,7 @@ CKHGetCoolKeyInfo(PK11SlotInfo *aSlot,Co
f477a5
 
f477a5
     //Let's see if we can get the ATR by force explicitly
f477a5
    
f477a5
-    atrRes = CoolKeyGetATRDirectly(atrChar,100,readerName);
f477a5
+    atrRes = CoolKeyGetATRDirectly(atrChar,100,actualReaderName);
f477a5
 
f477a5
     if(atrRes == E_FAIL) {
f477a5
         goto failed;
f477a5
@@ -2310,7 +2315,7 @@ CKHGetCoolKeyInfo(PK11SlotInfo *aSlot,Co
f477a5
 
f477a5
     info->mInfoFlags = MapGetFlags(&tokenInfo);
f477a5
 
f477a5
-    info->mReaderName = strdup(readerName);
f477a5
+    info->mReaderName = strdup(actualReaderName);
f477a5
 
f477a5
     info->mCUID = (char *)malloc(35); /* should be a define ! */
f477a5
 
f477a5
@@ -2361,6 +2366,9 @@ CKHGetCoolKeyInfo(PK11SlotInfo *aSlot,Co
f477a5
 
f477a5
     SECITEM_FreeItem(&label,PR_FALSE);
f477a5
 
f477a5
+    if(actualReaderName) {
f477a5
+        free(actualReaderName);
f477a5
+    }
f477a5
     info->mSlot = PK11_ReferenceSlot(aSlot);
f477a5
     info->mSeries = PK11_GetSlotSeries(aSlot);
f477a5
     return info;
f477a5
@@ -2372,7 +2380,9 @@ failed:
f477a5
     if (info) {
f477a5
       delete info;
f477a5
     }
f477a5
-
f477a5
-    CKYBuffer_FreeData(&cardATR);
f477a5
+    if (actualReaderName) {
f477a5
+        free(actualReaderName);
f477a5
+    }
f477a5
+    
f477a5
     return NULL;
f477a5
 }
f477a5
diff -up ./esc/src/lib/coolkey/CoolKey.h.fix6 ./esc/src/lib/coolkey/CoolKey.h
f477a5
--- ./esc/src/lib/coolkey/CoolKey.h.fix6	2019-11-13 18:30:37.263949374 -0800
f477a5
+++ ./esc/src/lib/coolkey/CoolKey.h	2019-11-14 17:15:23.216143691 -0800
f477a5
@@ -300,6 +300,7 @@ HRESULT CoolKeyGetATRDirectly(char *aBuf
f477a5
 HRESULT CoolKeyGetCUIDDirectly(char *aBuff, int aBuffLen, const char *readerName);
f477a5
 HRESULT CoolKeyGetCPLCDataDirectly(CKYAppletRespGetCPLCData *cplc,const char *readerName);
f477a5
 HRESULT CoolKeyGetLifeCycleDirectly(CKYByte *personalized,const char *readerName);
f477a5
+char *CoolKeyGetFullReaderName(const char *nssReaderName);
f477a5
 
f477a5
 }
f477a5
 
f477a5
diff -up ./esc/src/lib/coolkey/NSSManager.cpp.fix6 ./esc/src/lib/coolkey/NSSManager.cpp
f477a5
--- ./esc/src/lib/coolkey/NSSManager.cpp.fix6	2019-11-14 17:21:14.596622085 -0800
f477a5
+++ ./esc/src/lib/coolkey/NSSManager.cpp	2019-11-14 18:24:25.461109006 -0800
f477a5
@@ -402,7 +402,8 @@ HRESULT NSSManager::GetKeyIssuer(const C
f477a5
 
f477a5
             if(cert)
f477a5
             {
f477a5
-                if(cert->slot == slot)
f477a5
+                int not_equal = strncmp(PK11_GetSlotName(slot), PK11_GetSlotName(cert->slot),65);
f477a5
+                if(not_equal == 0)
f477a5
                 {
f477a5
                     if(IsCACert(cert))
f477a5
                     {
f477a5
@@ -478,7 +479,8 @@ HRESULT NSSManager::GetKeyUID(const Cool
f477a5
 
f477a5
             if(cert)
f477a5
             {
f477a5
-                if(cert->slot == slot)
f477a5
+                int not_equal = strncmp(PK11_GetSlotName(slot), PK11_GetSlotName(cert->slot),65);
f477a5
+                if(not_equal == 0)
f477a5
                 {
f477a5
                     if(IsCACert(cert))
f477a5
                     {
f477a5
@@ -557,7 +559,8 @@ HRESULT NSSManager::GetKeyIssuedTo(const
f477a5
 
f477a5
             if(cert)
f477a5
             {
f477a5
-                if(cert->slot == slot)
f477a5
+                int not_equal = strncmp(PK11_GetSlotName(slot), PK11_GetSlotName(cert->slot),65);
f477a5
+                if(not_equal == 0)
f477a5
                 {
f477a5
                     if(IsCACert(cert))
f477a5
                     {
f477a5
@@ -643,7 +646,8 @@ HRESULT NSSManager::GetKeyCertInfo(const
f477a5
             CERTCertificate *cert = node->cert;
f477a5
             if(cert)
f477a5
             {
f477a5
-                if(cert->slot == slot)
f477a5
+                int not_equal = strncmp(PK11_GetSlotName(slot), PK11_GetSlotName(cert->slot),65);
f477a5
+                if(not_equal == 0)
f477a5
                 {
f477a5
                     if(!strcmp(cert->nickname,aCertNickname))
f477a5
                     {