Bug 792808 - Change security/manager/tools scripts to import and instantiate XHRs from global properties rather than using Cc.createInstance(Ci.nsIXMLHttpRequest); r?keeler
MozReview-Commit-ID: 9lddED1IGeD
--- a/security/manager/tools/dumpGoogleRoots.js
+++ b/security/manager/tools/dumpGoogleRoots.js
@@ -8,19 +8,20 @@
//
// How to run this file:
// 1. [obtain firefox source code]
// 2. [build/obtain firefox binaries]
// 3. run `[path to]/run-mozilla.sh [path to]/xpcshell dumpGoogleRoots.js'
// 4. [paste the output into the appropriate section in
// security/manager/tools/PreloadedHPKPins.json]
+Cu.importGlobalProperties(["XMLHttpRequest"]);
+
function downloadRoots() {
- let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
- .createInstance(Ci.nsIXMLHttpRequest);
+ let req = new XMLHttpRequest();
req.open("GET", "https://pki.google.com/roots.pem", false);
try {
req.send();
} catch (e) {
throw new Error("ERROR: problem downloading Google Root PEMs: " + e);
}
if (req.status != 200) {
--- a/security/manager/tools/genHPKPStaticPins.js
+++ b/security/manager/tools/genHPKPStaticPins.js
@@ -18,16 +18,18 @@ if (arguments.length != 3) {
"<an unused argument - see bug 1205406> " +
"<absolute path to StaticHPKPins.h>");
}
var { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm", {});
var { FileUtils } = ChromeUtils.import("resource://gre/modules/FileUtils.jsm", {});
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm", {});
+Cu.importGlobalProperties(["XMLHttpRequest"]);
+
var gCertDB = Cc["@mozilla.org/security/x509certdb;1"]
.getService(Ci.nsIX509CertDB);
const SHA256_PREFIX = "sha256/";
const GOOGLE_PIN_PREFIX = "GOOGLE_PIN_";
// Pins expire in 14 weeks (6 weeks on Beta + 8 weeks on stable)
const PINNING_MINIMUM_REQUIRED_MAX_AGE = 60 * 60 * 24 * 7 * 14;
@@ -94,18 +96,17 @@ function stripComments(buf) {
if (!match) {
data = data + lines[i];
}
}
return data;
}
function download(filename) {
- let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
- .createInstance(Ci.nsIXMLHttpRequest);
+ let req = new XMLHttpRequest();
req.open("GET", filename, false); // doing the request synchronously
try {
req.send();
} catch (e) {
throw new Error(`ERROR: problem downloading '${filename}': ${e}`);
}
if (req.status != 200) {
--- a/security/manager/tools/getHSTSPreloadList.js
+++ b/security/manager/tools/getHSTSPreloadList.js
@@ -14,16 +14,18 @@
var gSSService = Cc["@mozilla.org/ssservice;1"]
.getService(Ci.nsISiteSecurityService);
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.importGlobalProperties(["XMLHttpRequest"]);
+
const SOURCE = "https://chromium.googlesource.com/chromium/src/net/+/master/http/transport_security_state_static.json?format=TEXT";
const OUTPUT = "nsSTSPreloadList.inc";
const ERROR_OUTPUT = "nsSTSPreloadList.errors";
const MINIMUM_REQUIRED_MAX_AGE = 60 * 60 * 24 * 7 * 18;
const MAX_CONCURRENT_REQUESTS = 5;
const MAX_RETRIES = 3;
const REQUEST_TIMEOUT = 30 * 1000;
const ERROR_NONE = "no error";
@@ -38,18 +40,17 @@ const HEADER = "/* This Source Code Form
"/* This is an automatically generated file. If you're not */\n" +
"/* nsSiteSecurityService.cpp, you shouldn't be #including it. */\n" +
"/*****************************************************************************/\n" +
"\n" +
"#include <stdint.h>\n";
const GPERF_DELIM = "%%\n";
function download() {
- let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
- .createInstance(Ci.nsIXMLHttpRequest);
+ let req = new XMLHttpRequest();
req.open("GET", SOURCE, false); // doing the request synchronously
try {
req.send();
} catch (e) {
throw new Error(`ERROR: problem downloading '${SOURCE}': ${e}`);
}
if (req.status != 200) {
@@ -161,18 +162,17 @@ RedirectAndAuthStopper.prototype = {
return this.QueryInterface(iid);
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIChannelEventSink,
Ci.nsIAuthPrompt2])
};
function getHSTSStatus(host, resultList) {
- let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
- .createInstance(Ci.nsIXMLHttpRequest);
+ let req = new XMLHttpRequest();
let inResultList = false;
let uri = "https://" + host.name + "/";
req.open("GET", uri, true);
req.setRequestHeader("X-Automated-Tool",
"https://hg.mozilla.org/mozilla-central/file/tip/security/manager/tools/getHSTSPreloadList.js");
req.timeout = REQUEST_TIMEOUT;
let errorhandler = (evt) => {