security/manager/ssl/tests/unit/test_name_constraints.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 // -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 // This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 // License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 5
michael@0 6 "use strict";
michael@0 7
michael@0 8 do_get_profile(); // must be called before getting nsIX509CertDB
michael@0 9 const certdb = Cc["@mozilla.org/security/x509certdb;1"]
michael@0 10 .getService(Ci.nsIX509CertDB);
michael@0 11
michael@0 12 function certFromFile(filename) {
michael@0 13 let der = readFile(do_get_file("test_name_constraints/" + filename, false));
michael@0 14 return certdb.constructX509(der, der.length);
michael@0 15 }
michael@0 16
michael@0 17 function load_cert(cert_name, trust_string) {
michael@0 18 var cert_filename = cert_name + ".der";
michael@0 19 addCertFromFile(certdb, "test_name_constraints/" + cert_filename, trust_string);
michael@0 20 return certFromFile(cert_filename);
michael@0 21 }
michael@0 22
michael@0 23 function check_cert_err_generic(cert, expected_error, usage) {
michael@0 24 do_print("cert cn=" + cert.commonName);
michael@0 25 do_print("cert issuer cn=" + cert.issuerCommonName);
michael@0 26 let hasEVPolicy = {};
michael@0 27 let verifiedChain = {};
michael@0 28 let error = certdb.verifyCertNow(cert, usage,
michael@0 29 NO_FLAGS, verifiedChain, hasEVPolicy);
michael@0 30 do_check_eq(error, expected_error);
michael@0 31 }
michael@0 32
michael@0 33 function check_cert_err(cert, expected_error) {
michael@0 34 check_cert_err_generic(cert, expected_error, certificateUsageSSLServer)
michael@0 35 }
michael@0 36
michael@0 37 function check_ok(x) {
michael@0 38 return check_cert_err(x, 0);
michael@0 39 }
michael@0 40
michael@0 41 function check_ok_ca (x) {
michael@0 42 return check_cert_err_generic(x, 0, certificateUsageSSLCA);
michael@0 43 }
michael@0 44
michael@0 45 function check_fail(x) {
michael@0 46 return check_cert_err(x, SEC_ERROR_CERT_NOT_IN_NAME_SPACE);
michael@0 47 }
michael@0 48
michael@0 49 function check_fail_ca(x) {
michael@0 50 return check_cert_err_generic(x, SEC_ERROR_CERT_NOT_IN_NAME_SPACE, certificateUsageSSLCA);
michael@0 51 }
michael@0 52
michael@0 53 function run_test_in_mode(useMozillaPKIX) {
michael@0 54 Services.prefs.setBoolPref("security.use_mozillapkix_verification", useMozillaPKIX);
michael@0 55
michael@0 56 // Note that CN is only looked at when there is NO subjectAltName!
michael@0 57
michael@0 58 // Testing with a unconstrained root, and intermediate constrained to PERMIT
michael@0 59 // foo.com. All failures on this section are doe to the cert DNS names
michael@0 60 // not being under foo.com.
michael@0 61 check_ok_ca(load_cert('int-nc-perm-foo.com-ca-nc', ',,'));
michael@0 62 // no dirName
michael@0 63 check_ok(certFromFile('cn-www.foo.com-int-nc-perm-foo.com-ca-nc.der'));
michael@0 64 check_fail(certFromFile('cn-www.foo.org-int-nc-perm-foo.com-ca-nc.der'));
michael@0 65 check_fail(certFromFile('cn-www.foo.com-alt-foo.org-int-nc-perm-foo.com-ca-nc.der'));
michael@0 66 check_ok(certFromFile('cn-www.foo.org-alt-foo.com-int-nc-perm-foo.com-ca-nc.der'));
michael@0 67 check_ok(certFromFile('cn-www.foo.com-alt-foo.com-int-nc-perm-foo.com-ca-nc.der'));
michael@0 68 check_fail(certFromFile('cn-www.foo.org-alt-foo.org-int-nc-perm-foo.com-ca-nc.der'));
michael@0 69 // multiple subjectAltnames
michael@0 70 check_fail(certFromFile('cn-www.foo.com-alt-foo.com-a.a.us-b.a.us-int-nc-perm-foo.com-ca-nc.der'));
michael@0 71 // C=US O=bar
michael@0 72 check_ok(certFromFile('cn-www.foo.com_o-bar_c-us-int-nc-perm-foo.com-ca-nc.der'));
michael@0 73 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-int-nc-perm-foo.com-ca-nc.der'));
michael@0 74 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.org-int-nc-perm-foo.com-ca-nc.der'));
michael@0 75 check_ok(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.com-int-nc-perm-foo.com-ca-nc.der'));
michael@0 76 check_ok(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-int-nc-perm-foo.com-ca-nc.der'));
michael@0 77 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.org-int-nc-perm-foo.com-ca-nc.der'));
michael@0 78 // multiple subjectAltnames
michael@0 79 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-a.a.us-b.a.us-int-nc-perm-foo.com-ca-nc.der'));
michael@0 80
michael@0 81 // Testing with an unconstrained root and intermediate constrained to
michael@0 82 // EXCLUDE DNS:example.com. All failures on this section are due to the cert
michael@0 83 // DNS names containing example.com. The dirname does not affect evaluation.
michael@0 84 check_ok_ca(load_cert('int-nc-excl-foo.com-ca-nc', ',,'));
michael@0 85 // no dirName
michael@0 86 check_fail(certFromFile('cn-www.foo.com-int-nc-excl-foo.com-ca-nc.der'));
michael@0 87 check_ok(certFromFile('cn-www.foo.org-int-nc-excl-foo.com-ca-nc.der'));
michael@0 88 // notice that since the name constrains apply to the dns name the cn is not
michael@0 89 // evaluated in the case where a subjectAltName exists. Thus the next case is
michael@0 90 // correctly passing.
michael@0 91 check_ok(certFromFile('cn-www.foo.com-alt-foo.org-int-nc-excl-foo.com-ca-nc.der'));
michael@0 92 check_fail(certFromFile('cn-www.foo.org-alt-foo.com-int-nc-excl-foo.com-ca-nc.der'));
michael@0 93 check_fail(certFromFile('cn-www.foo.com-alt-foo.com-int-nc-excl-foo.com-ca-nc.der'));
michael@0 94 check_ok(certFromFile('cn-www.foo.org-alt-foo.org-int-nc-excl-foo.com-ca-nc.der'));
michael@0 95 // multiple subjectAltnames
michael@0 96 check_fail(certFromFile('cn-www.foo.com-alt-foo.com-a.a.us-b.a.us-int-nc-excl-foo.com-ca-nc.der'));
michael@0 97 // C=US O=bar
michael@0 98 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-int-nc-excl-foo.com-ca-nc.der'));
michael@0 99 check_ok(certFromFile('cn-www.foo.org_o-bar_c-us-int-nc-excl-foo.com-ca-nc.der'));
michael@0 100 check_ok(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.org-int-nc-excl-foo.com-ca-nc.der'));
michael@0 101 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.com-int-nc-excl-foo.com-ca-nc.der'));
michael@0 102 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-int-nc-excl-foo.com-ca-nc.der'));
michael@0 103 check_ok(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.org-int-nc-excl-foo.com-ca-nc.der'));
michael@0 104 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-a.a.us-b.a.us-int-nc-excl-foo.com-ca-nc.der'));
michael@0 105
michael@0 106 // Testing with an unconstrained root, and intermediate constrained to
michael@0 107 // permitting dirName:C=US. All failures on this section are due to cert
michael@0 108 // name not being C=US.
michael@0 109 check_ok_ca(load_cert('int-nc-c-us-ca-nc', ',,'));
michael@0 110 check_fail(certFromFile('cn-www.foo.com-int-nc-c-us-ca-nc.der'));
michael@0 111 check_fail(certFromFile('cn-www.foo.org-int-nc-c-us-ca-nc.der'));
michael@0 112 check_fail(certFromFile('cn-www.foo.com-alt-foo.org-int-nc-c-us-ca-nc.der'));
michael@0 113 check_fail(certFromFile('cn-www.foo.org-alt-foo.com-int-nc-c-us-ca-nc.der'));
michael@0 114 check_fail(certFromFile('cn-www.foo.com-alt-foo.com-int-nc-c-us-ca-nc.der'));
michael@0 115 check_fail(certFromFile('cn-www.foo.org-alt-foo.org-int-nc-c-us-ca-nc.der'));
michael@0 116 check_fail(certFromFile('cn-www.foo.com-alt-foo.com-a.a.us-b.a.us-int-nc-c-us-ca-nc.der'));
michael@0 117 check_ok(certFromFile('cn-www.foo.com_o-bar_c-us-int-nc-c-us-ca-nc.der'));
michael@0 118 check_ok(certFromFile('cn-www.foo.org_o-bar_c-us-int-nc-c-us-ca-nc.der'));
michael@0 119 check_ok(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.org-int-nc-c-us-ca-nc.der'));
michael@0 120 check_ok(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.com-int-nc-c-us-ca-nc.der'));
michael@0 121 check_ok(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-int-nc-c-us-ca-nc.der'));
michael@0 122 check_ok(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.org-int-nc-c-us-ca-nc.der'));
michael@0 123 check_ok(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-a.a.us-b.a.us-int-nc-c-us-ca-nc.der'));
michael@0 124
michael@0 125 // Testing with an unconstrained root, and intermediate constrained to
michael@0 126 // permitting dirNAME:C=US that issues an intermediate name constrained to
michael@0 127 // permitting DNS:foo.com. Checks for inheritance and intersection of
michael@0 128 // different name constraints.
michael@0 129 check_ok_ca(load_cert('int-nc-foo.com-int-nc-c-us-ca-nc', ',,'));
michael@0 130 check_fail(certFromFile('cn-www.foo.com-int-nc-foo.com-int-nc-c-us-ca-nc.der'));
michael@0 131 check_fail(certFromFile('cn-www.foo.org-int-nc-foo.com-int-nc-c-us-ca-nc.der'));
michael@0 132 check_fail(certFromFile('cn-www.foo.com-alt-foo.org-int-nc-foo.com-int-nc-c-us-ca-nc.der'));
michael@0 133 check_fail(certFromFile('cn-www.foo.org-alt-foo.com-int-nc-foo.com-int-nc-c-us-ca-nc.der'));
michael@0 134 check_fail(certFromFile('cn-www.foo.com-alt-foo.com-int-nc-foo.com-int-nc-c-us-ca-nc.der'));
michael@0 135 check_fail(certFromFile('cn-www.foo.org-alt-foo.org-int-nc-foo.com-int-nc-c-us-ca-nc.der'));
michael@0 136 check_fail(certFromFile('cn-www.foo.com-alt-foo.com-a.a.us-b.a.us-int-nc-foo.com-int-nc-c-us-ca-nc.der'));
michael@0 137 check_ok(certFromFile('cn-www.foo.com_o-bar_c-us-int-nc-foo.com-int-nc-c-us-ca-nc.der'));
michael@0 138 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-int-nc-foo.com-int-nc-c-us-ca-nc.der'));
michael@0 139 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.org-int-nc-foo.com-int-nc-c-us-ca-nc.der'));
michael@0 140 check_ok(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.com-int-nc-foo.com-int-nc-c-us-ca-nc.der'));
michael@0 141 check_ok(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-int-nc-foo.com-int-nc-c-us-ca-nc.der'));
michael@0 142 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.org-int-nc-foo.com-int-nc-c-us-ca-nc.der'));
michael@0 143 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-a.a.us-b.a.us-int-nc-foo.com-int-nc-c-us-ca-nc.der'));
michael@0 144
michael@0 145 // Testing on a non constrainted root an intermediate name contrainted to
michael@0 146 // permited dirNAME:C=US and permited DNS:foo.com
michael@0 147 // checks for compostability of different name constraints with same cert
michael@0 148 check_ok_ca(load_cert('int-nc-perm-foo.com_c-us-ca-nc' , ',,'));
michael@0 149 check_fail(certFromFile('cn-www.foo.com-int-nc-perm-foo.com_c-us-ca-nc.der'));
michael@0 150 check_fail(certFromFile('cn-www.foo.org-int-nc-perm-foo.com_c-us-ca-nc.der'));
michael@0 151 check_fail(certFromFile('cn-www.foo.com-alt-foo.org-int-nc-perm-foo.com_c-us-ca-nc.der'));
michael@0 152 check_fail(certFromFile('cn-www.foo.org-alt-foo.com-int-nc-perm-foo.com_c-us-ca-nc.der'));
michael@0 153 check_fail(certFromFile('cn-www.foo.com-alt-foo.com-int-nc-perm-foo.com_c-us-ca-nc.der'));
michael@0 154 check_fail(certFromFile('cn-www.foo.org-alt-foo.org-int-nc-perm-foo.com_c-us-ca-nc.der'));
michael@0 155 check_fail(certFromFile('cn-www.foo.com-alt-foo.com-a.a.us-b.a.us-int-nc-perm-foo.com_c-us-ca-nc.der'));
michael@0 156 check_ok(certFromFile('cn-www.foo.com_o-bar_c-us-int-nc-perm-foo.com_c-us-ca-nc.der'));
michael@0 157 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-int-nc-perm-foo.com_c-us-ca-nc.der'));
michael@0 158 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.org-int-nc-perm-foo.com_c-us-ca-nc.der'));
michael@0 159 // next check is ok as there is an altname and thus the name constraints do
michael@0 160 // not apply to the common name
michael@0 161 check_ok(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.com-int-nc-perm-foo.com_c-us-ca-nc.der'));
michael@0 162 check_ok(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-int-nc-perm-foo.com_c-us-ca-nc.der'));
michael@0 163 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.org-int-nc-perm-foo.com_c-us-ca-nc.der'));
michael@0 164 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-a.a.us-b.a.us-int-nc-perm-foo.com_c-us-ca-nc.der'));
michael@0 165
michael@0 166 // Testing on an unconstrained root and an intermediate name constrained to
michael@0 167 // permitted dirNAME: C=UK all but the intermeduate should fail because they
michael@0 168 // dont have C=UK (missing or C=US)
michael@0 169 check_ok_ca(load_cert('int-nc-perm-c-uk-ca-nc', ',,'));
michael@0 170 check_fail(certFromFile('cn-www.foo.com-int-nc-perm-c-uk-ca-nc.der'));
michael@0 171 check_fail(certFromFile('cn-www.foo.org-int-nc-perm-c-uk-ca-nc.der'));
michael@0 172 check_fail(certFromFile('cn-www.foo.com-alt-foo.org-int-nc-perm-c-uk-ca-nc.der'));
michael@0 173 check_fail(certFromFile('cn-www.foo.org-alt-foo.com-int-nc-perm-c-uk-ca-nc.der'));
michael@0 174 check_fail(certFromFile('cn-www.foo.com-alt-foo.com-int-nc-perm-c-uk-ca-nc.der'));
michael@0 175 check_fail(certFromFile('cn-www.foo.org-alt-foo.org-int-nc-perm-c-uk-ca-nc.der'));
michael@0 176 check_fail(certFromFile('cn-www.foo.com-alt-foo.com-a.a.us-b.a.us-int-nc-perm-c-uk-ca-nc.der'));
michael@0 177 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-int-nc-perm-c-uk-ca-nc.der'));
michael@0 178 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-int-nc-perm-c-uk-ca-nc.der'));
michael@0 179 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.org-int-nc-perm-c-uk-ca-nc.der'));
michael@0 180 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.com-int-nc-perm-c-uk-ca-nc.der'));
michael@0 181 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-int-nc-perm-c-uk-ca-nc.der'));
michael@0 182 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.org-int-nc-perm-c-uk-ca-nc.der'));
michael@0 183 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-a.a.us-b.a.us-int-nc-perm-c-uk-ca-nc.der'));
michael@0 184
michael@0 185 // Testing on an unconstrained root and an intermediate name constrained to
michael@0 186 // permitted dirNAME: C=UK and an unconstrained intermediate that contains
michael@0 187 // dirNAME C=US. EE and and Intermediates should fail
michael@0 188 check_fail_ca(load_cert('int-c-us-int-nc-perm-c-uk-ca-nc', ',,'));
michael@0 189 check_fail(certFromFile('cn-www.foo.com-int-c-us-int-nc-perm-c-uk-ca-nc.der'));
michael@0 190 check_fail(certFromFile('cn-www.foo.org-int-c-us-int-nc-perm-c-uk-ca-nc.der'));
michael@0 191 check_fail(certFromFile('cn-www.foo.com-alt-foo.org-int-c-us-int-nc-perm-c-uk-ca-nc.der'));
michael@0 192 check_fail(certFromFile('cn-www.foo.org-alt-foo.com-int-c-us-int-nc-perm-c-uk-ca-nc.der'));
michael@0 193 check_fail(certFromFile('cn-www.foo.com-alt-foo.com-int-c-us-int-nc-perm-c-uk-ca-nc.der'));
michael@0 194 check_fail(certFromFile('cn-www.foo.org-alt-foo.org-int-c-us-int-nc-perm-c-uk-ca-nc.der'));
michael@0 195 check_fail(certFromFile('cn-www.foo.com-alt-foo.com-a.a.us-b.a.us-int-c-us-int-nc-perm-c-uk-ca-nc.der'));
michael@0 196 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-int-c-us-int-nc-perm-c-uk-ca-nc.der'));
michael@0 197 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-int-c-us-int-nc-perm-c-uk-ca-nc.der'));
michael@0 198 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.org-int-c-us-int-nc-perm-c-uk-ca-nc.der'));
michael@0 199 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.com-int-c-us-int-nc-perm-c-uk-ca-nc.der'));
michael@0 200 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-int-c-us-int-nc-perm-c-uk-ca-nc.der'));
michael@0 201 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.org-int-c-us-int-nc-perm-c-uk-ca-nc.der'));
michael@0 202 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-a.a.us-b.a.us-int-c-us-int-nc-perm-c-uk-ca-nc.der'));
michael@0 203
michael@0 204 // Testing on an unconstrained root and an intermediate name constrained to
michael@0 205 // permitted DNS: foo.com and permitted: DNS: a.us
michael@0 206 check_ok_ca(load_cert('int-nc-foo.com_a.us', ',,'));
michael@0 207 check_ok(certFromFile('cn-www.foo.com-int-nc-foo.com_a.us.der'));
michael@0 208 check_fail(certFromFile('cn-www.foo.org-int-nc-foo.com_a.us.der'));
michael@0 209 check_fail(certFromFile('cn-www.foo.com-alt-foo.org-int-nc-foo.com_a.us.der'));
michael@0 210 check_ok(certFromFile('cn-www.foo.org-alt-foo.com-int-nc-foo.com_a.us.der'));
michael@0 211 check_ok(certFromFile('cn-www.foo.com-alt-foo.com-int-nc-foo.com_a.us.der'));
michael@0 212 check_fail(certFromFile('cn-www.foo.org-alt-foo.org-int-nc-foo.com_a.us.der'));
michael@0 213 check_ok(certFromFile('cn-www.foo.com-alt-foo.com-a.a.us-b.a.us-int-nc-foo.com_a.us.der'));
michael@0 214 check_ok(certFromFile('cn-www.foo.com_o-bar_c-us-int-nc-foo.com_a.us.der'));
michael@0 215 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-int-nc-foo.com_a.us.der'));
michael@0 216 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.org-int-nc-foo.com_a.us.der'));
michael@0 217 check_ok(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.com-int-nc-foo.com_a.us.der'));
michael@0 218 check_ok(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-int-nc-foo.com_a.us.der'));
michael@0 219 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.org-int-nc-foo.com_a.us.der'));
michael@0 220 check_ok(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-a.a.us-b.a.us-int-nc-foo.com_a.us.der'));
michael@0 221
michael@0 222 // Testing on an unconstrained root and an intermediate name constrained to
michael@0 223 // permitted DNS: foo.com and permitted: DNS:a.us that issues an intermediate
michael@0 224 // permitted DNS: foo.com .
michael@0 225 // Goal is to ensure that the stricter (inner) name constraint ins enforced.
michael@0 226 // The multi-subject alt should fail and is the difference from the sets of
michael@0 227 // tests above.
michael@0 228 check_ok_ca(load_cert('int-nc-foo.com-int-nc-foo.com_a.us', ',,'));
michael@0 229 check_ok(certFromFile('cn-www.foo.com-int-nc-foo.com-int-nc-foo.com_a.us.der'));
michael@0 230 check_fail(certFromFile('cn-www.foo.org-int-nc-foo.com-int-nc-foo.com_a.us.der'));
michael@0 231 check_fail(certFromFile('cn-www.foo.com-alt-foo.org-int-nc-foo.com-int-nc-foo.com_a.us.der'));
michael@0 232 check_ok(certFromFile('cn-www.foo.org-alt-foo.com-int-nc-foo.com-int-nc-foo.com_a.us.der'));
michael@0 233 check_ok(certFromFile('cn-www.foo.com-alt-foo.com-int-nc-foo.com-int-nc-foo.com_a.us.der'));
michael@0 234 check_fail(certFromFile('cn-www.foo.org-alt-foo.org-int-nc-foo.com-int-nc-foo.com_a.us.der'));
michael@0 235 check_fail(certFromFile('cn-www.foo.com-alt-foo.com-a.a.us-b.a.us-int-nc-foo.com-int-nc-foo.com_a.us.der'));
michael@0 236 check_ok(certFromFile('cn-www.foo.com_o-bar_c-us-int-nc-foo.com-int-nc-foo.com_a.us.der'));
michael@0 237 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-int-nc-foo.com-int-nc-foo.com_a.us.der'));
michael@0 238 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.org-int-nc-foo.com-int-nc-foo.com_a.us.der'));
michael@0 239 check_ok(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.com-int-nc-foo.com-int-nc-foo.com_a.us.der'));
michael@0 240 check_ok(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-int-nc-foo.com-int-nc-foo.com_a.us.der'));
michael@0 241 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.org-int-nc-foo.com-int-nc-foo.com_a.us.der'));
michael@0 242 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-a.a.us-b.a.us-int-nc-foo.com-int-nc-foo.com_a.us.der'));
michael@0 243
michael@0 244 // Testing on a root name constrainted to DNS:foo.com and an unconstrained
michael@0 245 // intermediate.
michael@0 246 // Checks that root constraints are enforced.
michael@0 247 check_ok_ca(load_cert('int-ca-nc-perm-foo.com', ',,'));
michael@0 248 check_ok(certFromFile('cn-www.foo.com-int-ca-nc-perm-foo.com.der'));
michael@0 249 check_fail(certFromFile('cn-www.foo.org-int-ca-nc-perm-foo.com.der'));
michael@0 250 check_fail(certFromFile('cn-www.foo.com-alt-foo.org-int-ca-nc-perm-foo.com.der'));
michael@0 251 check_ok(certFromFile('cn-www.foo.org-alt-foo.com-int-ca-nc-perm-foo.com.der'));
michael@0 252 check_ok(certFromFile('cn-www.foo.com-alt-foo.com-int-ca-nc-perm-foo.com.der'));
michael@0 253 check_fail(certFromFile('cn-www.foo.org-alt-foo.org-int-ca-nc-perm-foo.com.der'));
michael@0 254 check_fail(certFromFile('cn-www.foo.com-alt-foo.com-a.a.us-b.a.us-int-ca-nc-perm-foo.com.der'));
michael@0 255 check_ok(certFromFile('cn-www.foo.com_o-bar_c-us-int-ca-nc-perm-foo.com.der'));
michael@0 256 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-int-ca-nc-perm-foo.com.der'));
michael@0 257 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.org-int-ca-nc-perm-foo.com.der'));
michael@0 258 check_ok(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.com-int-ca-nc-perm-foo.com.der'));
michael@0 259 check_ok(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-int-ca-nc-perm-foo.com.der'));
michael@0 260 check_fail(certFromFile('cn-www.foo.org_o-bar_c-us-alt-foo.org-int-ca-nc-perm-foo.com.der'));
michael@0 261 check_fail(certFromFile('cn-www.foo.com_o-bar_c-us-alt-foo.com-a.a.us-b.a.us-int-ca-nc-perm-foo.com.der'));
michael@0 262
michael@0 263 // We don't enforce dNSName name constraints on CN unless we're validating
michael@0 264 // for the server EKU. libpkix gets this wrong but mozilla::pkix and classic
michael@0 265 // NSS get it right.
michael@0 266 {
michael@0 267 let cert = certFromFile('cn-www.foo.org-int-nc-perm-foo.com-ca-nc.der');
michael@0 268 check_cert_err_generic(cert, SEC_ERROR_CERT_NOT_IN_NAME_SPACE, certificateUsageSSLServer);
michael@0 269 check_cert_err_generic(cert, 0, certificateUsageSSLClient);
michael@0 270 }
michael@0 271
michael@0 272 // DCISS tests
michael@0 273 // The certs used here were generated by the NSS test suite and are
michael@0 274 // originally located as security/nss/tests/libpkix/cert/
michael@0 275 load_cert("dcisscopy", "C,C,C");
michael@0 276 check_ok(certFromFile('NameConstraints.dcissallowed.cert'));
michael@0 277 check_fail(certFromFile('NameConstraints.dcissblocked.cert'));
michael@0 278 }
michael@0 279
michael@0 280 function run_test() {
michael@0 281 load_cert("ca-nc-perm-foo.com", "CTu,CTu,CTu");
michael@0 282 load_cert("ca-nc", "CTu,CTu,CTu");
michael@0 283
michael@0 284 run_test_in_mode(true);
michael@0 285 run_test_in_mode(false);
michael@0 286 }

mercurial