Blame SOURCES/esc-1.1.2-fix7.patch

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