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 // Tests that chains containing an end-entity cert with an overly long validity
7 // period are rejected.
9 do_get_profile(); // Must be called before getting nsIX509CertDB
10 const certDB = Cc["@mozilla.org/security/x509certdb;1"].getService(
14 const SERVER_PORT = 8888;
16 function getOCSPResponder(expectedCertNames) {
17 let expectedPaths = expectedCertNames.slice();
18 return startOCSPResponder(
27 function certFromFile(filename) {
28 return constructCertFromFile(`test_validity/${filename}`);
31 function loadCert(certFilename, trustString) {
32 addCertFromFile(certDB, `test_validity/${certFilename}`, trustString);
36 * Asynchronously runs a single EV test.
38 * @param {Array} expectedNamesForOCSP
39 * An array of nicknames of the certs to be responded to.
40 * @param {string} rootCertFileName
41 * The file name of the root cert. Can begin with ".." to reference
42 * certs in folders other than "test_validity/".
43 * @param {Array} intCertFileNames
44 * An array of file names of any intermediate certificates.
45 * @param {string} endEntityCertFileName
46 * The file name of the end entity cert.
47 * @param {boolean} expectedResult
48 * Whether the chain is expected to validate as EV.
50 async function doEVTest(
54 endEntityCertFileName,
58 let ocspResponder = getOCSPResponder(expectedNamesForOCSP);
60 loadCert(`${rootCertFileName}.pem`, "CTu,CTu,CTu");
61 for (let intCertFileName of intCertFileNames) {
62 loadCert(`${intCertFileName}.pem`, ",,");
66 certFromFile(`${endEntityCertFileName}.pem`),
67 certificateUsageSSLServer,
71 await stopOCSPResponder(ocspResponder);
74 async function checkEVChains() {
75 // Chain with an end entity cert with a validity period that is acceptable
77 const intFullName = "ev_int_60_months-evroot";
78 let eeFullName = `ev_ee_27_months-${intFullName}`;
79 let expectedNamesForOCSP = [eeFullName];
82 "../test_ev_certs/evroot",
88 // Chain with an end entity cert with a validity period that is too long
90 eeFullName = `ev_ee_28_months-${intFullName}`;
91 expectedNamesForOCSP = [eeFullName];
94 "../test_ev_certs/evroot",
101 add_task(async function () {
102 Services.prefs.setCharPref("network.dns.localDomains", "www.example.com");
103 Services.prefs.setIntPref("security.OCSP.enabled", 1);
105 await checkEVChains();