Blame SOURCES/esc-1.1.2-fix7.patch

1d0024
diff -up ./esc/src/app/esc.js.fix7 ./esc/src/app/esc.js
1d0024
--- ./esc/src/app/esc.js.fix7	2020-05-30 18:57:40.423388032 -0700
1d0024
+++ ./esc/src/app/esc.js	2020-05-30 19:01:40.769955310 -0700
1d0024
@@ -30,6 +30,12 @@ const ESC_CONFIG_FILE_NAME = "esc.conf";
1d0024
 const ESC_CONFIG_GROUP = "ESC";
1d0024
 const ESC_PWORD_FILE = "pword";
1d0024
 
1d0024
+const STATUS_ENROLLED="Enrolled";
1d0024
+const STATUS_FORMATTED="Formatted";
1d0024
+const STATUS_UNFORMATTED="Unformatted";
1d0024
+const STATUS_UNKNOWN="Unknown";
1d0024
+const FORMATTED_CODE=2;
1d0024
+
1d0024
 const UNKNOWN_LABEL = "unknown";
1d0024
 const CoolKeyNotifyIface = '<node> \
1d0024
 <interface name="com.jmagne.CoolKeyNotify"> \
1d0024
@@ -185,17 +191,17 @@ class ESC {
1d0024
     _getStatusString(intStatus) {
1d0024
         switch(intStatus) {
1d0024
             case 4:
1d0024
-                return "enrolled";
1d0024
+                return STATUS_ENROLLED;
1d0024
             break;
1d0024
 
1d0024
             case 2:
1d0024
-                return "uninitialized";
1d0024
+                return STATUS_FORMATTED;
1d0024
             break;
1d0024
             case 1:
1d0024
-                return "unknown";
1d0024
+                return STATUS_UNFORMATTED;
1d0024
             break;
1d0024
             default:
1d0024
-                return "unknown";
1d0024
+                return STATUS_UNKNOWN;
1d0024
             break;
1d0024
         }
1d0024
      }
1d0024
@@ -216,14 +222,30 @@ class ESC {
1d0024
              let issuer = inserted.issuer;
1d0024
              let issuedTo = inserted.issued_to;
1d0024
 
1d0024
+             let cachedIssuer = null;
1d0024
+
1d0024
+             if(inserted.is_a_cool_key) {
1d0024
+	         cachedIssuer = this._phoneHomeMgr.getCachedIssuer(aKeyID);
1d0024
+	     }
1d0024
+
1d0024
+	     if(cachedIssuer != null) {
1d0024
+                 issuer = cachedIssuer;
1d0024
+	     }
1d0024
+
1d0024
              if(issuer == null || issuer.length == 0) {
1d0024
-                 issuer = "unknown";
1d0024
+                 issuer = STATUS_UNKNOWN;
1d0024
              }
1d0024
              if(issuedTo == null || issuedTo.length == 0) {
1d0024
-                 issuedTo = "unknown";
1d0024
+                 issuedTo = STATUS_UNKNOWN;
1d0024
              }
1d0024
+             let newStatus = inserted.status;
1d0024
+             
1d0024
+             if(newStatus == FORMATTED_CODE) {
1d0024
+                 issuedTo = STATUS_UNKNOWN;
1d0024
+             }
1d0024
+
1d0024
              this._tokenStore.set (this._tokenStore.append(), [0, 1, 2, 3, 4],
1d0024
-                [issuer, issuedTo, this._getStatusString(inserted.status), aKeyID,aKeyType]);
1d0024
+                [issuer, issuedTo, this._getStatusString(newStatus), aKeyID,aKeyType]);
1d0024
 
1d0024
              let [ isSelected, iter]  = this._tokenStore.get_iter_first();
1d0024
 
1d0024
diff -up ./esc/src/app/opensc.esc.conf.fix7 ./esc/src/app/opensc.esc.conf
1d0024
--- ./esc/src/app/opensc.esc.conf.fix7	2020-05-30 18:54:14.079618060 -0700
1d0024
+++ ./esc/src/app/opensc.esc.conf	2020-05-30 19:02:16.191744158 -0700
1d0024
@@ -89,12 +89,12 @@ app default {
1d0024
     }
1d0024
     reader_driver openct {
1d0024
     };
1d0024
-    card_drivers = coolkey, cac, piv, default;
1d0024
+    card_drivers = coolkey, cac,cac1, piv, default;
1d0024
     secure_messaging local_authentic  {
1d0024
         module_path = /usr/lib64;
1d0024
     }
1d0024
     framework pkcs15 {
1d0024
-        builtin_emulators = coolkey, cac, piv;
1d0024
+        builtin_emulators = coolkey, cac, cac1, piv;
1d0024
     }
1d0024
 }
1d0024
 app opensc-pkcs11 {
1d0024
diff -up ./esc/src/app/operationDialog.js.fix7 ./esc/src/app/operationDialog.js
1d0024
--- ./esc/src/app/operationDialog.js.fix7	2020-05-30 18:54:48.700411683 -0700
1d0024
+++ ./esc/src/app/operationDialog.js	2020-05-30 19:03:01.354474940 -0700
1d0024
@@ -47,34 +47,32 @@ operationDialog.prototype = {
1d0024
         if(tokenInfo == null) {
1d0024
             this.app_alert("Invalid Token!");
1d0024
         }
1d0024
-        this.dialog = new Gtk.Dialog ({ transient_for: this.app._window,
1d0024
-                         modal: true,deletable: false,
1d0024
-                         title: TOKEN_OPERATION, border_width: 10 });
1d0024
 
1d0024
         this.operation = operation;
1d0024
         this.tokenInfo = tokenInfo;
1d0024
 
1d0024
         let opMessage = "";
1d0024
         if(this.operation == OP_FORMAT) {
1d0024
-            opMessage = "Format Smart Card";
1d0024
+            opMessage = "Format Smart Card:";
1d0024
 
1d0024
         } else if(this.operation == OP_ENROLL)  {
1d0024
-            opMessage = "Enroll Smart Card";
1d0024
+            opMessage = "Enroll Smart Card:";
1d0024
         } else if(this.operation == OP_PIN_RESET) {
1d0024
-            opMessage = "Reset Smart Card Pin";
1d0024
+            opMessage = "Reset Smart Card Pin:";
1d0024
         } else {
1d0024
             this.app._alert("operationdDialog: Invalid operation!");
1d0024
             return;
1d0024
         }
1d0024
 
1d0024
+        this.dialog = new Gtk.Dialog ({ transient_for: this.app._window,
1d0024
+                         modal: true,deletable: false,
1d0024
+                         title: TOKEN_OPERATION, border_width: 10 });
1d0024
+
1d0024
         this.area = this.dialog.get_content_area();
1d0024
         this.grid = new Gtk.Grid ({row_spacing: 20, column_spacing: 20});
1d0024
 
1d0024
-        this.message = new Gtk.Label ({label: opMessage});
1d0024
-        this.area.add (this.message);
1d0024
-
1d0024
         //this.throbberImage = new Gtk.Image({file: this.app._currentDir + "/" + "throbber-anim5.gif"});
1d0024
-
1d0024
+        this.label = new Gtk.Label({label: opMessage});
1d0024
         this.progressBar = new Gtk.ProgressBar ({ valign: Gtk.Align.CENTER });
1d0024
         this.progressBar.set_fraction(0.0);
1d0024
 
1d0024
@@ -86,15 +84,16 @@ operationDialog.prototype = {
1d0024
         this.ldapUserLabel = new Gtk.Label({label: "Ldap User:"});
1d0024
         this.ldapUserBox =  new Gtk.Entry();
1d0024
 
1d0024
-        this.grid.attach(this.ldapUserLabel, 0, 0, 1,1);
1d0024
-        this.grid.attach(this.ldapUserBox,1, 0,1,1);
1d0024
+        this.grid.attach(this.label,0,0,1,1);
1d0024
+        this.grid.attach(this.ldapUserLabel, 0, 1, 1,1);
1d0024
+        this.grid.attach(this.ldapUserBox,1, 1,1,1);
1d0024
 
1d0024
         this.ldapPasswordLabel = new Gtk.Label({label: "Ldap Password:"});
1d0024
         this.ldapPasswordBox = new Gtk.Entry();
1d0024
         this.ldapPasswordBox.set_visibility(false);
1d0024
 
1d0024
-        this.grid.attach(this.ldapPasswordLabel,2,0,1,1);
1d0024
-        this.grid.attach(this.ldapPasswordBox,3,0,1,1);
1d0024
+        this.grid.attach(this.ldapPasswordLabel,2,1,1,1);
1d0024
+        this.grid.attach(this.ldapPasswordBox,3,1,1,1);
1d0024
 
1d0024
         if(this.operation !=  OP_FORMAT ) {
1d0024
 
1d0024
@@ -106,10 +105,10 @@ operationDialog.prototype = {
1d0024
             this.confirmPinBox = new Gtk.Entry();
1d0024
             this.confirmPinBox.set_visibility(false);
1d0024
 
1d0024
-            this.grid.attach(this.newpinLabel, 0,1,1,1);
1d0024
-            this.grid.attach(this.newpinBox,1,1,1,1);
1d0024
-            this.grid.attach(this.confirmPinLabel,2,1,1,1);
1d0024
-            this.grid.attach(this.confirmPinBox,3,1,1,1);
1d0024
+            this.grid.attach(this.newpinLabel, 0,2,1,1);
1d0024
+            this.grid.attach(this.newpinBox,1,2,1,1);
1d0024
+            this.grid.attach(this.confirmPinLabel,2,2,1,1);
1d0024
+            this.grid.attach(this.confirmPinBox,3,2,1,1);
1d0024
         }
1d0024
 
1d0024
         this.oKButton = new  Gtk.Button ({label: OpLabels[this.operation]}); 
1d0024
@@ -117,11 +116,11 @@ operationDialog.prototype = {
1d0024
         this.dismissButton = new Gtk.Button({label: "Cancel" });
1d0024
 
1d0024
         //this.grid.attach(this.throbberImage,0,2,1,1);
1d0024
-        this.grid.attach(this.progressLabel, 0,2,1,1);
1d0024
+        this.grid.attach(this.progressLabel, 0,3,1,1);
1d0024
         //this.throbberImage.hide();
1d0024
-        this.grid.attach(this.progressBar, 1,2,1,1);
1d0024
-        this.grid.attach (this.oKButton,2,2,1,1);
1d0024
-        this.grid.attach (this.dismissButton,3,2,1,1);
1d0024
+        this.grid.attach(this.progressBar, 1,3,1,1);
1d0024
+        this.grid.attach (this.oKButton,2,3,1,1);
1d0024
+        this.grid.attach (this.dismissButton,3,3,1,1);
1d0024
 
1d0024
         // Connect the button to the function that handles what it does
1d0024
         this.oKButton.connect ("clicked", this.oKHandler.bind(this));
1d0024
diff -up ./esc/src/app/phoneHome.js.fix7 ./esc/src/app/phoneHome.js
1d0024
--- ./esc/src/app/phoneHome.js.fix7	2020-05-30 18:55:43.223086670 -0700
1d0024
+++ ./esc/src/app/phoneHome.js	2020-05-30 19:03:49.787186230 -0700
1d0024
@@ -93,7 +93,7 @@ phoneHome.prototype = {
1d0024
 
1d0024
         this.phArea = this.phDialog.get_content_area();
1d0024
         this.phMessage = new Gtk.Label ({label: "Enter url: ex: http://test.host.com:8080/tps/phoneHome"});
1d0024
-        this.phArea.add (this.phMessage);
1d0024
+        //this.phArea.add (this.phMessage);
1d0024
 
1d0024
         this.phActionArea = this.phDialog.get_action_area();
1d0024
         this.phUrlBox =  new Gtk.Entry({width_chars: 35});
1d0024
@@ -108,9 +108,9 @@ phoneHome.prototype = {
1d0024
         this.phActionArea.add(this.phGrid);
1d0024
 
1d0024
         this.phOKButton = Gtk.Button.new_from_stock (Gtk.STOCK_OK);
1d0024
-
1d0024
-        this.phGrid.attach(this.phUrlBox, 0, 0, 1,1);
1d0024
-        this.phGrid.attach(this.phOKButton,1, 0,1,1);
1d0024
+        this.phGrid.add(this.phMessage);
1d0024
+        this.phGrid.attach(this.phUrlBox, 0, 1, 1,1);
1d0024
+        this.phGrid.attach(this.phOKButton,1, 1,1,1);
1d0024
 
1d0024
         // Connect the button to the function that handles what it does
1d0024
         this.phOKButton.connect ("clicked", this.phoneHomeOKHandler.bind(this));
1d0024
@@ -228,9 +228,9 @@ phoneHome.prototype = {
1d0024
         if(!aKeyID)
1d0024
             return null;
1d0024
 
1d0024
-        var issuerValue = this.app._configValueWithKeyID(aKeyID,KEY_ISSUER);
1d0024
+        let issuerValue = this.app._configValueWithKeyID(aKeyID,KEY_ISSUER);
1d0024
 
1d0024
-        if(!issuerValue)
1d0024
+        if(issuerValue == null)
1d0024
             return null;
1d0024
 
1d0024
         issuer = this.app._getConfigValue(issuerValue);
1d0024
diff -up ./esc/src/app/pinDialog.js.fix7 ./esc/src/app/pinDialog.js
1d0024
--- ./esc/src/app/pinDialog.js.fix7	2020-05-30 18:55:09.395288320 -0700
1d0024
+++ ./esc/src/app/pinDialog.js	2020-05-30 19:04:51.380819066 -0700
1d0024
@@ -36,16 +36,15 @@ pinDialog.prototype = {
1d0024
     launchPinPrompt: function(notify) {
1d0024
 
1d0024
         this.notify = notify;
1d0024
+        this.message = "Token Pin Entry";
1d0024
         this.dialog = new Gtk.Dialog ({ transient_for: this.app._window,
1d0024
                          modal: true,
1d0024
                          expand: false,
1d0024
-                         title: PIN_OPERATION ,border_width: 20, deletable: false });
1d0024
+                         title: this.message ,border_width: 20, deletable: false });
1d0024
 
1d0024
         this.area = this.dialog.get_content_area();
1d0024
         this.grid = new Gtk.Grid ({row_spacing: 10, column_spacing: 20});
1d0024
 
1d0024
-        this.message = new Gtk.Label ({label: "Enter Token Pin"});
1d0024
-        this.area.add (this.message);
1d0024
 
1d0024
         this.actionArea = this.dialog.get_action_area();
1d0024
         this.pinBox =  new Gtk.Entry();
1d0024
diff -up ./esc/src/lib/coolkey/CoolKey.cpp.fix7 ./esc/src/lib/coolkey/CoolKey.cpp
1d0024
--- ./esc/src/lib/coolkey/CoolKey.cpp.fix7	2020-05-30 18:56:35.827773090 -0700
1d0024
+++ ./esc/src/lib/coolkey/CoolKey.cpp	2020-05-30 19:05:30.561585507 -0700
1d0024
@@ -511,6 +511,11 @@ HRESULT CoolKeyGetCUIDDirectly(char *aBu
1d0024
 
1d0024
     CKYCardConnection_BeginTransaction(conn);
1d0024
 
1d0024
+    status = CKYApplet_SelectCardManager(conn, &apduRC);
1d0024
+    if (status != CKYSUCCESS) {
1d0024
+        goto done;
1d0024
+    }
1d0024
+
1d0024
     status = CKYApplet_GetCUID(conn, &cuid, &apduRC);
1d0024
     if (status != CKYSUCCESS) {
1d0024
         goto done;
1d0024
@@ -764,7 +769,6 @@ HRESULT CoolKeyGetCPLCDataDirectly(CKYAp
1d0024
     }
1d0024
 
1d0024
     CKYCardConnection_BeginTransaction(conn);
1d0024
-    unsigned long state;
1d0024
 
1d0024
     status = CKYApplet_SelectCardManager(conn, &apduRC);
1d0024
     if (status != CKYSUCCESS) {
1d0024
diff -up ./esc/src/lib/coolkey/CoolKeyHandler.cpp.fix7 ./esc/src/lib/coolkey/CoolKeyHandler.cpp
1d0024
--- ./esc/src/lib/coolkey/CoolKeyHandler.cpp.fix7	2020-05-30 18:56:56.511649792 -0700
1d0024
+++ ./esc/src/lib/coolkey/CoolKeyHandler.cpp	2020-05-30 19:06:21.955279145 -0700
1d0024
@@ -2157,11 +2157,22 @@ copySerialNumber(char *dest, const char
1d0024
 // it will probably have Dashes and store in lower case some time in the
1d0024
 // future.
1d0024
 //
1d0024
-static HRESULT
1d0024
+static HRESULT 
1d0024
 getCUIDFromTokenInfo(CK_TOKEN_INFO *tokenInfo, char *tokenSerialNumber)
1d0024
 {
1d0024
+    const int minCUIDLen = 18;
1d0024
+
1d0024
     char *cp = tokenSerialNumber;
1d0024
 
1d0024
+    if( tokenSerialNumber == NULL) {
1d0024
+        return E_FAIL;
1d0024
+    }
1d0024
+
1d0024
+    if(tokenInfo == NULL) {
1d0024
+        *cp = 0;
1d0024
+	return E_FAIL;
1d0024
+    }
1d0024
+
1d0024
     if (isxdigit(tokenInfo->manufacturerID[0]) &&
1d0024
         isxdigit(tokenInfo->manufacturerID[1]) &&
1d0024
         isxdigit(tokenInfo->manufacturerID[2]) &&
1d0024
@@ -2181,6 +2192,10 @@ getCUIDFromTokenInfo(CK_TOKEN_INFO *toke
1d0024
     }
1d0024
     *cp=0;
1d0024
 
1d0024
+    if( strlen(tokenSerialNumber) < minCUIDLen) {
1d0024
+        return E_FAIL;
1d0024
+    }
1d0024
+
1d0024
     return S_OK;
1d0024
 }
1d0024
 
1d0024
@@ -2207,7 +2222,7 @@ CKHGetCoolKeyInfo(PK11SlotInfo *aSlot,Co
1d0024
     CK_TOKEN_INFO tokenInfo;
1d0024
     CoolKeyInfo *info = NULL;
1d0024
     SECStatus status;
1d0024
-    HRESULT hres,atrRes,cuidRes,cycleRes;
1d0024
+    HRESULT hres,atrRes,cycleRes,cuidRes;
1d0024
 
1d0024
     char *readerName =  PK11_GetSlotName(aSlot);
1d0024
 
1d0024
@@ -2327,22 +2342,16 @@ CKHGetCoolKeyInfo(PK11SlotInfo *aSlot,Co
1d0024
       goto failed;
1d0024
     }
1d0024
 
1d0024
-    hres = getCUIDFromTokenInfo(&tokenInfo, info->mCUID);
1d0024
-  /* shouldn't the be != S_SUCCESS? */
1d0024
-    if (hres == E_FAIL) {
1d0024
-        goto failed;
1d0024
-    }
1d0024
-
1d0024
+    cuidRes = getCUIDFromTokenInfo(&tokenInfo, info->mCUID);
1d0024
     //Check for blank cuid and put something there
1d0024
 
1d0024
-     if(isACOOLKey && strlen(info->mCUID) == 0 )
1d0024
-     {
1d0024
+     if(isACOOLKey && cuidRes == E_FAIL) {
1d0024
         //Let's try to get the cuid directly from the token.
1d0024
 
1d0024
         cuidRes = CoolKeyGetCUIDDirectly(cuidChar, 100, readerName);
1d0024
 
1d0024
         if(cuidRes != S_OK) {
1d0024
-           strcpy(info->mCUID, "blank-token");
1d0024
+           strcpy(info->mCUID, "unknown");
1d0024
         } else {
1d0024
            strcpy(info->mCUID, cuidChar);   
1d0024
         }