Bug 1506734 - Allow paths and distribution directory for certificates. r=Felipe
authorMichael Kaply <mozilla@kaply.com>
Wed, 14 Nov 2018 21:47:22 +0000
changeset 502869 e96d9b255d52bb341617eb34a6f2f8996b7a0033
parent 502868 a4b64b6bd26b0a5091f545c9389a8dca1e0641cf
child 502870 e762fce85daa2b0399f443c4644c6e61a11b1eb3
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe
bugs1506734
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1506734 - Allow paths and distribution directory for certificates. r=Felipe Differential Revision: https://phabricator.services.mozilla.com/D11707
browser/components/enterprisepolicies/Policies.jsm
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -151,47 +151,57 @@ var Policies = {
             ];
           } else if (platform == "macosx" || platform == "linux") {
             dirs = [
               // These two keys are named wrong. They return the Mozilla directory.
               Services.dirsvc.get("XREUserNativeManifests", Ci.nsIFile),
               Services.dirsvc.get("XRESysNativeManifests", Ci.nsIFile),
             ];
           }
-          for (let dir of dirs) {
-            dir.append(platform == "linux" ? "certificates" : "Certificates");
-            for (let certfilename of param.Install) {
-              let certfile = dir.clone();
-              certfile.append(certfilename);
-              let file;
-              try {
-                file = await File.createFromNsIFile(certfile);
-              } catch (e) {
-                log.info(`Unable to open certificate - ${certfile.path}`);
-                continue;
+          dirs.unshift(Services.dirsvc.get("XREAppDist", Ci.nsIFile));
+          for (let certfilename of param.Install) {
+            let certfile;
+            try {
+              certfile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
+              certfile.initWithPath(certfilename);
+            } catch (e) {
+              for (let dir of dirs) {
+                certfile = dir.clone();
+                certfile.append(platform == "linux" ? "certificates" : "Certificates");
+                certfile.append(certfilename);
+                if (certfile.exists()) {
+                  break;
+                }
               }
-              let reader = new FileReader();
-              reader.onloadend = function() {
-                if (reader.readyState != reader.DONE) {
-                  log.error(`Unable to read certificate - ${certfile.path}`);
-                  return;
+            }
+            let file;
+            try {
+              file = await File.createFromNsIFile(certfile);
+            } catch (e) {
+              log.error(`Unable to find certificate - ${certfilename}`);
+              continue;
+            }
+            let reader = new FileReader();
+            reader.onloadend = function() {
+              if (reader.readyState != reader.DONE) {
+                log.error(`Unable to read certificate - ${certfile.path}`);
+                return;
+              }
+              let cert = reader.result;
+              try {
+                if (/-----BEGIN CERTIFICATE-----/.test(cert)) {
+                  gCertDB.addCertFromBase64(pemToBase64(cert), "CTu,CTu,");
+                } else {
+                  gCertDB.addCert(cert, "CTu,CTu,");
                 }
-                let cert = reader.result;
-                try {
-                  if (/-----BEGIN CERTIFICATE-----/.test(cert)) {
-                    gCertDB.addCertFromBase64(pemToBase64(cert), "CTu,CTu,");
-                  } else {
-                    gCertDB.addCert(cert, "CTu,CTu,");
-                  }
-                } catch (e) {
-                  log.error(`Unable to add certificate - ${certfile.path}`);
-                }
-              };
-              reader.readAsBinaryString(file);
-            }
+              } catch (e) {
+                log.error(`Unable to add certificate - ${certfile.path}`);
+              }
+            };
+            reader.readAsBinaryString(file);
           }
         })();
       }
     },
   },
 
   "Cookies": {
     onBeforeUIStartup(manager, param) {