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 // In which we connect to a number of domains (as faked by a server running
8 // locally) with and without OCSP stapling enabled to determine that good
9 // things happen and bad things don't.
11 // Enable the collection (during test) for all products so even products
12 // that don't collect the data will be able to run the test without failure.
13 Services.prefs.setBoolPref(
14 "toolkit.telemetry.testing.overrideProductsCheck",
18 var gExpectOCSPRequest;
20 function add_ocsp_test(
24 aExpectOCSPRequest = false
26 add_connection_test(aHost, aExpectedResult, function () {
27 gExpectOCSPRequest = aExpectOCSPRequest;
30 Services.prefs.setBoolPref(
31 "security.ssl.enable_ocsp_stapling",
37 function add_tests() {
38 // In the absence of OCSP stapling, these should actually all work.
40 "ocsp-stapling-good.example.com",
46 "ocsp-stapling-revoked.example.com",
52 "ocsp-stapling-good-other-ca.example.com",
58 "ocsp-stapling-malformed.example.com",
64 "ocsp-stapling-srverr.example.com",
70 "ocsp-stapling-trylater.example.com",
76 "ocsp-stapling-needssig.example.com",
82 "ocsp-stapling-unauthorized.example.com",
88 "ocsp-stapling-unknown.example.com",
94 "ocsp-stapling-good-other.example.com",
100 "ocsp-stapling-none.example.com",
106 "ocsp-stapling-expired.example.com",
112 "ocsp-stapling-expired-fresh-ca.example.com",
118 "ocsp-stapling-skip-responseBytes.example.com",
124 "ocsp-stapling-critical-extension.example.com",
130 "ocsp-stapling-noncritical-extension.example.com",
136 "ocsp-stapling-empty-extensions.example.com",
142 // Now test OCSP stapling
143 // The following error codes are defined in security/nss/lib/util/SECerrs.h
145 add_ocsp_test("ocsp-stapling-good.example.com", PRErrorCodeSuccess, true);
148 "ocsp-stapling-revoked.example.com",
149 SEC_ERROR_REVOKED_CERTIFICATE,
153 // This stapled response is from a CA that is untrusted and did not issue
154 // the server's certificate.
155 let certDB = Cc["@mozilla.org/security/x509certdb;1"].getService(
158 let otherTestCA = constructCertFromFile("ocsp_certs/other-test-ca.pem");
159 add_test(function () {
162 Ci.nsIX509Cert.CA_CERT,
163 Ci.nsIX509CertDB.UNTRUSTED
168 "ocsp-stapling-good-other-ca.example.com",
169 SEC_ERROR_OCSP_INVALID_SIGNING_CERT,
174 // The stapled response is from a CA that is trusted but did not issue the
175 // server's certificate.
176 add_test(function () {
179 Ci.nsIX509Cert.CA_CERT,
180 Ci.nsIX509CertDB.TRUSTED_SSL
184 // TODO(bug 979055): When using ByName instead of ByKey, the error here is
185 // SEC_ERROR_OCSP_UNAUTHORIZED_RESPONSE. We should be testing both cases.
187 "ocsp-stapling-good-other-ca.example.com",
188 SEC_ERROR_OCSP_INVALID_SIGNING_CERT,
193 // TODO: Test the case where the signing cert can't be found at all, which
194 // will result in SEC_ERROR_BAD_DATABASE in the NSS classic case.
197 "ocsp-stapling-malformed.example.com",
198 SEC_ERROR_OCSP_MALFORMED_REQUEST,
202 "ocsp-stapling-srverr.example.com",
203 SEC_ERROR_OCSP_SERVER_ERROR,
207 "ocsp-stapling-trylater.example.com",
208 SEC_ERROR_OCSP_TRY_SERVER_LATER,
213 "ocsp-stapling-needssig.example.com",
214 SEC_ERROR_OCSP_REQUEST_NEEDS_SIG,
218 "ocsp-stapling-unauthorized.example.com",
219 SEC_ERROR_OCSP_UNAUTHORIZED_REQUEST,
223 "ocsp-stapling-unknown.example.com",
224 SEC_ERROR_OCSP_UNKNOWN_CERT,
228 "ocsp-stapling-good-other.example.com",
229 MOZILLA_PKIX_ERROR_OCSP_RESPONSE_FOR_CERT_MISSING,
232 // If the server doesn't staple an OCSP response, we continue as normal
233 // (this means that even though stapling is enabled, we expect an OCSP
236 "ocsp-stapling-none.example.com",
239 gExpectOCSPRequest = true;
242 Services.prefs.setBoolPref("security.ssl.enable_ocsp_stapling", true);
246 "ocsp-stapling-empty.example.com",
247 SEC_ERROR_OCSP_MALFORMED_RESPONSE,
252 "ocsp-stapling-skip-responseBytes.example.com",
253 SEC_ERROR_OCSP_MALFORMED_RESPONSE,
258 "ocsp-stapling-critical-extension.example.com",
259 SEC_ERROR_UNKNOWN_CRITICAL_EXTENSION,
263 "ocsp-stapling-noncritical-extension.example.com",
267 // TODO(bug 997994): Disallow empty Extensions in responses
269 "ocsp-stapling-empty-extensions.example.com",
275 "ocsp-stapling-delegated-included.example.com",
280 "ocsp-stapling-delegated-included-last.example.com",
285 "ocsp-stapling-delegated-missing.example.com",
286 SEC_ERROR_OCSP_INVALID_SIGNING_CERT,
291 "ocsp-stapling-delegated-missing-multiple.example.com",
292 SEC_ERROR_OCSP_INVALID_SIGNING_CERT,
297 "ocsp-stapling-delegated-no-extKeyUsage.example.com",
298 SEC_ERROR_OCSP_INVALID_SIGNING_CERT,
303 "ocsp-stapling-delegated-from-intermediate.example.com",
304 SEC_ERROR_OCSP_INVALID_SIGNING_CERT,
309 "ocsp-stapling-delegated-keyUsage-crlSigning.example.com",
310 SEC_ERROR_OCSP_INVALID_SIGNING_CERT,
315 "ocsp-stapling-delegated-wrong-extKeyUsage.example.com",
316 SEC_ERROR_OCSP_INVALID_SIGNING_CERT,
321 // ocsp-stapling-expired.example.com and
322 // ocsp-stapling-expired-fresh-ca.example.com are handled in
323 // test_ocsp_stapling_expired.js
325 // Check that OCSP responder certificates with key sizes below 1024 bits are
326 // rejected, even when the main certificate chain keys are at least 1024 bits.
328 "keysize-ocsp-delegated.example.com",
329 SEC_ERROR_OCSP_INVALID_SIGNING_CERT,
335 "revoked-ca-cert-used-as-end-entity.example.com",
336 SEC_ERROR_REVOKED_CERTIFICATE,
341 function check_ocsp_stapling_telemetry() {
342 let histogram = Services.telemetry
343 .getHistogramById("SSL_OCSP_STAPLING")
348 "Should have 0 connections for unused histogram bucket 0"
353 "Actual and expected connections with a good response should match"
358 "Actual and expected connections with no stapled response should match"
361 histogram.values[3] || 0,
363 "Actual and expected connections with an expired response should match"
368 "Actual and expected connections with bad responses should match"
373 function run_test() {
375 Services.prefs.setIntPref("security.OCSP.enabled", 1);
376 // This test may sometimes fail on android due to an OCSP request timing out.
377 // That aspect of OCSP requests is not what we're testing here, so we can just
378 // bump the timeout and hopefully avoid these failures.
379 Services.prefs.setIntPref("security.OCSP.timeoutMilliseconds.soft", 5000);
381 let fakeOCSPResponder = new HttpServer();
382 fakeOCSPResponder.registerPrefixHandler("/", function (request, response) {
383 response.setStatusLine(request.httpVersion, 500, "Internal Server Error");
386 "Should be getting an OCSP request only when expected"
389 fakeOCSPResponder.start(8888);
391 add_tls_server_setup("OCSPStaplingServer", "ocsp_certs");
395 add_test(function () {
396 fakeOCSPResponder.stop(check_ocsp_stapling_telemetry);