Blame SOURCES/esc-1.1.2-fix6.patch

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