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 "net/http/transport_security_state.h" | 5 #include "net/http/transport_security_state.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/base64.h" | 11 #include "base/base64.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/rand_util.h" |
13 #include "base/sha1.h" | 14 #include "base/sha1.h" |
14 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
15 #include "crypto/sha2.h" | 16 #include "crypto/sha2.h" |
16 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
17 #include "net/base/net_log.h" | 18 #include "net/base/net_log.h" |
18 #include "net/base/test_completion_callback.h" | 19 #include "net/base/test_completion_callback.h" |
19 #include "net/base/test_data_directory.h" | 20 #include "net/base/test_data_directory.h" |
20 #include "net/cert/asn1_util.h" | 21 #include "net/cert/asn1_util.h" |
21 #include "net/cert/cert_verifier.h" | 22 #include "net/cert/cert_verifier.h" |
22 #include "net/cert/cert_verify_result.h" | 23 #include "net/cert/cert_verify_result.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 TransportSecurityState::DomainState domain_state; | 86 TransportSecurityState::DomainState domain_state; |
86 const base::Time current_time(base::Time::Now()); | 87 const base::Time current_time(base::Time::Now()); |
87 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); | 88 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); |
88 | 89 |
89 EXPECT_FALSE(state.GetDynamicDomainState("yahoo.com", &domain_state)); | 90 EXPECT_FALSE(state.GetDynamicDomainState("yahoo.com", &domain_state)); |
90 bool include_subdomains = false; | 91 bool include_subdomains = false; |
91 state.AddHSTS("YAhoo.coM", expiry, include_subdomains); | 92 state.AddHSTS("YAhoo.coM", expiry, include_subdomains); |
92 EXPECT_TRUE(state.GetDynamicDomainState("yahoo.com", &domain_state)); | 93 EXPECT_TRUE(state.GetDynamicDomainState("yahoo.com", &domain_state)); |
93 } | 94 } |
94 | 95 |
| 96 TEST_F(TransportSecurityStateTest, Fuzz) { |
| 97 TransportSecurityState state; |
| 98 TransportSecurityState::DomainState domain_state; |
| 99 |
| 100 EnableStaticPins(&state); |
| 101 |
| 102 for (size_t i = 0; i < 128; i++) { |
| 103 std::string hostname; |
| 104 |
| 105 for (;;) { |
| 106 if (base::RandInt(0, 16) == 7) { |
| 107 break; |
| 108 } |
| 109 if (i > 0 && base::RandInt(0, 7) == 7) { |
| 110 hostname.append(1, '.'); |
| 111 } |
| 112 hostname.append(1, 'a' + base::RandInt(0, 25)); |
| 113 } |
| 114 state.GetStaticDomainState(hostname, &domain_state); |
| 115 } |
| 116 } |
| 117 |
95 TEST_F(TransportSecurityStateTest, MatchesCase2) { | 118 TEST_F(TransportSecurityStateTest, MatchesCase2) { |
96 TransportSecurityState state; | 119 TransportSecurityState state; |
97 TransportSecurityState::DomainState domain_state; | 120 TransportSecurityState::DomainState domain_state; |
98 const base::Time current_time(base::Time::Now()); | 121 const base::Time current_time(base::Time::Now()); |
99 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); | 122 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); |
100 | 123 |
101 EXPECT_FALSE(state.GetDynamicDomainState("YAhoo.coM", &domain_state)); | 124 EXPECT_FALSE(state.GetDynamicDomainState("YAhoo.coM", &domain_state)); |
102 bool include_subdomains = false; | 125 bool include_subdomains = false; |
103 state.AddHSTS("yahoo.com", expiry, include_subdomains); | 126 state.AddHSTS("yahoo.com", expiry, include_subdomains); |
104 EXPECT_TRUE(state.GetDynamicDomainState("YAhoo.coM", &domain_state)); | 127 EXPECT_TRUE(state.GetDynamicDomainState("YAhoo.coM", &domain_state)); |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 // These hosts used to only be HSTS when SNI was available. | 751 // These hosts used to only be HSTS when SNI was available. |
729 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( | 752 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( |
730 "gmail.com")); | 753 "gmail.com")); |
731 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( | 754 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( |
732 "googlegroups.com")); | 755 "googlegroups.com")); |
733 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( | 756 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( |
734 "www.googlegroups.com")); | 757 "www.googlegroups.com")); |
735 } | 758 } |
736 | 759 |
737 } // namespace net | 760 } // namespace net |
OLD | NEW |