Skip to content

Commit fd8faa8

Browse files
authored
Reorganizing compatability tests, rework certificates for better groking (#2305)
### Description of changes: This is mostly a re-organization PR so that the new comparability related tests are in a separate unit file for easier grokking in the future as more are added. I also re-generated the current certificates added in the previous PR for the trust-store change to define a better distinguished namespace hierarchy. Mainly to have better binding and name-spacing of the root certificate to any intermediate, and end-entity certificates generated for testing. Additionally added a text representation of the certificates as well. Note the certificate start dates are back date to 2015 through 2100. This is mainly for consistency with the other certificates BoringSSL had generated in various places in the library. Otherwise this also adds a test case for RFC 5280 4.2.1.1 which states with regards to the authority key identifier extension > Conforming CAs MUST mark this extension as non-critical. Previously this was unchecked on any certificates that were sourced from the trust-store (so an intermediate for example could have this marked as critical but would still be valid), and after making changes to validating the [trust store](1f367c9) this test case in x509-limbo suddenly passed. So simply adding a similar test case for ensuring that we actually validated this RFC statement. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.
1 parent 1f367c9 commit fd8faa8

File tree

5 files changed

+386
-125
lines changed

5 files changed

+386
-125
lines changed

crypto/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,10 +823,12 @@ if(BUILD_TESTING)
823823
spake25519/spake25519_test.cc
824824
test/file_util.cc
825825
test/file_test_gtest.cc
826+
test/x509_util.cc
826827
thread_test.cc
827828
trust_token/trust_token_test.cc
828829
x509/tab_test.cc
829830
x509/x509_test.cc
831+
x509/x509_compat_test.cc
830832
x509/x509_time_test.cc
831833
decrepit/blowfish/blowfish_test.cc
832834
decrepit/cast/cast_test.cc

crypto/test/x509_util.cc

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR ISC
3+
4+
#include "x509_util.h"
5+
#include "test_util.h"
6+
7+
int Verify(X509 *leaf, const std::vector<X509 *> &roots,
8+
const std::vector<X509 *> &intermediates,
9+
const std::vector<X509_CRL *> &crls, unsigned long flags,
10+
std::function<void(X509_STORE_CTX *)> configure_callback) {
11+
bssl::UniquePtr<STACK_OF(X509)> roots_stack(CertsToStack(roots));
12+
bssl::UniquePtr<STACK_OF(X509)> intermediates_stack(
13+
CertsToStack(intermediates));
14+
bssl::UniquePtr<STACK_OF(X509_CRL)> crls_stack(CRLsToStack(crls));
15+
16+
if (!roots_stack || !intermediates_stack || !crls_stack) {
17+
return X509_V_ERR_UNSPECIFIED;
18+
}
19+
20+
bssl::UniquePtr<X509_STORE_CTX> ctx(X509_STORE_CTX_new());
21+
bssl::UniquePtr<X509_STORE> store(X509_STORE_new());
22+
if (!ctx || !store) {
23+
return X509_V_ERR_UNSPECIFIED;
24+
}
25+
26+
if (!X509_STORE_CTX_init(ctx.get(), store.get(), leaf,
27+
intermediates_stack.get())) {
28+
return X509_V_ERR_UNSPECIFIED;
29+
}
30+
31+
X509_STORE_CTX_set0_trusted_stack(ctx.get(), roots_stack.get());
32+
X509_STORE_CTX_set0_crls(ctx.get(), crls_stack.get());
33+
34+
X509_VERIFY_PARAM *param = X509_STORE_CTX_get0_param(ctx.get());
35+
X509_VERIFY_PARAM_set_time_posix(param, kReferenceTime);
36+
if (configure_callback) {
37+
configure_callback(ctx.get());
38+
}
39+
if (flags) {
40+
X509_VERIFY_PARAM_set_flags(param, flags);
41+
}
42+
43+
ERR_clear_error();
44+
if (X509_verify_cert(ctx.get()) != 1) {
45+
return X509_STORE_CTX_get_error(ctx.get());
46+
}
47+
48+
return X509_V_OK;
49+
}
50+
51+
// CRLsToStack converts a vector of |X509_CRL*| to an OpenSSL
52+
// STACK_OF(X509_CRL), bumping the reference counts for each CRL in question.
53+
bssl::UniquePtr<STACK_OF(X509_CRL)> CRLsToStack(
54+
const std::vector<X509_CRL *> &crls) {
55+
bssl::UniquePtr<STACK_OF(X509_CRL)> stack(sk_X509_CRL_new_null());
56+
if (!stack) {
57+
return nullptr;
58+
}
59+
for (auto crl : crls) {
60+
if (!bssl::PushToStack(stack.get(), bssl::UpRef(crl))) {
61+
return nullptr;
62+
}
63+
}
64+
65+
return stack;
66+
}

crypto/test/x509_util.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR ISC
3+
4+
#ifndef OPENSSL_HEADER_CRYPTO_TEST_X509_UTIL_H
5+
#define OPENSSL_HEADER_CRYPTO_TEST_X509_UTIL_H
6+
7+
#include <functional>
8+
#include <vector>
9+
10+
#include <openssl/x509.h>
11+
12+
int Verify(X509 *leaf, const std::vector<X509 *> &roots,
13+
const std::vector<X509 *> &intermediates,
14+
const std::vector<X509_CRL *> &crls, unsigned long flags = 0,
15+
std::function<void(X509_STORE_CTX *)> configure_callback = nullptr);
16+
17+
bssl::UniquePtr<STACK_OF(X509_CRL)> CRLsToStack(
18+
const std::vector<X509_CRL *> &crls);
19+
20+
#endif

crypto/x509/x509_compat_test.cc

Lines changed: 297 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,297 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR ISC
3+
4+
#include <gtest/gtest.h>
5+
6+
#include <openssl/x509.h>
7+
8+
#include "../internal.h"
9+
#include "../test/test_util.h"
10+
#include "../test/x509_util.h"
11+
12+
/*
13+
14+
The default root certificate key, "ROOT_KEY_1", used for self-signed
15+
roots, unless otherwise specified. This is EC prime256v1 key.
16+
-----BEGIN PRIVATE KEY-----
17+
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgfVMH4tqIaJ6OzyxY
18+
mqWXNwmK7gpXYDFhX80mXKgzrGGhRANCAATCqXrfbdTjFimzdBHxj71Ejcc/stea
19+
5xAU/xxK+s77yXzB5lfy/zEbcYxuOrnwHrWsX9sugWgCy74ZRNWJPTDW
20+
-----END PRIVATE KEY-----
21+
22+
The default end-entity certificate key, "EE_KEY_1", used for ee certs,
23+
unless otherwise specified. This is EC prime256v1 key.
24+
-----BEGIN PRIVATE KEY-----
25+
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgfVMH4tqIaJ6OzyxY
26+
mqWXNwmK7gpXYDFhX80mXKgzrGGhRANCAATCqXrfbdTjFimzdBHxj71Ejcc/stea
27+
5xAU/xxK+s77yXzB5lfy/zEbcYxuOrnwHrWsX9sugWgCy74ZRNWJPTDW
28+
-----END PRIVATE KEY-----
29+
*/
30+
31+
/*
32+
This self-signed root certificate's basicConstraints extension
33+
cA:false. The root certificate though has the keyCertSign bit set for the
34+
keyUsage extension. This is in violation of RFC 5280 4.2.1.9:
35+
"If the cA boolean is not asserted, then the keyCertSign bit in the key
36+
usage extension MUST NOT be asserted"
37+
38+
Certificate:
39+
Data:
40+
Version: 3 (0x2)
41+
Serial Number:
42+
0b:1e:77:95:de:6d:eb:b6:ab:2b:c4:51:3c:a6:70:02:99:f7:e5:f3
43+
Signature Algorithm: ecdsa-with-SHA256
44+
Issuer: C = US, ST = Washington, O = AWS Libcrypto, OU = Bad CA, CN = RFC 5280 4.2.1.9 cA:false
45+
Validity
46+
Not Before: Jan 1 00:00:00 2015 GMT
47+
Not After : Jan 1 00:00:00 2100 GMT
48+
Subject: C = US, ST = Washington, O = AWS Libcrypto, OU = Bad CA, CN = RFC 5280 4.2.1.9 cA:false
49+
Subject Public Key Info:
50+
Public Key Algorithm: id-ecPublicKey
51+
Public-Key: (256 bit)
52+
pub:
53+
04:c2:a9:7a:df:6d:d4:e3:16:29:b3:74:11:f1:8f:
54+
bd:44:8d:c7:3f:b2:d7:9a:e7:10:14:ff:1c:4a:fa:
55+
ce:fb:c9:7c:c1:e6:57:f2:ff:31:1b:71:8c:6e:3a:
56+
b9:f0:1e:b5:ac:5f:db:2e:81:68:02:cb:be:19:44:
57+
d5:89:3d:30:d6
58+
ASN1 OID: prime256v1
59+
NIST CURVE: P-256
60+
X509v3 extensions:
61+
X509v3 Key Usage: critical
62+
Certificate Sign
63+
X509v3 Basic Constraints: critical
64+
CA:FALSE
65+
X509v3 Subject Key Identifier:
66+
19:19:E1:8C:09:E2:5D:5C:16:04:E1:9C:74:66:19:FD:B8:52:5B:DF
67+
Signature Algorithm: ecdsa-with-SHA256
68+
Signature Value:
69+
30:45:02:20:55:72:9f:65:36:59:eb:0f:c4:50:d0:d7:fb:58:
70+
3e:54:5e:dc:bf:7e:37:a8:a4:9c:41:a8:91:91:ae:ce:39:ff:
71+
02:21:00:8b:d0:01:0d:89:6f:61:4b:7a:ec:85:d4:ef:80:13:
72+
bd:52:44:ae:cd:56:32:08:5d:37:44:32:ac:50:f2:cb:c1
73+
*/
74+
static const char kRootBadBasicConstraints[] = R"(
75+
-----BEGIN CERTIFICATE-----
76+
MIICITCCAcegAwIBAgIUCx53ld5t67arK8RRPKZwApn35fMwCgYIKoZIzj0EAwIw
77+
bzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24xFjAUBgNVBAoMDUFX
78+
UyBMaWJjcnlwdG8xDzANBgNVBAsMBkJhZCBDQTEiMCAGA1UEAwwZUkZDIDUyODAg
79+
NC4yLjEuOSBjQTpmYWxzZTAgFw0xNTAxMDEwMDAwMDBaGA8yMTAwMDEwMTAwMDAw
80+
MFowbzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24xFjAUBgNVBAoM
81+
DUFXUyBMaWJjcnlwdG8xDzANBgNVBAsMBkJhZCBDQTEiMCAGA1UEAwwZUkZDIDUy
82+
ODAgNC4yLjEuOSBjQTpmYWxzZTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABMKp
83+
et9t1OMWKbN0EfGPvUSNxz+y15rnEBT/HEr6zvvJfMHmV/L/MRtxjG46ufAetaxf
84+
2y6BaALLvhlE1Yk9MNajPzA9MA4GA1UdDwEB/wQEAwICBDAMBgNVHRMBAf8EAjAA
85+
MB0GA1UdDgQWBBQZGeGMCeJdXBYE4Zx0Zhn9uFJb3zAKBggqhkjOPQQDAgNIADBF
86+
AiBVcp9lNlnrD8RQ0Nf7WD5UXty/fjeopJxBqJGRrs45/wIhAIvQAQ2Jb2FLeuyF
87+
1O+AE71SRK7NVjIIXTdEMqxQ8svB
88+
-----END CERTIFICATE-----
89+
)";
90+
91+
/*
92+
This is an EE certificate signed by |kRootBadBasicConstraints|.
93+
This should not be considered valid as the kRootBadBasicConstraints is a v3
94+
certificate which has a basicConstraints extension indicating that it is not
95+
a CA, and it violates the RFC 5280 condition.
96+
97+
Certificate:
98+
Data:
99+
Version: 3 (0x2)
100+
Serial Number:
101+
7b:8e:6c:6e:5a:d0:53:59:e7:fc:e2:93:b3:f4:19:16:1e:c3:81:82
102+
Signature Algorithm: ecdsa-with-SHA256
103+
Issuer: C = US, ST = Washington, O = AWS Libcrypto, OU = Bad CA, CN = RFC 5280 4.2.1.9 cA:false
104+
Validity
105+
Not Before: Jan 1 00:00:00 2015 GMT
106+
Not After : Jan 1 00:00:00 2100 GMT
107+
Subject: C = US, ST = Washington, O = AWS Libcrypto, OU = Bad Endpoint, CN = RFC 5280 4.2.1.9 cA:false
108+
Subject Public Key Info:
109+
Public Key Algorithm: id-ecPublicKey
110+
Public-Key: (256 bit)
111+
pub:
112+
04:b2:b7:bd:35:f2:eb:da:86:d5:dc:40:44:c7:23:
113+
14:f9:d0:a5:40:17:30:85:b6:c6:11:38:c2:db:2c:
114+
c5:bc:0c:19:11:d8:68:61:d6:a3:92:6b:8a:18:52:
115+
2c:dc:86:a7:ad:29:ad:91:ac:7e:df:87:24:3b:f3:
116+
b4:71:2b:4e:58
117+
ASN1 OID: prime256v1
118+
NIST CURVE: P-256
119+
X509v3 extensions:
120+
X509v3 Key Usage: critical
121+
Digital Signature, Key Encipherment
122+
X509v3 Basic Constraints: critical
123+
CA:FALSE
124+
X509v3 Extended Key Usage:
125+
TLS Web Server Authentication, TLS Web Client Authentication
126+
X509v3 Subject Key Identifier:
127+
C8:78:64:E9:F7:9C:0F:56:E2:1D:CE:EE:ED:24:E0:9F:1D:4B:A3:BF
128+
X509v3 Authority Key Identifier:
129+
19:19:E1:8C:09:E2:5D:5C:16:04:E1:9C:74:66:19:FD:B8:52:5B:DF
130+
Signature Algorithm: ecdsa-with-SHA256
131+
Signature Value:
132+
30:45:02:20:38:ca:c4:54:ed:fc:bb:76:60:e9:4e:b5:85:91:
133+
f8:dc:a5:6a:54:9b:d2:22:a4:2c:6e:a6:df:fd:00:85:c0:06:
134+
02:21:00:ee:15:23:50:40:1b:67:b0:eb:13:75:6e:29:66:b0:
135+
e6:58:cf:1f:c2:5e:a1:85:01:45:9c:4d:ab:e7:61:ac:70
136+
*/
137+
static const char kEndEntitySignedByBadRoot[] = R"(
138+
-----BEGIN CERTIFICATE-----
139+
MIICZzCCAg2gAwIBAgIUe45sblrQU1nn/OKTs/QZFh7DgYIwCgYIKoZIzj0EAwIw
140+
bzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24xFjAUBgNVBAoMDUFX
141+
UyBMaWJjcnlwdG8xDzANBgNVBAsMBkJhZCBDQTEiMCAGA1UEAwwZUkZDIDUyODAg
142+
NC4yLjEuOSBjQTpmYWxzZTAgFw0xNTAxMDEwMDAwMDBaGA8yMTAwMDEwMTAwMDAw
143+
MFowdTELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24xFjAUBgNVBAoM
144+
DUFXUyBMaWJjcnlwdG8xFTATBgNVBAsMDEJhZCBFbmRwb2ludDEiMCAGA1UEAwwZ
145+
UkZDIDUyODAgNC4yLjEuOSBjQTpmYWxzZTBZMBMGByqGSM49AgEGCCqGSM49AwEH
146+
A0IABLK3vTXy69qG1dxARMcjFPnQpUAXMIW2xhE4wtssxbwMGRHYaGHWo5JrihhS
147+
LNyGp60prZGsft+HJDvztHErTlijfzB9MA4GA1UdDwEB/wQEAwIFoDAMBgNVHRMB
148+
Af8EAjAAMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAdBgNVHQ4EFgQU
149+
yHhk6fecD1biHc7u7STgnx1Lo78wHwYDVR0jBBgwFoAUGRnhjAniXVwWBOGcdGYZ
150+
/bhSW98wCgYIKoZIzj0EAwIDSAAwRQIgOMrEVO38u3Zg6U61hZH43KVqVJvSIqQs
151+
bqbf/QCFwAYCIQDuFSNQQBtnsOsTdW4pZrDmWM8fwl6hhQFFnE2r52GscA==
152+
-----END CERTIFICATE-----
153+
)";
154+
155+
/*
156+
Certificate:
157+
Data:
158+
Version: 3 (0x2)
159+
Serial Number:
160+
2e:0f:2e:da:e3:11:b2:fa:42:b3:29:09:b0:cc:93:87:ac:15:25:3d
161+
Signature Algorithm: ecdsa-with-SHA256
162+
Issuer: C = US, ST = Washington, O = AWS Libcrypto, OU = Good CA, CN = Root CA 1
163+
Validity
164+
Not Before: Jan 1 00:00:00 2015 GMT
165+
Not After : Jan 1 00:00:00 2100 GMT
166+
Subject: C = US, ST = Washington, O = AWS Libcrypto, OU = Good CA, CN = Root CA 1
167+
Subject Public Key Info:
168+
Public Key Algorithm: id-ecPublicKey
169+
Public-Key: (256 bit)
170+
pub:
171+
04:c2:a9:7a:df:6d:d4:e3:16:29:b3:74:11:f1:8f:
172+
bd:44:8d:c7:3f:b2:d7:9a:e7:10:14:ff:1c:4a:fa:
173+
ce:fb:c9:7c:c1:e6:57:f2:ff:31:1b:71:8c:6e:3a:
174+
b9:f0:1e:b5:ac:5f:db:2e:81:68:02:cb:be:19:44:
175+
d5:89:3d:30:d6
176+
ASN1 OID: prime256v1
177+
NIST CURVE: P-256
178+
X509v3 extensions:
179+
X509v3 Key Usage: critical
180+
Digital Signature, Certificate Sign, CRL Sign
181+
X509v3 Basic Constraints: critical
182+
CA:TRUE
183+
X509v3 Subject Key Identifier:
184+
19:19:E1:8C:09:E2:5D:5C:16:04:E1:9C:74:66:19:FD:B8:52:5B:DF
185+
Signature Algorithm: ecdsa-with-SHA256
186+
Signature Value:
187+
30:45:02:21:00:a4:39:29:1b:07:a2:3e:cc:21:eb:f6:5c:fd:
188+
b8:88:ee:79:46:37:25:e5:9a:79:2e:3d:2f:21:15:56:43:c8:
189+
b8:02:20:36:bd:03:bc:df:f6:7d:d2:a3:d2:a5:48:a8:64:75:
190+
00:4e:01:cd:67:b9:19:87:49:2b:bd:15:94:3e:f5:75:ca
191+
*/
192+
static const char kValidRootCA1[] = R"(
193+
-----BEGIN CERTIFICATE-----
194+
MIICBjCCAaygAwIBAgIULg8u2uMRsvpCsykJsMyTh6wVJT0wCgYIKoZIzj0EAwIw
195+
YDELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24xFjAUBgNVBAoMDUFX
196+
UyBMaWJjcnlwdG8xEDAOBgNVBAsMB0dvb2QgQ0ExEjAQBgNVBAMMCVJvb3QgQ0Eg
197+
MTAgFw0xNTAxMDEwMDAwMDBaGA8yMTAwMDEwMTAwMDAwMFowYDELMAkGA1UEBhMC
198+
VVMxEzARBgNVBAgMCldhc2hpbmd0b24xFjAUBgNVBAoMDUFXUyBMaWJjcnlwdG8x
199+
EDAOBgNVBAsMB0dvb2QgQ0ExEjAQBgNVBAMMCVJvb3QgQ0EgMTBZMBMGByqGSM49
200+
AgEGCCqGSM49AwEHA0IABMKpet9t1OMWKbN0EfGPvUSNxz+y15rnEBT/HEr6zvvJ
201+
fMHmV/L/MRtxjG46ufAetaxf2y6BaALLvhlE1Yk9MNajQjBAMA4GA1UdDwEB/wQE
202+
AwIBhjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBQZGeGMCeJdXBYE4Zx0Zhn9
203+
uFJb3zAKBggqhkjOPQQDAgNIADBFAiEApDkpGweiPswh6/Zc/biI7nlGNyXlmnku
204+
PS8hFVZDyLgCIDa9A7zf9n3So9KlSKhkdQBOAc1nuRmHSSu9FZQ+9XXK
205+
-----END CERTIFICATE-----
206+
)";
207+
208+
/*
209+
This is an EE certificate signed by |kValidRootCA1|, and is invalid as it
210+
has an Authority Key Identifier (AKID) extension marked critical which
211+
is not valid per RFC 5280 4.2.1.1:
212+
"Conforming CAs MUST mark this extension as non-critical."
213+
214+
Certificate:
215+
Data:
216+
Version: 3 (0x2)
217+
Serial Number:
218+
27:8c:f7:17:16:47:56:c0:58:32:6c:dd:65:09:10:6b:44:bb:0e:a7
219+
Signature Algorithm: ecdsa-with-SHA256
220+
Issuer: C = US, ST = Washington, O = AWS Libcrypto, OU = Good CA, CN = Root CA 1
221+
Validity
222+
Not Before: Jan 1 00:00:00 2015 GMT
223+
Not After : Jan 1 00:00:00 2100 GMT
224+
Subject: C = US, ST = Washington, O = AWS Libcrypto, OU = Bad Endpoint, CN = RFC 5280 4.2.1.1 AKID MUST be non-critical
225+
Subject Public Key Info:
226+
Public Key Algorithm: id-ecPublicKey
227+
Public-Key: (256 bit)
228+
pub:
229+
04:b2:b7:bd:35:f2:eb:da:86:d5:dc:40:44:c7:23:
230+
14:f9:d0:a5:40:17:30:85:b6:c6:11:38:c2:db:2c:
231+
c5:bc:0c:19:11:d8:68:61:d6:a3:92:6b:8a:18:52:
232+
2c:dc:86:a7:ad:29:ad:91:ac:7e:df:87:24:3b:f3:
233+
b4:71:2b:4e:58
234+
ASN1 OID: prime256v1
235+
NIST CURVE: P-256
236+
X509v3 extensions:
237+
X509v3 Key Usage: critical
238+
Digital Signature, Key Encipherment
239+
X509v3 Basic Constraints: critical
240+
CA:FALSE
241+
X509v3 Extended Key Usage:
242+
TLS Web Server Authentication, TLS Web Client Authentication
243+
X509v3 Authority Key Identifier: critical
244+
19:19:E1:8C:09:E2:5D:5C:16:04:E1:9C:74:66:19:FD:B8:52:5B:DF
245+
X509v3 Subject Key Identifier:
246+
C8:78:64:E9:F7:9C:0F:56:E2:1D:CE:EE:ED:24:E0:9F:1D:4B:A3:BF
247+
Signature Algorithm: ecdsa-with-SHA256
248+
Signature Value:
249+
30:46:02:21:00:9f:57:ba:de:8e:1a:82:1f:02:11:87:8d:00:
250+
fa:a2:eb:85:43:0d:c2:57:c6:12:c6:65:3b:e6:e9:aa:66:13:
251+
9e:02:21:00:fc:7f:a9:58:79:ba:bf:51:50:21:8f:f8:6e:89:
252+
c9:2c:14:fd:9f:9b:dd:f7:15:a9:6e:8d:9e:fe:0d:df:4e:35
253+
*/
254+
static const char kInvalidEECertificateWithCriticalAKID[] = R"(
255+
-----BEGIN CERTIFICATE-----
256+
MIICcDCCAhWgAwIBAgIUJ4z3FxZHVsBYMmzdZQkQa0S7DqcwCgYIKoZIzj0EAwIw
257+
YDELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24xFjAUBgNVBAoMDUFX
258+
UyBMaWJjcnlwdG8xEDAOBgNVBAsMB0dvb2QgQ0ExEjAQBgNVBAMMCVJvb3QgQ0Eg
259+
MTAgFw0xNTAxMDEwMDAwMDBaGA8yMTAwMDEwMTAwMDAwMFowgYYxCzAJBgNVBAYT
260+
AlVTMRMwEQYDVQQIDApXYXNoaW5ndG9uMRYwFAYDVQQKDA1BV1MgTGliY3J5cHRv
261+
MRUwEwYDVQQLDAxCYWQgRW5kcG9pbnQxMzAxBgNVBAMMKlJGQyA1MjgwIDQuMi4x
262+
LjEgQUtJRCBNVVNUIGJlIG5vbi1jcml0aWNhbDBZMBMGByqGSM49AgEGCCqGSM49
263+
AwEHA0IABLK3vTXy69qG1dxARMcjFPnQpUAXMIW2xhE4wtssxbwMGRHYaGHWo5Jr
264+
ihhSLNyGp60prZGsft+HJDvztHErTlijgYMwgYAwDgYDVR0PAQH/BAQDAgWgMAwG
265+
A1UdEwEB/wQCMAAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMCIGA1Ud
266+
IwEB/wQYMBaAFBkZ4YwJ4l1cFgThnHRmGf24UlvfMB0GA1UdDgQWBBTIeGTp95wP
267+
VuIdzu7tJOCfHUujvzAKBggqhkjOPQQDAgNJADBGAiEAn1e63o4agh8CEYeNAPqi
268+
64VDDcJXxhLGZTvm6apmE54CIQD8f6lYebq/UVAhj/huicksFP2fm933FalujZ7+
269+
Dd9ONQ==
270+
-----END CERTIFICATE-----
271+
)";
272+
273+
// EE certificate should not verify if signed by invalid root CA
274+
TEST(X509CompatTest, CertificatesFromTrustStoreValidated) {
275+
bssl::UniquePtr<X509> root = CertFromPEM(kRootBadBasicConstraints);
276+
ASSERT_TRUE(root);
277+
bssl::UniquePtr<X509> leaf = CertFromPEM(kEndEntitySignedByBadRoot);
278+
ASSERT_TRUE(leaf);
279+
280+
EXPECT_EQ(X509_V_ERR_INVALID_CA,
281+
Verify(leaf.get(), /*roots=*/{root.get()}, /*intermediates=*/{},
282+
/*crls=*/{}, /*flags=*/0));
283+
}
284+
285+
// Certificate should be rejected if it contains a critical AKID extension.
286+
// This reports a X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION due to it being an unhandled
287+
// critical exception.
288+
TEST(X509CompatTest, EndpointCertificateWithCriticalAKID) {
289+
bssl::UniquePtr<X509> root = CertFromPEM(kValidRootCA1);
290+
ASSERT_TRUE(root);
291+
bssl::UniquePtr<X509> leaf = CertFromPEM(kInvalidEECertificateWithCriticalAKID);
292+
ASSERT_TRUE(leaf);
293+
294+
EXPECT_EQ(X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION,
295+
Verify(leaf.get(), /*roots=*/{root.get()}, /*intermediates=*/{},
296+
/*crls=*/{}, /*flags=*/0));
297+
}

0 commit comments

Comments
 (0)