Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / remote / marionette / cert.sys.mjs
blobc2cdf7b748e5ebfc2c1cf95af0d34b0317676dfc
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 file,
3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
7 const lazy = {};
9 XPCOMUtils.defineLazyServiceGetter(
10   lazy,
11   "sss",
12   "@mozilla.org/ssservice;1",
13   "nsISiteSecurityService"
16 XPCOMUtils.defineLazyServiceGetter(
17   lazy,
18   "certOverrideService",
19   "@mozilla.org/security/certoverride;1",
20   "nsICertOverrideService"
23 const CERT_PINNING_ENFORCEMENT_PREF = "security.cert_pinning.enforcement_level";
24 const HSTS_PRELOAD_LIST_PREF = "network.stricttransportsecurity.preloadlist";
26 /** @namespace */
27 export const allowAllCerts = {};
29 /**
30  * Disable all security check and allow all certs.
31  */
32 allowAllCerts.enable = function () {
33   // make it possible to register certificate overrides for domains
34   // that use HSTS or HPKP
35   Services.prefs.setBoolPref(HSTS_PRELOAD_LIST_PREF, false);
36   Services.prefs.setIntPref(CERT_PINNING_ENFORCEMENT_PREF, 0);
38   lazy.certOverrideService.setDisableAllSecurityChecksAndLetAttackersInterceptMyData(
39     true
40   );
43 /**
44  * Enable all security check.
45  */
46 allowAllCerts.disable = function () {
47   lazy.certOverrideService.setDisableAllSecurityChecksAndLetAttackersInterceptMyData(
48     false
49   );
51   Services.prefs.clearUserPref(HSTS_PRELOAD_LIST_PREF);
52   Services.prefs.clearUserPref(CERT_PINNING_ENFORCEMENT_PREF);
54   // clear collected HSTS and HPKP state
55   // through the site security service
56   lazy.sss.clearAll();