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