1 // -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
2 // Any copyright is dedicated to the Public Domain.
3 // http://creativecommons.org/publicdomain/zero/1.0/
6 // Checks that the security.OCSP.enabled pref correctly controls OCSP fetching
9 do_get_profile(); // Must be called before getting nsIX509CertDB
10 const gCertDB = Cc["@mozilla.org/security/x509certdb;1"].getService(
14 const SERVER_PORT = 8888;
16 function certFromFile(filename) {
17 return constructCertFromFile(`test_ev_certs/${filename}.pem`);
20 function loadCert(certName, trustString) {
21 addCertFromFile(gCertDB, `test_ev_certs/${certName}.pem`, trustString);
24 function getFailingOCSPResponder() {
25 return getFailingHttpServer(SERVER_PORT, ["www.example.com"]);
28 function getOCSPResponder(expectedCertNames) {
29 return startOCSPResponder(
38 // Tests that in ocspOff mode, OCSP fetches are never done.
39 async function testOff() {
40 Services.prefs.setIntPref("security.OCSP.enabled", 0);
41 info("Setting security.OCSP.enabled to 0");
43 // EV chains should verify successfully but never get EV status.
45 let ocspResponder = getFailingOCSPResponder();
48 certFromFile("test-oid-path-ee"),
49 certificateUsageSSLServer,
52 await stopOCSPResponder(ocspResponder);
54 // A DV chain should verify successfully.
56 ocspResponder = getFailingOCSPResponder();
57 await checkCertErrorGeneric(
59 certFromFile("non-ev-root-path-ee"),
61 certificateUsageSSLServer
63 await stopOCSPResponder(ocspResponder);
66 // Tests that in ocspOn mode, OCSP fetches are done for both EV and DV certs.
67 async function testOn() {
68 Services.prefs.setIntPref("security.OCSP.enabled", 1);
69 info("Setting security.OCSP.enabled to 1");
71 // If a successful OCSP response is fetched, then an EV chain should verify
72 // successfully and get EV status as well.
74 let ocspResponder = getOCSPResponder(["test-oid-path-ee"]);
77 certFromFile("test-oid-path-ee"),
78 certificateUsageSSLServer,
81 await stopOCSPResponder(ocspResponder);
83 // If a successful OCSP response is fetched, then a DV chain should verify
86 ocspResponder = getOCSPResponder(["non-ev-root-path-ee"]);
87 await checkCertErrorGeneric(
89 certFromFile("non-ev-root-path-ee"),
91 certificateUsageSSLServer
93 await stopOCSPResponder(ocspResponder);
96 // Tests that in ocspEVOnly mode, OCSP fetches are done for EV certs only.
97 async function testEVOnly() {
98 Services.prefs.setIntPref("security.OCSP.enabled", 2);
99 info("Setting security.OCSP.enabled to 2");
101 // If a successful OCSP response is fetched, then an EV chain should verify
102 // successfully and get EV status as well.
104 let ocspResponder = gEVExpected
105 ? getOCSPResponder(["test-oid-path-ee"])
106 : getFailingOCSPResponder();
109 certFromFile("test-oid-path-ee"),
110 certificateUsageSSLServer,
113 await stopOCSPResponder(ocspResponder);
115 // A DV chain should verify successfully even without doing OCSP fetches.
117 ocspResponder = getFailingOCSPResponder();
118 await checkCertErrorGeneric(
120 certFromFile("non-ev-root-path-ee"),
122 certificateUsageSSLServer
124 await stopOCSPResponder(ocspResponder);
127 add_task(async function () {
128 registerCleanupFunction(() => {
129 Services.prefs.clearUserPref("network.dns.localDomains");
130 Services.prefs.clearUserPref("security.OCSP.enabled");
131 Services.prefs.clearUserPref("security.OCSP.require");
133 Services.prefs.setCharPref("network.dns.localDomains", "www.example.com");
134 // Enable hard fail to ensure chains that should only succeed because they get
135 // a good OCSP response do not succeed due to soft fail leniency.
136 Services.prefs.setBoolPref("security.OCSP.require", true);
138 loadCert("evroot", "CTu,,");
139 loadCert("test-oid-path-int", ",,");
140 loadCert("non-evroot-ca", "CTu,,");
141 loadCert("non-ev-root-path-int", ",,");