OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stdint.h> | 5 #include <stdint.h> |
6 #include <algorithm> | 6 #include <algorithm> |
7 | 7 |
8 #include "base/base64.h" | 8 #include "base/base64.h" |
9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
10 #include "crypto/sha2.h" | 10 #include "crypto/sha2.h" |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
646 | 646 |
647 TEST_F(HttpSecurityHeadersTest, BogusPinsHeadersSHA256) { | 647 TEST_F(HttpSecurityHeadersTest, BogusPinsHeadersSHA256) { |
648 TestBogusPinsHeaders(HASH_VALUE_SHA256); | 648 TestBogusPinsHeaders(HASH_VALUE_SHA256); |
649 } | 649 } |
650 | 650 |
651 TEST_F(HttpSecurityHeadersTest, ValidPKPHeadersSHA256) { | 651 TEST_F(HttpSecurityHeadersTest, ValidPKPHeadersSHA256) { |
652 TestValidPKPHeaders(HASH_VALUE_SHA256); | 652 TestValidPKPHeaders(HASH_VALUE_SHA256); |
653 } | 653 } |
654 | 654 |
655 TEST_F(HttpSecurityHeadersTest, UpdateDynamicPKPOnly) { | 655 TEST_F(HttpSecurityHeadersTest, UpdateDynamicPKPOnly) { |
656 #if !BUILDFLAG(INCLUDE_TRANSPORT_SECURITY_STATE_PRELOAD_LIST) | |
657 return; | |
658 #endif | |
Ryan Sleevi
2017/06/29 20:47:40
To better allow the compiler to optimize this out,
xunjieli
2017/06/30 19:12:18
Done.
| |
656 TransportSecurityState state; | 659 TransportSecurityState state; |
657 TransportSecurityState::STSState static_sts_state; | 660 TransportSecurityState::STSState static_sts_state; |
658 TransportSecurityState::PKPState static_pkp_state; | 661 TransportSecurityState::PKPState static_pkp_state; |
659 | 662 |
660 // docs.google.com has preloaded pins. | 663 // docs.google.com has preloaded pins. |
661 std::string domain = "docs.google.com"; | 664 std::string domain = "docs.google.com"; |
662 state.enable_static_pins_ = true; | 665 state.enable_static_pins_ = true; |
663 EXPECT_TRUE( | 666 EXPECT_TRUE( |
664 state.GetStaticDomainState(domain, &static_sts_state, &static_pkp_state)); | 667 state.GetStaticDomainState(domain, &static_sts_state, &static_pkp_state)); |
665 EXPECT_GT(static_pkp_state.spki_hashes.size(), 1UL); | 668 EXPECT_GT(static_pkp_state.spki_hashes.size(), 1UL); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 hash = std::find(new_dynamic_pkp_state.spki_hashes.begin(), | 725 hash = std::find(new_dynamic_pkp_state.spki_hashes.begin(), |
723 new_dynamic_pkp_state.spki_hashes.end(), good_hash); | 726 new_dynamic_pkp_state.spki_hashes.end(), good_hash); |
724 EXPECT_NE(new_dynamic_pkp_state.spki_hashes.end(), hash); | 727 EXPECT_NE(new_dynamic_pkp_state.spki_hashes.end(), hash); |
725 | 728 |
726 hash = std::find(new_dynamic_pkp_state.spki_hashes.begin(), | 729 hash = std::find(new_dynamic_pkp_state.spki_hashes.begin(), |
727 new_dynamic_pkp_state.spki_hashes.end(), backup_hash); | 730 new_dynamic_pkp_state.spki_hashes.end(), backup_hash); |
728 EXPECT_NE(new_dynamic_pkp_state.spki_hashes.end(), hash); | 731 EXPECT_NE(new_dynamic_pkp_state.spki_hashes.end(), hash); |
729 } | 732 } |
730 | 733 |
731 TEST_F(HttpSecurityHeadersTest, UpdateDynamicPKPMaxAge0) { | 734 TEST_F(HttpSecurityHeadersTest, UpdateDynamicPKPMaxAge0) { |
735 #if !BUILDFLAG(INCLUDE_TRANSPORT_SECURITY_STATE_PRELOAD_LIST) | |
736 return; | |
737 #endif | |
732 TransportSecurityState state; | 738 TransportSecurityState state; |
733 TransportSecurityState::STSState static_sts_state; | 739 TransportSecurityState::STSState static_sts_state; |
734 TransportSecurityState::PKPState static_pkp_state; | 740 TransportSecurityState::PKPState static_pkp_state; |
735 | 741 |
736 // docs.google.com has preloaded pins. | 742 // docs.google.com has preloaded pins. |
737 std::string domain = "docs.google.com"; | 743 std::string domain = "docs.google.com"; |
738 state.enable_static_pins_ = true; | 744 state.enable_static_pins_ = true; |
739 ASSERT_TRUE( | 745 ASSERT_TRUE( |
740 state.GetStaticDomainState(domain, &static_sts_state, &static_pkp_state)); | 746 state.GetStaticDomainState(domain, &static_sts_state, &static_pkp_state)); |
741 EXPECT_GT(static_pkp_state.spki_hashes.size(), 1UL); | 747 EXPECT_GT(static_pkp_state.spki_hashes.size(), 1UL); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
800 domain_port, is_issued_by_known_root, | 806 domain_port, is_issued_by_known_root, |
801 new_static_pkp_state2.spki_hashes, nullptr, nullptr, | 807 new_static_pkp_state2.spki_hashes, nullptr, nullptr, |
802 TransportSecurityState::DISABLE_PIN_REPORTS, &failure_log)); | 808 TransportSecurityState::DISABLE_PIN_REPORTS, &failure_log)); |
803 EXPECT_NE(0UL, failure_log.length()); | 809 EXPECT_NE(0UL, failure_log.length()); |
804 } | 810 } |
805 | 811 |
806 // Tests that when a static HSTS and a static HPKP entry are present, adding a | 812 // Tests that when a static HSTS and a static HPKP entry are present, adding a |
807 // dynamic HSTS header does not clobber the static HPKP entry. Further, adding a | 813 // dynamic HSTS header does not clobber the static HPKP entry. Further, adding a |
808 // dynamic HPKP entry could not affect the HSTS entry for the site. | 814 // dynamic HPKP entry could not affect the HSTS entry for the site. |
809 TEST_F(HttpSecurityHeadersTest, NoClobberPins) { | 815 TEST_F(HttpSecurityHeadersTest, NoClobberPins) { |
816 #if !BUILDFLAG(INCLUDE_TRANSPORT_SECURITY_STATE_PRELOAD_LIST) | |
817 return; | |
818 #endif | |
810 TransportSecurityState state; | 819 TransportSecurityState state; |
811 TransportSecurityState::STSState sts_state; | 820 TransportSecurityState::STSState sts_state; |
812 TransportSecurityState::PKPState pkp_state; | 821 TransportSecurityState::PKPState pkp_state; |
813 | 822 |
814 // accounts.google.com has preloaded pins. | 823 // accounts.google.com has preloaded pins. |
815 std::string domain = "accounts.google.com"; | 824 std::string domain = "accounts.google.com"; |
816 state.enable_static_pins_ = true; | 825 state.enable_static_pins_ = true; |
817 | 826 |
818 // Retrieve the static STS and PKP states as it is by default, including its | 827 // Retrieve the static STS and PKP states as it is by default, including its |
819 // known good pins. | 828 // known good pins. |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1193 EXPECT_TRUE(ParseExpectCTHeader( | 1202 EXPECT_TRUE(ParseExpectCTHeader( |
1194 " max-age=999999999999999999999999999999999999999999999 ," | 1203 " max-age=999999999999999999999999999999999999999999999 ," |
1195 " enforce ", | 1204 " enforce ", |
1196 &max_age, &enforce, &report_uri)); | 1205 &max_age, &enforce, &report_uri)); |
1197 EXPECT_EQ(base::TimeDelta::FromSeconds(kMaxExpectCTAgeSecs), max_age); | 1206 EXPECT_EQ(base::TimeDelta::FromSeconds(kMaxExpectCTAgeSecs), max_age); |
1198 EXPECT_TRUE(enforce); | 1207 EXPECT_TRUE(enforce); |
1199 EXPECT_TRUE(report_uri.is_empty()); | 1208 EXPECT_TRUE(report_uri.is_empty()); |
1200 } | 1209 } |
1201 | 1210 |
1202 } // namespace net | 1211 } // namespace net |
OLD | NEW |