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

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

Issue 2050983002: Cast device revocation checking. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed test failure on 32 bit systems. Created 4 years, 4 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/cast_certificate/cast_cert_validator.h" 5 #include "components/cast_certificate/cast_cert_validator.h"
6 6
7 #include "components/cast_certificate/cast_cert_validator_test_helpers.h" 7 #include "components/cast_certificate/cast_cert_validator_test_helpers.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace cast_certificate { 10 namespace cast_certificate {
(...skipping 21 matching lines...) Expand all
32 // * |expected_policy| - The policy that should have been identified for the 32 // * |expected_policy| - The policy that should have been identified for the
33 // device certificate. 33 // device certificate.
34 // * |time| - The timestamp to use when verifying the certificate. 34 // * |time| - The timestamp to use when verifying the certificate.
35 // * |optional_signed_data_file_name| - optional path to a PEM file containing 35 // * |optional_signed_data_file_name| - optional path to a PEM file containing
36 // a valid signature generated by the device certificate. 36 // a valid signature generated by the device certificate.
37 // 37 //
38 void RunTest(TestResult expected_result, 38 void RunTest(TestResult expected_result,
39 const std::string& expected_common_name, 39 const std::string& expected_common_name,
40 CastDeviceCertPolicy expected_policy, 40 CastDeviceCertPolicy expected_policy,
41 const std::string& certs_file_name, 41 const std::string& certs_file_name,
42 const base::Time::Exploded& time, 42 const base::Time& time,
43 const std::string& optional_signed_data_file_name) { 43 const std::string& optional_signed_data_file_name) {
44 auto certs = 44 auto certs =
45 cast_certificate::testing::ReadCertificateChainFromFile(certs_file_name); 45 cast_certificate::testing::ReadCertificateChainFromFile(certs_file_name);
46 46
47 std::unique_ptr<CertVerificationContext> context; 47 std::unique_ptr<CertVerificationContext> context;
48 CastDeviceCertPolicy policy; 48 CastDeviceCertPolicy policy;
49 bool result = VerifyDeviceCert(certs, time, &context, &policy); 49 bool result = VerifyDeviceCert(certs, time, &context, &policy, nullptr,
50 CRLPolicy::CRL_OPTIONAL);
50 51
51 if (expected_result == RESULT_FAIL) { 52 if (expected_result == RESULT_FAIL) {
52 ASSERT_FALSE(result); 53 ASSERT_FALSE(result);
53 return; 54 return;
54 } 55 }
55 56
56 ASSERT_TRUE(result); 57 ASSERT_TRUE(result);
57 EXPECT_EQ(expected_policy, policy); 58 EXPECT_EQ(expected_policy, policy);
58 ASSERT_TRUE(context.get()); 59 ASSERT_TRUE(context.get());
59 60
(...skipping 22 matching lines...) Expand all
82 // TODO(eroman): This fails because there isn't currently support 83 // TODO(eroman): This fails because there isn't currently support
83 // for specifying a signature algorithm other than RSASSA PKCS#1 v1.5 with 84 // for specifying a signature algorithm other than RSASSA PKCS#1 v1.5 with
84 // SHA1. Once support for different algorithms is added to the API this 85 // SHA1. Once support for different algorithms is added to the API this
85 // should be changed to expect success. 86 // should be changed to expect success.
86 EXPECT_FALSE(context->VerifySignatureOverData( 87 EXPECT_FALSE(context->VerifySignatureOverData(
87 signature_data.signature_sha256, signature_data.message)); 88 signature_data.signature_sha256, signature_data.message));
88 } 89 }
89 } 90 }
90 91
91 // Creates a time in UTC at midnight. 92 // Creates a time in UTC at midnight.
92 base::Time::Exploded CreateDate(int year, int month, int day) { 93 //
94 // The maximum date usable here is limited to year 2038 on 32 bit systems due to
95 // base::Time::FromExploded clamping the range to what is supported by mktime
96 // and timegm.
97 base::Time CreateDate(int year, int month, int day) {
93 base::Time::Exploded time = {0}; 98 base::Time::Exploded time = {0};
94 time.year = year; 99 time.year = year;
95 time.month = month; 100 time.month = month;
96 time.day_of_month = day; 101 time.day_of_month = day;
97 return time; 102 base::Time result;
103 EXPECT_TRUE(base::Time::FromUTCExploded(time, &result));
104 return result;
98 } 105 }
99 106
100 // Returns 2016-04-01 00:00:00 UTC. 107 // Returns 2016-04-01 00:00:00 UTC.
101 // 108 //
102 // This is a time when most of the test certificate paths are 109 // This is a time when most of the test certificate paths are
103 // valid. 110 // valid.
104 base::Time::Exploded AprilFirst2016() { 111 base::Time AprilFirst2016() {
105 return CreateDate(2016, 4, 1); 112 return CreateDate(2016, 4, 1);
106 } 113 }
107 114
108 // Returns 2015-01-01 00:00:00 UTC. 115 // Returns 2015-01-01 00:00:00 UTC.
109 base::Time::Exploded JanuaryFirst2015() { 116 base::Time JanuaryFirst2015() {
110 return CreateDate(2015, 1, 1); 117 return CreateDate(2015, 1, 1);
111 } 118 }
112 119
113 // Returns 2040-03-01 00:00:00 UTC. 120 // Returns 2037-03-01 00:00:00 UTC.
114 // 121 //
115 // This is so far in the future that the test chains in this unit-test 122 // This is so far in the future that the test chains in this unit-test
116 // should all be invalid. 123 // should all be invalid.
117 base::Time::Exploded MarchFirst2040() { 124 base::Time MarchFirst2037() {
118 return CreateDate(2040, 3, 1); 125 return CreateDate(2037, 3, 1);
119 } 126 }
120 127
121 // Tests verifying a valid certificate chain of length 2: 128 // Tests verifying a valid certificate chain of length 2:
122 // 129 //
123 // 0: 2ZZBG9 FA8FCA3EF91A 130 // 0: 2ZZBG9 FA8FCA3EF91A
124 // 1: Eureka Gen1 ICA 131 // 1: Eureka Gen1 ICA
125 // 132 //
126 // Chains to trust anchor: 133 // Chains to trust anchor:
127 // Eureka Root CA (not included) 134 // Eureka Root CA (not included)
128 TEST(VerifyCastDeviceCertTest, ChromecastGen1) { 135 TEST(VerifyCastDeviceCertTest, ChromecastGen1) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // this test is pointless. 258 // this test is pointless.
252 RunTest(RESULT_SUCCESS, "3ZZAK6 FA8FCA3F0D35", CastDeviceCertPolicy::NONE, 259 RunTest(RESULT_SUCCESS, "3ZZAK6 FA8FCA3F0D35", CastDeviceCertPolicy::NONE,
253 kCertsFile, AprilFirst2016(), ""); 260 kCertsFile, AprilFirst2016(), "");
254 261
255 // Use a time before notBefore. 262 // Use a time before notBefore.
256 RunTest(RESULT_FAIL, "", CastDeviceCertPolicy::NONE, kCertsFile, 263 RunTest(RESULT_FAIL, "", CastDeviceCertPolicy::NONE, kCertsFile,
257 JanuaryFirst2015(), ""); 264 JanuaryFirst2015(), "");
258 265
259 // Use a time after notAfter. 266 // Use a time after notAfter.
260 RunTest(RESULT_FAIL, "", CastDeviceCertPolicy::NONE, kCertsFile, 267 RunTest(RESULT_FAIL, "", CastDeviceCertPolicy::NONE, kCertsFile,
261 MarchFirst2040(), ""); 268 MarchFirst2037(), "");
262 } 269 }
263 270
264 // Tests verifying a valid certificate chain of length 3: 271 // Tests verifying a valid certificate chain of length 3:
265 // 272 //
266 // 0: Audio Reference Dev Test 273 // 0: Audio Reference Dev Test
267 // 1: Audio Reference Dev Model 274 // 1: Audio Reference Dev Model
268 // 2: Cast Audio Dev Root CA 275 // 2: Cast Audio Dev Root CA
269 // 276 //
270 // Chains to trust anchor: 277 // Chains to trust anchor:
271 // Cast Root CA (not included) 278 // Cast Root CA (not included)
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 auto context = 435 auto context =
429 CertVerificationContextImplForTest(CreateString(kEx2PublicKeySpki)); 436 CertVerificationContextImplForTest(CreateString(kEx2PublicKeySpki));
430 437
431 EXPECT_TRUE(context->VerifySignatureOverData(CreateString(kEx2Signature), 438 EXPECT_TRUE(context->VerifySignatureOverData(CreateString(kEx2Signature),
432 CreateString(kEx2Message))); 439 CreateString(kEx2Message)));
433 } 440 }
434 441
435 } // namespace 442 } // namespace
436 443
437 } // namespace cast_certificate 444 } // namespace cast_certificate
OLDNEW
« no previous file with comments | « components/cast_certificate/cast_cert_validator_test_helpers.cc ('k') | components/cast_certificate/cast_crl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698