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