Blame SOURCES/esc-1.1.2-fix6.patch

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