1 // -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
2 // This Source Code Form is subject to the terms of the Mozilla Public
3 // License, v. 2.0. If a copy of the MPL was not distributed with this
4 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 // Tests OCSP Must Staple handling by connecting to various domains (as faked by
8 // a server running locally) that correspond to combinations of whether the
9 // extension is present in intermediate and end-entity certificates.
11 var gExpectOCSPRequest;
13 function add_ocsp_test(
17 aExpectOCSPRequest = false,
18 aWithSecurityInfo = undefined
24 gExpectOCSPRequest = aExpectOCSPRequest;
27 Services.prefs.setBoolPref(
28 "security.ssl.enable_ocsp_stapling",
36 function add_tests() {
37 // Next, a case where it's present in the intermediate, not the ee
39 "ocsp-stapling-plain-ee-with-must-staple-int.example.com",
40 MOZILLA_PKIX_ERROR_REQUIRED_TLS_FEATURE_MISSING,
44 // We disable OCSP stapling in the next two tests so we can perform checks
45 // on TLS Features in the chain without needing to support the TLS
46 // extension values used.
47 // Test an issuer with multiple TLS features in matched in the EE
49 "multi-tls-feature-good.example.com",
54 // Finally, an issuer with multiple TLS features not matched by the EE.
56 "multi-tls-feature-bad.example.com",
57 MOZILLA_PKIX_ERROR_REQUIRED_TLS_FEATURE_MISSING,
61 // Now a bunch of operations with only a must-staple ee
63 "ocsp-stapling-must-staple.example.com",
69 "ocsp-stapling-must-staple-revoked.example.com",
70 SEC_ERROR_REVOKED_CERTIFICATE,
75 "ocsp-stapling-must-staple-missing.example.com",
76 MOZILLA_PKIX_ERROR_REQUIRED_TLS_FEATURE_MISSING,
82 "ocsp-stapling-must-staple-empty.example.com",
83 SEC_ERROR_OCSP_MALFORMED_RESPONSE,
88 "ocsp-stapling-must-staple-missing.example.com",
94 // If the stapled response is expired, we will try to fetch a new one.
95 // If that fails, we should report the original error.
97 "ocsp-stapling-must-staple-expired.example.com",
98 SEC_ERROR_OCSP_OLD_RESPONSE,
102 // Similarly with a "try server later" response.
104 "ocsp-stapling-must-staple-try-later.example.com",
105 SEC_ERROR_OCSP_TRY_SERVER_LATER,
109 // And again with an invalid OCSP response signing certificate.
111 "ocsp-stapling-must-staple-invalid-signer.example.com",
112 SEC_ERROR_OCSP_INVALID_SIGNING_CERT,
117 // check that disabling must-staple works
118 add_test(function () {
120 Services.prefs.setBoolPref("security.ssl.enable_ocsp_must_staple", false);
125 "ocsp-stapling-must-staple-missing.example.com",
132 function run_test() {
134 Services.prefs.setBoolPref("security.ssl.enable_ocsp_must_staple", true);
135 Services.prefs.setIntPref("security.OCSP.enabled", 1);
136 // This test may sometimes fail on android due to an OCSP request timing out.
137 // That aspect of OCSP requests is not what we're testing here, so we can just
138 // bump the timeout and hopefully avoid these failures.
139 Services.prefs.setIntPref("security.OCSP.timeoutMilliseconds.soft", 5000);
141 let fakeOCSPResponder = new HttpServer();
142 fakeOCSPResponder.registerPrefixHandler("/", function (request, response) {
143 response.setStatusLine(request.httpVersion, 500, "Internal Server Error");
146 "Should be getting an OCSP request only when expected"
149 fakeOCSPResponder.start(8888);
151 add_tls_server_setup("OCSPStaplingServer", "ocsp_certs");
155 add_test(function () {
156 fakeOCSPResponder.stop(run_next_test);