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/.
8 do_get_profile(); // must be called before getting nsIX509CertDB
10 registerCleanupFunction(() => {
11 Services.prefs.clearUserPref("security.pki.certificate_transparency.mode");
12 Services.prefs.clearUserPref("security.test.built_in_root_hash");
13 let cert = constructCertFromFile("test_ct/ct-valid.example.com.pem");
14 setCertTrust(cert, ",,");
17 function add_tests_in_mode(mode) {
18 add_test(function set_mode() {
19 info(`setting CT to mode ${mode}`);
20 Services.prefs.setIntPref(
21 "security.pki.certificate_transparency.mode",
27 // Test that certificate transparency is not checked for certificates issued
28 // by roots that are not built-in.
30 "ct-unknown-log.example.com",
31 Ci.nsITransportSecurityInfo.CERTIFICATE_TRANSPARENCY_NOT_APPLICABLE,
35 add_test(function set_test_root_as_built_in() {
36 // Make the test root appear to be a built-in root, so that certificate
37 // transparency is checked.
38 let rootCert = constructCertFromFile("test_ct/test-ca.pem");
39 Services.prefs.setCharPref(
40 "security.test.built_in_root_hash",
41 rootCert.sha256Fingerprint
46 // These certificates have a validity period of 800 days, which is greater
47 // than 180 days. Our policy requires 3 embedded SCTs for certificates with a
48 // validity period greater than 180 days.
50 "ct-valid.example.com",
51 Ci.nsITransportSecurityInfo.CERTIFICATE_TRANSPARENCY_POLICY_COMPLIANT,
54 // This certificate has only 2 embedded SCTs, and so is not policy-compliant.
56 "ct-insufficient-scts.example.com",
57 Ci.nsITransportSecurityInfo.CERTIFICATE_TRANSPARENCY_POLICY_NOT_ENOUGH_SCTS,
58 mode == CT_MODE_COLLECT_TELEMETRY
61 // Test that SCTs with timestamps from the future are not valid.
63 "ct-future-timestamp.example.com",
64 Ci.nsITransportSecurityInfo.CERTIFICATE_TRANSPARENCY_POLICY_NOT_ENOUGH_SCTS,
65 mode == CT_MODE_COLLECT_TELEMETRY
68 // Test that additional SCTs from the same log do not contribute to meeting
71 "ct-multiple-from-same-log.example.com",
72 Ci.nsITransportSecurityInfo
73 .CERTIFICATE_TRANSPARENCY_POLICY_NOT_DIVERSE_SCTS,
74 mode == CT_MODE_COLLECT_TELEMETRY
77 // Test that SCTs from an unknown log do not contribute to meeting the
80 "ct-unknown-log.example.com",
81 Ci.nsITransportSecurityInfo.CERTIFICATE_TRANSPARENCY_POLICY_NOT_ENOUGH_SCTS,
82 mode == CT_MODE_COLLECT_TELEMETRY
87 Ci.nsITransportSecurityInfo.CERTIFICATE_TRANSPARENCY_POLICY_NOT_ENOUGH_SCTS,
88 mode == CT_MODE_COLLECT_TELEMETRY
90 add_test(function set_disable_ct_for_hosts_pref() {
91 // Disable CT enforcement for exactly 'ct-unknown-log.example.com' as well
92 // as 'sub.example.com' and all subdomains under 'sub.example.com'.
93 // CT will still be checked, and the security info of the connection will say
94 // the information is insufficient, but the connection will still succeed
95 // (essentially, it behaves like telemetry-only mode).
96 Services.prefs.setCharPref(
97 "security.pki.certificate_transparency.disable_for_hosts",
98 ".ct-unknown-log.example.com,no-ct.example.com"
104 "ct-unknown-log.example.com",
105 Ci.nsITransportSecurityInfo.CERTIFICATE_TRANSPARENCY_POLICY_NOT_ENOUGH_SCTS,
109 "sub.ct-unknown-log.example.com",
110 Ci.nsITransportSecurityInfo.CERTIFICATE_TRANSPARENCY_POLICY_NOT_ENOUGH_SCTS,
111 mode == CT_MODE_COLLECT_TELEMETRY
115 Ci.nsITransportSecurityInfo.CERTIFICATE_TRANSPARENCY_POLICY_NOT_ENOUGH_SCTS,
119 "sub.no-ct.example.com",
120 Ci.nsITransportSecurityInfo.CERTIFICATE_TRANSPARENCY_POLICY_NOT_ENOUGH_SCTS,
124 "ct-insufficient-scts.example.com",
125 Ci.nsITransportSecurityInfo.CERTIFICATE_TRANSPARENCY_POLICY_NOT_ENOUGH_SCTS,
126 mode == CT_MODE_COLLECT_TELEMETRY
128 add_test(function reset_disable_ct_for_hosts_pref() {
129 Services.prefs.clearUserPref(
130 "security.pki.certificate_transparency.disable_for_hosts"
136 add_test(function set_disable_ct_for_spki_hashes_pref_nonexistent_keys() {
137 // Disable CT enforcement for two SPKIs we don't actually have the private
139 Services.prefs.setCharPref(
140 "security.pki.certificate_transparency.disable_for_spki_hashes",
141 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=,BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB="
147 "ct-insufficient-scts.example.com",
148 Ci.nsITransportSecurityInfo.CERTIFICATE_TRANSPARENCY_POLICY_NOT_ENOUGH_SCTS,
149 mode == CT_MODE_COLLECT_TELEMETRY
151 add_test(function set_disable_ct_for_spki_hashes_pref() {
152 // Disable CT enforcement for the default test key's SPKI.
153 // Again, the behavior will be that of telemetry-only mode.
154 Services.prefs.setCharPref(
155 "security.pki.certificate_transparency.disable_for_spki_hashes",
156 "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC=,VCIlmPM9NkgFQtrs4Oa5TeFcDu6MWRTKSNdePEhOgD8="
162 "ct-insufficient-scts.example.com",
163 Ci.nsITransportSecurityInfo.CERTIFICATE_TRANSPARENCY_POLICY_NOT_ENOUGH_SCTS,
166 add_test(function set_disable_ct_for_spki_hashes_pref_alternate() {
167 // Disable CT enforcement for the alternate test key's SPKI.
168 Services.prefs.setCharPref(
169 "security.pki.certificate_transparency.disable_for_spki_hashes",
170 "MQj2tt1yGAfwFpWETYUCVrZxk2CD2705NKBQUlAaKJI=,DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD="
177 Ci.nsITransportSecurityInfo.CERTIFICATE_TRANSPARENCY_POLICY_NOT_ENOUGH_SCTS,
180 add_test(function reset_disable_ct_for_spki_hashes_pref() {
181 Services.prefs.clearUserPref(
182 "security.pki.certificate_transparency.disable_for_spki_hashes"
188 // Test that if an end-entity is marked as a trust anchor, CT verification
189 // returns a "not enough SCTs" result.
190 add_test(function set_up_end_entity_trust_anchor_test() {
191 let cert = constructCertFromFile("test_ct/ct-valid.example.com.pem");
192 Services.prefs.setCharPref(
193 "security.test.built_in_root_hash",
194 cert.sha256Fingerprint
196 setCertTrust(cert, "CTu,,");
201 "ct-valid.example.com",
202 Ci.nsITransportSecurityInfo.CERTIFICATE_TRANSPARENCY_POLICY_NOT_ENOUGH_SCTS,
203 mode == CT_MODE_COLLECT_TELEMETRY
206 add_test(function reset_for_next_test_mode() {
207 Services.prefs.clearUserPref("security.test.built_in_root_hash");
208 let cert = constructCertFromFile("test_ct/ct-valid.example.com.pem");
209 setCertTrust(cert, "u,,");
215 function run_test() {
216 add_tls_server_setup("BadCertAndPinningServer", "test_ct");
217 add_tests_in_mode(CT_MODE_COLLECT_TELEMETRY);
218 add_tests_in_mode(CT_MODE_ENFORCE);