| OLD | NEW |
| 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 Loading... |
| 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& time, | 42 const base::Time::Exploded& 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, nullptr, | 49 bool result = VerifyDeviceCert(certs, time, &context, &policy); |
| 50 CRLPolicy::CRL_OPTIONAL); | |
| 51 | 50 |
| 52 if (expected_result == RESULT_FAIL) { | 51 if (expected_result == RESULT_FAIL) { |
| 53 ASSERT_FALSE(result); | 52 ASSERT_FALSE(result); |
| 54 return; | 53 return; |
| 55 } | 54 } |
| 56 | 55 |
| 57 ASSERT_TRUE(result); | 56 ASSERT_TRUE(result); |
| 58 EXPECT_EQ(expected_policy, policy); | 57 EXPECT_EQ(expected_policy, policy); |
| 59 ASSERT_TRUE(context.get()); | 58 ASSERT_TRUE(context.get()); |
| 60 | 59 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 83 // TODO(eroman): This fails because there isn't currently support | 82 // TODO(eroman): This fails because there isn't currently support |
| 84 // for specifying a signature algorithm other than RSASSA PKCS#1 v1.5 with | 83 // for specifying a signature algorithm other than RSASSA PKCS#1 v1.5 with |
| 85 // SHA1. Once support for different algorithms is added to the API this | 84 // SHA1. Once support for different algorithms is added to the API this |
| 86 // should be changed to expect success. | 85 // should be changed to expect success. |
| 87 EXPECT_FALSE(context->VerifySignatureOverData( | 86 EXPECT_FALSE(context->VerifySignatureOverData( |
| 88 signature_data.signature_sha256, signature_data.message)); | 87 signature_data.signature_sha256, signature_data.message)); |
| 89 } | 88 } |
| 90 } | 89 } |
| 91 | 90 |
| 92 // Creates a time in UTC at midnight. | 91 // Creates a time in UTC at midnight. |
| 93 base::Time CreateDate(int year, int month, int day) { | 92 base::Time::Exploded CreateDate(int year, int month, int day) { |
| 94 base::Time::Exploded time = {0}; | 93 base::Time::Exploded time = {0}; |
| 95 time.year = year; | 94 time.year = year; |
| 96 time.month = month; | 95 time.month = month; |
| 97 time.day_of_month = day; | 96 time.day_of_month = day; |
| 98 base::Time result; | 97 return time; |
| 99 EXPECT_TRUE(base::Time::FromUTCExploded(time, &result)); | |
| 100 return result; | |
| 101 } | 98 } |
| 102 | 99 |
| 103 // Returns 2016-04-01 00:00:00 UTC. | 100 // Returns 2016-04-01 00:00:00 UTC. |
| 104 // | 101 // |
| 105 // This is a time when most of the test certificate paths are | 102 // This is a time when most of the test certificate paths are |
| 106 // valid. | 103 // valid. |
| 107 base::Time AprilFirst2016() { | 104 base::Time::Exploded AprilFirst2016() { |
| 108 return CreateDate(2016, 4, 1); | 105 return CreateDate(2016, 4, 1); |
| 109 } | 106 } |
| 110 | 107 |
| 111 // Returns 2015-01-01 00:00:00 UTC. | 108 // Returns 2015-01-01 00:00:00 UTC. |
| 112 base::Time JanuaryFirst2015() { | 109 base::Time::Exploded JanuaryFirst2015() { |
| 113 return CreateDate(2015, 1, 1); | 110 return CreateDate(2015, 1, 1); |
| 114 } | 111 } |
| 115 | 112 |
| 116 // Returns 2040-03-01 00:00:00 UTC. | 113 // Returns 2040-03-01 00:00:00 UTC. |
| 117 // | 114 // |
| 118 // This is so far in the future that the test chains in this unit-test | 115 // This is so far in the future that the test chains in this unit-test |
| 119 // should all be invalid. | 116 // should all be invalid. |
| 120 base::Time MarchFirst2040() { | 117 base::Time::Exploded MarchFirst2040() { |
| 121 return CreateDate(2040, 3, 1); | 118 return CreateDate(2040, 3, 1); |
| 122 } | 119 } |
| 123 | 120 |
| 124 // Tests verifying a valid certificate chain of length 2: | 121 // Tests verifying a valid certificate chain of length 2: |
| 125 // | 122 // |
| 126 // 0: 2ZZBG9 FA8FCA3EF91A | 123 // 0: 2ZZBG9 FA8FCA3EF91A |
| 127 // 1: Eureka Gen1 ICA | 124 // 1: Eureka Gen1 ICA |
| 128 // | 125 // |
| 129 // Chains to trust anchor: | 126 // Chains to trust anchor: |
| 130 // Eureka Root CA (not included) | 127 // Eureka Root CA (not included) |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 auto context = | 428 auto context = |
| 432 CertVerificationContextImplForTest(CreateString(kEx2PublicKeySpki)); | 429 CertVerificationContextImplForTest(CreateString(kEx2PublicKeySpki)); |
| 433 | 430 |
| 434 EXPECT_TRUE(context->VerifySignatureOverData(CreateString(kEx2Signature), | 431 EXPECT_TRUE(context->VerifySignatureOverData(CreateString(kEx2Signature), |
| 435 CreateString(kEx2Message))); | 432 CreateString(kEx2Message))); |
| 436 } | 433 } |
| 437 | 434 |
| 438 } // namespace | 435 } // namespace |
| 439 | 436 |
| 440 } // namespace cast_certificate | 437 } // namespace cast_certificate |
| OLD | NEW |