1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 // This file is a helper script that generates the list of certificates that
7 // make up the preloaded pinset for Google properties.
9 // How to run this file:
10 // 1. [obtain firefox source code]
11 // 2. [build/obtain firefox binaries]
12 // 3. run `[path to]/firefox -xpcshell dumpGoogleRoots.js'
13 // 4. [paste the output into the appropriate section in
14 // security/manager/tools/PreloadedHPKPins.json]
16 Services.prefs.setBoolPref("network.process.enabled", false);
18 function downloadRoots() {
19 let req = new XMLHttpRequest();
20 req.open("GET", "https://pki.google.com/roots.pem", false);
24 throw new Error("ERROR: problem downloading Google Root PEMs: " + e);
27 if (req.status != 200) {
29 "ERROR: problem downloading Google Root PEMs. Status: " + req.status
33 let pem = req.responseText;
36 let readingRoot = false;
37 let certDB = Cc["@mozilla.org/security/x509certdb;1"].getService(
40 for (let line of pem.split(/[\r\n]/)) {
41 if (line == "-----END CERTIFICATE-----") {
43 roots.push(certDB.constructX509FromBase64(currentPEM));
52 if (line == "-----BEGIN CERTIFICATE-----") {
59 function makeFormattedNickname(cert, knownNicknames) {
60 if (cert.displayName in knownNicknames) {
61 return `"${cert.displayName}"`;
63 // Otherwise, this isn't a built-in and we have to comment it out.
64 return `// "${cert.displayName}"`;
67 function gatherKnownNicknames() {
68 let certDB = Cc["@mozilla.org/security/x509certdb;1"].getService(
72 for (let cert of certDB.getCerts()) {
73 nicknames[cert.displayName] = true;
78 var knownNicknames = gatherKnownNicknames();
79 var roots = downloadRoots();
80 var rootNicknames = [];
81 for (var root of roots) {
82 rootNicknames.push(makeFormattedNickname(root, knownNicknames));
84 rootNicknames.sort(function (rootA, rootB) {
85 let rootALowercase = rootA.toLowerCase().replace(/(^[^"]*")|"/g, "");
86 let rootBLowercase = rootB.toLowerCase().replace(/(^[^"]*")|"/g, "");
87 if (rootALowercase < rootBLowercase) {
90 if (rootALowercase > rootBLowercase) {
96 dump(' "name": "google_root_pems",\n');
97 dump(' "sha256_hashes": [\n');
99 for (var nickname of rootNicknames) {
104 dump(" " + nickname);