| 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 "net/cert/internal/parsed_certificate.h" |
| 9 #include "net/cert/internal/trust_store.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 11 |
| 10 namespace cast_certificate { | 12 namespace cast_certificate { |
| 11 | 13 |
| 12 namespace { | 14 namespace { |
| 13 | 15 |
| 14 // Creates an std::string given a uint8_t array. | 16 // Creates an std::string given a uint8_t array. |
| 15 template <size_t N> | 17 template <size_t N> |
| 16 std::string CreateString(const uint8_t (&data)[N]) { | 18 std::string CreateString(const uint8_t (&data)[N]) { |
| 17 return std::string(reinterpret_cast<const char*>(data), N); | 19 return std::string(reinterpret_cast<const char*>(data), N); |
| 18 } | 20 } |
| 19 | 21 |
| 20 // Indicates the expected result of test verification. | 22 // Indicates the expected result of test verification. |
| 21 enum TestResult { | 23 enum TestResult { |
| 22 RESULT_SUCCESS, | 24 RESULT_SUCCESS, |
| 23 RESULT_FAIL, | 25 RESULT_FAIL, |
| 24 }; | 26 }; |
| 25 | 27 |
| 28 enum TrustStoreDependency { |
| 29 // Uses the built-in trust store for Cast. This is how certificates are |
| 30 // verified in production. |
| 31 TRUST_STORE_BUILTIN, |
| 32 |
| 33 // Instead of using the built-in trust store, use root certificate in the |
| 34 // provided test chain as the trust anchor. |
| 35 // |
| 36 // This trust anchor is initialized with anchor constraints, similar to how |
| 37 // TrustAnchors in the built-in store are setup. |
| 38 TRUST_STORE_FROM_TEST_FILE, |
| 39 |
| 40 // This is the same as TRUST_STORE_FROM_TEST_FILE except the TrustAnchor is |
| 41 // setup to NOT enforce anchor constraints. This mode is useful for |
| 42 // verifying control groups. It is not how code works in production. |
| 43 TRUST_STORE_FROM_TEST_FILE_UNCONSTRAINED, |
| 44 }; |
| 45 |
| 26 // Reads a test chain from |certs_file_name|, and asserts that verifying it as | 46 // Reads a test chain from |certs_file_name|, and asserts that verifying it as |
| 27 // a Cast device certificate yields |expected_result|. | 47 // a Cast device certificate yields |expected_result|. |
| 28 // | 48 // |
| 29 // RunTest() also checks that the resulting CertVerificationContext does not | 49 // RunTest() also checks that the resulting CertVerificationContext does not |
| 30 // incorrectly verify invalid signatures. | 50 // incorrectly verify invalid signatures. |
| 31 // | 51 // |
| 32 // * |expected_policy| - The policy that should have been identified for the | 52 // * |expected_policy| - The policy that should have been identified for the |
| 33 // device certificate. | 53 // device certificate. |
| 34 // * |time| - The timestamp to use when verifying the certificate. | 54 // * |time| - The timestamp to use when verifying the certificate. |
| 55 // * |trust_store_dependency| - Which trust store to use when verifying (see |
| 56 // enum's definition). |
| 35 // * |optional_signed_data_file_name| - optional path to a PEM file containing | 57 // * |optional_signed_data_file_name| - optional path to a PEM file containing |
| 36 // a valid signature generated by the device certificate. | 58 // a valid signature generated by the device certificate. |
| 37 // | 59 // |
| 38 void RunTest(TestResult expected_result, | 60 void RunTest(TestResult expected_result, |
| 39 const std::string& expected_common_name, | 61 const std::string& expected_common_name, |
| 40 CastDeviceCertPolicy expected_policy, | 62 CastDeviceCertPolicy expected_policy, |
| 41 const std::string& certs_file_name, | 63 const std::string& certs_file_name, |
| 42 const base::Time& time, | 64 const base::Time& time, |
| 65 TrustStoreDependency trust_store_dependency, |
| 43 const std::string& optional_signed_data_file_name) { | 66 const std::string& optional_signed_data_file_name) { |
| 44 auto certs = | 67 auto certs = |
| 45 cast_certificate::testing::ReadCertificateChainFromFile(certs_file_name); | 68 cast_certificate::testing::ReadCertificateChainFromFile(certs_file_name); |
| 46 | 69 |
| 70 std::unique_ptr<net::TrustStore> trust_store; |
| 71 |
| 72 switch (trust_store_dependency) { |
| 73 case TRUST_STORE_BUILTIN: |
| 74 // Leave trust_store as nullptr. |
| 75 break; |
| 76 |
| 77 case TRUST_STORE_FROM_TEST_FILE: |
| 78 case TRUST_STORE_FROM_TEST_FILE_UNCONSTRAINED: { |
| 79 ASSERT_FALSE(certs.empty()); |
| 80 |
| 81 // Parse the root certificate of the chain. |
| 82 scoped_refptr<net::ParsedCertificate> root = |
| 83 net::ParsedCertificate::CreateFromCertificateCopy(certs.back(), {}); |
| 84 ASSERT_TRUE(root); |
| 85 |
| 86 // Remove it from the chain. |
| 87 certs.pop_back(); |
| 88 |
| 89 // Add it to the trust store as a trust anchor |
| 90 trust_store.reset(new net::TrustStore); |
| 91 |
| 92 if (trust_store_dependency == TRUST_STORE_FROM_TEST_FILE_UNCONSTRAINED) { |
| 93 // This is a test-only mode where anchor constraints are not enforced. |
| 94 trust_store->AddTrustAnchor( |
| 95 net::TrustAnchor::CreateFromCertificateNoConstraints( |
| 96 std::move(root))); |
| 97 } else { |
| 98 // This is the regular mode used by the TrustAnchors for the built-in |
| 99 // Cast store. |
| 100 trust_store->AddTrustAnchor( |
| 101 net::TrustAnchor::CreateFromCertificateWithConstraints( |
| 102 std::move(root))); |
| 103 } |
| 104 } |
| 105 } |
| 106 |
| 47 std::unique_ptr<CertVerificationContext> context; | 107 std::unique_ptr<CertVerificationContext> context; |
| 48 CastDeviceCertPolicy policy; | 108 CastDeviceCertPolicy policy; |
| 49 bool result = VerifyDeviceCert(certs, time, &context, &policy, nullptr, | 109 |
| 50 CRLPolicy::CRL_OPTIONAL); | 110 bool result; |
| 111 if (trust_store.get()) { |
| 112 result = |
| 113 VerifyDeviceCertForTest(certs, time, &context, &policy, nullptr, |
| 114 CRLPolicy::CRL_OPTIONAL, trust_store.get()); |
| 115 } else { |
| 116 result = VerifyDeviceCert(certs, time, &context, &policy, nullptr, |
| 117 CRLPolicy::CRL_OPTIONAL); |
| 118 } |
| 51 | 119 |
| 52 if (expected_result == RESULT_FAIL) { | 120 if (expected_result == RESULT_FAIL) { |
| 53 ASSERT_FALSE(result); | 121 ASSERT_FALSE(result); |
| 54 return; | 122 return; |
| 55 } | 123 } |
| 56 | 124 |
| 57 ASSERT_TRUE(result); | 125 ASSERT_TRUE(result); |
| 58 EXPECT_EQ(expected_policy, policy); | 126 EXPECT_EQ(expected_policy, policy); |
| 59 ASSERT_TRUE(context.get()); | 127 ASSERT_TRUE(context.get()); |
| 60 | 128 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 base::Time MarchFirst2037() { | 192 base::Time MarchFirst2037() { |
| 125 return CreateDate(2037, 3, 1); | 193 return CreateDate(2037, 3, 1); |
| 126 } | 194 } |
| 127 | 195 |
| 128 // Tests verifying a valid certificate chain of length 2: | 196 // Tests verifying a valid certificate chain of length 2: |
| 129 // | 197 // |
| 130 // 0: 2ZZBG9 FA8FCA3EF91A | 198 // 0: 2ZZBG9 FA8FCA3EF91A |
| 131 // 1: Eureka Gen1 ICA | 199 // 1: Eureka Gen1 ICA |
| 132 // | 200 // |
| 133 // Chains to trust anchor: | 201 // Chains to trust anchor: |
| 134 // Eureka Root CA (not included) | 202 // Eureka Root CA (built-in trust store) |
| 135 TEST(VerifyCastDeviceCertTest, ChromecastGen1) { | 203 TEST(VerifyCastDeviceCertTest, ChromecastGen1) { |
| 136 RunTest(RESULT_SUCCESS, "2ZZBG9 FA8FCA3EF91A", CastDeviceCertPolicy::NONE, | 204 RunTest(RESULT_SUCCESS, "2ZZBG9 FA8FCA3EF91A", CastDeviceCertPolicy::NONE, |
| 137 "certificates/chromecast_gen1.pem", AprilFirst2016(), | 205 "certificates/chromecast_gen1.pem", AprilFirst2016(), |
| 138 "signeddata/2ZZBG9_FA8FCA3EF91A.pem"); | 206 TRUST_STORE_BUILTIN, "signeddata/2ZZBG9_FA8FCA3EF91A.pem"); |
| 139 } | 207 } |
| 140 | 208 |
| 141 // Tests verifying a valid certificate chain of length 2: | 209 // Tests verifying a valid certificate chain of length 2: |
| 142 // | 210 // |
| 143 // 0: 2ZZBG9 FA8FCA3EF91A | 211 // 0: 2ZZBG9 FA8FCA3EF91A |
| 144 // 1: Eureka Gen1 ICA | 212 // 1: Eureka Gen1 ICA |
| 145 // | 213 // |
| 146 // Chains to trust anchor: | 214 // Chains to trust anchor: |
| 147 // Cast Root CA (not included) | 215 // Cast Root CA (built-in trust store) |
| 148 TEST(VerifyCastDeviceCertTest, ChromecastGen1Reissue) { | 216 TEST(VerifyCastDeviceCertTest, ChromecastGen1Reissue) { |
| 149 RunTest(RESULT_SUCCESS, "2ZZBG9 FA8FCA3EF91A", CastDeviceCertPolicy::NONE, | 217 RunTest(RESULT_SUCCESS, "2ZZBG9 FA8FCA3EF91A", CastDeviceCertPolicy::NONE, |
| 150 "certificates/chromecast_gen1_reissue.pem", AprilFirst2016(), | 218 "certificates/chromecast_gen1_reissue.pem", AprilFirst2016(), |
| 151 "signeddata/2ZZBG9_FA8FCA3EF91A.pem"); | 219 TRUST_STORE_BUILTIN, "signeddata/2ZZBG9_FA8FCA3EF91A.pem"); |
| 152 } | 220 } |
| 153 | 221 |
| 154 // Tests verifying a valid certificate chain of length 2: | 222 // Tests verifying a valid certificate chain of length 2: |
| 155 // | 223 // |
| 156 // 0: 3ZZAK6 FA8FCA3F0D35 | 224 // 0: 3ZZAK6 FA8FCA3F0D35 |
| 157 // 1: Chromecast ICA 3 | 225 // 1: Chromecast ICA 3 |
| 158 // | 226 // |
| 159 // Chains to trust anchor: | 227 // Chains to trust anchor: |
| 160 // Cast Root CA (not included) | 228 // Cast Root CA (built-in trust store) |
| 161 TEST(VerifyCastDeviceCertTest, ChromecastGen2) { | 229 TEST(VerifyCastDeviceCertTest, ChromecastGen2) { |
| 162 RunTest(RESULT_SUCCESS, "3ZZAK6 FA8FCA3F0D35", CastDeviceCertPolicy::NONE, | 230 RunTest(RESULT_SUCCESS, "3ZZAK6 FA8FCA3F0D35", CastDeviceCertPolicy::NONE, |
| 163 "certificates/chromecast_gen2.pem", AprilFirst2016(), ""); | 231 "certificates/chromecast_gen2.pem", AprilFirst2016(), |
| 232 TRUST_STORE_BUILTIN, ""); |
| 164 } | 233 } |
| 165 | 234 |
| 166 // Tests verifying a valid certificate chain of length 3: | 235 // Tests verifying a valid certificate chain of length 3: |
| 167 // | 236 // |
| 168 // 0: -6394818897508095075 | 237 // 0: -6394818897508095075 |
| 169 // 1: Asus fugu Cast ICA | 238 // 1: Asus fugu Cast ICA |
| 170 // 2: Widevine Cast Subroot | 239 // 2: Widevine Cast Subroot |
| 171 // | 240 // |
| 172 // Chains to trust anchor: | 241 // Chains to trust anchor: |
| 173 // Cast Root CA (not included) | 242 // Cast Root CA (built-in trust store) |
| 174 TEST(VerifyCastDeviceCertTest, Fugu) { | 243 TEST(VerifyCastDeviceCertTest, Fugu) { |
| 175 RunTest(RESULT_SUCCESS, "-6394818897508095075", CastDeviceCertPolicy::NONE, | 244 RunTest(RESULT_SUCCESS, "-6394818897508095075", CastDeviceCertPolicy::NONE, |
| 176 "certificates/fugu.pem", AprilFirst2016(), ""); | 245 "certificates/fugu.pem", AprilFirst2016(), TRUST_STORE_BUILTIN, ""); |
| 177 } | 246 } |
| 178 | 247 |
| 179 // Tests verifying an invalid certificate chain of length 1: | 248 // Tests verifying an invalid certificate chain of length 1: |
| 180 // | 249 // |
| 181 // 0: Cast Test Untrusted Device | 250 // 0: Cast Test Untrusted Device |
| 182 // | 251 // |
| 183 // Chains to: | 252 // Chains to: |
| 184 // Cast Test Untrusted ICA (not included) | 253 // Cast Test Untrusted ICA (Not part of trust store) |
| 185 // | 254 // |
| 186 // This is invalid because it does not chain to a trust anchor. | 255 // This is invalid because it does not chain to a trust anchor. |
| 187 TEST(VerifyCastDeviceCertTest, Unchained) { | 256 TEST(VerifyCastDeviceCertTest, Unchained) { |
| 188 RunTest(RESULT_FAIL, "", CastDeviceCertPolicy::NONE, | 257 RunTest(RESULT_FAIL, "", CastDeviceCertPolicy::NONE, |
| 189 "certificates/unchained.pem", AprilFirst2016(), ""); | 258 "certificates/unchained.pem", AprilFirst2016(), TRUST_STORE_BUILTIN, |
| 259 ""); |
| 190 } | 260 } |
| 191 | 261 |
| 192 // Tests verifying one of the self-signed trust anchors (chain of length 1): | 262 // Tests verifying one of the self-signed trust anchors (chain of length 1): |
| 193 // | 263 // |
| 194 // 0: Cast Root CA | 264 // 0: Cast Root CA |
| 195 // | 265 // |
| 196 // Chains to trust anchor: | 266 // Chains to trust anchor: |
| 197 // Cast Root CA | 267 // Cast Root CA (built-in trust store) |
| 198 // | 268 // |
| 199 // Although this is a valid and trusted certificate (it is one of the | 269 // Although this is a valid and trusted certificate (it is one of the |
| 200 // trust anchors after all) it fails the test as it is not a *device | 270 // trust anchors after all) it fails the test as it is not a *device |
| 201 // certificate*. | 271 // certificate*. |
| 202 TEST(VerifyCastDeviceCertTest, CastRootCa) { | 272 TEST(VerifyCastDeviceCertTest, CastRootCa) { |
| 203 RunTest(RESULT_FAIL, "", CastDeviceCertPolicy::NONE, | 273 RunTest(RESULT_FAIL, "", CastDeviceCertPolicy::NONE, |
| 204 "certificates/cast_root_ca.pem", AprilFirst2016(), ""); | 274 "certificates/cast_root_ca.pem", AprilFirst2016(), |
| 275 TRUST_STORE_BUILTIN, ""); |
| 205 } | 276 } |
| 206 | 277 |
| 207 // Tests verifying a valid certificate chain of length 2: | 278 // Tests verifying a valid certificate chain of length 2: |
| 208 // | 279 // |
| 209 // 0: 4ZZDZJ FA8FCA7EFE3C | 280 // 0: 4ZZDZJ FA8FCA7EFE3C |
| 210 // 1: Chromecast ICA 4 (Audio) | 281 // 1: Chromecast ICA 4 (Audio) |
| 211 // | 282 // |
| 212 // Chains to trust anchor: | 283 // Chains to trust anchor: |
| 213 // Cast Root CA (not included) | 284 // Cast Root CA (built-in trust store) |
| 214 // | 285 // |
| 215 // This device certificate has a policy that means it is valid only for audio | 286 // This device certificate has a policy that means it is valid only for audio |
| 216 // devices. | 287 // devices. |
| 217 TEST(VerifyCastDeviceCertTest, ChromecastAudio) { | 288 TEST(VerifyCastDeviceCertTest, ChromecastAudio) { |
| 218 RunTest(RESULT_SUCCESS, "4ZZDZJ FA8FCA7EFE3C", | 289 RunTest(RESULT_SUCCESS, "4ZZDZJ FA8FCA7EFE3C", |
| 219 CastDeviceCertPolicy::AUDIO_ONLY, "certificates/chromecast_audio.pem", | 290 CastDeviceCertPolicy::AUDIO_ONLY, "certificates/chromecast_audio.pem", |
| 220 AprilFirst2016(), ""); | 291 AprilFirst2016(), TRUST_STORE_BUILTIN, ""); |
| 221 } | 292 } |
| 222 | 293 |
| 223 // Tests verifying a valid certificate chain of length 3: | 294 // Tests verifying a valid certificate chain of length 3: |
| 224 // | 295 // |
| 225 // 0: MediaTek Audio Dev Test | 296 // 0: MediaTek Audio Dev Test |
| 226 // 1: MediaTek Audio Dev Model | 297 // 1: MediaTek Audio Dev Model |
| 227 // 2: Cast Audio Dev Root CA | 298 // 2: Cast Audio Dev Root CA |
| 228 // | 299 // |
| 229 // Chains to trust anchor: | 300 // Chains to trust anchor: |
| 230 // Cast Root CA (not included) | 301 // Cast Root CA (built-in trust store) |
| 231 // | 302 // |
| 232 // This device certificate has a policy that means it is valid only for audio | 303 // This device certificate has a policy that means it is valid only for audio |
| 233 // devices. | 304 // devices. |
| 234 TEST(VerifyCastDeviceCertTest, MtkAudioDev) { | 305 TEST(VerifyCastDeviceCertTest, MtkAudioDev) { |
| 235 RunTest(RESULT_SUCCESS, "MediaTek Audio Dev Test", | 306 RunTest(RESULT_SUCCESS, "MediaTek Audio Dev Test", |
| 236 CastDeviceCertPolicy::AUDIO_ONLY, "certificates/mtk_audio_dev.pem", | 307 CastDeviceCertPolicy::AUDIO_ONLY, "certificates/mtk_audio_dev.pem", |
| 237 JanuaryFirst2015(), ""); | 308 JanuaryFirst2015(), TRUST_STORE_BUILTIN, ""); |
| 238 } | 309 } |
| 239 | 310 |
| 240 // Tests verifying a valid certificate chain of length 2: | 311 // Tests verifying a valid certificate chain of length 2: |
| 241 // | 312 // |
| 242 // 0: 9V0000VB FA8FCA784D01 | 313 // 0: 9V0000VB FA8FCA784D01 |
| 243 // 1: Cast TV ICA (Vizio) | 314 // 1: Cast TV ICA (Vizio) |
| 244 // | 315 // |
| 245 // Chains to trust anchor: | 316 // Chains to trust anchor: |
| 246 // Cast Root CA (not included) | 317 // Cast Root CA (built-in trust store) |
| 247 TEST(VerifyCastDeviceCertTest, Vizio) { | 318 TEST(VerifyCastDeviceCertTest, Vizio) { |
| 248 RunTest(RESULT_SUCCESS, "9V0000VB FA8FCA784D01", CastDeviceCertPolicy::NONE, | 319 RunTest(RESULT_SUCCESS, "9V0000VB FA8FCA784D01", CastDeviceCertPolicy::NONE, |
| 249 "certificates/vizio.pem", AprilFirst2016(), ""); | 320 "certificates/vizio.pem", AprilFirst2016(), TRUST_STORE_BUILTIN, ""); |
| 250 } | 321 } |
| 251 | 322 |
| 252 // Tests verifying a valid certificate chain of length 2 using expired | 323 // Tests verifying a valid certificate chain of length 2 using expired |
| 253 // time points. | 324 // time points. |
| 254 TEST(VerifyCastDeviceCertTest, ChromecastGen2InvalidTime) { | 325 TEST(VerifyCastDeviceCertTest, ChromecastGen2InvalidTime) { |
| 255 const char* kCertsFile = "certificates/chromecast_gen2.pem"; | 326 const char* kCertsFile = "certificates/chromecast_gen2.pem"; |
| 256 | 327 |
| 257 // Control test - certificate should be valid at some time otherwise | 328 // Control test - certificate should be valid at some time otherwise |
| 258 // this test is pointless. | 329 // this test is pointless. |
| 259 RunTest(RESULT_SUCCESS, "3ZZAK6 FA8FCA3F0D35", CastDeviceCertPolicy::NONE, | 330 RunTest(RESULT_SUCCESS, "3ZZAK6 FA8FCA3F0D35", CastDeviceCertPolicy::NONE, |
| 260 kCertsFile, AprilFirst2016(), ""); | 331 kCertsFile, AprilFirst2016(), TRUST_STORE_BUILTIN, ""); |
| 261 | 332 |
| 262 // Use a time before notBefore. | 333 // Use a time before notBefore. |
| 263 RunTest(RESULT_FAIL, "", CastDeviceCertPolicy::NONE, kCertsFile, | 334 RunTest(RESULT_FAIL, "", CastDeviceCertPolicy::NONE, kCertsFile, |
| 264 JanuaryFirst2015(), ""); | 335 JanuaryFirst2015(), TRUST_STORE_BUILTIN, ""); |
| 265 | 336 |
| 266 // Use a time after notAfter. | 337 // Use a time after notAfter. |
| 267 RunTest(RESULT_FAIL, "", CastDeviceCertPolicy::NONE, kCertsFile, | 338 RunTest(RESULT_FAIL, "", CastDeviceCertPolicy::NONE, kCertsFile, |
| 268 MarchFirst2037(), ""); | 339 MarchFirst2037(), TRUST_STORE_BUILTIN, ""); |
| 269 } | 340 } |
| 270 | 341 |
| 271 // Tests verifying a valid certificate chain of length 3: | 342 // Tests verifying a valid certificate chain of length 3: |
| 272 // | 343 // |
| 273 // 0: Audio Reference Dev Test | 344 // 0: Audio Reference Dev Test |
| 274 // 1: Audio Reference Dev Model | 345 // 1: Audio Reference Dev Model |
| 275 // 2: Cast Audio Dev Root CA | 346 // 2: Cast Audio Dev Root CA |
| 276 // | 347 // |
| 277 // Chains to trust anchor: | 348 // Chains to trust anchor: |
| 278 // Cast Root CA (not included) | 349 // Cast Root CA (built-in trust store) |
| 279 // | 350 // |
| 280 // This device certificate has a policy that means it is valid only for audio | 351 // This device certificate has a policy that means it is valid only for audio |
| 281 // devices. | 352 // devices. |
| 282 TEST(VerifyCastDeviceCertTest, AudioRefDevTestChain3) { | 353 TEST(VerifyCastDeviceCertTest, AudioRefDevTestChain3) { |
| 283 RunTest(RESULT_SUCCESS, "Audio Reference Dev Test", | 354 RunTest(RESULT_SUCCESS, "Audio Reference Dev Test", |
| 284 CastDeviceCertPolicy::AUDIO_ONLY, | 355 CastDeviceCertPolicy::AUDIO_ONLY, |
| 285 "certificates/audio_ref_dev_test_chain_3.pem", AprilFirst2016(), | 356 "certificates/audio_ref_dev_test_chain_3.pem", AprilFirst2016(), |
| 286 "signeddata/AudioReferenceDevTest.pem"); | 357 TRUST_STORE_BUILTIN, "signeddata/AudioReferenceDevTest.pem"); |
| 287 } | 358 } |
| 288 | 359 |
| 289 // Tests verifying a valid certificate chain of length 3. Note that the first | 360 // Tests verifying a valid certificate chain of length 3. Note that the first |
| 290 // intermediate has a serial number that is 21 octets long, which violates RFC | 361 // intermediate has a serial number that is 21 octets long, which violates RFC |
| 291 // 5280. However cast verification accepts this certificate for compatibility | 362 // 5280. However cast verification accepts this certificate for compatibility |
| 292 // reasons. | 363 // reasons. |
| 293 // | 364 // |
| 294 // 0: 8C579B806FFC8A9DFFFF F8:8F:CA:6B:E6:DA | 365 // 0: 8C579B806FFC8A9DFFFF F8:8F:CA:6B:E6:DA |
| 295 // 1: Sony so16vic CA | 366 // 1: Sony so16vic CA |
| 296 // 2: Cast Audio Sony CA | 367 // 2: Cast Audio Sony CA |
| 297 // | 368 // |
| 298 // Chains to trust anchor: | 369 // Chains to trust anchor: |
| 299 // Cast Root CA (not included) | 370 // Cast Root CA (built-in trust store) |
| 300 // | 371 // |
| 301 // This device certificate has a policy that means it is valid only for audio | 372 // This device certificate has a policy that means it is valid only for audio |
| 302 // devices. | 373 // devices. |
| 303 TEST(VerifyCastDeviceCertTest, IntermediateSerialNumberTooLong) { | 374 TEST(VerifyCastDeviceCertTest, IntermediateSerialNumberTooLong) { |
| 304 RunTest(RESULT_SUCCESS, "8C579B806FFC8A9DFFFF F8:8F:CA:6B:E6:DA", | 375 RunTest(RESULT_SUCCESS, "8C579B806FFC8A9DFFFF F8:8F:CA:6B:E6:DA", |
| 305 CastDeviceCertPolicy::AUDIO_ONLY, | 376 CastDeviceCertPolicy::AUDIO_ONLY, |
| 306 "certificates/intermediate_serialnumber_toolong.pem", | 377 "certificates/intermediate_serialnumber_toolong.pem", |
| 307 AprilFirst2016(), ""); | 378 AprilFirst2016(), TRUST_STORE_BUILTIN, ""); |
| 379 } |
| 380 |
| 381 // Tests verifying a valid certificate chain of length 2 when the trust anchor |
| 382 // is "expired". This is expected to work since expiration is not an enforced |
| 383 // anchor constraint, even though it may appear in the root certificate. |
| 384 // |
| 385 // 0: CastDevice |
| 386 // 1: CastIntermediate |
| 387 // |
| 388 // Chains to trust anchor: |
| 389 // Expired CastRoot (provided by test data) |
| 390 TEST(VerifyCastDeviceCertTest, ExpiredTrustAnchor) { |
| 391 // The root certificate is only valid in 2015, so validating with a time in |
| 392 // 2016 means it is expired. |
| 393 RunTest(RESULT_SUCCESS, "CastDevice", CastDeviceCertPolicy::NONE, |
| 394 "certificates/expired_root.pem", AprilFirst2016(), |
| 395 TRUST_STORE_FROM_TEST_FILE, ""); |
| 396 } |
| 397 |
| 398 // Tests verifying a certificate chain where the root certificate has a pathlen |
| 399 // constraint which is violated by the chain. In this case Root has a pathlen=1 |
| 400 // constraint, however neither intermediate is constrained. |
| 401 // |
| 402 // The expectation is for pathlen constraints on trust anchors to be enforced, |
| 403 // so this validation must fail. |
| 404 // |
| 405 // 0: Target |
| 406 // 1: Intermediate2 |
| 407 // 2: Intermediate1 |
| 408 // |
| 409 // Chains to trust anchor: |
| 410 // Root (provided by test data; has pathlen=1 constraint) |
| 411 TEST(VerifyCastDeviceCertTest, ViolatesPathlenTrustAnchorConstraint) { |
| 412 // First do a control test -- when anchor constraints are NOT enforced this |
| 413 // chain should validate just fine. |
| 414 RunTest(RESULT_SUCCESS, "Target", CastDeviceCertPolicy::NONE, |
| 415 "certificates/violates_root_pathlen_constraint.pem", AprilFirst2016(), |
| 416 TRUST_STORE_FROM_TEST_FILE_UNCONSTRAINED, ""); |
| 417 |
| 418 // Now do the real test and verify validation fails when using a TrustAncho |
| 419 // with pathlen constraint. |
| 420 RunTest(RESULT_FAIL, "Target", CastDeviceCertPolicy::NONE, |
| 421 "certificates/violates_root_pathlen_constraint.pem", AprilFirst2016(), |
| 422 TRUST_STORE_FROM_TEST_FILE, ""); |
| 308 } | 423 } |
| 309 | 424 |
| 310 // ------------------------------------------------------ | 425 // ------------------------------------------------------ |
| 311 // Valid signature using 1024-bit RSA key | 426 // Valid signature using 1024-bit RSA key |
| 312 // ------------------------------------------------------ | 427 // ------------------------------------------------------ |
| 313 | 428 |
| 314 // This test vector comes from the NIST test vectors (pkcs1v15sign-vectors.txt), | 429 // This test vector comes from the NIST test vectors (pkcs1v15sign-vectors.txt), |
| 315 // PKCS#1 v1.5 Signature Example 1.2. | 430 // PKCS#1 v1.5 Signature Example 1.2. |
| 316 // | 431 // |
| 317 // It is a valid signature using a 1024 bit key and SHA-1. | 432 // It is a valid signature using a 1024 bit key and SHA-1. |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 auto context = | 550 auto context = |
| 436 CertVerificationContextImplForTest(CreateString(kEx2PublicKeySpki)); | 551 CertVerificationContextImplForTest(CreateString(kEx2PublicKeySpki)); |
| 437 | 552 |
| 438 EXPECT_TRUE(context->VerifySignatureOverData(CreateString(kEx2Signature), | 553 EXPECT_TRUE(context->VerifySignatureOverData(CreateString(kEx2Signature), |
| 439 CreateString(kEx2Message))); | 554 CreateString(kEx2Message))); |
| 440 } | 555 } |
| 441 | 556 |
| 442 } // namespace | 557 } // namespace |
| 443 | 558 |
| 444 } // namespace cast_certificate | 559 } // namespace cast_certificate |
| OLD | NEW |