Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: components/cast_certificate/cast_crl_unittest.cc

Issue 2050983002: Cast device revocation checking. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test suite runner. Updated some tests. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/cast_certificate/cast_crl.h"
6
7 #include "base/time/time.h"
8 #include "components/cast_certificate/cast_cert_validator.h"
9 #include "components/cast_certificate/cast_cert_validator_test_helpers.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace cast_certificate {
13 namespace {
14
15 const unsigned char kCastCRLTestRootCaDer[] = {
16 0x30, 0x82, 0x03, 0xee, 0x30, 0x82, 0x02, 0xd6, 0xa0, 0x03, 0x02, 0x01,
17 0x02, 0x02, 0x02, 0x00, 0x91, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
18 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x81, 0x88, 0x31,
19 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53,
20 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x43,
21 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61, 0x31, 0x16, 0x30,
22 0x14, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x0d, 0x4d, 0x6f, 0x75, 0x6e,
23 0x74, 0x61, 0x69, 0x6e, 0x20, 0x56, 0x69, 0x65, 0x77, 0x31, 0x13, 0x30,
24 0x11, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x0a, 0x47, 0x6f, 0x6f, 0x67,
25 0x6c, 0x65, 0x20, 0x49, 0x6e, 0x63, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x03,
26 0x55, 0x04, 0x0b, 0x0c, 0x04, 0x43, 0x61, 0x73, 0x74, 0x31, 0x28, 0x30,
27 0x26, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x1f, 0x43, 0x61, 0x73, 0x74,
28 0x20, 0x43, 0x52, 0x4c, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x55, 0x6e,
29 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x20, 0x52, 0x6f, 0x6f, 0x74,
30 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x35, 0x32,
31 0x35, 0x32, 0x31, 0x30, 0x30, 0x30, 0x36, 0x5a, 0x17, 0x0d, 0x33, 0x36,
32 0x30, 0x35, 0x32, 0x30, 0x32, 0x31, 0x30, 0x30, 0x30, 0x36, 0x5a, 0x30,
33 0x81, 0x88, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
34 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08,
35 0x0c, 0x0a, 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61,
36 0x31, 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x0d, 0x4d,
37 0x6f, 0x75, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x20, 0x56, 0x69, 0x65, 0x77,
38 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x0a, 0x47,
39 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x20, 0x49, 0x6e, 0x63, 0x31, 0x0d, 0x30,
40 0x0b, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x04, 0x43, 0x61, 0x73, 0x74,
41 0x31, 0x28, 0x30, 0x26, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x1f, 0x43,
42 0x61, 0x73, 0x74, 0x20, 0x43, 0x52, 0x4c, 0x20, 0x54, 0x65, 0x73, 0x74,
43 0x20, 0x55, 0x6e, 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x20, 0x52,
44 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d,
45 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05,
46 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82,
47 0x01, 0x01, 0x00, 0xb5, 0xc1, 0xbe, 0xd4, 0x34, 0x2c, 0xd7, 0xdf, 0x99,
48 0x21, 0xa9, 0x4b, 0x56, 0xc3, 0x2e, 0x78, 0x21, 0x0d, 0xa8, 0xa9, 0xa0,
49 0x4c, 0x2d, 0x62, 0xcb, 0x4f, 0xc5, 0xa0, 0xa7, 0x47, 0x1c, 0x9d, 0x2a,
50 0xeb, 0x61, 0xd1, 0xd4, 0xcc, 0x24, 0x23, 0xe5, 0x11, 0x0f, 0x18, 0x81,
51 0x2a, 0x56, 0x41, 0x30, 0x6f, 0x84, 0x04, 0x09, 0xba, 0x0f, 0xec, 0xd7,
52 0x2f, 0xc6, 0xc4, 0xc4, 0x91, 0x2d, 0xca, 0x6d, 0x76, 0x54, 0xb2, 0xb2,
53 0x5a, 0x59, 0xc1, 0x3d, 0x17, 0xf2, 0x7f, 0x80, 0x22, 0xb9, 0x39, 0xc5,
54 0xc0, 0x74, 0x74, 0x9d, 0x70, 0xb9, 0xc7, 0x60, 0xe3, 0x84, 0x95, 0xa0,
55 0x49, 0xab, 0x6d, 0x8f, 0xcc, 0xb9, 0x3a, 0xc9, 0xdd, 0x4f, 0x50, 0x37,
56 0x9e, 0xb0, 0xc0, 0x6f, 0x22, 0x8c, 0xa9, 0x82, 0x56, 0x26, 0x8f, 0xe1,
57 0xb3, 0xe6, 0xb4, 0xb9, 0xbe, 0x4d, 0x83, 0xe0, 0xf4, 0xd4, 0x2f, 0x10,
58 0x9b, 0x7f, 0xc9, 0x4f, 0x77, 0x6f, 0xa0, 0x02, 0x34, 0x1a, 0xce, 0xbe,
59 0xe3, 0x0e, 0x25, 0x03, 0xba, 0xdb, 0xb1, 0xbc, 0xfa, 0xec, 0x01, 0xc2,
60 0xc0, 0xf4, 0xf5, 0x55, 0xb9, 0x7b, 0xef, 0xc0, 0x8a, 0x52, 0xfe, 0xf5,
61 0x07, 0xcf, 0x2d, 0xfa, 0x37, 0xfe, 0x4c, 0x54, 0xf2, 0x87, 0xe9, 0x32,
62 0xee, 0x04, 0x6c, 0xd6, 0xfa, 0xfc, 0x51, 0x94, 0x21, 0xe5, 0x43, 0xcb,
63 0x89, 0x02, 0x07, 0xb3, 0x5b, 0xdc, 0x09, 0x18, 0xcc, 0x55, 0x9c, 0x89,
64 0x3e, 0xff, 0x32, 0x6c, 0x93, 0x87, 0xf7, 0x18, 0x73, 0x7c, 0x6f, 0xca,
65 0x57, 0x41, 0xbd, 0xd2, 0x5b, 0x12, 0x60, 0x75, 0xa7, 0x44, 0xc3, 0x78,
66 0x35, 0x98, 0x12, 0xb6, 0x1e, 0x3c, 0x25, 0x72, 0x13, 0x2c, 0x9d, 0xfa,
67 0x74, 0x81, 0x11, 0x28, 0xcc, 0x55, 0x93, 0x46, 0x42, 0x17, 0x5a, 0x46,
68 0xee, 0x57, 0x17, 0x26, 0x83, 0x4c, 0x1b, 0x02, 0x03, 0x01, 0x00, 0x01,
69 0xa3, 0x60, 0x30, 0x5e, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04,
70 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x01, 0x30, 0x1d, 0x06,
71 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x56, 0x47, 0xa3, 0x12,
72 0xa6, 0xdb, 0xb7, 0xf3, 0xf1, 0xe4, 0x68, 0x62, 0xcb, 0x01, 0x45, 0xfd,
73 0x2b, 0x02, 0x73, 0x68, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04,
74 0x18, 0x30, 0x16, 0x80, 0x14, 0x56, 0x47, 0xa3, 0x12, 0xa6, 0xdb, 0xb7,
75 0xf3, 0xf1, 0xe4, 0x68, 0x62, 0xcb, 0x01, 0x45, 0xfd, 0x2b, 0x02, 0x73,
76 0x68, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03, 0x02,
77 0x02, 0x04, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
78 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x22, 0xce,
79 0x56, 0x31, 0xcd, 0xe0, 0xac, 0xb4, 0xaf, 0x70, 0x8a, 0x0a, 0x60, 0x4d,
80 0xa8, 0x16, 0x81, 0x11, 0xcf, 0xb6, 0xcf, 0x89, 0x87, 0x86, 0xec, 0x8e,
81 0x72, 0xb3, 0xbc, 0x01, 0xb4, 0x29, 0xb1, 0x88, 0x48, 0x65, 0xcd, 0x7c,
82 0x8f, 0xa0, 0x6f, 0x05, 0xb8, 0x60, 0x28, 0x60, 0x1b, 0x8d, 0x61, 0xeb,
83 0xe5, 0xa5, 0xc0, 0xb5, 0x11, 0x8d, 0x4d, 0x73, 0x73, 0x3a, 0x82, 0xa9,
84 0x39, 0xfe, 0x5a, 0x54, 0x28, 0x69, 0x1c, 0xec, 0x9e, 0xb7, 0x1c, 0x3d,
85 0x02, 0xd1, 0x33, 0x1c, 0x82, 0xcc, 0x14, 0x0d, 0xc9, 0xc7, 0xab, 0x7d,
86 0xc0, 0x89, 0x31, 0xff, 0x02, 0x17, 0x8a, 0xd0, 0x37, 0xe5, 0xdc, 0x03,
87 0x34, 0xd5, 0x07, 0xa7, 0x0f, 0x8c, 0xec, 0x3e, 0x47, 0x5d, 0xa9, 0xe9,
88 0x12, 0x6d, 0x0c, 0x8d, 0x89, 0x27, 0x73, 0x9c, 0x4c, 0x88, 0x97, 0x66,
89 0x9f, 0x4f, 0x76, 0x5b, 0xaf, 0xe6, 0x40, 0xde, 0x83, 0xb1, 0xde, 0x35,
90 0x2e, 0xae, 0x9e, 0x91, 0xda, 0xa3, 0x37, 0xa5, 0x89, 0x2a, 0x57, 0xa9,
91 0x98, 0x40, 0xf2, 0xe5, 0x8e, 0xad, 0x44, 0x4d, 0xf6, 0xc0, 0x55, 0xc8,
92 0x71, 0xdc, 0xa5, 0x81, 0x4a, 0x3b, 0x17, 0x3c, 0xfd, 0x40, 0x77, 0x0c,
93 0x26, 0x65, 0xda, 0xec, 0xda, 0x97, 0x19, 0xa0, 0x16, 0x99, 0x11, 0xd0,
94 0x2b, 0x0d, 0x2c, 0x58, 0x30, 0x9a, 0x76, 0x18, 0x4f, 0xd0, 0x3c, 0x24,
95 0x4b, 0x96, 0x51, 0x7e, 0x82, 0xce, 0xa1, 0x6c, 0xfa, 0xfb, 0x5a, 0x3c,
96 0xc2, 0x1d, 0x3c, 0x27, 0xf2, 0xea, 0x17, 0x2c, 0x5e, 0xab, 0x91, 0x45,
97 0xd3, 0x35, 0xd0, 0xdc, 0xa7, 0x41, 0xe0, 0xe3, 0x3e, 0x23, 0xdb, 0x63,
98 0xa8, 0xfc, 0xfb, 0x76, 0x37, 0x59, 0xf8, 0xb2, 0x31, 0xe5, 0x6d, 0xcf,
99 0xfa, 0x17, 0x84, 0xd9, 0x16, 0x2f, 0x97, 0x90, 0x8c, 0x83, 0xf2, 0x6f,
100 0x82, 0xed};
101
102 // Indicates the expected result of CRL verification
103 enum TestResultCRL {
104 RESULT_CRL_INVALID,
105 RESULT_CRL_VALID,
106 };
107
108 // Indicates the expected result of test verification
109 enum TestResultCert {
110 RESULT_CERT_INVALID,
111 RESULT_CERT_VALID,
112 };
113
114 base::Time::Exploded TestTimeValid() {
115 return cast_certificate::testing::CreateDate(2016, 6, 23);
116 }
117
118 base::Time::Exploded TestTimeIssuerExpired() {
119 return cast_certificate::testing::CreateDate(2016, 6, 25);
120 }
121
122 base::Time::Exploded TestTimeFuture() {
123 return cast_certificate::testing::CreateDate(2016, 10, 1);
124 }
125
126 base::Time::Exploded TestTimePast() {
127 return cast_certificate::testing::CreateDate(2016, 1, 1);
128 }
129
130 std::unique_ptr<CastCRL> RunTestVerifyCRL(TestResultCRL expected_result,
131 const std::string& crl_file_name,
132 const base::Time::Exploded& time,
133 bool set_trust_anchor) {
134 std::string crl_raw = cast_certificate::testing::ReadFromFile(crl_file_name);
135
136 ClearCRLTrustAnchorForTest();
137 if (set_trust_anchor)
138 EXPECT_TRUE(AddCRLTrustAnchorForTest(kCastCRLTestRootCaDer,
139 sizeof(kCastCRLTestRootCaDer)));
140
141 std::unique_ptr<CastCRL> crl = ParseCRL(crl_raw, time);
142 if (expected_result == RESULT_CRL_INVALID) {
143 EXPECT_EQ(crl.get(), nullptr);
144 return nullptr;
145 }
146 EXPECT_NE(crl.get(), nullptr);
147 return crl;
148 }
149
150 void RunTest(TestResultCert expected_result,
151 const std::string& certs_file_name,
152 const std::string& crl_file_name,
153 const base::Time::Exploded& time) {
154 auto certs =
155 cast_certificate::testing::ReadCertificateChainFromFile(certs_file_name);
156
157 std::unique_ptr<CastCRL> crl =
158 RunTestVerifyCRL(RESULT_CRL_VALID, crl_file_name, TestTimeValid(), true);
159 ASSERT_NE(crl.get(), nullptr);
160
161 std::unique_ptr<CertVerificationContext> context;
162 CastDeviceCertPolicy policy;
163 CRLOptions crl_options;
164 crl_options.crl_required = false;
165 // Check that verification passes without the CRL.
166 ASSERT_TRUE(
167 VerifyDeviceCert(certs, time, &context, &policy, nullptr, crl_options));
168 bool result = VerifyDeviceCert(certs, time, &context, &policy, crl.get(), {});
169 if (expected_result == RESULT_CERT_INVALID) {
170 ASSERT_FALSE(result);
171 return;
172 }
173 EXPECT_TRUE(result);
174 }
175
176 // Tests the verification and parsing of an empty CRL signed by an unexpired
177 // trusted CRL authoriy.
178 TEST(CastCRLTest, CRLEmpty) {
179 RunTestVerifyCRL(RESULT_CRL_VALID, "crl/empty.pb", TestTimeValid(), true);
180 }
181
182 // Tests the verification and parsing of a CRL signed by an unexpired trusted
183 // CRL authoriy.
184 TEST(CastCRLTest, CRLValid) {
185 RunTestVerifyCRL(RESULT_CRL_VALID, "crl/nonempty_norevoke.pb",
186 TestTimeValid(), true);
187 }
188
189 // Tests the verification and parsing of a CRL whose signer is not trusted.
190 TEST(CastCRLTest, CRLUntrusted) {
191 RunTestVerifyCRL(RESULT_CRL_INVALID, "crl/nonempty_norevoke.pb",
192 TestTimeValid(), false);
193 }
194
195 // Tests the verification and parsing of a CRL whose signer certificate is
196 // expired.
197 TEST(CastCRLTest, CRLSignerExpired) {
198 RunTestVerifyCRL(RESULT_CRL_INVALID, "crl/signer_expired.pb",
199 TestTimeIssuerExpired(), true);
200 }
201
202 // Tests the verification and parsing of a CRL whose certificate does not verify
203 // the signature
204 TEST(CastCRLTest, CRLWrongSignature) {
205 RunTestVerifyCRL(RESULT_CRL_INVALID, "crl/badsignature.pb", TestTimeValid(),
206 true);
207 }
208
209 // Tests the verification of an unrevoked certificate (empty CRL)
210 TEST(CastCRLTest, ValidEmpty) {
211 RunTest(RESULT_CERT_VALID, "certificates/chromecast_gen1.pem", "crl/empty.pb",
212 TestTimeValid());
213 }
214
215 // Tests the verification of an unrevoked certificate
216 TEST(CastCRLTest, ValidCert) {
217 RunTest(RESULT_CERT_VALID, "certificates/chromecast_gen1.pem",
218 "crl/nonempty_norevoke.pb", TestTimeValid());
219 }
220
221 // Tests the verification of unrevoked certificates (serial number edge cases)
222 TEST(CastCRLTest, ValidCertSerialEdges) {
223 RunTest(RESULT_CERT_VALID, "certificates/fugu.pem", "crl/revoked_serial.pb",
224 TestTimeValid());
225 }
226
227 // Tests the verification of an unrevoked certificate (serial revoked for
228 // different issuer)
229 TEST(CastCRLTest, ValidCertSerialRevokeWrongIssuer) {
230 RunTest(RESULT_CERT_VALID, "certificates/chromecast_gen1.pem",
231 "crl/revoked_serial.pb", TestTimeValid());
232 }
233
234 // Tests the verification of a certificate revoked by serial number
235 TEST(CastCRLTest, RevokedCertSerial) {
236 RunTest(RESULT_CERT_INVALID, "certificates/chromecast_gen2.pem",
237 "crl/revoked_serial.pb", TestTimeValid());
238 }
239
240 // Tests the verification of a certificate revoked by the public key hash
241 TEST(CastCRLTest, RevokedCertHash) {
242 RunTest(RESULT_CERT_INVALID, "certificates/chromecast_gen1.pem",
243 "crl/revoked_cert_hash.pb", TestTimeValid());
244 }
245 // Tests the verification of a certificate whose ICA is revoked by the public
246 // key hash.
247 TEST(CastCRLTest, RevokedICAHash) {
248 RunTest(RESULT_CERT_INVALID, "certificates/chromecast_gen2.pem",
249 "crl/revoked_ica_hash.pb", TestTimeValid());
250 }
251
252 // Tests the verification of a certificate whose ICA is revoked by the serial
253 // number.
254 TEST(CastCRLTest, RevokedICASerial) {
255 RunTest(RESULT_CERT_INVALID, "certificates/fugu.pem",
256 "crl/revoked_ica_serial1.pb", TestTimeValid());
257 }
258
259 // Tests the verification of a certificate whose ICA is revoked by the serial
260 // number (edge cases).
261 TEST(CastCRLTest, RevokedICASerialEdges) {
262 RunTest(RESULT_CERT_INVALID, "certificates/fugu.pem",
263 "crl/revoked_ica_serial2.pb", TestTimeValid());
264 RunTest(RESULT_CERT_INVALID, "certificates/chromecast_gen2.pem",
265 "crl/revoked_ica_serial2.pb", TestTimeValid());
266 }
267
268 // Tests the verification of a valid certificate with an expired CRL
269 TEST(CastCRLTest, ExpiredCRLValidCert) {
270 RunTest(RESULT_CERT_INVALID, "certificates/chromecast_gen1.pem",
271 "crl/nonempty_norevoke.pb", TestTimeFuture());
272 }
273
274 // Tests the verification of a valid certificate with a CRL whose signer
275 // cert chain has expired. The actual CRL has not expired but is treated such.
276 TEST(CastCRLTest, ExpiredCRLIssuerValidCert) {
277 RunTest(RESULT_CERT_INVALID, "certificates/chromecast_gen1.pem",
278 "crl/signer_expired.pb", TestTimeIssuerExpired());
279 }
280
281 // Tests the verification of a revoked certificate with an expired CRL
282 TEST(CastCRLTest, ExpiredCRLInvalidCert) {
283 RunTest(RESULT_CERT_INVALID, "certificates/chromecast_gen1.pem",
284 "crl/revoked_cert_hash.pb", TestTimeFuture());
285 }
286
287 // Tests the verification of a valid certificate with a CRL whose creation time
288 // is in the future.
289 TEST(CastCRLTest, PostdatedCRLValidCert) {
290 RunTest(RESULT_CERT_INVALID, "certificates/chromecast_gen1.pem",
291 "crl/nonempty_norevoke.pb", TestTimePast());
292 }
293
294 } // namespace
295
296 } // namespace cast_certificate
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698