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