Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "net/cert/ct_policy_enforcer.h" | 5 #include "net/cert/ct_policy_enforcer.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 sct->timestamp = | 85 sct->timestamp = |
| 86 base::Time::FromUTCExploded({2015, 8, 0, 15, 0, 0, 0, 0}); | 86 base::Time::FromUTCExploded({2015, 8, 0, 15, 0, 0, 0, 0}); |
| 87 else | 87 else |
| 88 sct->timestamp = | 88 sct->timestamp = |
| 89 base::Time::FromUTCExploded({2015, 6, 0, 15, 0, 0, 0, 0}); | 89 base::Time::FromUTCExploded({2015, 6, 0, 15, 0, 0, 0, 0}); |
| 90 | 90 |
| 91 verified_scts->push_back(sct); | 91 verified_scts->push_back(sct); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 void AddDisqualifiedLogSCT( | |
| 96 ct::SignedCertificateTimestamp::Origin desired_origin, | |
| 97 bool timestamp_after_disqualification_date, | |
| 98 ct::SCTList* verified_scts) { | |
| 99 static const char kCertlyLogID[] = | |
| 100 "\xcd\xb5\x17\x9b\x7f\xc1\xc0\x46\xfe\xea\x31\x13\x6a\x3f\x8f\x00\x2e" | |
| 101 "\x61\x82\xfa\xf8\x89\x6f\xec\xc8\xb2\xf5\xb5\xab\x60\x49\x00"; | |
| 102 static_assert(arraysize(kCertlyLogID) - 1 == crypto::kSHA256Length, | |
| 103 "Incorrect log ID length."); | |
| 104 | |
| 105 scoped_refptr<ct::SignedCertificateTimestamp> sct( | |
| 106 new ct::SignedCertificateTimestamp()); | |
| 107 sct->origin = desired_origin; | |
| 108 sct->log_id = std::string(kCertlyLogID, crypto::kSHA256Length); | |
| 109 if (timestamp_after_disqualification_date) | |
| 110 sct->timestamp = | |
|
eroman
2016/05/05 01:52:15
is this a multi-line if that requires curlies?
Ryan Sleevi
2016/05/05 03:08:43
Peter Kasting has said no, but I think yes.
| |
| 111 base::Time::FromUTCExploded({2016, 4, 0, 16, 0, 0, 0, 0}); | |
| 112 else | |
| 113 sct->timestamp = base::Time::FromUTCExploded({2016, 4, 0, 1, 0, 0, 0, 0}); | |
|
eroman
2016/05/05 01:52:15
Hm, didn't realize we allowed this feature yet.
Ryan Sleevi
2016/05/05 03:08:43
This is not an initializer list (which we do allow
eroman
2016/05/05 06:02:55
To be clear this is not simply C89 struct initiali
| |
| 114 | |
| 115 verified_scts->push_back(sct); | |
| 116 } | |
| 117 | |
| 95 void FillListWithSCTsOfOrigin( | 118 void FillListWithSCTsOfOrigin( |
| 96 ct::SignedCertificateTimestamp::Origin desired_origin, | 119 ct::SignedCertificateTimestamp::Origin desired_origin, |
| 97 size_t num_scts, | 120 size_t num_scts, |
| 98 ct::SCTList* verified_scts) { | 121 ct::SCTList* verified_scts) { |
| 99 std::vector<std::string> desired_log_ids; | 122 std::vector<std::string> desired_log_ids; |
| 100 desired_log_ids.push_back(google_log_id_); | 123 desired_log_ids.push_back(google_log_id_); |
| 101 FillListWithSCTsOfOrigin(desired_origin, num_scts, desired_log_ids, true, | 124 FillListWithSCTsOfOrigin(desired_origin, num_scts, desired_log_ids, true, |
| 102 verified_scts); | 125 verified_scts); |
| 103 } | 126 } |
| 104 | 127 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 chain_.get(), non_including_whitelist.get(), scts, BoundNetLog())); | 313 chain_.get(), non_including_whitelist.get(), scts, BoundNetLog())); |
| 291 | 314 |
| 292 // ... but should be OK if whitelisted. | 315 // ... but should be OK if whitelisted. |
| 293 scoped_refptr<ct::EVCertsWhitelist> whitelist( | 316 scoped_refptr<ct::EVCertsWhitelist> whitelist( |
| 294 new DummyEVCertsWhitelist(true, true)); | 317 new DummyEVCertsWhitelist(true, true)); |
| 295 EXPECT_EQ(ct::EVPolicyCompliance::EV_POLICY_COMPLIES_VIA_WHITELIST, | 318 EXPECT_EQ(ct::EVPolicyCompliance::EV_POLICY_COMPLIES_VIA_WHITELIST, |
| 296 policy_enforcer_->DoesConformToCTEVPolicy( | 319 policy_enforcer_->DoesConformToCTEVPolicy( |
| 297 chain_.get(), whitelist.get(), scts, BoundNetLog())); | 320 chain_.get(), whitelist.get(), scts, BoundNetLog())); |
| 298 } | 321 } |
| 299 | 322 |
| 323 TEST_F(CTPolicyEnforcerTest, DoesNotConformToCTEVPolicyNotEnoughFreshSCTs) { | |
| 324 ct::SCTList scts; | |
| 325 | |
| 326 // The results should be the same before and after disqualification, | |
| 327 // regardless of the delivery method. | |
| 328 | |
| 329 // SCT from before disqualification. | |
| 330 scts.clear(); | |
| 331 FillListWithSCTsOfOrigin( | |
| 332 ct::SignedCertificateTimestamp::SCT_FROM_TLS_EXTENSION, 1, &scts); | |
| 333 AddDisqualifiedLogSCT(ct::SignedCertificateTimestamp::SCT_FROM_TLS_EXTENSION, | |
| 334 false, &scts); | |
| 335 EXPECT_EQ(ct::CertPolicyCompliance::CERT_POLICY_NOT_DIVERSE_SCTS, | |
| 336 policy_enforcer_->DoesConformToCertPolicy(chain_.get(), scts, | |
| 337 BoundNetLog())); | |
| 338 EXPECT_EQ(ct::EVPolicyCompliance::EV_POLICY_NOT_DIVERSE_SCTS, | |
| 339 policy_enforcer_->DoesConformToCTEVPolicy(chain_.get(), nullptr, | |
| 340 scts, BoundNetLog())); | |
| 341 | |
| 342 // SCT from after disqualification. | |
| 343 scts.clear(); | |
| 344 FillListWithSCTsOfOrigin( | |
| 345 ct::SignedCertificateTimestamp::SCT_FROM_TLS_EXTENSION, 1, &scts); | |
| 346 AddDisqualifiedLogSCT(ct::SignedCertificateTimestamp::SCT_FROM_TLS_EXTENSION, | |
| 347 true, &scts); | |
| 348 EXPECT_EQ(ct::CertPolicyCompliance::CERT_POLICY_NOT_DIVERSE_SCTS, | |
| 349 policy_enforcer_->DoesConformToCertPolicy(chain_.get(), scts, | |
| 350 BoundNetLog())); | |
| 351 EXPECT_EQ(ct::EVPolicyCompliance::EV_POLICY_NOT_DIVERSE_SCTS, | |
| 352 policy_enforcer_->DoesConformToCTEVPolicy(chain_.get(), nullptr, | |
| 353 scts, BoundNetLog())); | |
| 354 | |
| 355 // Embedded SCT from before disqualification. | |
| 356 scts.clear(); | |
| 357 FillListWithSCTsOfOrigin( | |
| 358 ct::SignedCertificateTimestamp::SCT_FROM_TLS_EXTENSION, 1, &scts); | |
| 359 AddDisqualifiedLogSCT(ct::SignedCertificateTimestamp::SCT_EMBEDDED, false, | |
| 360 &scts); | |
| 361 EXPECT_EQ(ct::CertPolicyCompliance::CERT_POLICY_NOT_DIVERSE_SCTS, | |
| 362 policy_enforcer_->DoesConformToCertPolicy(chain_.get(), scts, | |
| 363 BoundNetLog())); | |
| 364 EXPECT_EQ(ct::EVPolicyCompliance::EV_POLICY_NOT_DIVERSE_SCTS, | |
| 365 policy_enforcer_->DoesConformToCTEVPolicy(chain_.get(), nullptr, | |
| 366 scts, BoundNetLog())); | |
| 367 | |
| 368 // Embedded SCT from after disqualification. | |
| 369 scts.clear(); | |
| 370 FillListWithSCTsOfOrigin( | |
| 371 ct::SignedCertificateTimestamp::SCT_FROM_TLS_EXTENSION, 1, &scts); | |
| 372 AddDisqualifiedLogSCT(ct::SignedCertificateTimestamp::SCT_EMBEDDED, true, | |
| 373 &scts); | |
| 374 EXPECT_EQ(ct::CertPolicyCompliance::CERT_POLICY_NOT_DIVERSE_SCTS, | |
| 375 policy_enforcer_->DoesConformToCertPolicy(chain_.get(), scts, | |
| 376 BoundNetLog())); | |
| 377 EXPECT_EQ(ct::EVPolicyCompliance::EV_POLICY_NOT_DIVERSE_SCTS, | |
| 378 policy_enforcer_->DoesConformToCTEVPolicy(chain_.get(), nullptr, | |
| 379 scts, BoundNetLog())); | |
| 380 } | |
| 381 | |
| 382 TEST_F(CTPolicyEnforcerTest, | |
| 383 ConformsWithDisqualifiedLogBeforeDisqualificationDate) { | |
| 384 ct::SCTList scts; | |
| 385 FillListWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED, 4, | |
| 386 &scts); | |
| 387 AddDisqualifiedLogSCT(ct::SignedCertificateTimestamp::SCT_EMBEDDED, false, | |
| 388 &scts); | |
| 389 | |
| 390 // This chain_ is valid for 10 years - over 121 months - so requires 5 SCTs. | |
|
eroman
2016/05/05 01:52:15
Looks like this is the style used throughout file,
Ryan Sleevi
2016/05/05 03:08:43
I agree, but have left it as an exercise for futur
| |
| 391 EXPECT_EQ(ct::CertPolicyCompliance::CERT_POLICY_COMPLIES_VIA_SCTS, | |
| 392 policy_enforcer_->DoesConformToCertPolicy(chain_.get(), scts, | |
| 393 BoundNetLog())); | |
| 394 EXPECT_EQ(ct::EVPolicyCompliance::EV_POLICY_COMPLIES_VIA_SCTS, | |
| 395 policy_enforcer_->DoesConformToCTEVPolicy(chain_.get(), nullptr, | |
| 396 scts, BoundNetLog())); | |
| 397 } | |
| 398 | |
| 399 TEST_F(CTPolicyEnforcerTest, | |
| 400 DoesNotConformWithDisqualifiedLogAfterDisqualificationDate) { | |
| 401 ct::SCTList scts; | |
| 402 FillListWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED, 4, | |
| 403 &scts); | |
| 404 AddDisqualifiedLogSCT(ct::SignedCertificateTimestamp::SCT_EMBEDDED, true, | |
| 405 &scts); | |
| 406 | |
| 407 // This chain_ is valid for 10 years - over 121 months - so requires 5 SCTs. | |
| 408 EXPECT_EQ(ct::CertPolicyCompliance::CERT_POLICY_NOT_ENOUGH_SCTS, | |
| 409 policy_enforcer_->DoesConformToCertPolicy(chain_.get(), scts, | |
| 410 BoundNetLog())); | |
| 411 EXPECT_EQ(ct::EVPolicyCompliance::EV_POLICY_NOT_ENOUGH_SCTS, | |
| 412 policy_enforcer_->DoesConformToCTEVPolicy(chain_.get(), nullptr, | |
| 413 scts, BoundNetLog())); | |
| 414 } | |
| 415 | |
| 416 TEST_F(CTPolicyEnforcerTest, | |
| 417 DoesNotConformWithIssuanceDateAfterDisqualificationDate) { | |
| 418 ct::SCTList scts; | |
| 419 AddDisqualifiedLogSCT(ct::SignedCertificateTimestamp::SCT_EMBEDDED, true, | |
| 420 &scts); | |
| 421 FillListWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED, 4, | |
| 422 &scts); | |
| 423 // Make sure all SCTs are after the disqualification date. | |
| 424 for (size_t i = 1; i < scts.size(); ++i) | |
| 425 scts[i]->timestamp = scts[0]->timestamp; | |
| 426 | |
| 427 // This chain_ is valid for 10 years - over 121 months - so requires 5 SCTs. | |
| 428 EXPECT_EQ(ct::CertPolicyCompliance::CERT_POLICY_NOT_ENOUGH_SCTS, | |
| 429 policy_enforcer_->DoesConformToCertPolicy(chain_.get(), scts, | |
| 430 BoundNetLog())); | |
| 431 EXPECT_EQ(ct::EVPolicyCompliance::EV_POLICY_NOT_ENOUGH_SCTS, | |
| 432 policy_enforcer_->DoesConformToCTEVPolicy(chain_.get(), nullptr, | |
| 433 scts, BoundNetLog())); | |
| 434 } | |
| 435 | |
| 300 TEST_F(CTPolicyEnforcerTest, | 436 TEST_F(CTPolicyEnforcerTest, |
| 301 DoesNotConformToCTEVPolicyNotEnoughUniqueEmbeddedLogs) { | 437 DoesNotConformToCTEVPolicyNotEnoughUniqueEmbeddedLogs) { |
| 302 ct::SCTList scts; | 438 ct::SCTList scts; |
| 303 std::vector<std::string> desired_logs; | 439 std::vector<std::string> desired_logs; |
| 304 | 440 |
| 305 // One Google Log. | 441 // One Google Log. |
| 306 desired_logs.clear(); | 442 desired_logs.clear(); |
| 307 desired_logs.push_back(google_log_id_); | 443 desired_logs.push_back(google_log_id_); |
| 308 FillListWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED, | 444 FillListWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED, |
| 309 desired_logs.size(), desired_logs, true, &scts); | 445 desired_logs.size(), desired_logs, true, &scts); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 FillListWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED, 2, | 569 FillListWithSCTsOfOrigin(ct::SignedCertificateTimestamp::SCT_EMBEDDED, 2, |
| 434 &scts); | 570 &scts); |
| 435 EXPECT_EQ(ct::EVPolicyCompliance::EV_POLICY_NOT_ENOUGH_SCTS, | 571 EXPECT_EQ(ct::EVPolicyCompliance::EV_POLICY_NOT_ENOUGH_SCTS, |
| 436 policy_enforcer_->DoesConformToCTEVPolicy(chain_.get(), nullptr, | 572 policy_enforcer_->DoesConformToCTEVPolicy(chain_.get(), nullptr, |
| 437 scts, BoundNetLog())); | 573 scts, BoundNetLog())); |
| 438 } | 574 } |
| 439 | 575 |
| 440 } // namespace | 576 } // namespace |
| 441 | 577 |
| 442 } // namespace net | 578 } // namespace net |
| OLD | NEW |