Bug 503515 - Try and ensure exported certificates include an extension by default. r=keeler
authorCykesiopka <cykesiopka.bmo@gmail.com>
Tue, 09 Feb 2016 00:17:00 +0100
changeset 329796 3b0ec072cd212b1449050cc87c5cbed862f30809
parent 329795 0fa3eddf8063895c3a45164a4416471c0eb5a026
child 329797 d7a8f54d6f6ba9bae4f655f117a7cc115e6bc8c2
push id10611
push userdmitchell@mozilla.com
push dateTue, 09 Feb 2016 15:15:43 +0000
reviewerskeeler
bugs503515
milestone47.0a1
Bug 503515 - Try and ensure exported certificates include an extension by default. r=keeler
security/manager/pki/resources/content/pippki.js
--- a/security/manager/pki/resources/content/pippki.js
+++ b/security/manager/pki/resources/content/pippki.js
@@ -67,39 +67,46 @@ function alertPromptService(title, messa
   var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
            getService(Components.interfaces.nsIPromptService);
   ps.alert(window, title, message);
 }
 
 function exportToFile(parent, cert)
 {
   var bundle = document.getElementById("pippki_bundle");
-  if (!cert)
+  if (!cert) {
     return;
+  }
 
   var nsIFilePicker = Components.interfaces.nsIFilePicker;
   var fp = Components.classes["@mozilla.org/filepicker;1"].
            createInstance(nsIFilePicker);
   fp.init(parent, bundle.getString("SaveCertAs"),
           nsIFilePicker.modeSave);
-  var filename = cert.commonName;
-  if (!filename.length)
+  let filename = cert.commonName;
+  if (filename.length == 0) {
     filename = cert.windowTitle;
-  // remove all whitespace from the default filename
-  fp.defaultString = filename.replace(/\s*/g,'');
+  }
+  // Remove all whitespace from the default filename, and try and ensure that
+  // an extension is included by default.
+  // Note: defaultExtension is more of a suggestion to some file picker
+  //       implementations, so we include the extension in the default file name
+  //       as well.
+  fp.defaultString = filename.replace(/\s*/g, "") + ".crt";
   fp.defaultExtension = "crt";
   fp.appendFilter(bundle.getString("CertFormatBase64"), "*.crt; *.pem");
   fp.appendFilter(bundle.getString("CertFormatBase64Chain"), "*.crt; *.pem");
   fp.appendFilter(bundle.getString("CertFormatDER"), "*.der");
   fp.appendFilter(bundle.getString("CertFormatPKCS7"), "*.p7c");
   fp.appendFilter(bundle.getString("CertFormatPKCS7Chain"), "*.p7c");
   fp.appendFilters(nsIFilePicker.filterAll);
   var res = fp.show();
-  if (res != nsIFilePicker.returnOK && res != nsIFilePicker.returnReplace)
+  if (res != nsIFilePicker.returnOK && res != nsIFilePicker.returnReplace) {
     return;
+  }
 
   var content = '';
   switch (fp.filterIndex) {
     case 1:
       content = getPEMString(cert);
       var chain = cert.getChain();
       for (var i = 1; i < chain.length; i++)
         content += getPEMString(chain.queryElementAt(i, Components.interfaces.nsIX509Cert));