Bug 503515 - Try and ensure exported certificates include an extension by default. draft
authorCykesiopka <cykesiopka.bmo@gmail.com>
Sun, 07 Feb 2016 22:02:12 -0800
changeset 329522 8f06eb9d8ad3e69bb5e6237ae7217094e616eb61
parent 329521 45554120ac30245ec2d4f7a12fc203ed4ca38586
child 513968 d120199958d33f5bbe233c42be139b24fbf226ae
push id10535
push usercykesiopka.bmo@gmail.com
push dateMon, 08 Feb 2016 06:09:01 +0000
bugs503515
milestone47.0a1
Bug 503515 - Try and ensure exported certificates include an extension by default.
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,45 @@ 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.init(parent, bundle.getString("SaveCertAs"), nsIFilePicker.modeSave);
   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));