Bug 940994 - Adding '.p7b' to 'known file types' list of 'Certificate Manager'. r=keeler
authorShashank Sabniveesu <shashank@linux.com>
Tue, 07 Oct 2014 14:30:00 +0200
changeset 226156 1d6c19a7af9f1da475a78fc586b409b81a28c653
parent 226155 e18a87bf1bfe45d5859a32390772ccbce5eb7532
child 226157 a33eb2f32a326620cf21ad1de9a6e5f38a14273c
push id36
push userdburns@mozilla.com
push dateMon, 10 Nov 2014 15:14:02 +0000
reviewerskeeler
bugs940994
milestone36.0a1
Bug 940994 - Adding '.p7b' to 'known file types' list of 'Certificate Manager'. r=keeler
security/manager/pki/resources/content/certManager.js
--- a/security/manager/pki/resources/content/certManager.js
+++ b/security/manager/pki/resources/content/certManager.js
@@ -11,16 +11,18 @@ const nsICertTree = Components.interface
 const nsCertTree = "@mozilla.org/security/nsCertTree;1";
 const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
 const nsDialogParamBlock = "@mozilla.org/embedcomp/dialogparam;1";
 const nsIPKIParamBlock    = Components.interfaces.nsIPKIParamBlock;
 const nsPKIParamBlock    = "@mozilla.org/security/pkiparamblock;1";
 const nsINSSCertCache = Components.interfaces.nsINSSCertCache;
 const nsNSSCertCache = "@mozilla.org/security/nsscertcache;1";
 
+const gCertFileTypes = "*.p7b; *.crt; *.cert; *.cer; *.pem; *.der";
+
 let { NetUtil } = Components.utils.import("resource://gre/modules/NetUtil.jsm", {});
 let { Services } = Components.utils.import("resource://gre/modules/Services.jsm", {});
 
 var key;
 
 var selected_certs = [];
 var selected_tree_items = [];
 var selected_index = [];
@@ -373,23 +375,31 @@ function restoreCerts()
   var bundle = document.getElementById("pippki_bundle");
   var fp = Components.classes[nsFilePicker].createInstance(nsIFilePicker);
   fp.init(window,
           bundle.getString("chooseP12RestoreFileDialog2"),
           nsIFilePicker.modeOpen);
   fp.appendFilter(bundle.getString("file_browse_PKCS12_spec"),
                   "*.p12; *.pfx");
   fp.appendFilter(bundle.getString("file_browse_Certificate_spec"),
-                  "*.crt; *.cert; *.cer; *.pem; *.der");
+                  gCertFileTypes);
   fp.appendFilters(nsIFilePicker.filterAll);
   if (fp.show() == nsIFilePicker.returnOK) {
     // If this is an X509 user certificate, import it as one.
-    if (fp.file.path.endsWith(".crt") || fp.file.path.endsWith(".cert") ||
-        fp.file.path.endsWith(".cer") || fp.file.path.endsWith(".pem") ||
-        fp.file.path.endsWith(".der")) {
+
+    var isX509FileType = false;
+    var fileTypesList = gFileTypesList.split('; ');
+    for (var type in fileTypesList) {
+      if (fp.file.path.endsWith(type)) {
+        isX509FileType = true;
+  	break;
+      }
+    }
+
+    if (isX509FileType) {
       let fstream = Components.classes["@mozilla.org/network/file-input-stream;1"]
                       .createInstance(Components.interfaces.nsIFileInputStream);
       fstream.init(fp.file, -1, 0, 0);
       let dataString = NetUtil.readInputStreamToString(fstream, fstream.available());
       let dataArray = [];
       for (let i = 0; i < dataString.length; i++) {
         dataArray.push(dataString.charCodeAt(i));
       }
@@ -533,17 +543,17 @@ function viewCerts()
 function addCACerts()
 {
   var bundle = document.getElementById("pippki_bundle");
   var fp = Components.classes[nsFilePicker].createInstance(nsIFilePicker);
   fp.init(window,
           bundle.getString("importCACertsPrompt"),
           nsIFilePicker.modeOpen);
   fp.appendFilter(bundle.getString("file_browse_Certificate_spec"),
-                  "*.crt; *.cert; *.cer; *.pem; *.der");
+                  gCertFileTypes);
   fp.appendFilters(nsIFilePicker.filterAll);
   if (fp.show() == nsIFilePicker.returnOK) {
     certdb.importCertsFromFile(null, fp.file, nsIX509Cert.CA_CERT);
     caTreeView.loadCerts(nsIX509Cert.CA_CERT);
     caTreeView.selection.clearSelection();
   }
 }
 
@@ -568,17 +578,17 @@ function onSmartCardChange()
 function addEmailCert()
 {
   var bundle = document.getElementById("pippki_bundle");
   var fp = Components.classes[nsFilePicker].createInstance(nsIFilePicker);
   fp.init(window,
           bundle.getString("importEmailCertPrompt"),
           nsIFilePicker.modeOpen);
   fp.appendFilter(bundle.getString("file_browse_Certificate_spec"),
-                  "*.crt; *.cert; *.cer; *.pem; *.der");
+                  gCertFileTypes);
   fp.appendFilters(nsIFilePicker.filterAll);
   if (fp.show() == nsIFilePicker.returnOK) {
     certdb.importCertsFromFile(null, fp.file, nsIX509Cert.EMAIL_CERT);
     var certcache = Components.classes[nsNSSCertCache].createInstance(nsINSSCertCache);
     certcache.cacheAllCerts();
     emailTreeView.loadCertsFromCache(certcache, nsIX509Cert.EMAIL_CERT);
     emailTreeView.selection.clearSelection();
     caTreeView.loadCertsFromCache(certcache, nsIX509Cert.CA_CERT);
@@ -589,17 +599,17 @@ function addEmailCert()
 function addWebSiteCert()
 {
   var bundle = document.getElementById("pippki_bundle");
   var fp = Components.classes[nsFilePicker].createInstance(nsIFilePicker);
   fp.init(window,
           bundle.getString("importServerCertPrompt"),
           nsIFilePicker.modeOpen);
   fp.appendFilter(bundle.getString("file_browse_Certificate_spec"),
-                  "*.crt; *.cert; *.cer; *.pem; *.der");
+                  gCertFileTypes);
   fp.appendFilters(nsIFilePicker.filterAll);
   if (fp.show() == nsIFilePicker.returnOK) {
     certdb.importCertsFromFile(null, fp.file, nsIX509Cert.SERVER_CERT);
 
     var certcache = Components.classes[nsNSSCertCache].createInstance(nsINSSCertCache);
     certcache.cacheAllCerts();
     serverTreeView.loadCertsFromCache(certcache, nsIX509Cert.SERVER_CERT);
     serverTreeView.selection.clearSelection();