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

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: API change: use base::Time instead of base::Time::ExplodedTime Created 4 years, 5 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 base::Time CreateDate(int year, int month, int day) {
93 base::Time::Exploded time = {0}; 94 base::Time::Exploded time = {0};
94 time.year = year; 95 time.year = year;
95 time.month = month; 96 time.month = month;
96 time.day_of_month = day; 97 time.day_of_month = day;
97 return time; 98 base::Time result;
99 EXPECT_TRUE(base::Time::FromUTCExploded(time, &result));
100 return result;
98 } 101 }
99 102
100 // Returns 2016-04-01 00:00:00 UTC. 103 // Returns 2016-04-01 00:00:00 UTC.
101 // 104 //
102 // This is a time when most of the test certificate paths are 105 // This is a time when most of the test certificate paths are
103 // valid. 106 // valid.
104 base::Time::Exploded AprilFirst2016() { 107 base::Time AprilFirst2016() {
105 return CreateDate(2016, 4, 1); 108 return CreateDate(2016, 4, 1);
106 } 109 }
107 110
108 // Returns 2015-01-01 00:00:00 UTC. 111 // Returns 2015-01-01 00:00:00 UTC.
109 base::Time::Exploded JanuaryFirst2015() { 112 base::Time JanuaryFirst2015() {
110 return CreateDate(2015, 1, 1); 113 return CreateDate(2015, 1, 1);
111 } 114 }
112 115
113 // Returns 2040-03-01 00:00:00 UTC. 116 // Returns 2040-03-01 00:00:00 UTC.
114 // 117 //
115 // This is so far in the future that the test chains in this unit-test 118 // This is so far in the future that the test chains in this unit-test
116 // should all be invalid. 119 // should all be invalid.
117 base::Time::Exploded MarchFirst2040() { 120 base::Time MarchFirst2040() {
118 return CreateDate(2040, 3, 1); 121 return CreateDate(2040, 3, 1);
119 } 122 }
120 123
121 // Tests verifying a valid certificate chain of length 2: 124 // Tests verifying a valid certificate chain of length 2:
122 // 125 //
123 // 0: 2ZZBG9 FA8FCA3EF91A 126 // 0: 2ZZBG9 FA8FCA3EF91A
124 // 1: Eureka Gen1 ICA 127 // 1: Eureka Gen1 ICA
125 // 128 //
126 // Chains to trust anchor: 129 // Chains to trust anchor:
127 // Eureka Root CA (not included) 130 // Eureka Root CA (not included)
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 auto context = 431 auto context =
429 CertVerificationContextImplForTest(CreateString(kEx2PublicKeySpki)); 432 CertVerificationContextImplForTest(CreateString(kEx2PublicKeySpki));
430 433
431 EXPECT_TRUE(context->VerifySignatureOverData(CreateString(kEx2Signature), 434 EXPECT_TRUE(context->VerifySignatureOverData(CreateString(kEx2Signature),
432 CreateString(kEx2Message))); 435 CreateString(kEx2Message)));
433 } 436 }
434 437
435 } // namespace 438 } // namespace
436 439
437 } // namespace cast_certificate 440 } // namespace cast_certificate
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698