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/.
6 // Tests that the extended key usage extension is properly processed by the
7 // platform when verifying certificates. There are already comprehensive tests
8 // in mozilla::pkix itself, but these tests serve as integration tests to ensure
9 // that the cases we're particularly concerned about are correctly handled.
13 do_get_profile(); // must be called before getting nsIX509CertDB
14 const certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
18 function certFromFile(certName) {
19 return constructCertFromFile(`test_cert_eku/${certName}.pem`);
22 function loadCertWithTrust(certName, trustString) {
23 addCertFromFile(certdb, `test_cert_eku/${certName}.pem`, trustString);
26 function checkEndEntity(cert, expectedResult) {
27 return checkCertErrorGeneric(
31 certificateUsageSSLServer
35 function checkCertOn25August2016(cert, expectedResult) {
36 // (new Date("2016-08-25T00:00:00Z")).getTime() / 1000
37 const VALIDATION_TIME = 1472083200;
38 return checkCertErrorGenericAtTime(
42 certificateUsageSSLServer,
47 add_task(async function () {
48 registerCleanupFunction(() => {
49 Services.prefs.clearUserPref("privacy.reduceTimerPrecision");
51 Services.prefs.setBoolPref("privacy.reduceTimerPrecision", false);
53 loadCertWithTrust("ca", "CTu,,");
54 // end-entity has id-kp-serverAuth => success
55 await checkEndEntity(certFromFile("ee-SA"), PRErrorCodeSuccess);
56 // end-entity has id-kp-serverAuth => success
57 await checkEndEntity(certFromFile("ee-SA-CA"), PRErrorCodeSuccess);
58 // end-entity has extended key usage, but id-kp-serverAuth is not present =>
60 await checkEndEntity(certFromFile("ee-CA"), SEC_ERROR_INADEQUATE_CERT_TYPE);
61 // end-entity has id-kp-serverAuth => success
62 await checkEndEntity(certFromFile("ee-SA-nsSGC"), PRErrorCodeSuccess);
64 // end-entity has extended key usage, but id-kp-serverAuth is not present =>
65 // failure (in particular, Netscape Server Gated Crypto (also known as
66 // Netscape Step Up) is not an acceptable substitute for end-entity
68 // Verify this for all Netscape Step Up policy configurations.
69 // 0 = "always accept nsSGC in place of serverAuth for CA certificates"
70 Services.prefs.setIntPref("security.pki.netscape_step_up_policy", 0);
72 certFromFile("ee-nsSGC"),
73 SEC_ERROR_INADEQUATE_CERT_TYPE
75 // 1 = "accept nsSGC before 23 August 2016"
76 Services.prefs.setIntPref("security.pki.netscape_step_up_policy", 1);
78 certFromFile("ee-nsSGC"),
79 SEC_ERROR_INADEQUATE_CERT_TYPE
81 // 2 = "accept nsSGC before 23 August 2015"
82 Services.prefs.setIntPref("security.pki.netscape_step_up_policy", 2);
84 certFromFile("ee-nsSGC"),
85 SEC_ERROR_INADEQUATE_CERT_TYPE
87 // 3 = "never accept nsSGC"
88 Services.prefs.setIntPref("security.pki.netscape_step_up_policy", 3);
90 certFromFile("ee-nsSGC"),
91 SEC_ERROR_INADEQUATE_CERT_TYPE
94 // end-entity has id-kp-OCSPSigning, which is not acceptable for end-entity
95 // certificates being verified as TLS server certificates => failure
97 certFromFile("ee-SA-OCSP"),
98 SEC_ERROR_INADEQUATE_CERT_TYPE
101 // intermediate has id-kp-serverAuth => success
102 loadCertWithTrust("int-SA", ",,");
103 await checkEndEntity(certFromFile("ee-int-SA"), PRErrorCodeSuccess);
104 // intermediate has id-kp-serverAuth => success
105 loadCertWithTrust("int-SA-CA", ",,");
106 await checkEndEntity(certFromFile("ee-int-SA-CA"), PRErrorCodeSuccess);
107 // intermediate has extended key usage, but id-kp-serverAuth is not present
109 loadCertWithTrust("int-CA", ",,");
110 await checkEndEntity(
111 certFromFile("ee-int-CA"),
112 SEC_ERROR_INADEQUATE_CERT_TYPE
114 // intermediate has id-kp-serverAuth => success
115 loadCertWithTrust("int-SA-nsSGC", ",,");
116 await checkEndEntity(certFromFile("ee-int-SA-nsSGC"), PRErrorCodeSuccess);
118 // Intermediate has Netscape Server Gated Crypto. Success will depend on the
119 // Netscape Step Up policy configuration and the notBefore property of the
121 loadCertWithTrust("int-nsSGC-recent", ",,");
122 loadCertWithTrust("int-nsSGC-old", ",,");
123 loadCertWithTrust("int-nsSGC-older", ",,");
124 // 0 = "always accept nsSGC in place of serverAuth for CA certificates"
125 Services.prefs.setIntPref("security.pki.netscape_step_up_policy", 0);
126 info("Netscape Step Up policy: always accept");
127 await checkCertOn25August2016(
128 certFromFile("ee-int-nsSGC-recent"),
131 await checkCertOn25August2016(
132 certFromFile("ee-int-nsSGC-old"),
135 await checkCertOn25August2016(
136 certFromFile("ee-int-nsSGC-older"),
139 // 1 = "accept nsSGC before 23 August 2016"
140 info("Netscape Step Up policy: accept before 23 August 2016");
141 Services.prefs.setIntPref("security.pki.netscape_step_up_policy", 1);
142 await checkCertOn25August2016(
143 certFromFile("ee-int-nsSGC-recent"),
144 SEC_ERROR_INADEQUATE_CERT_TYPE
146 await checkCertOn25August2016(
147 certFromFile("ee-int-nsSGC-old"),
150 await checkCertOn25August2016(
151 certFromFile("ee-int-nsSGC-older"),
154 // 2 = "accept nsSGC before 23 August 2015"
155 info("Netscape Step Up policy: accept before 23 August 2015");
156 Services.prefs.setIntPref("security.pki.netscape_step_up_policy", 2);
157 await checkCertOn25August2016(
158 certFromFile("ee-int-nsSGC-recent"),
159 SEC_ERROR_INADEQUATE_CERT_TYPE
161 await checkCertOn25August2016(
162 certFromFile("ee-int-nsSGC-old"),
163 SEC_ERROR_INADEQUATE_CERT_TYPE
165 await checkCertOn25August2016(
166 certFromFile("ee-int-nsSGC-older"),
169 // 3 = "never accept nsSGC"
170 info("Netscape Step Up policy: never accept");
171 Services.prefs.setIntPref("security.pki.netscape_step_up_policy", 3);
172 await checkCertOn25August2016(
173 certFromFile("ee-int-nsSGC-recent"),
174 SEC_ERROR_INADEQUATE_CERT_TYPE
176 await checkCertOn25August2016(
177 certFromFile("ee-int-nsSGC-old"),
178 SEC_ERROR_INADEQUATE_CERT_TYPE
180 await checkCertOn25August2016(
181 certFromFile("ee-int-nsSGC-older"),
182 SEC_ERROR_INADEQUATE_CERT_TYPE
185 // intermediate has id-kp-OCSPSigning, which is acceptable for CA
186 // certificates => success
187 loadCertWithTrust("int-SA-OCSP", ",,");
188 await checkEndEntity(certFromFile("ee-int-SA-OCSP"), PRErrorCodeSuccess);