summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpcshell/head_cert_handling.js
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/mozapps/extensions/test/xpcshell/head_cert_handling.js')
-rw-r--r--toolkit/mozapps/extensions/test/xpcshell/head_cert_handling.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/head_cert_handling.js b/toolkit/mozapps/extensions/test/xpcshell/head_cert_handling.js
new file mode 100644
index 0000000000..08c41a8c7e
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/xpcshell/head_cert_handling.js
@@ -0,0 +1,33 @@
+// Helpers for handling certs.
+// These are taken from
+// https://searchfox.org/mozilla-central/rev/36aa22c7ea92bd3cf7910774004fff7e63341cf5/security/manager/ssl/tests/unit/head_psm.js
+// but we don't want to drag that file in here because
+// - it conflicts with `head_addons.js`.
+// - it has a lot of extra code we don't need.
+// So dupe relevant code here.
+
+// This file will be included along with head_addons.js, use its globals.
+/* import-globals-from head_addons.js */
+
+"use strict";
+
+function readFile(file) {
+ let fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
+ Ci.nsIFileInputStream
+ );
+ fstream.init(file, -1, 0, 0);
+ let available = fstream.available();
+ let data =
+ available > 0 ? NetUtil.readInputStreamToString(fstream, available) : "";
+ fstream.close();
+ return data;
+}
+
+function loadCertChain(prefix, names) {
+ let chain = [];
+ for (let name of names) {
+ let filename = `${prefix}_${name}.pem`;
+ chain.push(readFile(do_get_file(filename)));
+ }
+ return chain;
+}