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