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

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

Powered by Google App Engine
This is Rietveld 408576698