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 domain (as faked by a server running locally) and
8 // start up an OCSP responder (also basically faked) that gives a response with
9 // a bad signature (and later, an empty response). With security.OCSP.require
10 // set to true, these connections should fail (but they also shouldn't cause
11 // assertion failures).
13 var gOCSPRequestCount = 0;
18 Services.prefs.setBoolPref("security.OCSP.require", true);
19 Services.prefs.setIntPref("security.OCSP.enabled", 1);
21 // We don't actually make use of stapling in this test. This is just how we
22 // get a TLS connection.
23 add_tls_server_setup("OCSPStaplingServer", "ocsp_certs");
25 let args = [["bad-signature", "default-ee", "unused", 0]];
26 let ocspResponses = generateOCSPResponses(args, "ocsp_certs");
27 // Start by replying with a response with a bad signature.
28 gOCSPResponse = ocspResponses[0];
30 let ocspResponder = new HttpServer();
31 ocspResponder.registerPrefixHandler("/", function (request, response) {
32 response.setStatusLine(request.httpVersion, 200, "OK");
33 response.setHeader("Content-Type", "application/ocsp-response");
34 response.write(gOCSPResponse);
37 ocspResponder.start(8888);
41 add_test(function () {
42 ocspResponder.stop(run_next_test);
48 function add_tests() {
50 "ocsp-stapling-none.example.com",
51 SEC_ERROR_OCSP_BAD_SIGNATURE,
53 function (aTransportSecurityInfo) {
55 aTransportSecurityInfo.madeOCSPRequests,
56 "An OCSP Request should have been made."
61 "ocsp-stapling-none.example.com",
62 SEC_ERROR_OCSP_BAD_SIGNATURE,
64 function (aTransportSecurityInfo) {
66 !aTransportSecurityInfo.madeOCSPRequests,
67 "An OCSP Request should not have been made."
71 add_test(function () {
75 "OCSP request count should be 1 due to OCSP response caching"
77 gOCSPRequestCount = 0;
78 // Now set the OCSP responder to reply with 200 OK but empty content.
85 "ocsp-stapling-none.example.com",
86 SEC_ERROR_OCSP_MALFORMED_RESPONSE,
88 function (aTransportSecurityInfo) {
90 aTransportSecurityInfo.madeOCSPRequests,
91 "An OCSP Request should have been made."