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 // This test connects to ocsp-stapling-none.example.com to test that OCSP
8 // requests are cancelled if they're taking too long.
9 // ocsp-stapling-none.example.com doesn't staple an OCSP response, so
10 // connecting to it will cause a request to the OCSP responder. As with all of
11 // these tests, the OCSP AIA (i.e. the url of the responder) in the certificate
12 // is http://localhost:8888. Since this test opens a TCP socket listening on
13 // port 8888 that just accepts connections and then ignores them (with
14 // connect/read/write timeouts of 30 seconds), the OCSP requests should cancel
15 // themselves. When OCSP hard-fail is enabled, connections will be terminated.
16 // Otherwise, they will succeed.
18 var gSocketListener = {
19 onSocketAccepted(serverSocket, socketTransport) {
20 socketTransport.setTimeout(Ci.nsISocketTransport.TIMEOUT_CONNECT, 30);
21 socketTransport.setTimeout(Ci.nsISocketTransport.TIMEOUT_READ_WRITE, 30);
29 Services.prefs.setIntPref("security.OCSP.enabled", 1);
31 add_tls_server_setup("OCSPStaplingServer", "ocsp_certs");
33 let socket = Cc["@mozilla.org/network/server-socket;1"].createInstance(
36 socket.init(8888, true, -1);
37 socket.asyncListen(gSocketListener);
39 add_one_test(false, "security.OCSP.timeoutMilliseconds.soft", 1000);
40 add_one_test(false, "security.OCSP.timeoutMilliseconds.soft", 2000);
41 add_one_test(false, "security.OCSP.timeoutMilliseconds.soft", 4000);
43 add_one_test(true, "security.OCSP.timeoutMilliseconds.hard", 3000);
44 add_one_test(true, "security.OCSP.timeoutMilliseconds.hard", 10000);
45 add_one_test(true, "security.OCSP.timeoutMilliseconds.hard", 15000);
47 add_test(function () {
54 function add_one_test(useHardFail, timeoutPrefName, timeoutMilliseconds) {
56 add_test(function () {
57 Services.prefs.setBoolPref("security.OCSP.require", useHardFail);
58 Services.prefs.setIntPref(timeoutPrefName, timeoutMilliseconds);
59 startTime = new Date();
64 "ocsp-stapling-none.example.com",
65 useHardFail ? SEC_ERROR_OCSP_SERVER_ERROR : PRErrorCodeSuccess,
69 add_test(function () {
70 let endTime = new Date();
71 let timeDifference = endTime - startTime;
72 info(`useHardFail = ${useHardFail}`);
73 info(`startTime = ${startTime.getTime()} (${startTime})`);
74 info(`endTime = ${endTime.getTime()} (${endTime})`);
75 info(`timeDifference = ${timeDifference}ms`);
76 // Date() is not guaranteed to be monotonic, so add extra fuzz time to
77 // prevent intermittent failures (this only appeared to be a problem on
78 // Windows XP). See Bug 1121117.
81 timeDifference + FUZZ_MS,
83 `OCSP timeout should be ~${timeoutMilliseconds}s for ` +
84 `${useHardFail ? "hard" : "soft"}-fail`
86 // Make sure we didn't wait too long.
87 // (Unfortunately, we probably can't have a tight upper bound on
88 // how long is too long for this test, because we might be running
93 "Automatic OCSP timeout shouldn't be more than 60s"
98 Services.prefs.clearUserPref("security.OCSP.require");
99 Services.prefs.clearUserPref(timeoutPrefName);