9b58a7
diff -up ./esc/src/app/esc.js.fix4 ./esc/src/app/esc.js
9b58a7
--- ./esc/src/app/esc.js.fix4	2019-01-10 16:19:14.676953557 -0800
9b58a7
+++ ./esc/src/app/esc.js	2019-01-10 16:19:22.530914751 -0800
9b58a7
@@ -23,7 +23,14 @@ const Gio = imports.gi.Gio;
9b58a7
 const GObject = imports.gi.GObject;
9b58a7
 const Pango = imports.gi.Pango;
9b58a7
 const GLib = imports.gi.GLib;
9b58a7
+const PhoneHome = imports.phoneHome;
9b58a7
+const OperationDialog = imports.operationDialog;
9b58a7
+const PinDialog = imports.pinDialog;
9b58a7
+const ESC_CONFIG_FILE_NAME = "esc.conf";
9b58a7
+const ESC_CONFIG_GROUP = "ESC";
9b58a7
+const ESC_PWORD_FILE = "pword";
9b58a7
 
9b58a7
+const UNKNOWN_LABEL = "unknown";
9b58a7
 const CoolKeyNotifyIface = '<node> \
9b58a7
 <interface name="com.jmagne.CoolKeyNotify"> \
9b58a7
 <method name="notifyCoolKeyEvent"> \
9b58a7
@@ -36,6 +43,25 @@ const CoolKeyNotifyIface = '<node> \
9b58a7
 </interface> \
9b58a7
 </node>';
9b58a7
 
9b58a7
+
9b58a7
+// Get application folder and add it into the imports path
9b58a7
+function getAppFileInfo() {
9b58a7
+    let stack = (new Error()).stack,
9b58a7
+        stackLine = stack.split('\n')[1],
9b58a7
+        coincidence, path, file;
9b58a7
+
9b58a7
+    if (!stackLine) throw new Error('Can not find path!');
9b58a7
+
9b58a7
+    coincidence = new RegExp('@(.+):\\d+').exec(stackLine);
9b58a7
+    if (!coincidence) throw new Error('Could not find current file!');
9b58a7
+
9b58a7
+    path = coincidence[1];
9b58a7
+    file = Gio.File.new_for_path(path);
9b58a7
+    return [file.get_path(), file.get_parent().get_path(), file.get_basename()];
9b58a7
+}
9b58a7
+const path = getAppFileInfo()[1];
9b58a7
+
9b58a7
+
9b58a7
 const CoolKeyNotify = new Lang.Class({
9b58a7
     Name: 'CoolKeyNotify',
9b58a7
 
9b58a7
@@ -73,8 +99,20 @@ class ESC {
9b58a7
         this.application = new Gtk.Application();
9b58a7
         this.application.connect('activate', this._onActivate.bind(this));
9b58a7
         this.application.connect('startup', this._onStartup.bind(this));
9b58a7
+        this._selectedTokenInfo = null;
9b58a7
+        this._notifyCallback = null;
9b58a7
+        this._currentDir = path;
9b58a7
     }
9b58a7
 
9b58a7
+    _setNotifyCallback(cb) {
9b58a7
+        this._notifyCallback = cb;
9b58a7
+
9b58a7
+    }
9b58a7
+
9b58a7
+    _clearNotifyCallback() {
9b58a7
+        this._notifyCallback = null;
9b58a7
+     }
9b58a7
+
9b58a7
     _onActivate() {
9b58a7
         this._window.present();
9b58a7
     }
9b58a7
@@ -94,6 +132,28 @@ class ESC {
9b58a7
          }
9b58a7
      }
9b58a7
 
9b58a7
+   _onCertDetail() {
9b58a7
+       this._promptPin();
9b58a7
+    }
9b58a7
+
9b58a7
+   _onFormat() {
9b58a7
+        this._operationMgr = new OperationDialog.operationDialog(this);
9b58a7
+        this._operationMgr.launchOperation(this._selectedTokenInfo,OperationDialog.OP_FORMAT);
9b58a7
+    }
9b58a7
+
9b58a7
+    _onEnroll() {
9b58a7
+        this._operationMgr = new OperationDialog.operationDialog(this);
9b58a7
+        this._operationMgr.launchOperation(this._selectedTokenInfo,OperationDialog.OP_ENROLL);
9b58a7
+    }
9b58a7
+
9b58a7
+    _onResetPin() {
9b58a7
+       this._operationMgr = new OperationDialog.operationDialog(this);
9b58a7
+       this._operationMgr.launchOperation(this._selectedTokenInfo,OperationDialog.OP_PIN_RESET);
9b58a7
+    }
9b58a7
+
9b58a7
+   _onPhoneHome() {
9b58a7
+       this._phoneHomeMgr.getPhoneHomeInfo(this._selectedTokenInfo,true);
9b58a7
+    }
9b58a7
     _onExit() {
9b58a7
         if(this.notify) {
9b58a7
             this.notify._dbusImpl.unexport();
9b58a7
@@ -115,6 +175,9 @@ class ESC {
9b58a7
                this._removeCoolkey(aKeyType, aKeyID, aKeyState, aData, strData);
9b58a7
             break;
9b58a7
             default:
9b58a7
+               if(this._notifyCallback) {
9b58a7
+                   this._notifyCallback(aKeyType, aKeyID,aKeyState, aData,strData);
9b58a7
+               }
9b58a7
             break;
9b58a7
         }
9b58a7
     }
9b58a7
@@ -126,10 +189,10 @@ class ESC {
9b58a7
             break;
9b58a7
 
9b58a7
             case 2:
9b58a7
-                return "unitialized";
9b58a7
+                return "uninitialized";
9b58a7
             break;
9b58a7
             case 1:
9b58a7
-                return "no applet";
9b58a7
+                return "unknown";
9b58a7
             break;
9b58a7
             default:
9b58a7
                 return "unknown";
9b58a7
@@ -137,8 +200,12 @@ class ESC {
9b58a7
         }
9b58a7
      }
9b58a7
 
9b58a7
-    _insertCoolkey(aKeyType, aKeyID, aKeyState, aData, strData) {
9b58a7
+    _phoneHome(url) {
9b58a7
+        let info = this.mgr.phone_home(url); 
9b58a7
+        return info;
9b58a7
+     }
9b58a7
 
9b58a7
+    _insertCoolkey(aKeyType, aKeyID, aKeyState, aData, strData) {
9b58a7
          if(aKeyType && aKeyID) {
9b58a7
 
9b58a7
              let inserted = new Coolkey.Token({ key_type: String(aKeyType) ,
9b58a7
@@ -146,8 +213,68 @@ class ESC {
9b58a7
 
9b58a7
              this.mgr.get_token_info(inserted);
9b58a7
 
9b58a7
+             let issuer = inserted.issuer;
9b58a7
+             let issuedTo = inserted.issued_to;
9b58a7
+
9b58a7
+             if(issuer == null || issuer.length == 0) {
9b58a7
+                 issuer = "unknown";
9b58a7
+             }
9b58a7
+             if(issuedTo == null || issuedTo.length == 0) {
9b58a7
+                 issuedTo = "unknown";
9b58a7
+             }
9b58a7
              this._tokenStore.set (this._tokenStore.append(), [0, 1, 2, 3, 4],
9b58a7
-                [inserted.issuer, inserted.issued_to, this._getStatusString(inserted.status), aKeyID,aKeyType]);
9b58a7
+                [issuer, issuedTo, this._getStatusString(inserted.status), aKeyID,aKeyType]);
9b58a7
+
9b58a7
+             let [ isSelected, iter]  = this._tokenStore.get_iter_first();
9b58a7
+
9b58a7
+              while(isSelected) {
9b58a7
+                  if(aKeyID == this._tokenStore.get_value(iter,3)) {
9b58a7
+                      this.selection.select_iter(iter);
9b58a7
+                      break;
9b58a7
+                  }
9b58a7
+                  isSelected  = this._tokenStore.iter_next(iter);
9b58a7
+              }
9b58a7
+
9b58a7
+         }
9b58a7
+     }
9b58a7
+
9b58a7
+     _updateCoolkey(originalKey) {
9b58a7
+         if(originalKey) {
9b58a7
+             this._removeCoolkey(originalKey.key_type, originalKey.cuid,null, null, null);
9b58a7
+             this._insertCoolkey(originalKey.key_type, originalKey.cuid,null, null, null);
9b58a7
+         }
9b58a7
+
9b58a7
+     }
9b58a7
+     _updateOperationsArea(insertedToken, doReset) {
9b58a7
+         if(!insertedToken && !doReset) {
9b58a7
+             return;
9b58a7
+         }
9b58a7
+     
9b58a7
+         if(doReset) {
9b58a7
+             this._operationsGrid.remove(this._phoneHomeButton);
9b58a7
+             this._operationsGrid.remove(this._enrollButton);
9b58a7
+             this._operationsGrid.remove(this._resetPinButton);
9b58a7
+             this._operationsGrid.remove(this._formatButton);
9b58a7
+             this._operationsGrid.remove(this._certDetailButton);
9b58a7
+             this._operationsGrid.show_all();
9b58a7
+             return;
9b58a7
+         }
9b58a7
+ 
9b58a7
+         if(insertedToken.is_a_cool_key) {   
9b58a7
+             this._operationsGrid.add(this._phoneHomeButton);
9b58a7
+             this._operationsGrid.add(this._formatButton);
9b58a7
+             if(insertedToken.status == 2 ) {
9b58a7
+                 this._operationsGrid.add(this._enrollButton);
9b58a7
+             }
9b58a7
+          
9b58a7
+             // if enrolled 
9b58a7
+             if(insertedToken.status == 4) { 
9b58a7
+                 this._operationsGrid.add(this._enrollButton);
9b58a7
+                 this._operationsGrid.add(this._resetPinButton);
9b58a7
+                 this._operationsGrid.add(this._certDetailButton);
9b58a7
+             }
9b58a7
+
9b58a7
+             this._operationsGrid.show_all();
9b58a7
          }
9b58a7
      }
9b58a7
 
9b58a7
@@ -158,10 +285,13 @@ class ESC {
9b58a7
               if(aKeyID == this._tokenStore.get_value(iter,3)) {
9b58a7
                   this._tokenStore.remove(iter);
9b58a7
                   this._tokenInfoBuffer.text = "";
9b58a7
+                  this._updateOperationsArea(null,true);
9b58a7
                   return;
9b58a7
               }
9b58a7
               isSelected  = this._tokenStore.iter_next(iter);
9b58a7
          }
9b58a7
+
9b58a7
+         this._updateOperationsArea(null,true);
9b58a7
      }
9b58a7
 
9b58a7
     _updateTokenInfoTextView(coolkey_token) {
9b58a7
@@ -172,9 +302,160 @@ class ESC {
9b58a7
         let atr  = coolkey_token.atr;
9b58a7
         let issuer_info = coolkey_token.issuer_info;
9b58a7
 
9b58a7
-        this._tokenInfoBuffer.text = "Token ID: " + cuid + "\n" 
9b58a7
+        this._tokenInfoBuffer.text = "Token ID: " + cuid + "\n"
9b58a7
              + "ATR: " + atr + "\n"
9b58a7
-             + "Token Issuer URL: " + issuer_info + "\n";
9b58a7
+             + "Token Issuer URL: " + issuer_info + "\n"
9b58a7
+             + "Token is a CoolKey: " + coolkey_token.is_a_cool_key + "\n\n\n " ;
9b58a7
+
9b58a7
+     }
9b58a7
+
9b58a7
+     _getCertListDetail(certsList,pFileName) {
9b58a7
+
9b58a7
+          let i = 0;
9b58a7
+          let detail = "\n\nCerts In Detail \n\n";
9b58a7
+          let curDetail = "";
9b58a7
+          if(certsList == null) {
9b58a7
+             return null;
9b58a7
+          }
9b58a7
+
9b58a7
+          //right now for some reason specifying a nickname will list all certs
9b58a7
+          for(i = 0 ; i < 1; i++ ) {
9b58a7
+              curDetail = this._getCertDetail(certsList[i],pFileName); 
9b58a7
+
9b58a7
+              if(curDetail.length < 100) {
9b58a7
+                  detail += "Error finding cert detail.";
9b58a7
+              } else {
9b58a7
+                  detail += curDetail + "\n";
9b58a7
+              }
9b58a7
+          }
9b58a7
+
9b58a7
+          return detail;    
9b58a7
+
9b58a7
+     }
9b58a7
+
9b58a7
+     _getCertDetail(certObj, pFileName) {
9b58a7
+         if(certObj == null || pFileName == null) {
9b58a7
+             return null;
9b58a7
+         }
9b58a7
+
9b58a7
+         let certDetail = "";
9b58a7
+         let token = "";
9b58a7
+         let nick = "";
9b58a7
+         if(certObj.token == null) 
9b58a7
+             token = "internal"; 
9b58a7
+         else
9b58a7
+             token = certObj.token;
9b58a7
+
9b58a7
+         nick = certObj.nick;
9b58a7
+ 
9b58a7
+         certDetail = this._execProgram(['/usr/bin/certutil','-L','-d', this._getConfigPath(), '-h', token, '-f' , pFileName, '-n', token + ":" + nick]);
9b58a7
+
9b58a7
+         return certDetail;
9b58a7
+     }
9b58a7
+
9b58a7
+     _getCertList(coolkey_token,pFileName) {
9b58a7
+
9b58a7
+        let certInfo = "";
9b58a7
+
9b58a7
+        certInfo =  this._execProgram(['/usr/bin/certutil','-L','-d', this._getConfigPath(), '-h', 'all', '-f' , pFileName]);
9b58a7
+
9b58a7
+        let certs = this._parseCertList(certInfo);
9b58a7
+
9b58a7
+        let i = 0;
9b58a7
+        let certsInfo = "Certificate List\n";
9b58a7
+
9b58a7
+        if(certs.length == 0 ) {
9b58a7
+            certsInfo = certsInfo + "No Certificates Found\n";
9b58a7
+            return certsInfo;
9b58a7
+        }
9b58a7
+      
9b58a7
+        for(i = 0 ; i < certs.length; i++ ) {
9b58a7
+            certsInfo += "\n" + certs[i].token + " : " + certs[i].nick +  "\n";
9b58a7
+        }
9b58a7
+
9b58a7
+        certsInfo += this._getCertListDetail(certs,pFileName) + "\n";
9b58a7
+
9b58a7
+        return certsInfo;
9b58a7
+     }
9b58a7
+
9b58a7
+     _parseCertList(listStr) {
9b58a7
+
9b58a7
+         if(!listStr)
9b58a7
+            return;
9b58a7
+
9b58a7
+         let lines = listStr.split('\n');
9b58a7
+
9b58a7
+         let line = "";
9b58a7
+         let i = 0;
9b58a7
+         let token = "";
9b58a7
+         let nick = "";
9b58a7
+
9b58a7
+         let certlist = [];
9b58a7
+         for(i = 3 ; i < lines.length; i++) {
9b58a7
+
9b58a7
+             token = "";
9b58a7
+             nick = "";
9b58a7
+             let index = lines[i].search(/,/i);
9b58a7
+
9b58a7
+             if(index > 0) {
9b58a7
+                 line = lines[i];
9b58a7
+                 index -= 2;
9b58a7
+                 line = line.substring(0,index);
9b58a7
+                 line = line.trim();
9b58a7
+
9b58a7
+                 let sepIndex = line.indexOf(":");
9b58a7
+
9b58a7
+                 if(sepIndex > 0 ) {
9b58a7
+
9b58a7
+                     let res = line.split(":");
9b58a7
+
9b58a7
+                      if(res.length == 2) {
9b58a7
+                         token = res[0];
9b58a7
+                          nick = res[1];
9b58a7
+                      } else {
9b58a7
+                          token = "";
9b58a7
+                          nick = line;
9b58a7
+                      }
9b58a7
+                 
9b58a7
+                     certlist.push({
9b58a7
+                         token: token,
9b58a7
+                         nick: nick,
9b58a7
+                         certDetail: ""
9b58a7
+                     });
9b58a7
+                 }
9b58a7
+             }
9b58a7
+
9b58a7
+
9b58a7
+         }
9b58a7
+     
9b58a7
+         return certlist;   
9b58a7
+     }
9b58a7
+
9b58a7
+    _execProgram(args) {
9b58a7
+
9b58a7
+        let result = -1;
9b58a7
+        try {
9b58a7
+            let proc = new Gio.Subprocess({
9b58a7
+                argv: args ,
9b58a7
+                flags: Gio.SubprocessFlags.STDOUT_PIPE
9b58a7
+            });
9b58a7
+
9b58a7
+            proc.init(null);
9b58a7
+
9b58a7
+            let [res,stdoutb,stderrb] =  proc.communicate_utf8(null,null);
9b58a7
+
9b58a7
+            if(res == false) {
9b58a7
+               result = -1;
9b58a7
+               return result;
9b58a7
+            }
9b58a7
+
9b58a7
+            result = stdoutb.toString();
9b58a7
+
9b58a7
+        } catch (e) {
9b58a7
+            return result;
9b58a7
+        }
9b58a7
+
9b58a7
+        return result;
9b58a7
      }
9b58a7
 
9b58a7
     _onTokenTreeViewSelectionChanged()  {
9b58a7
@@ -188,9 +469,78 @@ class ESC {
9b58a7
              cuid: this._tokenStore.get_value(iter,3) } );
9b58a7
 
9b58a7
         this.mgr.get_token_info(selected);
9b58a7
+        this._updateOperationsArea(selected,true);
9b58a7
+        this._updateOperationsArea(selected,false);
9b58a7
+        this._selectedTokenInfo = selected;
9b58a7
         this._updateTokenInfoTextView(selected);
9b58a7
     }
9b58a7
 
9b58a7
+    _configValueWithKeyID(aKeyID,configValue) {
9b58a7
+        if(!configValue || !aKeyID)
9b58a7
+            return null;
9b58a7
+
9b58a7
+        return configValue + "-" + aKeyID;
9b58a7
+
9b58a7
+    }
9b58a7
+
9b58a7
+    _setConfigValue(name,value) {
9b58a7
+        if(!this._configFile) {
9b58a7
+            return;
9b58a7
+        }
9b58a7
+
9b58a7
+        try {
9b58a7
+            this._configFile.set_string(ESC_CONFIG_GROUP,name,value);
9b58a7
+            this._configFile.save_to_file(this._configFileName);
9b58a7
+        } catch(e) {
9b58a7
+            return;
9b58a7
+        }
9b58a7
+    }
9b58a7
+
9b58a7
+    _getConfigValue(name) {
9b58a7
+         if(!this._configFile) {
9b58a7
+             return null;
9b58a7
+         }
9b58a7
+
9b58a7
+         let value = null;
9b58a7
+         try {
9b58a7
+             value = this._configFile.get_string(ESC_CONFIG_GROUP,name);
9b58a7
+         } catch(e) {
9b58a7
+             return null;
9b58a7
+         }
9b58a7
+
9b58a7
+         return value;
9b58a7
+     }
9b58a7
+
9b58a7
+    _getPropertyValue(name) {
9b58a7
+         if(!this._propFile) {
9b58a7
+             return null;
9b58a7
+         }
9b58a7
+
9b58a7
+         let value = null;
9b58a7
+         try {
9b58a7
+             value = this._propFile.get_string(ESC_CONFIG_GROUP,name);
9b58a7
+         } catch(e) {
9b58a7
+             return null;
9b58a7
+         }
9b58a7
+
9b58a7
+         return value;
9b58a7
+     }
9b58a7
+
9b58a7
+    _initProperties() {
9b58a7
+
9b58a7
+         this._propFile = new GLib.KeyFile();    
9b58a7
+
9b58a7
+         this._propFileName =  this._currentDir + "/esc.properties";
9b58a7
+         let res = false;
9b58a7
+         try {
9b58a7
+             res = this._propFile.load_from_file (this._propFileName,  0 );
9b58a7
+         } catch(e) {
9b58a7
+             this._onExitClicked();
9b58a7
+             //IO error
9b58a7
+         }
9b58a7
+
9b58a7
+
9b58a7
+    }
9b58a7
     _initConfig() {
9b58a7
          // See if it exists already, otherwise create
9b58a7
          this._configFile =  new GLib.KeyFile();
9b58a7
@@ -208,17 +558,17 @@ class ESC {
9b58a7
              }
9b58a7
          }
9b58a7
 
9b58a7
-         let config_name = this._configPath + "/esc.conf";
9b58a7
+         this._configFileName = this._configPath + "/esc.conf";
9b58a7
          let res = false;
9b58a7
          try {
9b58a7
-             res = this._configFile.load_from_file (config_name,  0 );
9b58a7
+             res = this._configFile.load_from_file (this._configFileName,  0 );
9b58a7
          } catch(e) {
9b58a7
              // need to create config file
9b58a7
          }
9b58a7
 
9b58a7
          if (res == false) {
9b58a7
              this._configFile.set_string("ESC","name","Smart Card Utility");
9b58a7
-             res = this._configFile.save_to_file(config_name); 
9b58a7
+             this._configFile.save_to_file(this._configFileName); 
9b58a7
          } 
9b58a7
      }
9b58a7
 
9b58a7
@@ -235,24 +585,30 @@ class ESC {
9b58a7
                 this._window.set_icon_name('application-x-executable');
9b58a7
             }
9b58a7
 
9b58a7
-            this._hb = new Gtk.HeaderBar();
9b58a7
+            this._hb = new Gtk.HeaderBar({spacing: 10 });
9b58a7
             this._hb.set_title("Smart Card Manager");
9b58a7
             this._hb.set_show_close_button(true);
9b58a7
-            this._window.set_titlebar(this._hb);
9b58a7
 
9b58a7
-            this._headerTokenBox = new Gtk.Box({orientation: Gtk.Orientation.HORIZONTAL,halign: Gtk.Align.CENTER});
9b58a7
-            this._headerInfoBox = new Gtk.Box({orientation: Gtk.Orientation.HORIZONTAL,halign: Gtk.Align.CENTER});
9b58a7
+            this._window.set_titlebar(this._hb);
9b58a7
 
9b58a7
             this._infoLabel = new Gtk.Label({label: "Token Information",use_markup: true});
9b58a7
             this._tokenLabel = new Gtk.Label({label: "Tokens",use_markup: true});
9b58a7
 
9b58a7
-            this._headerInfoBox.add(this._infoLabel);
9b58a7
+            this._vSep = new Gtk.VSeparator();
9b58a7
+
9b58a7
+            this._hb.add(this._tokenLabel);
9b58a7
+            this._hb.pack_end(this._infoLabel);
9b58a7
+            //this._hb.add(this._vSep);
9b58a7
 
9b58a7
-            this._headerTokenBox.add(this._tokenLabel);
9b58a7
 
9b58a7
             this._initConfig();
9b58a7
+            this._initProperties();
9b58a7
+
9b58a7
+            this._statusMessages = null; 
9b58a7
+            this._getStatusMessages();
9b58a7
+         
9b58a7
             this._outerGrid = new Gtk.Grid({orientation: Gtk.Orientation.HORIZONTAL, border_width: 0});
9b58a7
-            this._tokenFrame = new Gtk.Frame({hexpand: true});
9b58a7
+            this._tokenFrame = new Gtk.Frame({hexpand: false, width_request: 300});
9b58a7
             this._infoFrame  = new Gtk.Frame({border_width: 0});
9b58a7
             
9b58a7
             this._tokenBox = new Gtk.Grid({orientation: Gtk.Orientation.VERTICAL, border_width: 0,hexpand: true});
9b58a7
@@ -280,33 +636,33 @@ class ESC {
9b58a7
 
9b58a7
              // Create the treeview
9b58a7
             this._tokenTreeView = new Gtk.TreeView ({
9b58a7
-                expand: true,
9b58a7
+                hexpand: true,
9b58a7
+                vexpand: true,
9b58a7
                 model: this._tokenStore });
9b58a7
 
9b58a7
             let issuer = new Gtk.TreeViewColumn ({ title: "Issuer" });
9b58a7
             let issuedTo = new Gtk.TreeViewColumn ({ title: "Issued To" });
9b58a7
             let status = new Gtk.TreeViewColumn ({ title: "Status" });
9b58a7
-            let tokenId = new Gtk.TreeViewColumn({ title: "Token Id"});
9b58a7
+            //let tokenId = new Gtk.TreeViewColumn({ title: "Token Id"});
9b58a7
 
9b58a7
             let bold = new Gtk.CellRendererText ({
9b58a7
-              weight: Pango.Weight.BOLD });
9b58a7
-
9b58a7
+              weight: Pango.Weight.BOLD});
9b58a7
             let normal = new Gtk.CellRendererText ();
9b58a7
 
9b58a7
             issuer.pack_start (bold, true);
9b58a7
             issuedTo.pack_start (normal, true);
9b58a7
             status.pack_start (normal, true);
9b58a7
-            tokenId.pack_start(normal,true);
9b58a7
+            //tokenId.pack_start(normal,true);
9b58a7
  
9b58a7
             issuer.add_attribute (bold, "text", 0);
9b58a7
             issuedTo.add_attribute (normal, "text", 1);
9b58a7
             status.add_attribute (normal, "text", 2);
9b58a7
-            tokenId.add_attribute(normal,"text",3);
9b58a7
+            //tokenId.add_attribute(normal,"text",3);
9b58a7
 
9b58a7
             this._tokenTreeView.insert_column (issuer, 0);
9b58a7
             this._tokenTreeView.insert_column (issuedTo, 1);
9b58a7
             this._tokenTreeView.insert_column (status, 2);
9b58a7
-            this._tokenTreeView.insert_column (tokenId, 3);
9b58a7
+            //this._tokenTreeView.insert_column (tokenId, 3);
9b58a7
 
9b58a7
             // Connect view slection to a method
9b58a7
             this._label = new Gtk.Label ({ label: "" });
9b58a7
@@ -329,37 +685,175 @@ class ESC {
9b58a7
                 hscrollbar_policy: Gtk.PolicyType.AUTOMATIC,
9b58a7
                 vscrollbar_policy: Gtk.PolicyType.AUTOMATIC,
9b58a7
                 shadow_type: Gtk.ShadowType.ETCHED_IN,
9b58a7
-                height_request: 400,
9b58a7
-                width_request: 400, });
9b58a7
+                height_request: 500,
9b58a7
+                width_request: 400 });
9b58a7
            
9b58a7
             this._scrolledTokenInfoWindow.add_with_viewport (this._tokenInfoTextView);
9b58a7
-            this._infoBox.add(this._headerInfoBox);
9b58a7
+            //this._infoBox.add(this._headerInfoBox);
9b58a7
+
9b58a7
+            //this._escImage = new Gtk.Image({file: this._currentDir + "/" + "enrolled-keyx2.png"});
9b58a7
+            //this._infoBox.add(this._escImage);
9b58a7
             this._infoBox.add(this._scrolledTokenInfoWindow);
9b58a7
-            this._operationsGrid =  new Gtk.Grid({orientation: Gtk.Orientation.VERTICAL, 
9b58a7
+
9b58a7
+            this._operationsGrid =  new Gtk.Grid({orientation: Gtk.Orientation.HORIZONTAL, 
9b58a7
                 halign: Gtk.Align.CENTER,
9b58a7
                 valign: Gtk.Align.CENTER,
9b58a7
-                row_spacing: 20,
9b58a7
-                border_width: 0});
9b58a7
+                row_spacing: 10,
9b58a7
+                column_spacing: 6,
9b58a7
+                border_width: 6});
9b58a7
 
9b58a7
             this._operationsLabel = new Gtk.Label({label: "Operations", use_markup: true});
9b58a7
+
9b58a7
+            this._certDetailButton = new Gtk.Button({ label: "Cert Info" });
9b58a7
+            this._certDetailButton.connect("clicked", this._onCertDetail.bind(this));
9b58a7
+
9b58a7
+
9b58a7
             this._infoBox.add(this._operationsGrid); 
9b58a7
-            this._operationsGrid.add(this._operationsLabel);
9b58a7
 
9b58a7
             this._exitButton = new Gtk.Button({ label: "Exit" });
9b58a7
             this._exitButton.connect("clicked", this._onExit.bind(this));
9b58a7
+
9b58a7
             this._operationsGrid.add(this._exitButton);
9b58a7
-           
9b58a7
-            this._tokenBox.add(this._headerTokenBox);
9b58a7
+            
9b58a7
+            this._operationsGrid.add(this._operationsLabel);
9b58a7
+            // operations buttons
9b58a7
+
9b58a7
+
9b58a7
+            this._phoneHomeButton = new Gtk.Button({ label: "Phone Home" });
9b58a7
+            this._phoneHomeButton.connect("clicked", this._onPhoneHome.bind(this));
9b58a7
+          
9b58a7
+            this._formatButton = new Gtk.Button({ label: "Format" });
9b58a7
+            this._formatButton.connect("clicked", this._onFormat.bind(this));
9b58a7
+
9b58a7
+            this._enrollButton = new Gtk.Button({ label: "Enroll" });
9b58a7
+            this._enrollButton.connect("clicked", this._onEnroll.bind(this));
9b58a7
+
9b58a7
+            this._resetPinButton = new Gtk.Button({ label: "Reset Pin" });
9b58a7
+            this._resetPinButton.connect("clicked", this._onResetPin.bind(this));
9b58a7
+
9b58a7
             this._tokenBox.add(this._tokenTreeView);
9b58a7
 
9b58a7
-            this._window.set_default_size(750, 550);
9b58a7
+            this._window.set_default_size(950, 500);
9b58a7
             this._window.connect('destroy',this._onWindowDestroy.bind(this));
9b58a7
             this._window.show_all();
9b58a7
+           
9b58a7
     } 
9b58a7
     _createCoolKeyMgr(dbusName) {
9b58a7
-        this.mgr = new Coolkey.Mgr({ dbusUniqueName: dbusName, config_dir: this._configPath});
9b58a7
-        //this.mgr.speak("Welcome to ESC...");
9b58a7
+        this.mgr = new Coolkey.Mgr({ dbusUniqueName: dbusName, config_dir: this._configPath, config_file_name: ESC_CONFIG_FILE_NAME });
9b58a7
+
9b58a7
+        this._phoneHomeMgr = new PhoneHome.phoneHome(this);
9b58a7
+       
9b58a7
+        if(!this.mgr || !this._phoneHomeMgr) {
9b58a7
+            this._onExitClicked(); 
9b58a7
+        }
9b58a7
     }
9b58a7
+
9b58a7
+    _alert(msg) {
9b58a7
+        this._messageDialog = new Gtk.MessageDialog ({
9b58a7
+            transient_for: this._window,
9b58a7
+            modal: true,
9b58a7
+            buttons: Gtk.ButtonsType.OK,
9b58a7
+            message_type: Gtk.MessageType.WARNING,
9b58a7
+            text: msg });
9b58a7
+
9b58a7
+        this._messageDialog.connect ('response', Lang.bind(this, this._response_cb));
9b58a7
+        this._messageDialog.show();
9b58a7
+    }
9b58a7
+
9b58a7
+    _promptPin() {
9b58a7
+
9b58a7
+        let status = this._selectedTokenInfo.status;
9b58a7
+
9b58a7
+        if(status == 4 /* enrolled */) {
9b58a7
+            this._pinMgr = new PinDialog.pinDialog(this);
9b58a7
+            this._pinMgr.launchPinPrompt(this._promptPinDone.bind(this));
9b58a7
+        }
9b58a7
+      
9b58a7
+    }
9b58a7
+    _promptPinDone(tempFileName) {
9b58a7
+
9b58a7
+        let coolkey_token = this._selectedTokenInfo;
9b58a7
+
9b58a7
+        this._tokenInfoBuffer.text += 
9b58a7
+              this._getCertList(coolkey_token,tempFileName)  + "\n";
9b58a7
+
9b58a7
+     }
9b58a7
+    _response_cb() {
9b58a7
+        if(this._messageDialog) {
9b58a7
+            this._messageDialog.destroy();
9b58a7
+        }
9b58a7
+        this._messageDialog = null;
9b58a7
+    }
9b58a7
+    _getConfigPath() {
9b58a7
+        return this._configPath;
9b58a7
+    }
9b58a7
+
9b58a7
+    _getStatusMessages() {
9b58a7
+
9b58a7
+        this._statusMessages = new Array(
9b58a7
+            this._getPropertyValue("errorNone"),
9b58a7
+            this._getPropertyValue("errorInternalServer"),
9b58a7
+            this._getPropertyValue("errorInternalServer"),
9b58a7
+            this._getPropertyValue("errorProblemCommToken"),
9b58a7
+            this._getPropertyValue("errorProblemResetTokenPin"),
9b58a7
+            this._getPropertyValue("errorInternalServer"),
9b58a7
+            this._getPropertyValue("errorLifeCyclePDU"),
9b58a7
+            this._getPropertyValue("errorTokenEnrollment"),
9b58a7
+            this._getPropertyValue("errorProblemCommToken"),
9b58a7
+            this._getPropertyValue("errorInternalServer"),
9b58a7
+            this._getPropertyValue("errorInternalServer"),
9b58a7
+            this._getPropertyValue("errorInternalServer"),
9b58a7
+            this._getPropertyValue("errorInternalServer"),
9b58a7
+            this._getPropertyValue("errorTermSecureConn"),
9b58a7
+            this._getPropertyValue("errorAuthFailure"),
9b58a7
+            this._getPropertyValue("errorInternalServer"),
9b58a7
+            this._getPropertyValue("errorTokenDisabled"),
9b58a7
+            this._getPropertyValue("errorSecureChannel"),
9b58a7
+            this._getPropertyValue("errorServerMisconfig"),
9b58a7
+            this._getPropertyValue("errorTokenUpgrade"),
9b58a7
+            this._getPropertyValue("errorInternalServer"),
9b58a7
+            this._getPropertyValue("errorExternalAuth"),
9b58a7
+            this._getPropertyValue("errorInvalidTokenType"),
9b58a7
+            this._getPropertyValue("errorInvalidTokenTypeParams"),
9b58a7
+            this._getPropertyValue("errorCannotPublish"),
9b58a7
+            this._getPropertyValue("errorCommTokenDB"),
9b58a7
+            this._getPropertyValue("errorTokenSuspended"),
9b58a7
+            this._getPropertyValue("errorPinResetable"),
9b58a7
+            this._getPropertyValue("errorConnLost"),
9b58a7
+            this._getPropertyValue("errorEntryTokenDB"),
9b58a7
+            this._getPropertyValue("errorNoTokenState"),
9b58a7
+            this._getPropertyValue("errorInvalidLostTokenReason"),
9b58a7
+            this._getPropertyValue("errorTokenUnusable"),
9b58a7
+            this._getPropertyValue("errorNoInactiveToken"),
9b58a7
+            this._getPropertyValue("errorProcessMultiTokens"),
9b58a7
+            this._getPropertyValue("errorTokenTerminated"),
9b58a7
+            this._getPropertyValue("errorInternalServer"),
9b58a7
+            this._getPropertyValue("errorKeyRecoveryFailed"),
9b58a7
+            this._getPropertyValue("errorInternalServer"),
9b58a7
+            this._getPropertyValue("errorKeyArchival"),
9b58a7
+            this._getPropertyValue("errorConnTKS"),
9b58a7
+            this._getPropertyValue("errorFailUpdateTokenDB"),
9b58a7
+            this._getPropertyValue("errorCertRevocation"),
9b58a7
+            this._getPropertyValue("errorNotOwnToken"),
9b58a7
+            this._getPropertyValue("errorESCMisconfigured"),
9b58a7
+            this._getPropertyValue("errorESCNoCommCardReader"),
9b58a7
+            this._getPropertyValue("errorESCNoTokenSession"),
9b58a7
+            this._getPropertyValue("errorESCNoTalkTPS"),
9b58a7
+            this._getPropertyValue("errorESCNoTalkTokenReader")
9b58a7
+        );
9b58a7
+
9b58a7
+    }
9b58a7
+
9b58a7
+    _getErrorMessage(status_code) {
9b58a7
+        let result =  this._getPropertyValue("errorInternalServer");
9b58a7
+
9b58a7
+        if(status_code < 0 && status_code >= this._statusMessages.length)
9b58a7
+        {
9b58a7
+            return result;
9b58a7
+        }   
9b58a7
+      
9b58a7
+        return this._statusMessages[status_code];
9b58a7
+    }   
9b58a7
 }
9b58a7
 
9b58a7
 let app = new ESC();
9b58a7
diff -up ./esc/src/app/esc.properties.fix4 ./esc/src/app/esc.properties
9b58a7
--- ./esc/src/app/esc.properties.fix4	2019-01-10 16:19:56.456747125 -0800
9b58a7
+++ ./esc/src/app/esc.properties	2019-01-10 16:20:47.731493781 -0800
9b58a7
@@ -0,0 +1,217 @@
9b58a7
+# ***** BEGIN COPYRIGHT BLOCK *****
9b58a7
+# This Program is free software; you can redistribute it and/or modify it under
9b58a7
+# the terms of the GNU General Public License as published by the Free Software
9b58a7
+# Foundation; version 2 of the License.
9b58a7
+#
9b58a7
+# This Program is distributed in the hope that it will be useful, but WITHOUT
9b58a7
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9b58a7
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.#
9b58a7
+# You should have received a copy of the GNU General Public License along with
9b58a7
+# this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
9b58a7
+# Place, Suite 330, Boston, MA 02111-1307 USA.
9b58a7
+#
9b58a7
+# Copyright (C) 2005 Red Hat, Inc.
9b58a7
+# All rights reserved.
9b58a7
+# ***** END COPYRIGHT BLOCK
9b58a7
+
9b58a7
+#ESC strings used in Javascript
9b58a7
+#Strings for ESC.js 
9b58a7
+[ESC]
9b58a7
+escTitle=Smart Card Manager
9b58a7
+smartCard=smart card
9b58a7
+smartCardU=Smart Card
9b58a7
+enrolledKey=Enrolled
9b58a7
+noKeysPresent=No Cards Present
9b58a7
+blankKey=Blank
9b58a7
+uninitializedKey=Uninitialized
9b58a7
+statusEnrolled=Enrolled
9b58a7
+statusUnavailable=Unavailable
9b58a7
+statusNoApplet=Unformatted
9b58a7
+statusUninitialized=Formatted
9b58a7
+statusLoggedIn=Logged In
9b58a7
+statusUnknown=Unknown
9b58a7
+statusBusy=Busy
9b58a7
+unknownIssuer=Unknown
9b58a7
+redHatUser=User
9b58a7
+statusUnknown=Unknown
9b58a7
+appletVersion = Smart Card Applet Version:
9b58a7
+operationPINReset=Resetting Key Password..
9b58a7
+operationEnrollment=Enrolling Key..
9b58a7
+operationFormat=Formatting Key..
9b58a7
+tokenInformation=CARD INFORMATION
9b58a7
+advancedInformation=Diagnostics Information
9b58a7
+keyID=Key ID:
9b58a7
+tpsURI=Smart Card Server URL:
9b58a7
+tpsUI=Enrollment UI URL:
9b58a7
+tpsPhoneHomeURL=Phone Home URL:
9b58a7
+status=Status:
9b58a7
+issuer=Issuer:
9b58a7
+atr=Atr:
9b58a7
+escLogEntries=Smart Card Activity
9b58a7
+noLogFileOrData=No log file or log file has no data.
9b58a7
+dataCopiedToClipboard=Diagnostics information copied to the clipboard.
9b58a7
+diagnosticsReport=SMART CARD DIAGNOSTICS REPORT
9b58a7
+diagnosticsSystemInfo=Software Version Information
9b58a7
+diagnosticsSoftVersioInfo=System Versions:
9b58a7
+diagnosticsDetails=Active Smart Card Details
9b58a7
+secCard=Card
9b58a7
+certsOnToken=Certificates on Smart Card 
9b58a7
+certificateNickname=Certificate Nickname:
9b58a7
+certIssuedTo=Issued to;
9b58a7
+certIssuedBy=Issued by;
9b58a7
+certValidityFrom=Validity from:
9b58a7
+certValidityTo=Validity to:
9b58a7
+certSerialNumber=Serial number:
9b58a7
+coolkeyComponentVersion=Smart Card Manager Version:
9b58a7
+coolkeyDetectedNumberKeys=Number of Smart Cards Detected:
9b58a7
+enrolledDetected=Enrolled Smart Card Detected
9b58a7
+enrolledDetectedMessage=Smart Card Manager has detected an already enrolled card. If you do not wish to re-enroll, press the "Close" button.
9b58a7
+enrolledDetectedMessageGeneric=Smart Card Manager has detected an already enrolled card. Click Proceed to continue.
9b58a7
+unenrolledDetectedMessage=Smart Card Manager has detected that you have entered a new and un-enrolled smart card. Before you can use this smart card, you have to enroll it.  Enrolling your smart card personalizes it so only you can use it for secure operations.
9b58a7
+enrollAnyway=If you would like to re-enroll anyway, click  Enroll My Smart Card Now.
9b58a7
+readyToProceed=When you are ready to begin the process,click  Enroll My Smart Card Now.
9b58a7
+formatingToken=Formatting... 
9b58a7
+enrollingToken=Enrolling... 
9b58a7
+resettingTokenPIN=Password Reset.. 
9b58a7
+cancellingOperation=Cancelling.. 
9b58a7
+blinkingToken=Blinking.. 
9b58a7
+keyInserted=Smart Card Inserted!
9b58a7
+keyRemoved=Smart Card Removed!
9b58a7
+keyInsertedComputer=smart card inserted.
9b58a7
+keyRemovedComputer=smart card removed.
9b58a7
+diagnosticsMessage=The information below is diagnostic information that your system generates as you use your smart card. If you are having smart card problems, you may be asked by your support engineer to send this information for analysis.
9b58a7
+
9b58a7
+menuManageKeys=Manage Smart Cards...
9b58a7
+menuExit=Quit   
9b58a7
+#ESC Error Messages from TPS
9b58a7
+errorNone=Operation Completed Successfully.
9b58a7
+serverError=Smart Card Server error.
9b58a7
+errorProblemResetTokenPin=The Smart Card Server cannot reset your smart card's password.
9b58a7
+errorTokenEnrollment=The Smart Card Server cannot import the required certificates into your smart card.
9b58a7
+errorLifeCyclePDU=The Smart Card Server cannot finalize the enrollment of your smart card.
9b58a7
+errorCommCA=Error communicating with the Certification Authority.
9b58a7
+errorInternalServer=Internal Smart Card Server error.
9b58a7
+errorResetPin=Error resetting the smart card's password.
9b58a7
+errorInternalServer=Internal Smart Card Server error.
9b58a7
+errorAuthFailure=The Smart Card Server cannot validate your credentials. Please try again with the correct credentials.
9b58a7
+errorTokenDisabled=The Smart Card Server does not know about your smart card.
9b58a7
+errorSecureChannel=The Smart Card Server cannot establish a secure channel with the smart card.
9b58a7
+errorServerMisconfig=The Smart Card Server has not been configured correctly.
9b58a7
+errorProblemCommToken=Your smart card can not perform the operation requested by the Smart Card Server.
9b58a7
+errorExternalAuth=Your smart card cannot correctly identify the Smart Card Server.
9b58a7
+errorTokenUpgrade=The Smart Card Server cannot upgrade the software on your smart card.
9b58a7
+errorTermSecureConn=The Smart Card Server can not terminate the secure cummunications channel with the smart card.
9b58a7
+errorInvalidTokenType=The Smart Card Server does not recognize the requested type of card enrollment.
9b58a7
+errorInvalidTokenTypeParams=The Smart Card Server cannot process the requested type of enrollment due to a misconfiguration.
9b58a7
+errorCannotPublish=The Smart Card Server cannot publish your card's certificates to the certificate directory.
9b58a7
+errorCommTokenDB=The Smart Card Server cannot connect to its internal database.
9b58a7
+errorTokenSuspended=You are not allowed to perform this operation with this smart card.
9b58a7
+errorPinResetable=You are not allowed to reset the password of this smart card.
9b58a7
+errorConnLost=The Smart Card Manager has lost the connection to the Smart Card Server.
9b58a7
+errorEntryTokenDB=The Smart Card Server cannot add your smart card to its internal database.
9b58a7
+errorNoTokenState=The Smart Card server does not recognize your smart card's current status.
9b58a7
+errorInvalidLostTokenReason=The Smart Card server cannot process your smart card which has been reported lost.
9b58a7
+errorTokenUnusable=The Smart Card Server cannot process your smart card which has been reported stolen.
9b58a7
+errorNoInactiveToken=The Smart Card Server cannot restore your smart card's security keys.
9b58a7
+errorProcessMultiTokens=The Smart Card Server has detected that you already have one enrolled smart card. The server only allows one enrolled card per user.
9b58a7
+errorTokenTerminated=The Smart Card Server can not process your smart card which is marked as terminated.
9b58a7
+errorKeyRecoveryProcessed=Smart card key recovery has been processed.
9b58a7
+errorKeyRecoveryFailed=The Smart Card Server can not restore the security keys onto your smart card.
9b58a7
+errorNoOperateLostToken=Cannot process this smart card, which has been reported lost.
9b58a7
+errorKeyArchival=The Smart Card Server can not restore the security keys onto your smart card due to a server misconfiguration.
9b58a7
+errorConnTKS=The Smart Card server cannot contact its security key server,which is required for processing.
9b58a7
+errorFailUpdateTokenDB=The Smart Card Server cannot reset the status of your smart card.
9b58a7
+errorCertRevocation=The Smart Card Server cannot mark the security keys on your smart card as revoked.
9b58a7
+errorNotOwnToken=The Smart Card Server cannot process a smart card which you do not own.
9b58a7
+errorESCMisconfigured=The Smart Card Manager has been misconfigured.
9b58a7
+errorESCNoCommCardReader=The Smart Card Manager cannot initiate communications with the smart card.
9b58a7
+errorESCNoTokenSession=The Smart Card Manager cannot establish a communications session with the smart card.
9b58a7
+errorESCNoTalkTPS=The Smart Card Manager cannot initiate communications with the Smart Card Server.
9b58a7
+errorESCNoTalkTokenReader=The Smart Card Manager cannot finalize communications with the smart card.
9b58a7
+#ESC text in general  Alert messages
9b58a7
+errorCoolKeyIsAuth=coolkey.GetCoolKeyIsAuthenticated() failed!
9b58a7
+errorAuthCoolKey=coolkey.AuthenticateCoolKey failed!
9b58a7
+errorJsNotifyInterface=Can't find jsNotify interface.
9b58a7
+errorUniversalXPConnect=Can't get UniversalXPConnect.
9b58a7
+errorConfigValue=Error obtaining issuer info for key.
9b58a7
+errorConfigValue=Error Getting Config Value:
9b58a7
+errorSetConfigValue=Error SettingConfig Value: 
9b58a7
+errorBlankTPSURI=Blank Tps Uri submitted.
9b58a7
+noTpsConfigUrl=You must provide a Url to test!
9b58a7
+aboutToTestTPSURI=About to test Smart Card Server URI:
9b58a7
+errorSelectKey=Please select a Smart card.
9b58a7
+tpsURLContacted=Smart Card Server URL has been successfully contacted.
9b58a7
+errorContactTPSURL=Error contacting Smart Card Server URL, reconfigure and try again.
9b58a7
+errorBlankEnrollURI=Blank Enroll Uri submitted.
9b58a7
+aboutToTestEnrollURI=About to test Enroll URI:
9b58a7
+enrollURLContacted=x Enrollment URL has been successfully contacted.
9b58a7
+errorContactEnrollURL=Error contacting  Enroll URL, reconfigure and try again.
9b58a7
+tpsConfigSuccess=Smart Card Server config information successfully obtained!
9b58a7
+tpsConfigError=Error obtaining Smart Card Server config information!
9b58a7
+tpsConfigTest=About to test the Smart Card Server Phone Home Url :
9b58a7
+tpsNoConfigUrl=Provide a valid Smart Card Server config URL!
9b58a7
+tpsURIMustHaveValue=Smart Card Server URL item must have a value!
9b58a7
+errorSetConfigValue=Error setting config value!:
9b58a7
+configChangesSubmitted=Configuration changes submitted.
9b58a7
+errorSetDataValue=Error Setting data values:
9b58a7
+errorCoolKeyGetStatus=coolkey.GetCoolKeyStatus() failed!
9b58a7
+errorCoolKeyGetPolicy=coolkey.GetCoolKeyPolicy() failed!
9b58a7
+errorCoolKeyRequiresAuth=coolkey.GetCoolKeyRequiresAuthentication() failed!
9b58a7
+errorCoolKeyIsAuth=coolkey.GetCoolKeyIsAuthenticated() failed!
9b58a7
+errorCoolKeyCertNicknames=coolkey.GetCoolKeyCertNicknames() failed!
9b58a7
+errorAuthCoolKey=coolkey.AuthenticateCoolKey failed!
9b58a7
+errorCoolKeyCertInfo=coolkey.GetCoolKeyCertInfo() failed!
9b58a7
+errorGetAvailCoolKeys=coolkey.GetAvailableCoolKeys() failed!
9b58a7
+errorEnollCoolKey=coolkey.EnrollCoolKey() failed!
9b58a7
+errorCoolKeyIsEnrolled=coolkey.GetCoolKeyIsEnrolled failed!
9b58a7
+errorResetCoolKeyPIN=coolkey.ResestCoolKeyPASSWORD() failed! Make sure smart card is enrolled.
9b58a7
+errorFormatCoolKey=coolkey.FormatCoolKey() failed!
9b58a7
+errorCancelCoolKey=coolkeyCancelCoolKeyOperation() failed!
9b58a7
+errorBlinkCoolKey=coolkey.BlinkCoolKey() failes!
9b58a7
+noCurrentlySelectedToken=No currently selected smart card!
9b58a7
+errorProvideScreenName=You must provide a valid screen name!
9b58a7
+errorProvideTokenPIN=You must provide a valid card password!
9b58a7
+errorMatchPinValues=The Password values you entered don't match!
9b58a7
+errorValidUserPassword=You must provide a valid user password!
9b58a7
+errorSelectKey=Please select a smart card.
9b58a7
+errorEnrolledFirst=Smart card must be enrolled first! Enroll card and try again.
9b58a7
+enrollmentFor=Enrollment of your 
9b58a7
+errorNeedKeyForSecMode=Please insert enrolled smart card before attempting secure mode.
9b58a7
+errorEnrollmentUI=Problem loading Enrollment UI, check your network connection, re-insert the card, and try again!
9b58a7
+errorPhoneHomeInfo=Problem loading Phone Home Information, check your network connection, re-insert the card, and try again!
9b58a7
+wasSuccessful=was successful.
9b58a7
+pinResetSuccessful=Password Reset was successfull!
9b58a7
+formatOf=Format of
9b58a7
+error=Error
9b58a7
+serverResponse= Server Response: 
9b58a7
+enrollmentOfKey=Enrollment of smart card 
9b58a7
+formatingOfKey=Formatting of smart card
9b58a7
+pinResetOfKey=Password Reset for smart card 
9b58a7
+operationForKey=Operation for smart card 
9b58a7
+failed=failed. 
9b58a7
+cancelled=cancelled.
9b58a7
+errorFindESCPlatform=Unable to determine Smart Card Manager platform.
9b58a7
+errorIssuerInfo=Error obtaining Issuer Info for key.
9b58a7
+
9b58a7
+escUsage1=Usage:    
9b58a7
+escUsage2=esc
9b58a7
+escUsage3=esc -secmode SECURITY_URL
9b58a7
+escUsage4=Ex: esc -secmode http://test.host.com
9b58a7
+escUsage5=esc -usage
9b58a7
+
9b58a7
+#Strings for TRAY.j
9b58a7
+errorTrayIsInitialized=Can't determine if Icon component is already intialized!
9b58a7
+errorShowAllWindows=Error Showing All Windows:
9b58a7
+errorHideAllWindows=Error Hiding all Windows:
9b58a7
+errorShowWindow=Error Showing Window:
9b58a7
+errorHideWindow=Error Hiding Window:
9b58a7
+errorRemoveWindow=Error Removing Window:
9b58a7
+errorTrayNotification=Error Sending Tray notification:
9b58a7
+#Strings for GenericAuth.js
9b58a7
+value=Value
9b58a7
+mustMatch=must match
9b58a7
+mustHaveValue=Must have value set for field:
9b58a7
+noParentWindow=No parent window.
9b58a7
+authDialogNoParent=Auth dialog has no parent!
9b58a7
+authSubmit=Submit
9b58a7
+authSubmitAccessKey=S
9b58a7
diff -up ./esc/src/app/Makefile.am.fix4 ./esc/src/app/Makefile.am
9b58a7
--- ./esc/src/app/Makefile.am.fix4	2019-01-10 17:44:13.841523700 -0800
9b58a7
+++ ./esc/src/app/Makefile.am	2019-01-10 17:44:45.545372112 -0800
9b58a7
@@ -15,4 +15,4 @@
9b58a7
 # All rights reserved.
9b58a7
 # END COPYRIGHT BLOCK
9b58a7
 
9b58a7
-dist_bin_SCRIPTS = esc.js opensc.esc.conf
9b58a7
+dist_bin_SCRIPTS = esc.js opensc.esc.conf phoneHome.js operationDialog.js pinDialog.js esc.properties
9b58a7
diff -up ./esc/src/app/opensc.esc.conf.fix4 ./esc/src/app/opensc.esc.conf
9b58a7
--- ./esc/src/app/opensc.esc.conf.fix4	2019-01-10 16:28:07.169377285 -0800
9b58a7
+++ ./esc/src/app/opensc.esc.conf	2019-01-10 16:29:24.545004705 -0800
9b58a7
@@ -18,6 +18,15 @@
9b58a7
 app default {
9b58a7
     enable_default_driver = true;
9b58a7
 
9b58a7
+    #debug = 9;
9b58a7
+
9b58a7
+        # The file to which debug output will be written
9b58a7
+        #
9b58a7
+        # Special values 'stdout' and 'stderr' are recognized.
9b58a7
+        # Default: stderr
9b58a7
+        #
9b58a7
+    #debug_file = /tmp/opensc.log;
9b58a7
+
9b58a7
     card_atr
9b58a7
       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 {
9b58a7
                 pkcs11_enable_InitToken = yes;
9b58a7
@@ -32,6 +41,24 @@ app default {
9b58a7
       3B:FF:14:00:FF:81:31:FE:45:80:25:A0:00:00:00:56:57:53:43:36:35:30:03:00:3B {
9b58a7
                 pkcs11_enable_InitToken = yes;
9b58a7
     }
9b58a7
+
9b58a7
+    card_atr 
9b58a7
+      3B:FB:96:00:00:80:31:FE:45:00:31:C0:64:77:E3:02:00:82:90:00:76 {
9b58a7
+                pkcs11_enable_InitToken = yes;
9b58a7
+    }
9b58a7
+
9b58a7
+    card_atr
9b58a7
+      3B:65:00:00:9C:02:02:01:02 {
9b58a7
+                pkcs11_enable_InitToken = yes;
9b58a7
+    }
9b58a7
+
9b58a7
+
9b58a7
+    card_atr
9b58a7
+      3B:FE:18:00:00:80:31:FE:45:53:43:45:36:30:2D:43:44:30:38:31:2D:6E:46:A9 {
9b58a7
+               pkcs11_enable_InitToken = yes;
9b58a7
+    }
9b58a7
+
9b58a7
+
9b58a7
     reader_driver ctapi {
9b58a7
     }
9b58a7
     reader_driver pcsc {
9b58a7
diff -up ./esc/src/app/operationDialog.js.fix4 ./esc/src/app/operationDialog.js
9b58a7
--- ./esc/src/app/operationDialog.js.fix4	2019-01-10 16:20:30.353579643 -0800
9b58a7
+++ ./esc/src/app/operationDialog.js	2019-01-10 16:51:54.600521629 -0800
9b58a7
@@ -0,0 +1,333 @@
9b58a7
+/** BEGIN COPYRIGHT BLOCK
9b58a7
+ * This Program is free software; you can redistribute it and/or modify it under
9b58a7
+ * the terms of the GNU General Public License as published by the Free Software
9b58a7
+ * Foundation; version 2 of the License.
9b58a7
+ *    
9b58a7
+ * This Program is distributed in the hope that it will be useful, but WITHOUT
9b58a7
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9b58a7
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
9b58a7
+ *
9b58a7
+ * You should have received a copy of the GNU General Public License along with
9b58a7
+ * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
9b58a7
+ * Place, Suite 330, Boston, MA 02111-1307 USA.
9b58a7
+ *
9b58a7
+ * Copyright (C) 2005 Red Hat, Inc.
9b58a7
+ * All rights reserved.
9b58a7
+ * END COPYRIGHT BLOCK **/
9b58a7
+
9b58a7
+imports.gi.versions.Gtk = '3.0'
9b58a7
+const Gtk = imports.gi.Gtk;
9b58a7
+const Lang = imports.lang;
9b58a7
+const Gio = imports.gi.Gio;
9b58a7
+const GObject = imports.gi.GObject;
9b58a7
+const GLib = imports.gi.GLib;
9b58a7
+
9b58a7
+var  OP_FORMAT = 0;
9b58a7
+var  OP_ENROLL = 1;
9b58a7
+var  OP_PIN_RESET = 2;
9b58a7
+
9b58a7
+const  DEF_TOKEN_TYPE = "userKey";
9b58a7
+
9b58a7
+
9b58a7
+var OpLabels = new Array("Format", "Enroll", "ResetPin" ); 
9b58a7
+
9b58a7
+
9b58a7
+const TOKEN_OPERATION = "Token Operation";
9b58a7
+
9b58a7
+function operationDialog(app) {
9b58a7
+  if(!app)
9b58a7
+      return;
9b58a7
+  this.app = app;
9b58a7
+
9b58a7
+}
9b58a7
+
9b58a7
+operationDialog.prototype = {
9b58a7
+    launchOperation: function(tokenInfo,operation) {
9b58a7
+
9b58a7
+        if(tokenInfo == null) {
9b58a7
+            this.app_alert("Invalid Token!");
9b58a7
+        }
9b58a7
+        this.dialog = new Gtk.Dialog ({ transient_for: this.app._window,
9b58a7
+                         modal: true,deletable: false,
9b58a7
+                         title: TOKEN_OPERATION, border_width: 10 });
9b58a7
+
9b58a7
+        this.operation = operation;
9b58a7
+        this.tokenInfo = tokenInfo;
9b58a7
+
9b58a7
+        let opMessage = "";
9b58a7
+        if(this.operation == OP_FORMAT) {
9b58a7
+            opMessage = "Format Smart Card";
9b58a7
+
9b58a7
+        } else if(this.operation == OP_ENROLL)  {
9b58a7
+            opMessage = "Enroll Smart Card";
9b58a7
+        } else if(this.operation == OP_PIN_RESET) {
9b58a7
+            opMessage = "Reset Smart Card Pin";
9b58a7
+        } else {
9b58a7
+            this.app._alert("operationdDialog: Invalid operation!");
9b58a7
+            return;
9b58a7
+        }
9b58a7
+
9b58a7
+        this.area = this.dialog.get_content_area();
9b58a7
+        this.grid = new Gtk.Grid ({row_spacing: 20, column_spacing: 20});
9b58a7
+
9b58a7
+        this.message = new Gtk.Label ({label: opMessage});
9b58a7
+        this.area.add (this.message);
9b58a7
+
9b58a7
+        //this.throbberImage = new Gtk.Image({file: this.app._currentDir + "/" + "throbber-anim5.gif"});
9b58a7
+
9b58a7
+        this.progressBar = new Gtk.ProgressBar ({ valign: Gtk.Align.CENTER });
9b58a7
+        this.progressBar.set_fraction(0.0);
9b58a7
+
9b58a7
+        this.progressLabel = new Gtk.Label({label: "Progress:"});
9b58a7
+        this.actionArea = this.dialog.get_action_area();
9b58a7
+
9b58a7
+        this.actionArea.add(this.grid);
9b58a7
+
9b58a7
+        this.ldapUserLabel = new Gtk.Label({label: "Ldap User:"});
9b58a7
+        this.ldapUserBox =  new Gtk.Entry();
9b58a7
+
9b58a7
+        this.grid.attach(this.ldapUserLabel, 0, 0, 1,1);
9b58a7
+        this.grid.attach(this.ldapUserBox,1, 0,1,1);
9b58a7
+
9b58a7
+        this.ldapPasswordLabel = new Gtk.Label({label: "Ldap Password:"});
9b58a7
+        this.ldapPasswordBox = new Gtk.Entry();
9b58a7
+        this.ldapPasswordBox.set_visibility(false);
9b58a7
+
9b58a7
+        this.grid.attach(this.ldapPasswordLabel,2,0,1,1);
9b58a7
+        this.grid.attach(this.ldapPasswordBox,3,0,1,1);
9b58a7
+
9b58a7
+        if(this.operation !=  OP_FORMAT ) {
9b58a7
+
9b58a7
+            this.newpinLabel = new Gtk.Label({label: "New Pin:"});
9b58a7
+            this.newpinBox   = new Gtk.Entry();
9b58a7
+            this.newpinBox.set_visibility(false);
9b58a7
+
9b58a7
+            this.confirmPinLabel = new Gtk.Label({label: "Confirm Pin:"});
9b58a7
+            this.confirmPinBox = new Gtk.Entry();
9b58a7
+            this.confirmPinBox.set_visibility(false);
9b58a7
+
9b58a7
+            this.grid.attach(this.newpinLabel, 0,1,1,1);
9b58a7
+            this.grid.attach(this.newpinBox,1,1,1,1);
9b58a7
+            this.grid.attach(this.confirmPinLabel,2,1,1,1);
9b58a7
+            this.grid.attach(this.confirmPinBox,3,1,1,1);
9b58a7
+        }
9b58a7
+
9b58a7
+        this.oKButton = new  Gtk.Button ({label: OpLabels[this.operation]}); 
9b58a7
+
9b58a7
+        this.dismissButton = new Gtk.Button({label: "Cancel" });
9b58a7
+
9b58a7
+        //this.grid.attach(this.throbberImage,0,2,1,1);
9b58a7
+        this.grid.attach(this.progressLabel, 0,2,1,1);
9b58a7
+        //this.throbberImage.hide();
9b58a7
+        this.grid.attach(this.progressBar, 1,2,1,1);
9b58a7
+        this.grid.attach (this.oKButton,2,2,1,1);
9b58a7
+        this.grid.attach (this.dismissButton,3,2,1,1);
9b58a7
+
9b58a7
+        // Connect the button to the function that handles what it does
9b58a7
+        this.oKButton.connect ("clicked", this.oKHandler.bind(this));
9b58a7
+
9b58a7
+        this.dismissButton.connect("clicked", this.cancelHandler.bind(this));
9b58a7
+        this.dialog.show_all();
9b58a7
+        this.hideThrobberImage();
9b58a7
+        this.inProgress = false;
9b58a7
+    },
9b58a7
+
9b58a7
+    hideThrobberImage() {
9b58a7
+        //this.throbberImage.hide();
9b58a7
+    },
9b58a7
+
9b58a7
+    showThrobberImage() {
9b58a7
+        //this.throbberImage.show();
9b58a7
+    },
9b58a7
+
9b58a7
+    updateUI(state) {
9b58a7
+    },
9b58a7
+
9b58a7
+    checkSanity: function() {
9b58a7
+
9b58a7
+         if(this.operation ==  OP_ENROLL || this.operation == OP_PIN_RESET) {
9b58a7
+
9b58a7
+             let pin = this.newpinBox.get_text();
9b58a7
+             let confirm = this.confirmPinBox.get_text();
9b58a7
+            
9b58a7
+             if( pin && confirm) {
9b58a7
+
9b58a7
+                 if(pin != confirm) {
9b58a7
+
9b58a7
+                     this.app._alert("Pins must match!");
9b58a7
+                     return false;
9b58a7
+                 }
9b58a7
+
9b58a7
+             } else {
9b58a7
+                 this.app._alert("Must provide token pin!");
9b58a7
+                 return false;             
9b58a7
+             } 
9b58a7
+
9b58a7
+         }
9b58a7
+
9b58a7
+         // Now check the ldap user info
9b58a7
+
9b58a7
+        
9b58a7
+         let ldapUser = this.ldapUserBox.get_text();
9b58a7
+         let ldapPin = this.ldapPasswordBox.get_text();
9b58a7
+
9b58a7
+         if(!ldapUser || !ldapPin) {
9b58a7
+             this.app._alert("Must provide user name and password!");
9b58a7
+             return false;
9b58a7
+         }
9b58a7
+
9b58a7
+         return true;  
9b58a7
+    },
9b58a7
+
9b58a7
+    cancelHandler() {
9b58a7
+        if(this.inProgress == false) {
9b58a7
+            this.dialog.destroy();
9b58a7
+        } else {
9b58a7
+           this.app.mgr.cancel_token_operation(this.tokenInfo); 
9b58a7
+        }
9b58a7
+    },
9b58a7
+    oKHandler: function() {
9b58a7
+
9b58a7
+        if(this.inProgress) {
9b58a7
+            return;
9b58a7
+        }
9b58a7
+
9b58a7
+        if(!this.checkSanity()) {
9b58a7
+           return;
9b58a7
+        }
9b58a7
+
9b58a7
+        let res = 0;
9b58a7
+        this.app._setNotifyCallback(this.notify.bind(this));
9b58a7
+
9b58a7
+        if(this.operation == OP_FORMAT) {
9b58a7
+           this.inProgress = 1;
9b58a7
+           this.showThrobberImage();
9b58a7
+           res = this.app.mgr.format_token(this.tokenInfo, DEF_TOKEN_TYPE, this.ldapUserBox.get_text(), "" /* pin */ ,this.ldapPasswordBox.get_text(),""
9b58a7
+               ); 
9b58a7
+
9b58a7
+        } else if(this.operation == OP_ENROLL) {
9b58a7
+           this.inProgress = true;
9b58a7
+           this.showThrobberImage();
9b58a7
+           res = this.app.mgr.enroll_token(this.tokenInfo, DEF_TOKEN_TYPE, this.ldapUserBox.get_text(), this.newpinBox.get_text() /* pin */ ,this.ldapPasswordBox.get_text(),""
9b58a7
+               );
9b58a7
+
9b58a7
+        } else if(this.operation == OP_PIN_RESET) {
9b58a7
+           this.inProgress = true;
9b58a7
+           this.showThrobberImage();
9b58a7
+           res = this.app.mgr.reset_token_pin(this.tokenInfo, DEF_TOKEN_TYPE, this.ldapUserBox.get_text(), this.newpinBox.get_text() /* pin */ ,this.ldapPasswordBox.get_text(),""
9b58a7
+               );
9b58a7
+
9b58a7
+        } else { 
9b58a7
+            this.app_alert("Invalid token operation!");
9b58a7
+        }
9b58a7
+    },
9b58a7
+
9b58a7
+    notify: function(aKeyType, aKeyID, aKeyState, aData, strData) {
9b58a7
+
9b58a7
+        this.onCoolKeyStateChange(aKeyType, aKeyID, aKeyState, aData, strData);
9b58a7
+        //print("notify: aKeyType: " + aKeyType + " aKeyID: " + aKeyID + " aKeyState: " + aKeyState + " aData: " + aData + " strDAta: " + strData);
9b58a7
+    }, 
9b58a7
+
9b58a7
+    onCoolKeyStateChange: function(keyType, keyID, keyState, data,strData) {
9b58a7
+
9b58a7
+        //this.app._alert("KeyID:    " + keyID + "\n" +
9b58a7
+        //      "KeyState: " + keyState + "\n" +
9b58a7
+        //      "Data:     " + data);
9b58a7
+        //this.app._alert("State Change ="+keyState);
9b58a7
+
9b58a7
+        switch(keyState)
9b58a7
+        {
9b58a7
+           case 1000: // KeyInserted
9b58a7
+               break;
9b58a7
+           case 1001: // KeyRemoved
9b58a7
+               break;
9b58a7
+           case 1002: // EnrollmentStart
9b58a7
+               this.inProgress = true;
9b58a7
+               break;
9b58a7
+           case 1003: // EnrollmentComplete
9b58a7
+               this.onCoolKeyEnrollmentComplete(keyType, keyID);
9b58a7
+               this.inProgress = false;
9b58a7
+               break;
9b58a7
+           case 1004: // EnrollmentError
9b58a7
+               this.inProgress = false;
9b58a7
+               this.onCoolKeyStateError(keyType, keyID, keyState, data);
9b58a7
+           break;
9b58a7
+          case 1008: // PINResetStart
9b58a7
+               this.inProgress = true;
9b58a7
+               break;
9b58a7
+          case 1009: // PINResetComplete
9b58a7
+              this.onCoolKeyPINResetComplete(keyType, keyID);
9b58a7
+              this.inProgress = false;
9b58a7
+              break;
9b58a7
+          case 1010: // PINResetError
9b58a7
+              this.onCoolKeyStateError(keyType, keyID, keyState, data);
9b58a7
+              this.inProgress = false;
9b58a7
+              break;
9b58a7
+          case 1014: // FormatStart
9b58a7
+              this.inProgress = true;
9b58a7
+              break;
9b58a7
+          case 1015: // FormatComplete
9b58a7
+              this.onCoolKeyFormatComplete(keyType, keyID);
9b58a7
+              this.inProgress = false;
9b58a7
+              break;
9b58a7
+          case 1016: // FormatError
9b58a7
+              this.onCoolKeyStateError(keyType, keyID, keyState, data);
9b58a7
+              this.inProgress = false;
9b58a7
+              break;
9b58a7
+          case 1017: // BlinkStatus Update?
9b58a7
+              break;
9b58a7
+          case 1018: 
9b58a7
+              break;
9b58a7
+          case 1020: // OperationCancelled
9b58a7
+              this.onCoolKeyStateError(keyType, keyID, keyState, data);
9b58a7
+              this.inProgress = false;
9b58a7
+          break;
9b58a7
+          case 1021: // OperationStatusUpdate
9b58a7
+              this.onCoolKeyStatusUpdate(keyType, keyID, data);
9b58a7
+          break;
9b58a7
+
9b58a7
+          case 1022: //Need Auth 
9b58a7
+              inProgress = false;
9b58a7
+              break;
9b58a7
+       }
9b58a7
+    },
9b58a7
+
9b58a7
+    onCoolKeyEnrollmentComplete: function(keyType, keyID) {
9b58a7
+        this.hideThrobberImage();
9b58a7
+        this.app._alert("Enrollment Succesfully Complete!");
9b58a7
+        this.app._updateCoolkey( this.tokenInfo);
9b58a7
+        this.dialog.destroy();
9b58a7
+        
9b58a7
+    },
9b58a7
+
9b58a7
+    onCoolKeyStateError: function(keyType, keyID, keyState, data) {
9b58a7
+        this.hideThrobberImage();
9b58a7
+        this.app._alert(OpLabels[this.operation] + " Error: " + this.app._getErrorMessage(data));
9b58a7
+
9b58a7
+        this.app._updateCoolkey( this.tokenInfo );
9b58a7
+        this.dialog.destroy();
9b58a7
+    },
9b58a7
+
9b58a7
+    onCoolKeyPINResetComplete: function(keyType, keyID) {
9b58a7
+        this.hideThrobberImage();
9b58a7
+        this.app._alert("Pin Reset Successfully Completed!");
9b58a7
+        this.dialog.destroy();
9b58a7
+    },
9b58a7
+
9b58a7
+    onCoolKeyFormatComplete: function(keyType, keyID) {
9b58a7
+       this.hideThrobberImage();
9b58a7
+       this.app._alert("Format Succesfully Completed!"); 
9b58a7
+       this.app._updateCoolkey(this.tokenInfo);
9b58a7
+       this.dialog.destroy();
9b58a7
+    },
9b58a7
+
9b58a7
+    onCoolKeyStatusUpdate: function(keyType, keyID, data) {
9b58a7
+
9b58a7
+        if(data) {
9b58a7
+            let  percent =  parseFloat(data);
9b58a7
+
9b58a7
+            this.progressBar.set_fraction( percent / 100);
9b58a7
+        }
9b58a7
+    }
9b58a7
+}
9b58a7
+
9b58a7
diff -up ./esc/src/app/phoneHome.js.fix4 ./esc/src/app/phoneHome.js
9b58a7
--- ./esc/src/app/phoneHome.js.fix4	2019-01-10 16:25:23.036167620 -0800
9b58a7
+++ ./esc/src/app/phoneHome.js	2019-01-10 16:25:43.978066779 -0800
9b58a7
@@ -0,0 +1,260 @@
9b58a7
+/** BEGIN COPYRIGHT BLOCK
9b58a7
+ * This Program is free software; you can redistribute it and/or modify it under
9b58a7
+ * the terms of the GNU General Public License as published by the Free Software
9b58a7
+ * Foundation; version 2 of the License.
9b58a7
+ *
9b58a7
+ * This Program is distributed in the hope that it will be useful, but WITHOUT
9b58a7
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9b58a7
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
9b58a7
+ *
9b58a7
+ * You should have received a copy of the GNU General Public License along with
9b58a7
+ * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
9b58a7
+ * Place, Suite 330, Boston, MA 02111-1307 USA.
9b58a7
+ *
9b58a7
+ * Copyright (C) 2005 Red Hat, Inc.
9b58a7
+ * All rights reserved.
9b58a7
+ * END COPYRIGHT BLOCK **/
9b58a7
+
9b58a7
+imports.gi.versions.Gtk = '3.0'
9b58a7
+const Gtk = imports.gi.Gtk;
9b58a7
+const Lang = imports.lang;
9b58a7
+const Gio = imports.gi.Gio;
9b58a7
+const GObject = imports.gi.GObject;
9b58a7
+const GLib = imports.gi.GLib;
9b58a7
+
9b58a7
+//Phone Home related Constants
9b58a7
+
9b58a7
+const  KEY_ISSUER_URL    = "keyIssuerUrl";
9b58a7
+const  KEY_ISSUER        = "keyIssuer";
9b58a7
+const  TPS_URL           = "Operation";
9b58a7
+const  TPS_UI            = "UI";
9b58a7
+const  SERVICES_TAG      = "Services";
9b58a7
+const  ISSUER_TAG        = "IssuerName";
9b58a7
+const  SERVICE_INFO_TAG  = "ServiceInfo";
9b58a7
+const  ENROLLED_TOKEN_BROWSER_URL = "EnrolledTokenBrowserURL";
9b58a7
+const  ENROLLED_TOKEN_URL = "EnrolledTokenURL";
9b58a7
+const  TOKEN_TYPE = "TokenType";
9b58a7
+const  RESET_PHONE_HOME  = "ResetPhoneHome";
9b58a7
+
9b58a7
+const  PHONE_HOME_CONFIG_INFO = "Phone Home Configuration Information";
9b58a7
+
9b58a7
+
9b58a7
+function phoneHome(app) {
9b58a7
+  if(!app)
9b58a7
+      return;
9b58a7
+  this.app = app;
9b58a7
+  this.url = "";
9b58a7
+  this.tokenType = "";
9b58a7
+  this.operationUrl = "";
9b58a7
+  this.enrolledTokenBrowserURL = "";
9b58a7
+  this.issuerName = "";
9b58a7
+}
9b58a7
+
9b58a7
+phoneHome.prototype = {
9b58a7
+    getPhoneHomeInfo: function(tokenInfo,forceUserInput) {
9b58a7
+        if(!tokenInfo && !forceUserInput) {
9b58a7
+            return null;
9b58a7
+        }
9b58a7
+
9b58a7
+        this.tokenInfo = tokenInfo;
9b58a7
+
9b58a7
+        if(!forceUserInput && this.tokenInfo.issuer_info != null) {
9b58a7
+            this.url = this.tokenInfo.issuerInfo;
9b58a7
+            this.getPhoneHomeFromServer(tokenInfo);
9b58a7
+        }  else { 
9b58a7
+            this.promptPhoneHomeURL();
9b58a7
+        }
9b58a7
+
9b58a7
+    },
9b58a7
+
9b58a7
+    getPhoneHomeFromServer: function(tokenInfo) {
9b58a7
+        if(!this.url || !tokenInfo) {
9b58a7
+            return;
9b58a7
+        }
9b58a7
+
9b58a7
+        this.phoneHomeInfo = this.app._phoneHome(this.url);
9b58a7
+        if(this.phoneHomeInfo) {
9b58a7
+           this.parse(this.phoneHomeInfo,tokenInfo);
9b58a7
+           this.app._alert("Phone Home Info Successfully Obtained!");
9b58a7
+        } else {
9b58a7
+           this.app._alert("Unable to obtain phone home info!");
9b58a7
+        }
9b58a7
+
9b58a7
+    },
9b58a7
+
9b58a7
+    promptPhoneHomeURL: function() {
9b58a7
+        this.createPhoneHomeDialog();
9b58a7
+    },
9b58a7
+
9b58a7
+    createPhoneHomeDialog: function() {
9b58a7
+        this.phDialog = new Gtk.Dialog ({ transient_for: this.app._window,
9b58a7
+                         modal: true,
9b58a7
+                         title: PHONE_HOME_CONFIG_INFO, border_width: 20 });
9b58a7
+
9b58a7
+        this.phArea = this.phDialog.get_content_area();
9b58a7
+        this.phMessage = new Gtk.Label ({label: "Enter url: ex: http://test.host.com:8080/tps/phoneHome"});
9b58a7
+        this.phArea.add (this.phMessage);
9b58a7
+
9b58a7
+        this.phActionArea = this.phDialog.get_action_area();
9b58a7
+        this.phUrlBox =  new Gtk.Entry({width_chars: 35});
9b58a7
+        this.phGrid = new Gtk.Grid ({halign: Gtk.Align.CENTER,
9b58a7
+                                     valign: Gtk.Align.CENTER,
9b58a7
+                                     row_spacing: 10, column_spacing: 10});
9b58a7
+
9b58a7
+        if(this.tokenInfo.issuer_info) {
9b58a7
+            this.phUrlBox.set_text(this.tokenInfo.issuer_info);
9b58a7
+        }
9b58a7
+
9b58a7
+        this.phActionArea.add(this.phGrid);
9b58a7
+
9b58a7
+        this.phOKButton = Gtk.Button.new_from_stock (Gtk.STOCK_OK);
9b58a7
+
9b58a7
+        this.phGrid.attach(this.phUrlBox, 0, 0, 1,1);
9b58a7
+        this.phGrid.attach(this.phOKButton,1, 0,1,1);
9b58a7
+
9b58a7
+        // Connect the button to the function that handles what it does
9b58a7
+        this.phOKButton.connect ("clicked", this.phoneHomeOKHandler.bind(this));
9b58a7
+
9b58a7
+        this.phDialog.show_all();
9b58a7
+    },
9b58a7
+
9b58a7
+    phoneHomeOKHandler: function() {
9b58a7
+
9b58a7
+        this.url = this.phUrlBox.get_text();
9b58a7
+
9b58a7
+        this.getPhoneHomeFromServer(this.tokenInfo);
9b58a7
+
9b58a7
+        if(this.phDialog) { 
9b58a7
+            this.phDialog.destroy();
9b58a7
+            this.phDialog = null;
9b58a7
+        }
9b58a7
+    }, 
9b58a7
+
9b58a7
+    parse: function(info,tokenInfo) {
9b58a7
+        if(!info) {
9b58a7
+            return;
9b58a7
+        }
9b58a7
+        //Find tokenType
9b58a7
+
9b58a7
+        this.tokenType = this.findValue(info,"<TokenType>","</TokenType>");
9b58a7
+        this.operationUrl = this.findValue(info,"<Operation>","</Operation>");
9b58a7
+        this.enrolledTokenBrowserURL = this.findValue(info,"<EnrolledTokenBrowserURL","</EnrolledTokenBrowserURL>");
9b58a7
+        this.issuerName = this.findValue(info,"<IssuerName>","</IssuerName>");       
9b58a7
+
9b58a7
+        let key_issuer_url = this.app._configValueWithKeyID(tokenInfo.cuid,KEY_ISSUER_URL);
9b58a7
+        this.app._setConfigValue(key_issuer_url,this.url);
9b58a7
+
9b58a7
+        let key_issuer = this.app._configValueWithKeyID(tokenInfo.cuid,KEY_ISSUER); 
9b58a7
+        this.app._setConfigValue(key_issuer,this.issuerName);
9b58a7
+
9b58a7
+        let operation_url = this.app._configValueWithKeyID(tokenInfo.cuid,TPS_URL);
9b58a7
+        this.app._setConfigValue(operation_url,this.operationUrl);
9b58a7
+
9b58a7
+        let enrolled_token_browser_url = this.app._configValueWithKeyID(tokenInfo.cuid,ENROLLED_TOKEN_BROWSER_URL);
9b58a7
+        this.app._setConfigValue(enrolled_token_browser_url, this.enrolledTokenBrowserURL);
9b58a7
+
9b58a7
+        let token_type = this.app._configValueWithKeyID(tokenInfo.cuid,TOKEN_TYPE);
9b58a7
+        this.app._setConfigValue(token_type, this.tokenType);
9b58a7
+    },
9b58a7
+
9b58a7
+    findValue: function(fullString, startTag, endTag) {
9b58a7
+        if(!fullString || !startTag || !endTag) {
9b58a7
+           return null;
9b58a7
+        }
9b58a7
+
9b58a7
+        let spos = fullString.search(startTag) + startTag.length;
9b58a7
+        let epos = fullString.search(endTag);
9b58a7
+
9b58a7
+        let value = fullString.slice(spos,epos);
9b58a7
+
9b58a7
+        if(value) {
9b58a7
+            return value.trim();
9b58a7
+        }
9b58a7
+
9b58a7
+        return null;
9b58a7
+    },
9b58a7
+
9b58a7
+    getTokenType: function() {
9b58a7
+        return this.tokenType;
9b58a7
+    },
9b58a7
+
9b58a7
+    getOperationURL: function() {
9b58a7
+        return this.operationURL;
9b58a7
+    },
9b58a7
+
9b58a7
+    getEnrolledTokenBrowserURL: function() {
9b58a7
+        return this.enrolledTokenBrowserURL;
9b58a7
+    },
9b58a7
+
9b58a7
+    getIssuerName: function() {
9b58a7
+        return this.issuerName;
9b58a7
+    },
9b58a7
+
9b58a7
+    getCachedPhoneHomeValue: function(aKeyID,aValue) {
9b58a7
+        var retValue = null;
9b58a7
+
9b58a7
+        if(!aKeyID || ! aValue)
9b58a7
+            return null;
9b58a7
+
9b58a7
+        var theValue = this.app._configValueWithKeyID(aKeyID,aValue);
9b58a7
+
9b58a7
+        if(!theValue)
9b58a7
+            return null;
9b58a7
+
9b58a7
+         retValue = this.app._getConfigValue(theValue);
9b58a7
+
9b58a7
+         return retValue;
9b58a7
+    },
9b58a7
+
9b58a7
+    getCachedPhoneHomeURL: function(aKeyID) {
9b58a7
+        var url = null;
9b58a7
+
9b58a7
+         if(!aKeyID)
9b58a7
+             return null;
9b58a7
+
9b58a7
+         var urlValue = this.app._configValueWithKeyID(aKeyID,KEY_ISSUER_URL);
9b58a7
+
9b58a7
+         if(!urlValue)
9b58a7
+             return null;
9b58a7
+
9b58a7
+         url = this.app._getConfigValue(urlValue);
9b58a7
+
9b58a7
+         return url;
9b58a7
+    },
9b58a7
+
9b58a7
+    getCachedIssuer: function(aKeyID) {
9b58a7
+        var issuer = null;
9b58a7
+
9b58a7
+        if(!aKeyID)
9b58a7
+            return null;
9b58a7
+
9b58a7
+        var issuerValue = this.app._configValueWithKeyID(aKeyID,KEY_ISSUER);
9b58a7
+
9b58a7
+        if(!issuerValue)
9b58a7
+            return null;
9b58a7
+
9b58a7
+        issuer = this.app._getConfigValue(issuerValue);
9b58a7
+
9b58a7
+        return issuer;
9b58a7
+    },
9b58a7
+
9b58a7
+    getCachedTPSURL: function(aKeyID) {
9b58a7
+        var url = null;
9b58a7
+
9b58a7
+        if(!aKeyID)
9b58a7
+            return null;
9b58a7
+
9b58a7
+         var urlValue = this.app_.configValueWithKeyID(aKeyID,TPS_URL);
9b58a7
+
9b58a7
+         if(!urlValue)
9b58a7
+             return null;
9b58a7
+
9b58a7
+         url = this.app._getConfigValue(urlValue);
9b58a7
+
9b58a7
+         return url;
9b58a7
+    },
9b58a7
+
9b58a7
+    getCachedTokenType: function(aKeyID) {
9b58a7
+        return getCachedPhoneHomeValue(aKeyID,TOKEN_TYPE);
9b58a7
+    }
9b58a7
+}
9b58a7
diff -up ./esc/src/app/pinDialog.js.fix4 ./esc/src/app/pinDialog.js
9b58a7
--- ./esc/src/app/pinDialog.js.fix4	2019-01-10 16:26:01.510982356 -0800
9b58a7
+++ ./esc/src/app/pinDialog.js	2019-01-10 16:26:11.322935109 -0800
9b58a7
@@ -0,0 +1,109 @@
9b58a7
+/** BEGIN COPYRIGHT BLOCK
9b58a7
+ * This Program is free software; you can redistribute it and/or modify it under
9b58a7
+ * the terms of the GNU General Public License as published by the Free Software
9b58a7
+ * Foundation; version 2 of the License.
9b58a7
+ *    
9b58a7
+ * This Program is distributed in the hope that it will be useful, but WITHOUT
9b58a7
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9b58a7
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
9b58a7
+ *
9b58a7
+ * You should have received a copy of the GNU General Public License along with
9b58a7
+ * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
9b58a7
+ * Place, Suite 330, Boston, MA 02111-1307 USA.
9b58a7
+ *
9b58a7
+ * Copyright (C) 2005 Red Hat, Inc.
9b58a7
+ * All rights reserved.
9b58a7
+ * END COPYRIGHT BLOCK **/
9b58a7
+
9b58a7
+imports.gi.versions.Gtk = '3.0'
9b58a7
+const Gtk = imports.gi.Gtk;
9b58a7
+const Lang = imports.lang;
9b58a7
+const Gio = imports.gi.Gio;
9b58a7
+const GObject = imports.gi.GObject;
9b58a7
+const GLib = imports.gi.GLib;
9b58a7
+
9b58a7
+
9b58a7
+const TMP_FILE_NAME = "v135tr";
9b58a7
+const PIN_OPERATION = "Password";
9b58a7
+
9b58a7
+function pinDialog(app) {
9b58a7
+  if(!app)
9b58a7
+      return;
9b58a7
+  this.app = app;
9b58a7
+}
9b58a7
+
9b58a7
+pinDialog.prototype = {
9b58a7
+    launchPinPrompt: function(notify) {
9b58a7
+
9b58a7
+        this.notify = notify;
9b58a7
+        this.dialog = new Gtk.Dialog ({ transient_for: this.app._window,
9b58a7
+                         modal: true,
9b58a7
+                         expand: false,
9b58a7
+                         title: PIN_OPERATION ,border_width: 20, deletable: false });
9b58a7
+
9b58a7
+        this.area = this.dialog.get_content_area();
9b58a7
+        this.grid = new Gtk.Grid ({row_spacing: 10, column_spacing: 20});
9b58a7
+
9b58a7
+        this.message = new Gtk.Label ({label: "Enter Token Pin"});
9b58a7
+        this.area.add (this.message);
9b58a7
+
9b58a7
+        this.actionArea = this.dialog.get_action_area();
9b58a7
+        this.pinBox =  new Gtk.Entry();
9b58a7
+        this.pinBox.set_visibility(false);
9b58a7
+        this.grid.add(this.pinBox);
9b58a7
+        this.oKButton = Gtk.Button.new_from_stock (Gtk.STOCK_OK);
9b58a7
+        this.grid.add (this.oKButton);
9b58a7
+
9b58a7
+        this.actionArea.add(this.grid);
9b58a7
+
9b58a7
+        // Connect the button to the function that handles what it does
9b58a7
+        this.oKButton.connect ("clicked", this.oKHandler.bind(this));
9b58a7
+
9b58a7
+        this.dialog.show_all();
9b58a7
+    },
9b58a7
+
9b58a7
+    clearTempFile() {
9b58a7
+        this.saveToTempFile(this.tempFileName,true);
9b58a7
+    },
9b58a7
+
9b58a7
+    saveToTempFile(name,clear) {
9b58a7
+
9b58a7
+        if (name == null) {
9b58a7
+            return null;
9b58a7
+        }
9b58a7
+
9b58a7
+        let contents = "";
9b58a7
+
9b58a7
+        if(clear == false)
9b58a7
+            contents = this.pinBox.get_text();
9b58a7
+        else
9b58a7
+            contents = "";
9b58a7
+
9b58a7
+        try {
9b58a7
+            GLib.file_set_contents(name , contents);
9b58a7
+        } catch(e) {
9b58a7
+            return null;
9b58a7
+        }
9b58a7
+
9b58a7
+
9b58a7
+    },
9b58a7
+
9b58a7
+    oKHandler: function() {
9b58a7
+        if(this.dialog) {
9b58a7
+            this.tempFileName = this.app._getConfigPath() + "/"  + TMP_FILE_NAME; 
9b58a7
+            this.saveToTempFile(this.tempFileName,false);
9b58a7
+            if(this.notify) {
9b58a7
+                this.notify(this.tempFileName);
9b58a7
+            }
9b58a7
+
9b58a7
+            this.clearTempFile();
9b58a7
+            this.dialog.destroy();
9b58a7
+            this.dialog = null;
9b58a7
+        }
9b58a7
+    },
9b58a7
+    getTempFileName() {
9b58a7
+        return this.tempFileName;
9b58a7
+
9b58a7
+   }
9b58a7
+}
9b58a7
+
9b58a7
diff -up ./esc/src/lib/coolkey/cky_base.h.fix4 ./esc/src/lib/coolkey/cky_base.h
9b58a7
--- ./esc/src/lib/coolkey/cky_base.h.fix4	2019-01-10 16:32:37.132077352 -0800
9b58a7
+++ ./esc/src/lib/coolkey/cky_base.h	2019-01-10 16:32:51.426008523 -0800
9b58a7
@@ -19,7 +19,6 @@
9b58a7
 
9b58a7
 #ifndef CKY_BASE_H
9b58a7
 #define CKY_BASE_H 1
9b58a7
-
9b58a7
 /*
9b58a7
  * Common types and structs
9b58a7
  */
9b58a7
@@ -34,19 +33,15 @@ typedef unsigned char CKYBool;
9b58a7
 
9b58a7
 typedef unsigned long CKYBitFlags;
9b58a7
 
9b58a7
-#define CKYBUFFER_PUBLIC \
9b58a7
-    unsigned long reserved1;\
9b58a7
-    unsigned long reserved2;\
9b58a7
-    void *reserved3;\
9b58a7
-    void *reserved4;
9b58a7
-
9b58a7
-#define CKYAPDU_PUBLIC \
9b58a7
-    unsigned long reserved1;\
9b58a7
-    unsigned long reserved2;\
9b58a7
-    void *reserved3;\
9b58a7
-    void *reserved4; \
9b58a7
-    void *reserved5;
9b58a7
-
9b58a7
+#define CKYBUFFER_PRIVATE \
9b58a7
+    CKYSize len; \
9b58a7
+    CKYSize size; \
9b58a7
+    CKYByte *data; \
9b58a7
+    void   *reserved;
9b58a7
+
9b58a7
+#define CKYAPDU_PRIVATE \
9b58a7
+    CKYBuffer apduBuf; \
9b58a7
+    void *reserved;
9b58a7
 
9b58a7
 typedef struct _CKYBuffer {
9b58a7
 #ifdef CKYBUFFER_PRIVATE
9b58a7
diff -up ./esc/src/lib/coolkey/cky_basei.h.fix4 ./esc/src/lib/coolkey/cky_basei.h
9b58a7
--- ./esc/src/lib/coolkey/cky_basei.h.fix4	2019-01-10 16:33:28.080832022 -0800
9b58a7
+++ ./esc/src/lib/coolkey/cky_basei.h	2019-01-10 16:33:48.463733874 -0800
9b58a7
@@ -21,15 +21,18 @@
9b58a7
 #ifndef CKY_BASEI_H
9b58a7
 #define CKY_BASEI_H 1
9b58a7
 
9b58a7
-#define CKYBUFFER_PRIVATE \
9b58a7
-    CKYSize len; \
9b58a7
-    CKYSize size; \
9b58a7
-    CKYByte *data; \
9b58a7
-    void   *reserved; 
9b58a7
+#define CKYBUFFER_PUBLIC \
9b58a7
+    unsigned long reserved1;\
9b58a7
+    unsigned long reserved2;\
9b58a7
+    void *reserved3;\
9b58a7
+    void *reserved4;
9b58a7
 
9b58a7
-#define CKYAPDU_PRIVATE \
9b58a7
-    CKYBuffer apduBuf; \
9b58a7
-    void *reserved;
9b58a7
+#define CKYAPDU_PUBLIC \
9b58a7
+    unsigned long reserved1;\
9b58a7
+    unsigned long reserved2;\
9b58a7
+    void *reserved3;\
9b58a7
+    void *reserved4; \
9b58a7
+    void *reserved5;
9b58a7
     
9b58a7
 #endif /* CKY_BASE_H */
9b58a7
 #endif /* CKY_BASEI_H */
9b58a7
diff -up ./esc/src/lib/coolkey/cky_card.c.fix4 ./esc/src/lib/coolkey/cky_card.c
9b58a7
--- ./esc/src/lib/coolkey/cky_card.c.fix4	2019-01-10 16:34:10.863626014 -0800
9b58a7
+++ ./esc/src/lib/coolkey/cky_card.c	2019-01-10 16:34:31.326527479 -0800
9b58a7
@@ -973,6 +973,24 @@ CKYCardConnection_Disconnect(CKYCardConn
9b58a7
     return CKYSUCCESS;
9b58a7
 }
9b58a7
 
9b58a7
+CKYStatus
9b58a7
+CKYCardConnection_Eject(CKYCardConnection *conn)
9b58a7
+{
9b58a7
+    unsigned long rv;
9b58a7
+    if (conn->cardHandle == 0) {
9b58a7
+        return CKYSUCCESS;
9b58a7
+    }
9b58a7
+    rv = conn->scard->SCardDisconnect( conn->cardHandle, SCARD_EJECT_CARD);
9b58a7
+    conn->cardHandle = 0;
9b58a7
+    if (rv != SCARD_S_SUCCESS) {
9b58a7
+        conn->lastError = rv;
9b58a7
+        return CKYSCARDERR;
9b58a7
+    }
9b58a7
+    return CKYSUCCESS;
9b58a7
+}
9b58a7
+
9b58a7
+
9b58a7
+
9b58a7
 CKYBool 
9b58a7
 CKYCardConnection_IsConnected(const CKYCardConnection *conn)
9b58a7
 {
9b58a7
@@ -988,8 +1006,8 @@ CKYCardConnection_GetProtocol(const CKYC
9b58a7
 CKYStatus 
9b58a7
 ckyCardConnection_reconnectRaw(CKYCardConnection *conn, unsigned long init)
9b58a7
 {
9b58a7
-    unsigned long rv;
9b58a7
-    unsigned long protocol;
9b58a7
+    unsigned long rv = CKYSUCCESS;
9b58a7
+    unsigned long protocol = 0;
9b58a7
 
9b58a7
     rv = conn->scard->SCardReconnect(conn->cardHandle,
9b58a7
 	SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1 , init, &protocol);
9b58a7
@@ -1120,11 +1138,11 @@ CKYCardConnection_GetStatus(CKYCardConne
9b58a7
 				unsigned long *state, CKYBuffer *ATR)
9b58a7
 {
9b58a7
     unsigned long readerLen = 0;
9b58a7
-    unsigned long protocol;
9b58a7
-    unsigned long rv;
9b58a7
-    CKYSize atrLen;
9b58a7
-    char *readerStr;
9b58a7
-    CKYStatus ret;
9b58a7
+    unsigned long protocol = 0;
9b58a7
+    unsigned long rv = 0;
9b58a7
+    CKYSize atrLen = 0;
9b58a7
+    char *readerStr = NULL;
9b58a7
+    CKYStatus ret = CKYSUCCESS;
9b58a7
 
9b58a7
 
9b58a7
     /*
9b58a7
diff -up ./esc/src/lib/coolkey/cky_card.h.fix4 ./esc/src/lib/coolkey/cky_card.h
9b58a7
--- ./esc/src/lib/coolkey/cky_card.h.fix4	2019-01-10 16:35:49.381151632 -0800
9b58a7
+++ ./esc/src/lib/coolkey/cky_card.h	2019-01-10 16:35:54.632126347 -0800
9b58a7
@@ -116,6 +116,7 @@ CKYStatus CKYCardConnection_ExchangeAPDU
9b58a7
 CKYStatus CKYCardConnection_Connect(CKYCardConnection *connection, 
9b58a7
 					const char *readerName);
9b58a7
 CKYStatus CKYCardConnection_Disconnect(CKYCardConnection *connection);
9b58a7
+CKYStatus CKYCardConnection_Eject(CKYCardConnection *connection);
9b58a7
 unsigned long CKYCardConnection_GetProtocol(const CKYCardConnection *conn);
9b58a7
 CKYBool CKYCardConnection_IsConnected(const CKYCardConnection *connection);
9b58a7
 CKYStatus CKYCardConnection_Reconnect(CKYCardConnection *connection);
9b58a7
diff -up ./esc/src/lib/coolkey/CoolKey.cpp.fix4 ./esc/src/lib/coolkey/CoolKey.cpp
9b58a7
--- ./esc/src/lib/coolkey/CoolKey.cpp.fix4	2019-01-10 16:36:29.910956473 -0800
9b58a7
+++ ./esc/src/lib/coolkey/CoolKey.cpp	2019-01-10 16:36:44.046888406 -0800
9b58a7
@@ -257,6 +257,7 @@ static CoolKeyReference g_Reference = NU
9b58a7
 static CoolKeyRelease g_Release = NULL;
9b58a7
 static CoolKeyGetConfigValue g_GetConfigValue = NULL;
9b58a7
 static CoolKeySetConfigValue g_SetConfigValue = NULL;
9b58a7
+static CoolKeyFreeConfigValue g_FreeConfigValue = NULL;
9b58a7
 static CoolKeyBadCertHandler g_BadCertHandler = NULL;
9b58a7
 
9b58a7
 char* CoolKeyVerifyPassword(PK11SlotInfo *,PRBool,void *);
9b58a7
@@ -264,6 +265,7 @@ char* CoolKeyVerifyPassword(PK11SlotInfo
9b58a7
 COOLKEY_API HRESULT CoolKeySetCallbacks(CoolKeyDispatch dispatch,
9b58a7
 	CoolKeyReference reference, CoolKeyRelease release,
9b58a7
         CoolKeyGetConfigValue getconfigvalue,CoolKeySetConfigValue setconfigvalue,
9b58a7
+        CoolKeyFreeConfigValue freeconfigvalue,
9b58a7
         CoolKeyBadCertHandler badcerthandler)
9b58a7
 {
9b58a7
     char tBuff[56];
9b58a7
@@ -271,6 +273,7 @@ COOLKEY_API HRESULT CoolKeySetCallbacks(
9b58a7
     g_Reference = reference;
9b58a7
     g_Release = release;
9b58a7
     g_GetConfigValue = getconfigvalue;
9b58a7
+    g_FreeConfigValue = freeconfigvalue;
9b58a7
     g_SetConfigValue = setconfigvalue;
9b58a7
     g_BadCertHandler = badcerthandler;
9b58a7
 
9b58a7
@@ -293,7 +296,7 @@ COOLKEY_API HRESULT CoolKeySetCallbacks(
9b58a7
 
9b58a7
 #define RELEASE_LISTENER(list) \
9b58a7
   if (list) { \
9b58a7
-    (*g_Reference)(list); \
9b58a7
+    (*g_Release)(list); \
9b58a7
   }
9b58a7
 
9b58a7
 char *CoolKeyVerifyPassword(PK11SlotInfo *slot,PRBool retry,void *arg)
9b58a7
@@ -728,6 +731,30 @@ HRESULT CoolKeyGetCPLCDataDirectly(CKYAp
9b58a7
     return result;
9b58a7
 }
9b58a7
 
9b58a7
+char *CoolKeyGetPhoneHomeData(const char *url) {
9b58a7
+
9b58a7
+	string host_port = "";
9b58a7
+	string urlOffset = "";
9b58a7
+	string hostName = "";
9b58a7
+	int isSSL = 0;
9b58a7
+
9b58a7
+	NSS_HTTP_HANDLE http_handle = httpAllocateClient();
9b58a7
+
9b58a7
+	string fullUrl = url;
9b58a7
+
9b58a7
+	int portNum = 80;
9b58a7
+
9b58a7
+	CoolKeyHandler::ExtractFromUrl(fullUrl, host_port, urlOffset, hostName,
9b58a7
+			&isSSL, &portNum);
9b58a7
+
9b58a7
+	char *result = httpSend((char *) host_port.c_str(), url, (char *) "GET",
9b58a7
+			NULL, http_handle,/* mSSL */
9b58a7
+			PR_FALSE, 30);
9b58a7
+
9b58a7
+        httpDestroyClient(http_handle);
9b58a7
+	return result;
9b58a7
+}
9b58a7
+
9b58a7
 
9b58a7
 static std::list<ActiveKeyNode *> g_ActiveKeyList;
9b58a7
 
9b58a7
@@ -990,7 +1017,7 @@ HRESULT CoolKeyEnrollToken(const CoolKey
9b58a7
         return hres;
9b58a7
     }
9b58a7
   
9b58a7
-    CoolKeyNotify(aKey, eCKState_EnrollmentStart, aScreenName ? 1 : 0);
9b58a7
+    //CoolKeyNotify(aKey, eCKState_EnrollmentStart, aScreenName ? 1 : 0);
9b58a7
   
9b58a7
     return S_OK;
9b58a7
 }
9b58a7
@@ -1040,7 +1067,7 @@ HRESULT CoolKeyResetTokenPIN(const CoolK
9b58a7
         return hres;
9b58a7
     }
9b58a7
   
9b58a7
-    CoolKeyNotify(aKey, eCKState_PINResetStart, aScreenName ? 1 : 0);
9b58a7
+    //CoolKeyNotify(aKey, eCKState_PINResetStart, aScreenName ? 1 : 0);
9b58a7
   
9b58a7
     return S_OK;
9b58a7
 }
9b58a7
@@ -1091,7 +1118,7 @@ HRESULT CoolKeyFormatToken(const CoolKey
9b58a7
         return hres;
9b58a7
     }
9b58a7
   
9b58a7
-    CoolKeyNotify(aKey, eCKState_FormatStart, 0);
9b58a7
+    //CoolKeyNotify(aKey, eCKState_FormatStart, 0);
9b58a7
   
9b58a7
     return S_OK;
9b58a7
 }
9b58a7
@@ -1568,6 +1595,16 @@ const char *CoolKeyGetConfig(const char
9b58a7
     return res;
9b58a7
 }
9b58a7
 
9b58a7
+void CoolKeyFreeConfig(const char *aValue) 
9b58a7
+{
9b58a7
+    if(!g_FreeConfigValue || ! aValue)
9b58a7
+    {
9b58a7
+        return;
9b58a7
+    }
9b58a7
+
9b58a7
+    (*g_FreeConfigValue)(aValue);
9b58a7
+}
9b58a7
+
9b58a7
 HRESULT     CoolKeySetConfig(const char *aName,const char *aValue)
9b58a7
 {
9b58a7
     if( !aName || !aValue)
9b58a7
diff -up ./esc/src/lib/coolkey/CoolKeyHandler.cpp.fix4 ./esc/src/lib/coolkey/CoolKeyHandler.cpp
9b58a7
--- ./esc/src/lib/coolkey/CoolKeyHandler.cpp.fix4	2019-01-10 16:37:47.556582593 -0800
9b58a7
+++ ./esc/src/lib/coolkey/CoolKeyHandler.cpp	2019-01-10 16:37:56.118541366 -0800
9b58a7
@@ -378,8 +378,8 @@ CoolKeyHandler::~CoolKeyHandler()
9b58a7
     if(mCharScreenNamePwd)
9b58a7
     {
9b58a7
         PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s CoolKeyHandler::~CoolKeyHandler: attempt to  free mCharScreenNamePwd\n",GetTStamp(tBuff,56)));  
9b58a7
-        mCharScreenNamePwd = NULL;
9b58a7
         free(mCharScreenNamePwd);
9b58a7
+        mCharScreenNamePwd = NULL;
9b58a7
 
9b58a7
         PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s CoolKeyHandler::~CoolKeyHandler: done free mCharScreenNamePwd\n",GetTStamp(tBuff,56)));
9b58a7
 
9b58a7
@@ -570,6 +570,104 @@ HRESULT CoolKeyHandler::Init(const CoolK
9b58a7
     return S_OK;
9b58a7
 }
9b58a7
 
9b58a7
+void CoolKeyHandler::ExtractFromUrl(string &fullUrl, string &host_port, string &url, string &hostName, int *isSSL,
9b58a7
+		int *portNum) {
9b58a7
+
9b58a7
+	if (isSSL == NULL || portNum == NULL) {
9b58a7
+		return;
9b58a7
+	}
9b58a7
+
9b58a7
+	char tBuff[56];
9b58a7
+	string ssl_str = "https://";
9b58a7
+	string non_ssl_str = "http://";
9b58a7
+
9b58a7
+	size_t pos = fullUrl.find(ssl_str, 0);
9b58a7
+
9b58a7
+	*isSSL = 0;
9b58a7
+
9b58a7
+	if (pos == 0) {
9b58a7
+		pos += ssl_str.length();
9b58a7
+		*isSSL = 1;
9b58a7
+	} else {
9b58a7
+		pos = fullUrl.find(non_ssl_str, 0);
9b58a7
+		if (pos == string::npos) {
9b58a7
+			return;
9b58a7
+		}
9b58a7
+
9b58a7
+		pos += non_ssl_str.length();
9b58a7
+
9b58a7
+	}
9b58a7
+
9b58a7
+	// Now grab the host name and host port from the tps url
9b58a7
+
9b58a7
+	string host_name_port_str = "";
9b58a7
+	string slash_str = "/";
9b58a7
+
9b58a7
+	size_t end_host_port_pos = fullUrl.find(slash_str, pos);
9b58a7
+	size_t end_host_port_count = 0;
9b58a7
+
9b58a7
+	if (end_host_port_pos == string::npos) {
9b58a7
+		end_host_port_count = fullUrl.length() - pos;
9b58a7
+	} else {
9b58a7
+		end_host_port_count = end_host_port_pos - pos;
9b58a7
+	}
9b58a7
+
9b58a7
+	string tps_url_offset = fullUrl.substr(end_host_port_pos);
9b58a7
+
9b58a7
+	if (!tps_url_offset.length()) {
9b58a7
+		PR_LOG(coolKeyLogHN, PR_LOG_DEBUG,
9b58a7
+				("%s CoolKeyHandler::ExtractFromUrl NULL tps_url_offset string!.\n",GetTStamp(tBuff,56)));
9b58a7
+		return;
9b58a7
+	}
9b58a7
+
9b58a7
+	url = tps_url_offset;
9b58a7
+
9b58a7
+	PR_LOG(coolKeyLogHN, PR_LOG_DEBUG,
9b58a7
+			("%s CoolKeyHandler::ExtractFromUrl  tps_url_offset string! %s.\n",GetTStamp(tBuff,56),tps_url_offset.c_str()));
9b58a7
+
9b58a7
+	host_port = fullUrl.substr(pos, end_host_port_count);
9b58a7
+
9b58a7
+	if (!host_port.length()) {
9b58a7
+		CoolKeyLogMsg(PR_LOG_ERROR,
9b58a7
+				"%s ExtractFromUrl.  Bad hostname and port value!.\n",
9b58a7
+				GetTStamp(tBuff, 56));
9b58a7
+		return;
9b58a7
+	}
9b58a7
+
9b58a7
+	PR_LOG(coolKeyLogHN, PR_LOG_DEBUG,
9b58a7
+			("%s CoolKeyHandler::ExtractFromUrl host_name_port %s.\n",GetTStamp(tBuff,56),host_port.c_str()));
9b58a7
+
9b58a7
+	string delim = ":";
9b58a7
+	string port_num_str = "";
9b58a7
+
9b58a7
+	size_t delimPos = host_port.find(delim, 0);
9b58a7
+
9b58a7
+	if (delimPos == string::npos) {
9b58a7
+		*portNum = 80;
9b58a7
+		hostName = host_port;
9b58a7
+		PR_LOG(coolKeyLogHN, PR_LOG_DEBUG,
9b58a7
+				("%s CoolKeyHandler::ExtractFromUrl no port number assuming 80!.\n",GetTStamp(tBuff,56)));
9b58a7
+	} else {
9b58a7
+		port_num_str = host_port.substr(delimPos + 1);
9b58a7
+		hostName = host_port.substr(0, delimPos);
9b58a7
+		PR_LOG(coolKeyLogHN, PR_LOG_DEBUG,
9b58a7
+				("%s CoolKeyHandler::ExtractFromUrl mCharHostName %s!.\n",hostName.c_str(),GetTStamp(tBuff,56)));
9b58a7
+
9b58a7
+	}
9b58a7
+
9b58a7
+	if (port_num_str.length()) {
9b58a7
+		*portNum = atoi(port_num_str.c_str());
9b58a7
+
9b58a7
+
9b58a7
+		PR_LOG(coolKeyLogHN, PR_LOG_DEBUG,
9b58a7
+				("%s CoolKeyHandler::ExtractFromUrl port_num_str %s.\n",GetTStamp(tBuff,56),port_num_str.c_str()));
9b58a7
+	}
9b58a7
+
9b58a7
+	PR_LOG(coolKeyLogHN, PR_LOG_DEBUG,
9b58a7
+			("%s CoolKeyHandler::ExtractFromUrl port number %d.\n",GetTStamp(tBuff,56),*portNum));
9b58a7
+
9b58a7
+}
9b58a7
+
9b58a7
 void CoolKeyHandler::CollectPreferences()
9b58a7
 {
9b58a7
     char tBuff[56];
9b58a7
@@ -590,12 +688,15 @@ void CoolKeyHandler::CollectPreferences(
9b58a7
 
9b58a7
     //Quickly grab the configurable http message timeout
9b58a7
 
9b58a7
+    const char *tps_url = NULL;
9b58a7
     const char *msg_timeout = CoolKeyGetConfig("esc.tps.message.timeout");
9b58a7
 
9b58a7
     if(msg_timeout)
9b58a7
     {
9b58a7
         httpMessageTimeout = atoi(msg_timeout);
9b58a7
 
9b58a7
+        CoolKeyFreeConfig(msg_timeout);
9b58a7
+        
9b58a7
         PR_LOG( coolKeyLogHN, PR_LOG_DEBUG,("%s CoolKeyHandler::CollectPreferences! Message timeout %d\n",GetTStamp(tBuff,56),httpMessageTimeout));
9b58a7
 
9b58a7
     }
9b58a7
@@ -611,7 +712,7 @@ void CoolKeyHandler::CollectPreferences(
9b58a7
     const char *tps_url_for_key_str = tps_url_for_key.c_str();
9b58a7
 
9b58a7
     PR_LOG( coolKeyLogHN, PR_LOG_DEBUG,("%s CoolKeyHandler::CollectPreferences! tps_url %s\n",GetTStamp(tBuff,56),tps_url_for_key_str)); 
9b58a7
-    const char *tps_url = CoolKeyGetConfig(tps_url_for_key_str);
9b58a7
+    tps_url = CoolKeyGetConfig(tps_url_for_key_str);
9b58a7
 
9b58a7
     if(!tps_url)
9b58a7
     {
9b58a7
@@ -625,12 +726,15 @@ void CoolKeyHandler::CollectPreferences(
9b58a7
 
9b58a7
             return;
9b58a7
         }
9b58a7
+
9b58a7
     }
9b58a7
 
9b58a7
     PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s CoolKeyHandler::CollectPreferences esc.tps.url %s\n",GetTStamp(tBuff,56),tps_url));
9b58a7
 
9b58a7
     string tps_url_str = tps_url;
9b58a7
 
9b58a7
+    CoolKeyFreeConfig(tps_url);
9b58a7
+
9b58a7
     // determine whether or not we are SSL
9b58a7
 
9b58a7
     string ssl_str =     "https://";
9b58a7
@@ -926,7 +1030,7 @@ HRESULT CoolKeyHandler::Format( const ch
9b58a7
     HRESULT res = S_OK;
9b58a7
 
9b58a7
     PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s CoolKeyHandler::Format:\n",GetTStamp(tBuff,56)));  
9b58a7
-  
9b58a7
+ 
9b58a7
     if(aTokenType)
9b58a7
         mCharTokenType = strdup(aTokenType);
9b58a7
 
9b58a7
@@ -1986,7 +2090,7 @@ CoolKeyHandler::DisconnectFromReader()
9b58a7
     char tBuff[56];
9b58a7
     PR_LOG( coolKeyLogHN, PR_LOG_DEBUG, ("%s CoolKeyHandler::DisconnectFromReader:\n",GetTStamp(tBuff,56)));
9b58a7
     if (mCardConnection) {
9b58a7
-        CKYCardConnection_Disconnect(mCardConnection);
9b58a7
+        CKYCardConnection_Eject(mCardConnection);
9b58a7
         CKYCardConnection_Destroy(mCardConnection);
9b58a7
         mCardConnection = 0;
9b58a7
     }
9b58a7
@@ -2164,9 +2268,9 @@ CKHGetCoolKeyInfo(PK11SlotInfo *aSlot,Co
9b58a7
     // Since we are configured to only be notified of coolkey's, cac's and piv's
9b58a7
     // non blank coolkeys will be identified by NOT being cac or piv in the manu id field.
9b58a7
 
9b58a7
-    if(!strcmp((const char *) tokenInfo.manufacturerID,cac_manu_id)) {
9b58a7
+    if(!memcmp( tokenInfo.manufacturerID,cac_manu_id,strlen(cac_manu_id ))) {
9b58a7
         isACAC = 1;
9b58a7
-    } else if(!strcmp((const char *) tokenInfo.manufacturerID, piv_manu_id)) {
9b58a7
+    } else if(!memcmp(tokenInfo.manufacturerID, piv_manu_id, strlen(piv_manu_id))) {
9b58a7
         isAPIV = 1;
9b58a7
     } else {
9b58a7
         isACOOLKey = 1;
9b58a7
diff -up ./esc/src/lib/coolkey/CoolKeyHandler.h.fix4 ./esc/src/lib/coolkey/CoolKeyHandler.h
9b58a7
--- ./esc/src/lib/coolkey/CoolKeyHandler.h.fix4	2019-01-10 16:38:36.918345731 -0800
9b58a7
+++ ./esc/src/lib/coolkey/CoolKeyHandler.h	2019-01-10 16:38:44.109311258 -0800
9b58a7
@@ -154,6 +154,7 @@ eCKMessage *AllocateMessage(eCKMessage::
9b58a7
   HRESULT SetPassword(const char *password);
9b58a7
   HRESULT SetTokenPin(const char *pin);
9b58a7
 
9b58a7
+  static void ExtractFromUrl(string &fullUrl, string &host_port, string &url, string &hostName,int  *isSSL, int *portNum);
9b58a7
 
9b58a7
   nsNKeyREQUIRED_PARAMETERS_LIST *GetAuthParametersList() { return &mReqParamList;}
9b58a7
 
9b58a7
diff -up ./esc/src/lib/coolkey/CoolKey.h.fix4 ./esc/src/lib/coolkey/CoolKey.h
9b58a7
--- ./esc/src/lib/coolkey/CoolKey.h.fix4	2019-01-10 16:37:11.893754318 -0800
9b58a7
+++ ./esc/src/lib/coolkey/CoolKey.h	2019-01-10 16:37:17.142729043 -0800
9b58a7
@@ -95,6 +95,7 @@ typedef HRESULT (*CoolKeyRelease)(CoolKe
9b58a7
 
9b58a7
 typedef HRESULT (*CoolKeySetConfigValue)(const char *name,const char *value);
9b58a7
 typedef const char * (*CoolKeyGetConfigValue)(const char *name);
9b58a7
+typedef void (*CoolKeyFreeConfigValue)(const char *name);
9b58a7
 typedef SECStatus (*CoolKeyBadCertHandler)(void *arg, PRFileDesc *fd);
9b58a7
 
9b58a7
 class CoolKeyListener  {
9b58a7
@@ -104,7 +105,7 @@ public:
9b58a7
 
9b58a7
     CoolKeyListener() {
9b58a7
         clientNotify = NULL;
9b58a7
-        client = NULL;};
9b58a7
+        client = NULL; notify = NULL;};
9b58a7
     CoolKeyListener(CoolKeyDispatch theListener, CoolKeyDispatch internalListener) {
9b58a7
         clientNotify = NULL;
9b58a7
         client = NULL; 
9b58a7
@@ -144,6 +145,7 @@ COOLKEY_API HRESULT CoolKeyUnregisterLis
9b58a7
 COOLKEY_API HRESULT CoolKeySetCallbacks(CoolKeyDispatch dispatch,
9b58a7
                         CoolKeyReference reference, CoolKeyRelease release,
9b58a7
                         CoolKeyGetConfigValue getconfigvalue,CoolKeySetConfigValue setconfigvalue,
9b58a7
+                        CoolKeyFreeConfigValue freeconfigvalue,
9b58a7
                         CoolKeyBadCertHandler badcerthandler=NULL);
9b58a7
 
9b58a7
 COOLKEY_API bool    CoolKeyRequiresAuthentication(const CoolKey *aKey);
9b58a7
@@ -210,6 +212,8 @@ COOLKEY_API HRESULT CoolKeyGetATR(const
9b58a7
 
9b58a7
 COOLKEY_API int CoolKeyGetAppletVer(const CoolKey *aKey, const bool isMajor);
9b58a7
 
9b58a7
+COOLKEY_API char *CoolKeyGetPhoneHomeData(const char *url);
9b58a7
+
9b58a7
 COOLKEY_API HRESULT CoolKeyInitializeLog(char *logFileName, int maxNumLines);
9b58a7
 
9b58a7
 COOLKEY_API HRESULT CoolKeyLogMsg(int logLevel, const char *fmt, ...);
9b58a7
@@ -289,6 +293,7 @@ const char *CoolKeyGetTokenName(const Co
9b58a7
 const char *CoolKeyGetKeyID(const char *tokenName, int *aKeyType);
9b58a7
 
9b58a7
 const char *CoolKeyGetConfig(const char *aName);
9b58a7
+void        CoolKeyFreeConfig(const char *aValue);
9b58a7
 HRESULT     CoolKeySetConfig(const char *aName,const char *aValue);
9b58a7
 CoolKeyBadCertHandler CoolKeyGetBadCertHandler();
9b58a7
 HRESULT CoolKeyGetATRDirectly(char *aBuff, int aBuffLen, const char *readerName);
9b58a7
diff -up ./esc/src/lib/coolkey/CoolKey_Message.cpp.fix4 ./esc/src/lib/coolkey/CoolKey_Message.cpp
9b58a7
--- ./esc/src/lib/coolkey/CoolKey_Message.cpp.fix4	2019-01-10 16:39:21.887130153 -0800
9b58a7
+++ ./esc/src/lib/coolkey/CoolKey_Message.cpp	2019-01-10 16:39:33.879072661 -0800
9b58a7
@@ -181,7 +181,7 @@ string eCKMessage::intToString(int aInt)
9b58a7
     sprintf(temp,"%d",aInt);
9b58a7
 
9b58a7
     result = temp;
9b58a7
-    delete temp;
9b58a7
+    delete [] temp;
9b58a7
 
9b58a7
     return result;
9b58a7
 }
9b58a7
@@ -241,7 +241,7 @@ void  eCKMessage::setBinValue(string &aK
9b58a7
 
9b58a7
     mTokenMap[aKey] = data;
9b58a7
 
9b58a7
-    delete encode_output;
9b58a7
+    delete [] encode_output;
9b58a7
 
9b58a7
 }
9b58a7
 
9b58a7
@@ -1002,7 +1002,7 @@ void URLDecode_str(const string &data,st
9b58a7
     //printf("output %s \n",decode_output);
9b58a7
     output = (char *) decode_output;
9b58a7
 
9b58a7
-    delete decode_output;
9b58a7
+    delete []decode_output;
9b58a7
 }
9b58a7
 void URLDecode(char *data, unsigned char *buf, int *ret_len, int buff_len)
9b58a7
 {
9b58a7
@@ -1065,7 +1065,7 @@ void URLEncode_str(const string &data,st
9b58a7
     output = encode_output;
9b58a7
 
9b58a7
     //printf("output %s \n",encode_output);
9b58a7
-    delete encode_output;
9b58a7
+    delete [] encode_output;
9b58a7
 }
9b58a7
 
9b58a7
 
9b58a7
diff -up ./esc/src/lib/coolkey-mgr/coolkey-api.cpp.fix4 ./esc/src/lib/coolkey-mgr/coolkey-api.cpp
9b58a7
--- ./esc/src/lib/coolkey-mgr/coolkey-api.cpp.fix4	2019-01-10 16:41:27.076529992 -0800
9b58a7
+++ ./esc/src/lib/coolkey-mgr/coolkey-api.cpp	2019-01-10 16:41:46.470437015 -0800
9b58a7
@@ -20,99 +20,179 @@
9b58a7
 
9b58a7
 static rhCoolKey *coolkey = NULL;
9b58a7
 static const char * coolkeyDbusName = NULL;
9b58a7
+static const char * configFilePathName = NULL;
9b58a7
+static CoolKeyListener *listener = NULL;
9b58a7
 
9b58a7
-int notify( CoolKeyListener *listener,
9b58a7
-        unsigned long keyType, const char *keyID, unsigned long keyState,
9b58a7
-        unsigned long data, const char *strData
9b58a7
-    )
9b58a7
-{
9b58a7
-   CoolKeyDispatch clientListener = listener->GetClientListener();
9b58a7
-
9b58a7
-   /* notify our instance of rhCoolKey */
9b58a7
-
9b58a7
-   coolkey->RhNotifyKeyStateChange(keyType,keyID,keyState,data,strData);
9b58a7
-
9b58a7
-   if(clientListener) {
9b58a7
-       (clientListener )((CoolKeyListener *) listener->GetClient(),keyType, keyID, keyState,
9b58a7
-       data, strData);
9b58a7
-   }
9b58a7
-   return S_OK;
9b58a7
+#define DEF_TOKEN_TYPE "userKey"
9b58a7
+
9b58a7
+
9b58a7
+int notify(CoolKeyListener *listener, unsigned long keyType, const char *keyID,
9b58a7
+		unsigned long keyState, unsigned long data, const char *strData) {
9b58a7
+	CoolKeyDispatch clientListener = listener->GetClientListener();
9b58a7
+
9b58a7
+	/* notify our instance of rhCoolKey */
9b58a7
+
9b58a7
+	coolkey->RhNotifyKeyStateChange(keyType, keyID, keyState, data, strData);
9b58a7
+
9b58a7
+	if (clientListener) {
9b58a7
+		(clientListener)((CoolKeyListener *) listener->GetClient(), keyType,
9b58a7
+				keyID, keyState, data, strData);
9b58a7
+	}
9b58a7
+	return S_OK;
9b58a7
 }
9b58a7
 
9b58a7
 void coolkey_destroy() {
9b58a7
-    if(coolkey != NULL) {
9b58a7
-        coolkey->ShutDownInstance();
9b58a7
-        delete coolkey;
9b58a7
-        coolkey = NULL;
9b58a7
-    }
9b58a7
+	if (coolkey != NULL) {
9b58a7
+                if(listener) {
9b58a7
+                    coolkey->UnregisterCoolKeyListener(listener);
9b58a7
+                }
9b58a7
+		coolkey->ShutDownInstance();
9b58a7
+		delete coolkey;
9b58a7
+		coolkey = NULL;
9b58a7
+	}
9b58a7
 }
9b58a7
 
9b58a7
-void coolkey_init(const char *db_dir,CoolKeyNotifyCallback cb,void* notifyClient,const char* dbusUniqueName) {
9b58a7
+void coolkey_init(const char *db_dir, const char *configFileName, CoolKeyNotifyCallback cb,
9b58a7
+		void* notifyClient, const char* dbusUniqueName) {
9b58a7
 
9b58a7
-    coolkeyDbusName = dbusUniqueName;
9b58a7
-    if(coolkey == NULL) {
9b58a7
-        coolkey = new rhCoolKey(db_dir);
9b58a7
+	coolkeyDbusName = dbusUniqueName;
9b58a7
+	if (coolkey == NULL) {
9b58a7
+		coolkey = new rhCoolKey(db_dir,configFileName);
9b58a7
+
9b58a7
+		listener = new CoolKeyListener();
9b58a7
+		listener->SetListener((CoolKeyDispatch) cb, (CoolKeyDispatch) notify);
9b58a7
+		listener->SetClient(notifyClient);
9b58a7
+		coolkey->RegisterCoolKeyListener(listener);
9b58a7
+	}
9b58a7
+}
9b58a7
 
9b58a7
-        CoolKeyListener *listener = new CoolKeyListener();
9b58a7
-        listener->SetListener((CoolKeyDispatch) cb,(CoolKeyDispatch) notify);
9b58a7
-        listener->SetClient(notifyClient);
9b58a7
-        coolkey->RegisterCoolKeyListener(listener);
9b58a7
-    }
9b58a7
+char *coolkey_get_phone_home(char *url) {
9b58a7
+   if(!url) {
9b58a7
+       return NULL;
9b58a7
+   }
9b58a7
+   if (coolkey != NULL) {
9b58a7
+       char *_retval = NULL;
9b58a7
+       coolkey->GetCoolKeyPhoneHomeData(url, &_retval);
9b58a7
+       return _retval;
9b58a7
+   } else {
9b58a7
+      return NULL;
9b58a7
+   } 
9b58a7
 }
9b58a7
 
9b58a7
+
9b58a7
 /* get a block of data about a token in a structure format */
9b58a7
-tokenInfo *coolkey_get_token_info(int keyType,const char *keyID) {
9b58a7
+tokenInfo *coolkey_get_token_info(int keyType, const char *keyID) {
9b58a7
+
9b58a7
+	if (coolkey == NULL) {
9b58a7
+		return NULL;
9b58a7
+	}
9b58a7
+	tokenInfo *tInfo = (tokenInfo *) malloc(sizeof(tokenInfo));
9b58a7
+
9b58a7
+	if (tInfo == NULL) {
9b58a7
+		exit(1);
9b58a7
+	}
9b58a7
+
9b58a7
+	tInfo->atr = NULL;
9b58a7
+	tInfo->issuerInfo = NULL;
9b58a7
+	tInfo->issuer = NULL;
9b58a7
+	tInfo->issuedTo = NULL;
9b58a7
+	tInfo->status = 0;
9b58a7
+        tInfo->isACoolKey = 0;
9b58a7
+
9b58a7
+	coolkey->GetCoolKeyATR(keyType, keyID, &tInfo->atr);
9b58a7
+
9b58a7
+	coolkey->GetCoolKeyIssuerInfo(keyType, keyID, &tInfo->issuerInfo);
9b58a7
+
9b58a7
+	coolkey->GetCoolKeyIssuer(keyType, keyID, &tInfo->issuer);
9b58a7
+
9b58a7
+	coolkey->GetCoolKeyIssuedTo(keyType, keyID, &tInfo->issuedTo);
9b58a7
+
9b58a7
+	coolkey->GetCoolKeyStatus(keyType, keyID, &tInfo->status);
9b58a7
+
9b58a7
+        bool isACoolKey = false;
9b58a7
+        coolkey->GetCoolKeyIsReallyCoolKey(keyType, keyID, &isACoolKey);
9b58a7
+        tInfo->isACoolKey = (int) isACoolKey;
9b58a7
+
9b58a7
+	return tInfo;
9b58a7
+}
9b58a7
+
9b58a7
+int coolkey_cancel_token_operation(int keyType, const char *keyId) {
9b58a7
 
9b58a7
     if(coolkey == NULL) {
9b58a7
-        return NULL;
9b58a7
+        return E_FAIL;
9b58a7
     }
9b58a7
-    tokenInfo   *tInfo = (tokenInfo *) malloc(sizeof(tokenInfo)); 
9b58a7
 
9b58a7
-    if(tInfo == NULL) {
9b58a7
-       exit(1);
9b58a7
+    int ret = E_FAIL;
9b58a7
+    ret = coolkey->CancelCoolKeyOperation(keyType, keyId);
9b58a7
+
9b58a7
+    return S_OK;
9b58a7
+}
9b58a7
+
9b58a7
+int coolkey_format_token(int keyType, const char *keyId, const char *screenName, const char *pin, const char *screenNamePin, const char *tokenCode) {
9b58a7
+
9b58a7
+    if (coolkey == NULL) {
9b58a7
+        return E_FAIL;
9b58a7
+    }
9b58a7
+
9b58a7
+    int ret = E_FAIL;
9b58a7
+
9b58a7
+    ret = coolkey->FormatCoolKey(keyType, keyId, DEF_TOKEN_TYPE, screenName, pin, screenNamePin, tokenCode);
9b58a7
+
9b58a7
+    return S_OK;
9b58a7
+
9b58a7
+}
9b58a7
+
9b58a7
+int coolkey_enroll_token(int keyType, const char *keyId, const char *screenName, const char *pin, const char *screenNamePin, const char *tokenCode ) {
9b58a7
+
9b58a7
+    if (coolkey == NULL) {
9b58a7
+        return E_FAIL;
9b58a7
     }
9b58a7
 
9b58a7
-    tInfo ->atr = NULL;
9b58a7
-    tInfo->issuerInfo = NULL;
9b58a7
-    tInfo->issuer = NULL;
9b58a7
-    tInfo->issuedTo = NULL;
9b58a7
-    tInfo->status = 0;
9b58a7
-    
9b58a7
-    coolkey->GetCoolKeyATR(keyType, keyID, &tInfo->atr); 
9b58a7
+    int ret = E_FAIL;
9b58a7
 
9b58a7
-    coolkey->GetCoolKeyIssuerInfo(keyType, keyID, &tInfo->issuerInfo);
9b58a7
+    ret = coolkey->EnrollCoolKey(keyType, keyId, DEF_TOKEN_TYPE, screenName, pin, screenNamePin, tokenCode);
9b58a7
 
9b58a7
-    coolkey->GetCoolKeyIssuer(keyType, keyID, &tInfo->issuer);
9b58a7
 
9b58a7
-    coolkey->GetCoolKeyIssuedTo(keyType, keyID, &tInfo->issuedTo);
9b58a7
+    return S_OK;
9b58a7
+}
9b58a7
+
9b58a7
+int coolkey_reset_token_pin(int keyType, const char *keyId, const char *screenName, const char *pin, const char *screenNamePin, const char *tokenCode) {
9b58a7
 
9b58a7
-    coolkey->GetCoolKeyStatus(keyType, keyID, &tInfo->status);
9b58a7
 
9b58a7
-    return tInfo;
9b58a7
+    if (coolkey == NULL) {
9b58a7
+        return E_FAIL;
9b58a7
+    }
9b58a7
+
9b58a7
+    int ret = E_FAIL;
9b58a7
+
9b58a7
+    ret = coolkey->ResetCoolKeyPIN(keyType, keyId,  screenName, pin, screenNamePin);
9b58a7
+
9b58a7
+
9b58a7
+    return S_OK;
9b58a7
 }
9b58a7
 
9b58a7
 void coolkey_free_token_info(tokenInfo *tInfo) {
9b58a7
-    if(tInfo) {
9b58a7
-        if(tInfo->atr) {
9b58a7
-           PL_strfree(tInfo->atr);
9b58a7
-           tInfo->atr = NULL;
9b58a7
-        }
9b58a7
-
9b58a7
-        if(tInfo->issuerInfo) {
9b58a7
-           PL_strfree(tInfo->issuerInfo);
9b58a7
-           tInfo->issuerInfo = NULL;
9b58a7
-        }
9b58a7
-        
9b58a7
-        if(tInfo->issuer) {
9b58a7
-           PL_strfree(tInfo->issuer);
9b58a7
-           tInfo->issuer = NULL;
9b58a7
-        }
9b58a7
-
9b58a7
-        if(tInfo->issuedTo) {
9b58a7
-           PL_strfree(tInfo->issuedTo);
9b58a7
-           tInfo->issuedTo = NULL;
9b58a7
-        }
9b58a7
+	if (tInfo) {
9b58a7
+		if (tInfo->atr) {
9b58a7
+			PL_strfree(tInfo->atr);
9b58a7
+			tInfo->atr = NULL;
9b58a7
+		}
9b58a7
+
9b58a7
+		if (tInfo->issuerInfo) {
9b58a7
+			PL_strfree(tInfo->issuerInfo);
9b58a7
+			tInfo->issuerInfo = NULL;
9b58a7
+		}
9b58a7
+
9b58a7
+		if (tInfo->issuer) {
9b58a7
+			PL_strfree(tInfo->issuer);
9b58a7
+			tInfo->issuer = NULL;
9b58a7
+		}
9b58a7
+
9b58a7
+		if (tInfo->issuedTo) {
9b58a7
+			PL_strfree(tInfo->issuedTo);
9b58a7
+			tInfo->issuedTo = NULL;
9b58a7
+		}
9b58a7
 
9b58a7
-        free(tInfo);
9b58a7
-    }
9b58a7
+		free(tInfo);
9b58a7
+	}
9b58a7
 }
9b58a7
diff -up ./esc/src/lib/coolkey-mgr/coolkey-api.h.fix4 ./esc/src/lib/coolkey-mgr/coolkey-api.h
9b58a7
--- ./esc/src/lib/coolkey-mgr/coolkey-api.h.fix4	2019-01-10 16:42:11.556316752 -0800
9b58a7
+++ ./esc/src/lib/coolkey-mgr/coolkey-api.h	2019-01-10 16:42:21.254270258 -0800
9b58a7
@@ -19,7 +19,6 @@
9b58a7
 #ifndef __COOLKEY_API_H__
9b58a7
 #define __COOLKEY_API_H__
9b58a7
 
9b58a7
-
9b58a7
 typedef struct tokenInfo {
9b58a7
     int keyType;
9b58a7
     char* cuid;
9b58a7
@@ -28,6 +27,7 @@ typedef struct tokenInfo {
9b58a7
     char* issuer;
9b58a7
     char* issuedTo;
9b58a7
     unsigned int   status;
9b58a7
+    unsigned int   isACoolKey;
9b58a7
 } tokenInfo;
9b58a7
 
9b58a7
 #ifdef __cplusplus
9b58a7
@@ -38,13 +38,20 @@ typedef int (*CoolKeyNotifyCallback)(voi
9b58a7
    unsigned long aKeyType, const char *aKeyID, unsigned long aKeyState,
9b58a7
    unsigned long aData, const char *aStrData);
9b58a7
 
9b58a7
-void coolkey_init(const char *db_dir,CoolKeyNotifyCallback cb, void *notifyClient,const char *dbusUniqueName);
9b58a7
+void coolkey_init(const char *db_dir, const char *configFileName, CoolKeyNotifyCallback cb, void *notifyClient,const char *dbusUniqueName);
9b58a7
 
9b58a7
 void coolkey_destroy();
9b58a7
 
9b58a7
+char *coolkey_get_phone_home(char *url);
9b58a7
 tokenInfo *coolkey_get_token_info(int keyType,const char *keyID);
9b58a7
 void coolkey_free_token_info(tokenInfo *tInfo);
9b58a7
 
9b58a7
+int coolkey_cancel_token_operation(int keyType, const char *keyId);
9b58a7
+int coolkey_format_token(int keyType, const char *keyId, const char *screenName, const char *pin, const char *screenNamePin, const char *tokenCode);
9b58a7
+int coolkey_enroll_token(int keyType, const char *keyId, const char *screenName, const char *pin, const char *screenNamePin, const char *tokenCode);
9b58a7
+int coolkey_reset_token_pin(int keyType, const char *keyId, const char *screenName, const char *pin, const char *screenNamePin, const char *tokenCode);
9b58a7
+
9b58a7
+
9b58a7
 #ifdef __cplusplus
9b58a7
 }
9b58a7
 #endif
9b58a7
diff -up ./esc/src/lib/coolkey-mgr/coolkey-mgr.c.fix4 ./esc/src/lib/coolkey-mgr/coolkey-mgr.c
9b58a7
--- ./esc/src/lib/coolkey-mgr/coolkey-mgr.c.fix4	2019-01-10 16:42:49.189136339 -0800
9b58a7
+++ ./esc/src/lib/coolkey-mgr/coolkey-mgr.c	2019-01-10 16:42:55.436106392 -0800
9b58a7
@@ -26,11 +26,15 @@
9b58a7
 #include <stdio.h>
9b58a7
 #include <stdlib.h>
9b58a7
 
9b58a7
+#define SUCCESS 1
9b58a7
+#define FAIL 0
9b58a7
+
9b58a7
 enum
9b58a7
 {
9b58a7
     PROP_0,
9b58a7
     PROP_DBUS_UNIQUE_NAME,
9b58a7
     PROP_CONFIG_DIR,
9b58a7
+    PROP_CONFIG_FILE_NAME,
9b58a7
     N_PROPERTIES
9b58a7
 };
9b58a7
 
9b58a7
@@ -43,6 +47,7 @@ struct _CoolkeyMgrPrivate {
9b58a7
     CoolKeyNotifyCallback cb;
9b58a7
     char *dbusUniqueName;
9b58a7
     char *configDir;
9b58a7
+    char *configFileName;
9b58a7
     DBusConnection* dbusConn; 
9b58a7
 };
9b58a7
 
9b58a7
@@ -101,6 +106,11 @@ coolkey_mgr_set_property (GObject      *
9b58a7
         priv->configDir = g_value_dup_string(value);
9b58a7
         break;
9b58a7
 
9b58a7
+    case PROP_CONFIG_FILE_NAME:
9b58a7
+        g_free(priv->configFileName);
9b58a7
+        priv->configFileName = g_value_dup_string(value);
9b58a7
+        break;
9b58a7
+
9b58a7
     default:
9b58a7
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
9b58a7
         break;
9b58a7
@@ -123,6 +133,9 @@ coolkey_mgr_get_property (GObject    *ob
9b58a7
     case PROP_CONFIG_DIR:
9b58a7
         g_value_set_string(value,priv->configDir);
9b58a7
         break;
9b58a7
+    case PROP_CONFIG_FILE_NAME:
9b58a7
+        g_value_set_string(value,priv->configFileName);
9b58a7
+        break;
9b58a7
     default:
9b58a7
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
9b58a7
         break;
9b58a7
@@ -137,6 +150,7 @@ coolkey_mgr_finalize (GObject *object)
9b58a7
     if(priv) {
9b58a7
         g_free (priv->dbusUniqueName);
9b58a7
         g_free(priv->configDir);
9b58a7
+        g_free(priv->configFileName);
9b58a7
         if(priv->dbusConn) {
9b58a7
             dbus_connection_unref(priv->dbusConn);
9b58a7
             priv->dbusConn = NULL;
9b58a7
@@ -150,7 +164,7 @@ static void
9b58a7
 coolkey_mgr_constructed (GObject *object)
9b58a7
 {
9b58a7
     CoolkeyMgrPrivate *priv = COOLKEY_MGR_GET_PRIVATE (object);
9b58a7
-    coolkey_init(priv->configDir,priv->cb,(void *) object,priv->dbusUniqueName);
9b58a7
+    coolkey_init(priv->configDir,priv->configFileName,priv->cb,(void *) object,priv->dbusUniqueName);
9b58a7
 }
9b58a7
 
9b58a7
 // class initialization
9b58a7
@@ -174,13 +188,22 @@ coolkey_mgr_class_init (CoolkeyMgrClass
9b58a7
                              G_PARAM_CONSTRUCT);
9b58a7
 
9b58a7
    obj_properties[PROP_CONFIG_DIR] = 
9b58a7
-    g_param_spec_string ("config_dir",
9b58a7
+        g_param_spec_string ("config_dir",
9b58a7
                              "Config_dir",
9b58a7
                              "User config directory path",
9b58a7
                              "World",
9b58a7
                              G_PARAM_READWRITE |
9b58a7
                              G_PARAM_CONSTRUCT);
9b58a7
 
9b58a7
+    obj_properties[PROP_CONFIG_FILE_NAME] =
9b58a7
+        g_param_spec_string ("config_file_name",
9b58a7
+                             "Config_file_name",
9b58a7
+                             "User config file name",
9b58a7
+                             "World",
9b58a7
+                             G_PARAM_READWRITE |
9b58a7
+                             G_PARAM_CONSTRUCT);
9b58a7
+
9b58a7
+
9b58a7
     g_object_class_install_properties (object_class,
9b58a7
                                        N_PROPERTIES,
9b58a7
                                        obj_properties);
9b58a7
@@ -206,6 +229,124 @@ coolkey_mgr_new (void)
9b58a7
   return mgr;
9b58a7
 }
9b58a7
 
9b58a7
+int coolkey_mgr_cancel_token_operation(CoolkeyMgr* self, CoolkeyToken* token) {
9b58a7
+
9b58a7
+    gchar *cuid = NULL;
9b58a7
+    gchar *keyType = NULL;
9b58a7
+
9b58a7
+    int ret = FAIL;
9b58a7
+
9b58a7
+    if(token == NULL) {
9b58a7
+        return ret;
9b58a7
+    }
9b58a7
+
9b58a7
+    g_object_get(token,"key_type", &keyType,NULL);
9b58a7
+
9b58a7
+    g_object_get(token,"cuid", &cuid, NULL);
9b58a7
+
9b58a7
+    if(keyType == NULL || cuid == NULL) {
9b58a7
+       goto cleanup;
9b58a7
+    }
9b58a7
+
9b58a7
+    int res = coolkey_cancel_token_operation(atoi( keyType), cuid);
9b58a7
+cleanup:
9b58a7
+
9b58a7
+    g_free (keyType);
9b58a7
+    g_free (cuid);
9b58a7
+
9b58a7
+    return ret;
9b58a7
+
9b58a7
+}
9b58a7
+
9b58a7
+
9b58a7
+int coolkey_mgr_format_token(CoolkeyMgr* self, CoolkeyToken* token, gchar *tokenType, gchar *userId, gchar* pin, gchar *userPwd, gchar *tokenCode) {
9b58a7
+
9b58a7
+    gchar *cuid = NULL;
9b58a7
+    gchar *keyType = NULL;
9b58a7
+
9b58a7
+    int ret = FAIL;
9b58a7
+
9b58a7
+    if(token == NULL || userId == NULL || userPwd == NULL ) {
9b58a7
+        return ret; 
9b58a7
+    }
9b58a7
+
9b58a7
+    g_object_get(token,"key_type", &keyType,NULL);
9b58a7
+
9b58a7
+    g_object_get(token,"cuid", &cuid, NULL);
9b58a7
+
9b58a7
+    if(keyType == NULL || cuid == NULL) {
9b58a7
+       goto cleanup;
9b58a7
+    }
9b58a7
+
9b58a7
+    int res = coolkey_format_token(atoi( keyType), cuid, userId, pin, userPwd,  tokenCode);
9b58a7
+cleanup:
9b58a7
+
9b58a7
+    g_free (keyType);
9b58a7
+    g_free (cuid);
9b58a7
+
9b58a7
+    return ret;
9b58a7
+}
9b58a7
+
9b58a7
+int coolkey_mgr_enroll_token(CoolkeyMgr* self, CoolkeyToken* token,gchar *tokenType, gchar *userId, gchar *pin,gchar *userPwd, gchar *tokenCode) {
9b58a7
+
9b58a7
+    gchar *cuid = NULL;
9b58a7
+    gchar *keyType = NULL;
9b58a7
+
9b58a7
+    int ret = FAIL;
9b58a7
+
9b58a7
+    if(token == NULL || userId == NULL || userPwd == NULL || pin == NULL) {
9b58a7
+        return ret;
9b58a7
+    }
9b58a7
+
9b58a7
+    g_object_get(token,"key_type", &keyType,NULL);
9b58a7
+
9b58a7
+    g_object_get(token,"cuid", &cuid, NULL);
9b58a7
+
9b58a7
+    int res = coolkey_enroll_token(atoi( keyType), cuid, userId, pin, userPwd,  tokenCode);
9b58a7
+
9b58a7
+    if(keyType == NULL || cuid == NULL) {
9b58a7
+       goto cleanup;
9b58a7
+    }
9b58a7
+
9b58a7
+cleanup:
9b58a7
+
9b58a7
+    g_free (keyType);
9b58a7
+    g_free (cuid);
9b58a7
+
9b58a7
+    return ret;
9b58a7
+}
9b58a7
+
9b58a7
+int coolkey_mgr_reset_token_pin(CoolkeyMgr* self, CoolkeyToken* token, gchar *tokenType, gchar *userId,gchar *pin, gchar *userPwd, gchar *tokenCode) {
9b58a7
+
9b58a7
+    gchar *cuid = NULL;
9b58a7
+    gchar *keyType = NULL;
9b58a7
+
9b58a7
+    int ret = FAIL;
9b58a7
+
9b58a7
+    if(token == NULL || userId == NULL || userPwd == NULL || pin == NULL) {
9b58a7
+        return ret;
9b58a7
+    }
9b58a7
+
9b58a7
+    g_object_get(token,"key_type", &keyType,NULL);
9b58a7
+
9b58a7
+    g_object_get(token,"cuid", &cuid, NULL);
9b58a7
+
9b58a7
+    if(keyType == NULL || cuid == NULL) {
9b58a7
+       goto cleanup;
9b58a7
+    }
9b58a7
+
9b58a7
+     int res = coolkey_reset_token_pin(atoi( keyType), cuid, userId, pin, userPwd,  tokenCode);
9b58a7
+
9b58a7
+cleanup:
9b58a7
+
9b58a7
+    g_free (keyType);
9b58a7
+    g_free (cuid);
9b58a7
+
9b58a7
+    return ret;
9b58a7
+}
9b58a7
+
9b58a7
+
9b58a7
+
9b58a7
 void 
9b58a7
 coolkey_mgr_get_token_info(CoolkeyMgr* self, CoolkeyToken* token) {
9b58a7
 
9b58a7
@@ -218,7 +359,7 @@ coolkey_mgr_get_token_info(CoolkeyMgr* s
9b58a7
 
9b58a7
     g_object_get(token,"cuid", &cuid, NULL);
9b58a7
 
9b58a7
-    if(keyType == NULL) {
9b58a7
+    if(keyType == NULL || cuid == NULL) {
9b58a7
        goto cleanup;
9b58a7
     }
9b58a7
 
9b58a7
@@ -231,7 +372,7 @@ coolkey_mgr_get_token_info(CoolkeyMgr* s
9b58a7
             "issuer_info", tInfo->issuerInfo,
9b58a7
             "issuer",tInfo->issuer, 
9b58a7
             "issued_to", tInfo->issuedTo, 
9b58a7
-            "status", tInfo->status,NULL);
9b58a7
+            "status", tInfo->status,"is_a_cool_key", tInfo->isACoolKey,NULL);
9b58a7
     }
9b58a7
 
9b58a7
 cleanup:
9b58a7
@@ -239,10 +380,25 @@ cleanup:
9b58a7
     coolkey_free_token_info(tInfo);
9b58a7
     g_free (keyType);
9b58a7
     g_free (cuid);
9b58a7
-
9b58a7
-    
9b58a7
 }
9b58a7
 
9b58a7
+/**
9b58a7
+* coolkey_mgr_phone_home:
9b58a7
+* @url: phone home url to query
9b58a7
+*
9b58a7
+* Returns: raw phone home xml text.
9b58a7
+*
9b58a7
+*/
9b58a7
+
9b58a7
+gchar * 
9b58a7
+coolkey_mgr_phone_home(CoolkeyMgr* self,gchar *url)
9b58a7
+{
9b58a7
+   gchar *phoneInfo = NULL;
9b58a7
+
9b58a7
+   phoneInfo = coolkey_get_phone_home(url);
9b58a7
+
9b58a7
+   return phoneInfo;
9b58a7
+}
9b58a7
 
9b58a7
 /**
9b58a7
  * coolkey_mgr_speak:
9b58a7
@@ -256,8 +412,6 @@ coolkey_mgr_speak (CoolkeyMgr* self, gch
9b58a7
 {
9b58a7
   gchar *retval= 0;
9b58a7
 
9b58a7
-  printf("Coolkey says: %s \n", words);
9b58a7
-
9b58a7
   return retval;
9b58a7
 }
9b58a7
 
9b58a7
diff -up ./esc/src/lib/coolkey-mgr/coolkey-mgr.h.fix4 ./esc/src/lib/coolkey-mgr/coolkey-mgr.h
9b58a7
--- ./esc/src/lib/coolkey-mgr/coolkey-mgr.h.fix4	2019-01-10 16:43:15.341010967 -0800
9b58a7
+++ ./esc/src/lib/coolkey-mgr/coolkey-mgr.h	2019-01-10 16:43:22.355977338 -0800
9b58a7
@@ -23,7 +23,6 @@
9b58a7
 
9b58a7
 typedef struct _CoolkeyMgrPrivate CoolkeyMgrPrivate;
9b58a7
 
9b58a7
-
9b58a7
 // Declare CoolkeyMgr as a final (non-derivable) class inherited from GObject
9b58a7
 #define COOLKEY_TYPE_MGR coolkey_mgr_get_type ()
9b58a7
 G_DECLARE_FINAL_TYPE (CoolkeyMgr, coolkey_mgr, COOLKEY, MGR, GObject)
9b58a7
@@ -35,8 +34,20 @@ CoolkeyMgr * coolkey_mgr_new (void);
9b58a7
  * CoolkeyMgr method declarations.
9b58a7
  */
9b58a7
 
9b58a7
+
9b58a7
+int coolkey_mgr_format_token(CoolkeyMgr* self, CoolkeyToken* token, gchar *tokenType, gchar *userId,gchar *pin, gchar *userPwd, gchar *tokenCode);
9b58a7
+
9b58a7
+int coolkey_mgr_enroll_token(CoolkeyMgr* self, CoolkeyToken* token, gchar *tokenType, gchar *userId, gchar *pin, gchar *userPwd, gchar *tokenCode);
9b58a7
+
9b58a7
+int coolkey_mgr_reset_token_pin(CoolkeyMgr* self, CoolkeyToken* token, gchar *tokenType, gchar *userId, gchar *pin, gchar *userPwd, gchar *tokenCode);
9b58a7
+
9b58a7
+int coolkey_mgr_cancel_token_operation(CoolkeyMgr* self, CoolkeyToken* token);
9b58a7
+
9b58a7
+
9b58a7
 void  coolkey_mgr_get_token_info(CoolkeyMgr* self, CoolkeyToken* token);
9b58a7
 
9b58a7
+gchar * coolkey_mgr_phone_home(CoolkeyMgr* self, gchar *url);
9b58a7
+
9b58a7
 gchar * coolkey_mgr_speak (CoolkeyMgr* self, gchar *words);
9b58a7
 void coolkey_mgr_cleanup(CoolkeyMgr *self);
9b58a7
 
9b58a7
diff -up ./esc/src/lib/coolkey-mgr/coolkey-token.c.fix4 ./esc/src/lib/coolkey-mgr/coolkey-token.c
9b58a7
--- ./esc/src/lib/coolkey-mgr/coolkey-token.c.fix4	2019-01-10 16:43:53.652827301 -0800
9b58a7
+++ ./esc/src/lib/coolkey-mgr/coolkey-token.c	2019-01-10 16:44:00.252795662 -0800
9b58a7
@@ -35,6 +35,7 @@ enum
9b58a7
     PROP_ISSUER,
9b58a7
     PROP_ISSUEDTO,
9b58a7
     PROP_STATUS,
9b58a7
+    PROP_IS_COOLKEY,
9b58a7
     N_PROPERTIES
9b58a7
 };
9b58a7
 
9b58a7
@@ -51,6 +52,7 @@ struct _CoolkeyTokenPrivate {
9b58a7
     gchar* issuer;
9b58a7
     gchar* issued_to;
9b58a7
     int    status;
9b58a7
+    int    is_a_cool_key;
9b58a7
 };
9b58a7
 
9b58a7
 
9b58a7
@@ -82,6 +84,7 @@ coolkey_token_init (CoolkeyToken *self)
9b58a7
    priv->issuer_info = NULL;
9b58a7
    priv->issuer = NULL;
9b58a7
    priv->issued_to = NULL;
9b58a7
+   priv->is_a_cool_key = 0;
9b58a7
 }
9b58a7
 
9b58a7
 static void
9b58a7
@@ -128,6 +131,9 @@ coolkey_token_set_property (GObject
9b58a7
         priv->status = g_value_get_int(value);
9b58a7
         break;
9b58a7
 
9b58a7
+    case PROP_IS_COOLKEY:
9b58a7
+        priv->is_a_cool_key = g_value_get_int(value);
9b58a7
+        break;
9b58a7
  
9b58a7
     default:
9b58a7
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
9b58a7
@@ -170,13 +176,16 @@ coolkey_token_get_property (GObject    *
9b58a7
     case PROP_STATUS:
9b58a7
         g_value_set_int(value, priv->status);
9b58a7
         break;
9b58a7
+
9b58a7
+    case PROP_IS_COOLKEY:
9b58a7
+        g_value_set_int(value, priv->is_a_cool_key);
9b58a7
+        break;
9b58a7
     default:
9b58a7
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
9b58a7
         break;
9b58a7
     }
9b58a7
 }
9b58a7
 
9b58a7
-
9b58a7
 static void
9b58a7
 coolkey_token_finalize (GObject *object)
9b58a7
 {
9b58a7
@@ -267,6 +276,13 @@ coolkey_token_class_init (CoolkeyTokenCl
9b58a7
                              0, INT_MAX,0,
9b58a7
                              G_PARAM_READWRITE); 
9b58a7
 
9b58a7
+    obj_properties[PROP_IS_COOLKEY]  =
9b58a7
+        g_param_spec_int ("is_a_cool_key",
9b58a7
+                             "Is_a_cool_key",
9b58a7
+                             "Is the token a CoolKey",
9b58a7
+                             0, INT_MAX,0,
9b58a7
+                             G_PARAM_READWRITE);
9b58a7
+
9b58a7
 
9b58a7
     g_object_class_install_properties (object_class,
9b58a7
                                        N_PROPERTIES,
9b58a7
@@ -292,3 +308,19 @@ coolkey_token_new (void)
9b58a7
   token = g_object_new(COOLKEY_TYPE_TOKEN, NULL);
9b58a7
   return token;
9b58a7
 }
9b58a7
+
9b58a7
+/**
9b58a7
+ * coolkey_token_phone_home:
9b58a7
+ * @url: url of smart card server to phone home
9b58a7
+ *
9b58a7
+ * Returns: Text of the phone home xml file 
9b58a7
+ *
9b58a7
+ */
9b58a7
+gchar *
9b58a7
+coolkey_token_phone_home (CoolkeyToken* self, gchar *url)
9b58a7
+{
9b58a7
+  gchar *retval= 0;
9b58a7
+
9b58a7
+  return retval;
9b58a7
+}
9b58a7
+
9b58a7
diff -up ./esc/src/lib/coolkey-mgr/coolkey-token.h.fix4 ./esc/src/lib/coolkey-mgr/coolkey-token.h
9b58a7
--- ./esc/src/lib/coolkey-mgr/coolkey-token.h.fix4	2019-01-10 16:44:25.228675926 -0800
9b58a7
+++ ./esc/src/lib/coolkey-mgr/coolkey-token.h	2019-01-10 16:44:30.212652031 -0800
9b58a7
@@ -29,4 +29,8 @@ G_DECLARE_FINAL_TYPE (CoolkeyToken, cool
9b58a7
 // constructor
9b58a7
 CoolkeyToken * coolkey_token_new (void);
9b58a7
 
9b58a7
+//Methods
9b58a7
+
9b58a7
+gchar *coolkey_token_phone_home(CoolkeyToken *self,gchar *url);
9b58a7
+
9b58a7
 #endif /* __COOLKEY_TOKEN_H__ */
9b58a7
diff -up ./esc/src/lib/coolkey-mgr/rhCoolKey.cpp.fix4 ./esc/src/lib/coolkey-mgr/rhCoolKey.cpp
9b58a7
--- ./esc/src/lib/coolkey-mgr/rhCoolKey.cpp.fix4	2019-01-10 16:45:08.109470350 -0800
9b58a7
+++ ./esc/src/lib/coolkey-mgr/rhCoolKey.cpp	2019-01-10 16:45:15.508434880 -0800
9b58a7
@@ -28,6 +28,7 @@
9b58a7
 #include <vector>
9b58a7
 #include <string>
9b58a7
 #include <time.h>
9b58a7
+#include <glib.h>
9b58a7
 
9b58a7
 #define STRINGIFY(x) #x
9b58a7
 #define GETSTRING(x) STRINGIFY(x)
9b58a7
@@ -50,6 +51,7 @@ static PRLogModuleInfo *coolKeyLog = PR_
9b58a7
 
9b58a7
 static rhCoolKey *single = NULL;
9b58a7
 
9b58a7
+char *rhCoolKey::configFilePathName = NULL;
9b58a7
 
9b58a7
 class CoolKeyShutdownObserver
9b58a7
  {
9b58a7
@@ -179,15 +181,15 @@ ASCCalcBase64EncodedLength(unsigned int
9b58a7
   return ((aDataLength + 2) / 3) * 4;
9b58a7
 }
9b58a7
 
9b58a7
-rhCoolKey::rhCoolKey(const char* dbDir)
9b58a7
+rhCoolKey::rhCoolKey(const char* dbDir, const char* configFileName)
9b58a7
 {
9b58a7
     char tBuff[56];
9b58a7
     PR_LOG( coolKeyLog, PR_LOG_DEBUG, ("%s rhCoolKey::rhCoolKey: %p \n",GetTStamp(tBuff,56),this));
9b58a7
 
9b58a7
+    rhCoolKey::configFilePathName = NULL;
9b58a7
     if(!single)
9b58a7
     {
9b58a7
         single = this;
9b58a7
-
9b58a7
     }
9b58a7
     else
9b58a7
     {
9b58a7
@@ -217,6 +219,12 @@ rhCoolKey::rhCoolKey(const char* dbDir)
9b58a7
         exit(1);
9b58a7
      }
9b58a7
 
9b58a7
+     res = InitConfig(dbDir,configFileName);
9b58a7
+
9b58a7
+     if(res == PR_FALSE) {
9b58a7
+         PR_LOG( coolKeyLog, PR_LOG_DEBUG, ("%s ESC InitConfig failed,exiting. CoolKey instance %p\n",GetTStamp(tBuff,56),single));
9b58a7
+     }
9b58a7
+
9b58a7
   /* member initializers and constructor code */ 
9b58a7
 }
9b58a7
 
9b58a7
@@ -227,6 +235,11 @@ rhCoolKey::~rhCoolKey()
9b58a7
     char tBuff[56];
9b58a7
     PR_LOG( coolKeyLog, PR_LOG_DEBUG, ("%s rhCoolKey::~rhCoolKey: %p \n",GetTStamp(tBuff,56),this));
9b58a7
 
9b58a7
+    if(rhCoolKey::configFilePathName != NULL) {
9b58a7
+        delete [] rhCoolKey::configFilePathName;
9b58a7
+        rhCoolKey::configFilePathName = NULL;
9b58a7
+    }
9b58a7
+
9b58a7
     if(certCBLock) {
9b58a7
         PR_DestroyLock(certCBLock);
9b58a7
     }
9b58a7
@@ -241,7 +254,7 @@ void rhCoolKey::ShutDownInstance()
9b58a7
     char tBuff[56];
9b58a7
     PR_LOG( coolKeyLog, PR_LOG_DEBUG, ("%s rhCoolKey::ShutDownInstance. %p \n",GetTStamp(tBuff,56),this));    
9b58a7
 
9b58a7
-    //ClearNotifyKeyList();
9b58a7
+    ClearAvailableList();
9b58a7
 
9b58a7
     CoolKeyShutdown();
9b58a7
 }
9b58a7
@@ -270,6 +283,9 @@ HRESULT rhCoolKey::Reference( CoolKeyLis
9b58a7
 
9b58a7
 HRESULT rhCoolKey::Release( CoolKeyListener *listener )
9b58a7
 {
9b58a7
+    if(listener) {
9b58a7
+        delete listener;
9b58a7
+    }
9b58a7
     return S_OK;
9b58a7
 }
9b58a7
 
9b58a7
@@ -366,25 +382,57 @@ SECStatus rhCoolKey::badCertHandler(void
9b58a7
 HRESULT rhCoolKey::doSetCoolKeyConfigValue(const char *aName, const char *aValue) 
9b58a7
 {
9b58a7
 
9b58a7
-    if(!aName || !aValue)
9b58a7
-    {
9b58a7
-        return E_FAIL;
9b58a7
-    }
9b58a7
+    //Unimplimented
9b58a7
 
9b58a7
-
9b58a7
-    return S_OK;
9b58a7
+    return E_FAIL;
9b58a7
 
9b58a7
 }          
9b58a7
 
9b58a7
+void rhCoolKey::doFreeCoolKeyConfigValue(const char *aValue) {
9b58a7
+
9b58a7
+    if(!aValue)
9b58a7
+        return;
9b58a7
+
9b58a7
+    g_free((gchar *)aValue);
9b58a7
+
9b58a7
+}
9b58a7
 const char *rhCoolKey::doGetCoolKeyConfigValue(const char *aName )
9b58a7
 {
9b58a7
+
9b58a7
+    char tBuff[56];
9b58a7
     const char* prefValue = NULL;
9b58a7
     if(!aName)
9b58a7
     {
9b58a7
         return NULL;
9b58a7
     }
9b58a7
 
9b58a7
-    return (const char *) prefValue;
9b58a7
+    g_autoptr(GError) error = NULL;
9b58a7
+    g_autoptr(GKeyFile) key_file = g_key_file_new ();
9b58a7
+
9b58a7
+    if (!g_key_file_load_from_file (key_file, rhCoolKey::configFilePathName,G_KEY_FILE_NONE, &error))
9b58a7
+    {
9b58a7
+        if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) {
9b58a7
+
9b58a7
+            PR_LOG(coolKeyLog, PR_LOG_DEBUG,
9b58a7
+                          ("%s rhCoolKey::doGetCoolKeyConfigValue error opening key file.",
9b58a7
+                          GetTStamp(tBuff,56)));
9b58a7
+            return NULL;
9b58a7
+        }
9b58a7
+    }
9b58a7
+
9b58a7
+    gchar *val = g_key_file_get_string (key_file, "ESC", aName, &error);
9b58a7
+    if (val == NULL)
9b58a7
+    {
9b58a7
+        PR_LOG(coolKeyLog, PR_LOG_DEBUG,
9b58a7
+                          ("%s rhCoolKey::doGetCoolKeyConfigValue error can't get value for: %s.",
9b58a7
+                          GetTStamp(tBuff,56), aName));
9b58a7
+
9b58a7
+        return NULL;
9b58a7
+    }
9b58a7
+   
9b58a7
+    prefValue = (const char*) val; 
9b58a7
+
9b58a7
+    return prefValue;
9b58a7
 }
9b58a7
 
9b58a7
 void rhCoolKey::RegisterCoolKeyListener(CoolKeyListener *listener) {
9b58a7
@@ -393,6 +441,14 @@ void rhCoolKey::RegisterCoolKeyListener(
9b58a7
     }
9b58a7
 }
9b58a7
 
9b58a7
+void rhCoolKey::UnregisterCoolKeyListener(CoolKeyListener *listener) {
9b58a7
+
9b58a7
+    if(listener) {
9b58a7
+        CoolKeyUnregisterListener(listener);
9b58a7
+    }
9b58a7
+}
9b58a7
+
9b58a7
+
9b58a7
 PRBool rhCoolKey::InitInstance(const char* dbDir)
9b58a7
 {
9b58a7
     char tBuff[56];
9b58a7
@@ -400,9 +456,7 @@ PRBool rhCoolKey::InitInstance(const cha
9b58a7
 
9b58a7
     PR_LOG( coolKeyLog, PR_LOG_DEBUG, ("%s rhCoolKey::InitInstance %p \n",GetTStamp(tBuff,56),this));
9b58a7
 
9b58a7
-    CoolKeySetCallbacks(Dispatch,Reference, Release,doGetCoolKeyConfigValue ,doSetCoolKeyConfigValue,badCertHandler);
9b58a7
-
9b58a7
-    //CoolKeyRegisterListener();
9b58a7
+    CoolKeySetCallbacks(Dispatch,Reference, Release,doGetCoolKeyConfigValue,doSetCoolKeyConfigValue,doFreeCoolKeyConfigValue,badCertHandler);
9b58a7
 
9b58a7
     // Now setup CoolKey.
9b58a7
 
9b58a7
@@ -411,6 +465,37 @@ PRBool rhCoolKey::InitInstance(const cha
9b58a7
     return ret;
9b58a7
 }
9b58a7
 
9b58a7
+PRBool rhCoolKey::InitConfig(const char *dbDir,const char* configFileName) 
9b58a7
+{
9b58a7
+    char tBuff[56];
9b58a7
+    PRBool ret = PR_TRUE;
9b58a7
+
9b58a7
+    if(!dbDir || !configFileName) {
9b58a7
+        ret = PR_FALSE;
9b58a7
+        return ret;
9b58a7
+    }  
9b58a7
+
9b58a7
+    int size = strlen(dbDir) + strlen(configFileName) + 2;
9b58a7
+
9b58a7
+    //sanity
9b58a7
+
9b58a7
+    if(size > 200) {
9b58a7
+       ret = PR_FALSE;
9b58a7
+       return ret;
9b58a7
+    }
9b58a7
+
9b58a7
+    if(rhCoolKey::configFilePathName == NULL) {
9b58a7
+        rhCoolKey::configFilePathName = new char[size];
9b58a7
+    }
9b58a7
+
9b58a7
+    snprintf(rhCoolKey::configFilePathName,200,"%s/%s",dbDir,configFileName);
9b58a7
+
9b58a7
+    PR_LOG( coolKeyLog, PR_LOG_DEBUG, ("%s rhCoolKey::InitConfig  full file Name: %s \n",GetTStamp(tBuff,56),configFilePathName));
9b58a7
+
9b58a7
+    return ret;
9b58a7
+    
9b58a7
+}
9b58a7
+
9b58a7
 CoolKeyNode* rhCoolKey::GetCoolKeyInfo(unsigned long aKeyType, const char * aKeyID)
9b58a7
 {
9b58a7
     char tBuff[56];
9b58a7
@@ -456,8 +541,9 @@ HRESULT  rhCoolKey::ASCGetAvailableCoolK
9b58a7
         std::list<CoolKeyNode*>::const_iterator it;
9b58a7
         for(it=gASCAvailableKeys.begin(); it!=gASCAvailableKeys.end(); ++it) {
9b58a7
           if (aIndex-- == 0) {
9b58a7
-              *aKeyType = (*it)->mKeyType;
9b58a7
-              *aKeyID = (char *) (*it)->mKeyID;
9b58a7
+        	  CoolKeyNode *node = (*it);
9b58a7
+              *aKeyType = node->mKeyType;
9b58a7
+              *aKeyID = (char *) node->mKeyID;
9b58a7
                return S_OK;
9b58a7
           }
9b58a7
         }
9b58a7
@@ -1359,3 +1445,18 @@ HRESULT rhCoolKey::GetCoolKeyVersion(cha
9b58a7
 
9b58a7
     return NS_OK;
9b58a7
 }
9b58a7
+
9b58a7
+HRESULT rhCoolKey::GetCoolKeyPhoneHomeData(const char *url, char **_retval) {
9b58a7
+	char *phoneHomeData = NULL;
9b58a7
+
9b58a7
+	*_retval = NULL;
9b58a7
+
9b58a7
+	phoneHomeData = CoolKeyGetPhoneHomeData(url);
9b58a7
+
9b58a7
+	if (phoneHomeData) {
9b58a7
+	    *_retval = PL_strdup(phoneHomeData);
9b58a7
+             phoneHomeData = NULL;
9b58a7
+	}
9b58a7
+ 
9b58a7
+	return NS_OK;
9b58a7
+}
9b58a7
diff -up ./esc/src/lib/coolkey-mgr/rhCoolKey.h.fix4 ./esc/src/lib/coolkey-mgr/rhCoolKey.h
9b58a7
--- ./esc/src/lib/coolkey-mgr/rhCoolKey.h.fix4	2019-01-10 16:45:36.015336570 -0800
9b58a7
+++ ./esc/src/lib/coolkey-mgr/rhCoolKey.h	2019-01-10 16:45:45.896289201 -0800
9b58a7
@@ -74,18 +74,20 @@ class rhCoolKey
9b58a7
 {
9b58a7
 public:
9b58a7
 
9b58a7
-    rhCoolKey(const char* dbDir);
9b58a7
+    rhCoolKey(const char* dbDir, const char* configFileName);
9b58a7
 
9b58a7
     void ShutDownInstance();
9b58a7
     ~rhCoolKey();
9b58a7
 public:
9b58a7
     static void RegisterCoolKeyListener(CoolKeyListener *listener);
9b58a7
+    static void UnregisterCoolKeyListener(CoolKeyListener *listener);
9b58a7
     static HRESULT Dispatch( CoolKeyListener *listener,
9b58a7
     unsigned long keyType, const char *keyID, unsigned long keyState,
9b58a7
     unsigned long data, const char *strData);
9b58a7
     static HRESULT Reference( CoolKeyListener *listener );
9b58a7
     static HRESULT Release( CoolKeyListener *listener );
9b58a7
 
9b58a7
+    static void doFreeCoolKeyConfigValue(const char *aValue);
9b58a7
     static HRESULT doSetCoolKeyConfigValue(const char *aName, const char *aValue); 
9b58a7
     static const char *doGetCoolKeyConfigValue(const char *aName );
9b58a7
     static SECStatus badCertHandler(void *arg, PRFileDesc *fd);
9b58a7
@@ -121,8 +123,7 @@ public:
9b58a7
     HRESULT AuthenticateCoolKey(PRUint32 aKeyType, const char *aKeyID, const char *aPIN, bool *_retval);
9b58a7
     HRESULT SetCoolKeyDataValue(PRUint32 aKeyType, const char *aKeyID, const char *name, const char *value);
9b58a7
     HRESULT GetCoolKeyVersion(char **_retval);
9b58a7
-
9b58a7
-    //nsCOMPtr<rhIKeyNotify> mJsNotify;
9b58a7
+    HRESULT GetCoolKeyPhoneHomeData(const char *url, char **_retval);
9b58a7
 
9b58a7
     static std::list<CoolKeyNode*> gASCAvailableKeys;
9b58a7
 
9b58a7
@@ -132,8 +133,8 @@ public:
9b58a7
 
9b58a7
     static PRBool      gAutoEnrollBlankTokens;
9b58a7
 
9b58a7
-    //nsCOMPtr<nsISupports> nssComponent;
9b58a7
     PRBool InitInstance(const char* dbDir);
9b58a7
+    PRBool InitConfig(const char *dbDir,const char* configFileName);
9b58a7
 
9b58a7
     HRESULT ASCSetCoolKeyPin(unsigned long aKeyType, const char * aKeyID, const char * aPin);
9b58a7
     PRBool ASCCoolKeyIsAvailable(unsigned long aKeyType, char * aKeyID);
9b58a7
@@ -151,15 +152,11 @@ public:
9b58a7
 
9b58a7
     void RemoveKeyFromAvailableList(unsigned long aKeyType, const char * aKeyID);
9b58a7
 
9b58a7
-    //rhIKeyNotify* GetNotifyKeyListener(rhIKeyNotify *listener);
9b58a7
-
9b58a7
-    //int GetNotifyKeyListenerListSize();
9b58a7
-    //void AddNotifyKeyListener(rhIKeyNotify *listener);
9b58a7
-    //void RemoveNotifyKeyListener(rhIKeyNotify *listener);
9b58a7
-    //void ClearNotifyKeyList();
9b58a7
-
9b58a7
     void ClearAvailableList();
9b58a7
 
9b58a7
+    private:
9b58a7
+
9b58a7
+    static  char *configFilePathName;
9b58a7
 
9b58a7
 };
9b58a7
 #endif
9b58a7
diff -up ./esc/src/lib/coolkey/NSSManager.cpp.fix4 ./esc/src/lib/coolkey/NSSManager.cpp
9b58a7
--- ./esc/src/lib/coolkey/NSSManager.cpp.fix4	2019-01-10 16:40:09.075903931 -0800
9b58a7
+++ ./esc/src/lib/coolkey/NSSManager.cpp	2019-01-10 16:40:20.324850003 -0800
9b58a7
@@ -154,6 +154,10 @@ void NSSManager::Shutdown()
9b58a7
   // Logout all tokens.
9b58a7
     PK11_LogoutAll();
9b58a7
 
9b58a7
+    if(userModule) {
9b58a7
+        SECMOD_UnloadUserModule(userModule);
9b58a7
+    }
9b58a7
+
9b58a7
     if(systemCertDB)
9b58a7
     {
9b58a7
         SECMOD_CloseUserDB(systemCertDB);
9b58a7
@@ -162,9 +166,6 @@ void NSSManager::Shutdown()
9b58a7
         systemCertDB = NULL;
9b58a7
     }
9b58a7
    
9b58a7
-    if(userModule) {
9b58a7
-        SECMOD_UnloadUserModule(userModule);
9b58a7
-    }
9b58a7
     NSS_Shutdown();
9b58a7
 }
9b58a7
 
9b58a7
diff -up ./esc/src/lib/nss-http-client/httpClientNss.cpp.fix4 ./esc/src/lib/nss-http-client/httpClientNss.cpp
9b58a7
--- ./esc/src/lib/nss-http-client/httpClientNss.cpp.fix4	2019-01-10 16:46:22.792112323 -0800
9b58a7
+++ ./esc/src/lib/nss-http-client/httpClientNss.cpp	2019-01-10 16:46:35.788050020 -0800
9b58a7
@@ -57,6 +57,48 @@ HttpClientNss::~HttpClientNss()
9b58a7
     }
9b58a7
 }
9b58a7
 
9b58a7
+PSHttpResponse *HttpClientNss::httpSend(char *host_port,const char *uri,
9b58a7
+		char *method, char *body, PRBool doSSL, int messageTimeout) {
9b58a7
+
9b58a7
+	int family = PR_AF_INET;
9b58a7
+	char hostName[512] = { 0 };
9b58a7
+
9b58a7
+	extractHost(host_port, hostName, 512);
9b58a7
+	family = this->getFamily(hostName);
9b58a7
+
9b58a7
+	PSHttpServer server(host_port, family);
9b58a7
+
9b58a7
+	PSHttpRequest request(&server, uri, HTTP11, 0);
9b58a7
+	_request = &request;
9b58a7
+
9b58a7
+	int timeout = 30;
9b58a7
+
9b58a7
+	if (messageTimeout >= 0) {
9b58a7
+		timeout = messageTimeout;
9b58a7
+
9b58a7
+	}
9b58a7
+
9b58a7
+	request.setSSL(doSSL);
9b58a7
+
9b58a7
+	request.addHeader( "Content-Type", "text/plain" );
9b58a7
+
9b58a7
+	_engine = new HttpEngine();
9b58a7
+
9b58a7
+	if (!_engine)
9b58a7
+		return NULL;
9b58a7
+
9b58a7
+	PSHttpResponse *resp = _engine->makeRequest(request, server,
9b58a7
+			timeout /*_timeout*/, PR_FALSE /* expect chunked*/,
9b58a7
+			PR_FALSE /* process streamed */);
9b58a7
+
9b58a7
+	_response = resp;
9b58a7
+
9b58a7
+	if (resp && resp->getStatus() != 200) {
9b58a7
+		return NULL;
9b58a7
+	}
9b58a7
+
9b58a7
+	return resp;
9b58a7
+}
9b58a7
 /*
9b58a7
 Send a http message with a persistant transfer chunked encoded message type
9b58a7
 
9b58a7
@@ -67,7 +109,7 @@ PSHttpResponse *HttpClientNss::httpSendC
9b58a7
     char *pPort = NULL;
9b58a7
     char *pPortActual = NULL;
9b58a7
 
9b58a7
-    char hostName[512];
9b58a7
+    char hostName[512] = {0};
9b58a7
 
9b58a7
     /*
9b58a7
      * Isolate the host name, account for IPV6 numeric addresses.
9b58a7
@@ -101,7 +143,7 @@ PSHttpResponse *HttpClientNss::httpSendC
9b58a7
 
9b58a7
     ai = PR_GetAddrInfoByName(hostName, PR_AF_UNSPEC, PR_AI_ADDRCONFIG);
9b58a7
     if (ai) {
9b58a7
-        printf("%s\n", PR_GetCanonNameFromAddrInfo(ai));
9b58a7
+        //printf("%s\n", PR_GetCanonNameFromAddrInfo(ai));
9b58a7
         iter = NULL;
9b58a7
         while ((iter = PR_EnumerateAddrInfo(iter, ai, 0, &addr)) != NULL) {
9b58a7
             family = PR_NetAddrFamily(&addr);
9b58a7
@@ -211,4 +253,51 @@ PRBool HttpClientNss::sendChunkedEntityD
9b58a7
     }
9b58a7
 }
9b58a7
 
9b58a7
+int HttpClientNss::getFamily(char *hostName) {
9b58a7
+
9b58a7
+	PRAddrInfo *ai;
9b58a7
+	void *iter;
9b58a7
+	PRNetAddr addr;
9b58a7
+	int family = PR_AF_INET;
9b58a7
+
9b58a7
+	ai = PR_GetAddrInfoByName(hostName, PR_AF_UNSPEC, PR_AI_ADDRCONFIG);
9b58a7
+	if (ai) {
9b58a7
+		//printf("%s\n", PR_GetCanonNameFromAddrInfo(ai));
9b58a7
+		iter = NULL;
9b58a7
+		while ((iter = PR_EnumerateAddrInfo(iter, ai, 0, &addr)) != NULL) {
9b58a7
+			family = PR_NetAddrFamily(&addr);
9b58a7
+			break;
9b58a7
+		}
9b58a7
+		PR_FreeAddrInfo(ai);
9b58a7
+	}
9b58a7
+
9b58a7
+	return family;
9b58a7
+}
9b58a7
+
9b58a7
+void HttpClientNss::extractHost(char *host_port, char *host, int hostLen) {
9b58a7
+
9b58a7
+	char *pPort = NULL;
9b58a7
+	char *pPortActual = NULL;
9b58a7
+
9b58a7
+	if(!host_port || !host || hostLen <= 0)
9b58a7
+		return;
9b58a7
+
9b58a7
+	if(host_port)
9b58a7
+	        strncpy(host,host_port,hostLen);
9b58a7
+
9b58a7
+	    pPort = host;
9b58a7
+	    while(1)  {
9b58a7
+	        pPort = strchr(pPort, ':');
9b58a7
+	        if (pPort) {
9b58a7
+	            pPortActual = pPort;
9b58a7
+	            pPort++;
9b58a7
+	        } else
9b58a7
+	            break;
9b58a7
+	    }
9b58a7
+
9b58a7
+	    if(pPortActual)
9b58a7
+	        *pPortActual = '\0';
9b58a7
+
9b58a7
+}
9b58a7
+
9b58a7
 
9b58a7
diff -up ./esc/src/lib/nss-http-client/HttpClientNss.h.fix4 ./esc/src/lib/nss-http-client/HttpClientNss.h
9b58a7
--- ./esc/src/lib/nss-http-client/HttpClientNss.h.fix4	2019-01-10 16:47:19.171842036 -0800
9b58a7
+++ ./esc/src/lib/nss-http-client/HttpClientNss.h	2019-01-10 16:47:37.786752798 -0800
9b58a7
@@ -33,12 +33,19 @@ public:
9b58a7
     PSHttpRequest *        _request;
9b58a7
     PSHttpResponse*        _response;
9b58a7
 
9b58a7
-    PSHttpResponse *httpSendChunked(char *host_port, char *uri, char *method, char *body,PSChunkedResponseCallback cb,void *uw,PRBool doSSL = PR_FALSE,int messageTimeout =30);
9b58a7
-
9b58a7
+	PSHttpResponse *httpSendChunked(char *host_port, char *uri, char *method,
9b58a7
+			char *body, PSChunkedResponseCallback cb, void *uw, PRBool doSSL =
9b58a7
+					PR_FALSE, int messageTimeout = 30);
9b58a7
+	PSHttpResponse *httpSend(char *host_port,const char *uri, char *method,
9b58a7
+			char *body, PRBool doSSL = PR_FALSE, int messageTimeout = 30);
9b58a7
     PRBool sendChunkedEntityData(int body_len,unsigned char * body);
9b58a7
     HttpEngine *getEngine() { return _engine;}
9b58a7
 
9b58a7
     void CloseConnection();
9b58a7
+
9b58a7
+private:
9b58a7
+	void extractHost(char *host_port, char *host, int hostLen);
9b58a7
+	int getFamily(char *hostName);
9b58a7
 };
9b58a7
 
9b58a7
 #endif
9b58a7
diff -up ./esc/src/lib/nss-http-client/NssHttpClient.cpp.fix4 ./esc/src/lib/nss-http-client/NssHttpClient.cpp
9b58a7
--- ./esc/src/lib/nss-http-client/NssHttpClient.cpp.fix4	2019-01-10 16:48:14.117578626 -0800
9b58a7
+++ ./esc/src/lib/nss-http-client/NssHttpClient.cpp	2019-01-10 16:48:29.082506883 -0800
9b58a7
@@ -156,46 +156,93 @@ NSS_HTTP_CLIENT_API NSS_HTTP_RESULT http
9b58a7
     return 1;
9b58a7
 }
9b58a7
 
9b58a7
-NSS_HTTP_CLIENT_API NSS_HTTP_RESULT httpSendChunked(char *host_port, char *uri, char *method, char *body,NSChunkedResponseCallback cb,void *cb_uw,NSS_HTTP_HANDLE handle,PRBool doSSL, int messageTimeout )
9b58a7
-{
9b58a7
-    NSS_HTTP_RESULT res = 0;
9b58a7
-
9b58a7
-    if(!clientTableLock)
9b58a7
-    {
9b58a7
-        return res;
9b58a7
-    }
9b58a7
-
9b58a7
-    if(!handle)
9b58a7
-    {
9b58a7
-        return res;
9b58a7
-    }
9b58a7
-    
9b58a7
-    PR_Lock(clientTableLock);
9b58a7
-
9b58a7
-    HttpClientNss *client = NULL;
9b58a7
-
9b58a7
-    client = client_table[handle];
9b58a7
-
9b58a7
-    if(!client)
9b58a7
-    {
9b58a7
-        PR_Unlock(clientTableLock);
9b58a7
-        return res;
9b58a7
-    }
9b58a7
-
9b58a7
-    PR_Unlock(clientTableLock);
9b58a7
-
9b58a7
-    PSHttpResponse * resp = client->httpSendChunked(host_port,uri,method,body,cb,cb_uw,doSSL,messageTimeout);
9b58a7
-
9b58a7
-    if(!resp)
9b58a7
-    {
9b58a7
-        res = 0;
9b58a7
-    }
9b58a7
-    else
9b58a7
-    {
9b58a7
-        res = 1;
9b58a7
-    }
9b58a7
+NSS_HTTP_CLIENT_API char * httpSend(char *host_port,const char *uri,
9b58a7
+		char *method, char *body, NSS_HTTP_HANDLE handle, PRBool doSSL,
9b58a7
+		int messageTimeout) {
9b58a7
 
9b58a7
-    return res;
9b58a7
+	char *res = 0;
9b58a7
+
9b58a7
+	if(host_port == NULL || uri == NULL) {
9b58a7
+		return NULL;
9b58a7
+	}
9b58a7
+
9b58a7
+	if (!clientTableLock) {
9b58a7
+		return res;
9b58a7
+	}
9b58a7
+
9b58a7
+	if (!handle) {
9b58a7
+		return res;
9b58a7
+	}
9b58a7
+
9b58a7
+	PR_Lock(clientTableLock);
9b58a7
+
9b58a7
+	HttpClientNss *client = NULL;
9b58a7
+
9b58a7
+	client = client_table[handle];
9b58a7
+
9b58a7
+	if (!client) {
9b58a7
+		PR_Unlock(clientTableLock);
9b58a7
+		return res;
9b58a7
+	}
9b58a7
+
9b58a7
+	PR_Unlock(clientTableLock);
9b58a7
+
9b58a7
+	PSHttpResponse *resp = client->httpSend(host_port, uri, method,
9b58a7
+	NULL, doSSL, messageTimeout);
9b58a7
+
9b58a7
+	int retCode = 0;
9b58a7
+	if (!resp) {
9b58a7
+		res = NULL;
9b58a7
+	} else {
9b58a7
+		retCode = resp->getReturnCode();
9b58a7
+
9b58a7
+		if(retCode != 200) {
9b58a7
+			return NULL;
9b58a7
+		}
9b58a7
+
9b58a7
+		res = resp->getContent();
9b58a7
+	}
9b58a7
+
9b58a7
+	return res;
9b58a7
+
9b58a7
+}
9b58a7
+
9b58a7
+NSS_HTTP_CLIENT_API NSS_HTTP_RESULT httpSendChunked(char *host_port, char *uri,
9b58a7
+		char *method, char *body, NSChunkedResponseCallback cb, void *cb_uw,
9b58a7
+		NSS_HTTP_HANDLE handle, PRBool doSSL, int messageTimeout) {
9b58a7
+	NSS_HTTP_RESULT res = 0;
9b58a7
+
9b58a7
+	if (!clientTableLock) {
9b58a7
+		return res;
9b58a7
+	}
9b58a7
+
9b58a7
+	if (!handle) {
9b58a7
+		return res;
9b58a7
+	}
9b58a7
+
9b58a7
+	PR_Lock(clientTableLock);
9b58a7
+
9b58a7
+	HttpClientNss *client = NULL;
9b58a7
+
9b58a7
+	client = client_table[handle];
9b58a7
+
9b58a7
+	if (!client) {
9b58a7
+		PR_Unlock(clientTableLock);
9b58a7
+		return res;
9b58a7
+	}
9b58a7
+
9b58a7
+	PR_Unlock(clientTableLock);
9b58a7
+
9b58a7
+	PSHttpResponse * resp = client->httpSendChunked(host_port, uri, method,
9b58a7
+			body, cb, cb_uw, doSSL, messageTimeout);
9b58a7
+
9b58a7
+	if (!resp) {
9b58a7
+		res = 0;
9b58a7
+	} else {
9b58a7
+		res = 1;
9b58a7
+	}
9b58a7
+
9b58a7
+	return res;
9b58a7
 }
9b58a7
 
9b58a7
 NSS_HTTP_CLIENT_API NSS_HTTP_RESULT sendChunkedEntityData(int body_len,unsigned char *body,NSS_HTTP_HANDLE handle)
9b58a7
diff -up ./esc/src/lib/nss-http-client/NssHttpClient.h.fix4 ./esc/src/lib/nss-http-client/NssHttpClient.h
9b58a7
--- ./esc/src/lib/nss-http-client/NssHttpClient.h.fix4	2019-01-10 17:28:26.200053405 -0800
9b58a7
+++ ./esc/src/lib/nss-http-client/NssHttpClient.h	2019-01-10 17:28:49.771941100 -0800
9b58a7
@@ -28,6 +28,7 @@
9b58a7
 
9b58a7
 #include "nspr.h"
9b58a7
 
9b58a7
+#include "response.h"
9b58a7
 #define NSS_HTTP_CLIENT_API
9b58a7
 
9b58a7
 #define NSS_HTTP_CHUNK_COMPLETE 1
9b58a7
@@ -45,9 +46,17 @@ NSS_HTTP_CLIENT_API NSS_HTTP_HANDLE http
9b58a7
 
9b58a7
 NSS_HTTP_CLIENT_API NSS_HTTP_RESULT httpDestroyClient(NSS_HTTP_HANDLE handle);
9b58a7
 
9b58a7
-NSS_HTTP_CLIENT_API NSS_HTTP_RESULT httpSendChunked(char *host_port, char *uri, char *method, char *body,NSChunkedResponseCallback cb,void *cb_uw,NSS_HTTP_HANDLE handle,PRBool doSSL = PR_FALSE,int messageTimeout = 30);
9b58a7
+NSS_HTTP_CLIENT_API NSS_HTTP_RESULT httpSendChunked(char *host_port, char *uri,
9b58a7
+		char *method, char *body, NSChunkedResponseCallback cb, void *cb_uw,
9b58a7
+		NSS_HTTP_HANDLE handle, PRBool doSSL = PR_FALSE,
9b58a7
+		int messageTimeout = 30);
9b58a7
+
9b58a7
+NSS_HTTP_CLIENT_API char * httpSend(char *host_port,const char *uri,
9b58a7
+		char *method, char *body, NSS_HTTP_HANDLE handle, PRBool doSSL =
9b58a7
+				PR_FALSE, int messageTimeout = 30);
9b58a7
 
9b58a7
-NSS_HTTP_CLIENT_API NSS_HTTP_RESULT sendChunkedEntityData(int body_len,unsigned char *body,NSS_HTTP_HANDLE handle);
9b58a7
+NSS_HTTP_CLIENT_API NSS_HTTP_RESULT sendChunkedEntityData(int body_len,
9b58a7
+		unsigned char *body, NSS_HTTP_HANDLE handle);
9b58a7
 
9b58a7
 NSS_HTTP_CLIENT_API NSS_HTTP_RESULT httpCloseConnection(NSS_HTTP_HANDLE handle);
9b58a7
 
9b58a7
diff -up ./esc/src/lib/nss-http-client/response.cpp.fix4 ./esc/src/lib/nss-http-client/response.cpp
9b58a7
--- ./esc/src/lib/nss-http-client/response.cpp.fix4	2019-01-10 16:49:06.754326282 -0800
9b58a7
+++ ./esc/src/lib/nss-http-client/response.cpp	2019-01-10 16:49:15.049286517 -0800
9b58a7
@@ -52,6 +52,7 @@ RecvBuf::RecvBuf( const PRFileDesc *sock
9b58a7
     _socket = socket;
9b58a7
     _allocSize = size;
9b58a7
     _buf = (char *)PR_Malloc(size);
9b58a7
+    _buf[size -1 ] = 0;
9b58a7
     _curPos = 0;
9b58a7
     _curSize = 0;
9b58a7
     // sns can't do "chunked", but ca needs "chunked"
9b58a7
@@ -198,7 +199,11 @@ int RecvBuf::getAllContent() {
9b58a7
                 if (_buf[i+1] == '\n' && _buf[i+2] == '\r' 
9b58a7
                   && _buf[i+3] == '\n') {
9b58a7
                     // find content length
9b58a7
-                    char *clen = strstr(_buf, "Content-length:");
9b58a7
+                    char *clen = NULL;
9b58a7
+                    clen =  strstr(_buf, "Content-length:");
9b58a7
+                    if(!clen) {
9b58a7
+                        clen = strstr(_buf,"Content-Length:");
9b58a7
+                    }
9b58a7
                     if (clen != NULL) {
9b58a7
                         clen = &clen[16];
9b58a7
                         while (1) {
9b58a7
@@ -859,6 +864,7 @@ PRBool PSHttpResponse::processResponse(P
9b58a7
 
9b58a7
         // Get status string
9b58a7
         int index = 0;
9b58a7
+        PRBool inName = PR_TRUE;
9b58a7
         do {
9b58a7
             char ch = buf.getChar();
9b58a7
             if ( ch != -1 && ch != '\r' ) {
9b58a7
@@ -880,15 +886,14 @@ PRBool PSHttpResponse::processResponse(P
9b58a7
 
9b58a7
         // loop over response headers
9b58a7
         index = 0;
9b58a7
-//#ifdef CHECK
9b58a7
         PRBool doneParsing = PR_FALSE;
9b58a7
         PRBool atEOL = PR_FALSE;
9b58a7
-        PRBool inName = PR_TRUE;
9b58a7
+        inName = PR_TRUE;
9b58a7
         char name[2048];
9b58a7
+        char value[2048];
9b58a7
         int nameLen = sizeof(name);
9b58a7
 
9b58a7
         while ( !doneParsing ) {
9b58a7
-            char value[2048];
9b58a7
             int valueLen = sizeof(value);
9b58a7
             char ch = buf.getChar();
9b58a7
 
9b58a7
@@ -901,15 +906,8 @@ PRBool PSHttpResponse::processResponse(P
9b58a7
 
9b58a7
                     nRead = readHeader( buf, value, valueLen );
9b58a7
                     if ( nRead < 0 ) {
9b58a7
-
9b58a7
-                        //                        return PR_FALSE;    
9b58a7
-                    } else {
9b58a7
-                    //    value[index++] = ch;
9b58a7
-                        if ( index >= (int)(sizeof(value) - 1 ) ) {
9b58a7
-
9b58a7
-                            //                            return PR_FALSE;            
9b58a7
-                        }
9b58a7
-                    }
9b58a7
+                        return PR_FALSE;    
9b58a7
+                    } 
9b58a7
                     break;
9b58a7
                 case '\r':
9b58a7
                     if ( inName && !atEOL ) {
9b58a7
@@ -928,6 +926,7 @@ PRBool PSHttpResponse::processResponse(P
9b58a7
 
9b58a7
                         //                        return PR_FALSE;
9b58a7
                     }
9b58a7
+                    
9b58a7
                     value[index] = '\0';
9b58a7
                     index = 0;
9b58a7
                     inName = PR_TRUE;
9b58a7
@@ -936,25 +935,29 @@ PRBool PSHttpResponse::processResponse(P
9b58a7
                     break;
9b58a7
                 default:
9b58a7
                     atEOL = PR_FALSE;
9b58a7
-                    if (inName) {
9b58a7
-                         name[index++] = ch;
9b58a7
-                    } else {
9b58a7
-                         value[index++] = ch;
9b58a7
-                    }
9b58a7
-                    if ( inName && (index >= (nameLen-2)) ) {
9b58a7
-                        name[index] = '\0';
9b58a7
+                    if (inName == PR_TRUE) {
9b58a7
 
9b58a7
-                        //                        return PR_FALSE;            
9b58a7
-                    } else if ( !inName && (index >= (valueLen-1)) ) {
9b58a7
+                         if(index >= (nameLen -2)) {
9b58a7
+                             return false;
9b58a7
+                         } else {
9b58a7
+                             name[index++] = ch;
9b58a7
+                         }
9b58a7
+                    } 
9b58a7
+
9b58a7
+                    if (inName == PR_FALSE) {
9b58a7
+
9b58a7
+                         if(index >= (valueLen - 1)) {
9b58a7
+                             return false;
9b58a7
+                         } else {
9b58a7
+                             value[index++] = ch;
9b58a7
+                         }
9b58a7
+                    }
9b58a7
 
9b58a7
-                        //                        return PR_FALSE;            
9b58a7
-                    }    
9b58a7
                     break;
9b58a7
                 }
9b58a7
             }
9b58a7
 
9b58a7
         } //while
9b58a7
-//#endif //CHECK
9b58a7
     } catch ( RecvBuf::EndOfFile & ) {
9b58a7
         if ( !_request->isHangupOk() ) {
9b58a7