| 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 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 const base::Time current_time(base::Time::Now()); | 136 const base::Time current_time(base::Time::Now()); |
| 137 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); | 137 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); |
| 138 const base::Time older = current_time - base::TimeDelta::FromSeconds(1000); | 138 const base::Time older = current_time - base::TimeDelta::FromSeconds(1000); |
| 139 | 139 |
| 140 EXPECT_FALSE(state.GetDomainState("yahoo.com", true, &domain_state)); | 140 EXPECT_FALSE(state.GetDomainState("yahoo.com", true, &domain_state)); |
| 141 bool include_subdomains = false; | 141 bool include_subdomains = false; |
| 142 state.AddHSTS("yahoo.com", expiry, include_subdomains); | 142 state.AddHSTS("yahoo.com", expiry, include_subdomains); |
| 143 | 143 |
| 144 state.DeleteAllDynamicDataSince(expiry); | 144 state.DeleteAllDynamicDataSince(expiry); |
| 145 EXPECT_TRUE(state.GetDomainState("yahoo.com", true, &domain_state)); | 145 EXPECT_TRUE(state.GetDomainState("yahoo.com", true, &domain_state)); |
| 146 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
| 147 domain_state.dynamic_sts.upgrade_mode); |
| 146 state.DeleteAllDynamicDataSince(older); | 148 state.DeleteAllDynamicDataSince(older); |
| 147 EXPECT_FALSE(state.GetDomainState("yahoo.com", true, &domain_state)); | 149 EXPECT_TRUE(state.GetDomainState("yahoo.com", true, &domain_state)); |
| 150 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT, |
| 151 domain_state.dynamic_sts.upgrade_mode); |
| 148 } | 152 } |
| 149 | 153 |
| 150 TEST_F(TransportSecurityStateTest, DeleteDynamicDataForHost) { | 154 TEST_F(TransportSecurityStateTest, DeleteDynamicDataForHost) { |
| 151 TransportSecurityState state; | 155 TransportSecurityState state; |
| 152 TransportSecurityState::DomainState domain_state; | 156 TransportSecurityState::DomainState domain_state; |
| 153 const base::Time current_time(base::Time::Now()); | 157 const base::Time current_time(base::Time::Now()); |
| 154 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); | 158 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); |
| 155 bool include_subdomains = false; | 159 bool include_subdomains = false; |
| 156 state.AddHSTS("yahoo.com", expiry, include_subdomains); | 160 state.AddHSTS("yahoo.com", expiry, include_subdomains); |
| 157 | 161 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 168 const std::string a_www_paypal = CanonicalizeHost("a.www.paypal.com"); | 172 const std::string a_www_paypal = CanonicalizeHost("a.www.paypal.com"); |
| 169 const std::string abc_paypal = CanonicalizeHost("a.b.c.paypal.com"); | 173 const std::string abc_paypal = CanonicalizeHost("a.b.c.paypal.com"); |
| 170 const std::string example = CanonicalizeHost("example.com"); | 174 const std::string example = CanonicalizeHost("example.com"); |
| 171 const std::string aypal = CanonicalizeHost("aypal.com"); | 175 const std::string aypal = CanonicalizeHost("aypal.com"); |
| 172 | 176 |
| 173 TransportSecurityState state; | 177 TransportSecurityState state; |
| 174 TransportSecurityState::DomainState domain_state; | 178 TransportSecurityState::DomainState domain_state; |
| 175 | 179 |
| 176 EXPECT_TRUE(GetStaticDomainState(&state, paypal, true, &domain_state)); | 180 EXPECT_TRUE(GetStaticDomainState(&state, paypal, true, &domain_state)); |
| 177 EXPECT_TRUE(GetStaticDomainState(&state, www_paypal, true, &domain_state)); | 181 EXPECT_TRUE(GetStaticDomainState(&state, www_paypal, true, &domain_state)); |
| 178 EXPECT_FALSE(domain_state.sts_include_subdomains); | 182 EXPECT_FALSE(domain_state.static_sts.include_subdomains); |
| 179 EXPECT_FALSE(domain_state.pkp_include_subdomains); | 183 EXPECT_FALSE(domain_state.static_pkp.include_subdomains); |
| 180 EXPECT_FALSE(GetStaticDomainState(&state, a_www_paypal, true, &domain_state)); | 184 EXPECT_FALSE(GetStaticDomainState(&state, a_www_paypal, true, &domain_state)); |
| 181 EXPECT_FALSE(GetStaticDomainState(&state, abc_paypal, true, &domain_state)); | 185 EXPECT_FALSE(GetStaticDomainState(&state, abc_paypal, true, &domain_state)); |
| 182 EXPECT_FALSE(GetStaticDomainState(&state, example, true, &domain_state)); | 186 EXPECT_FALSE(GetStaticDomainState(&state, example, true, &domain_state)); |
| 183 EXPECT_FALSE(GetStaticDomainState(&state, aypal, true, &domain_state)); | 187 EXPECT_FALSE(GetStaticDomainState(&state, aypal, true, &domain_state)); |
| 184 } | 188 } |
| 185 | 189 |
| 186 TEST_F(TransportSecurityStateTest, PreloadedDomainSet) { | 190 TEST_F(TransportSecurityStateTest, PreloadedDomainSet) { |
| 187 TransportSecurityState state; | 191 TransportSecurityState state; |
| 188 TransportSecurityState::DomainState domain_state; | 192 TransportSecurityState::DomainState domain_state; |
| 189 | 193 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 static bool HasPublicKeyPins(const char* hostname) { | 225 static bool HasPublicKeyPins(const char* hostname) { |
| 222 return HasPublicKeyPins(hostname, true); | 226 return HasPublicKeyPins(hostname, true); |
| 223 } | 227 } |
| 224 | 228 |
| 225 static bool OnlyPinning(const char *hostname) { | 229 static bool OnlyPinning(const char *hostname) { |
| 226 TransportSecurityState state; | 230 TransportSecurityState state; |
| 227 TransportSecurityState::DomainState domain_state; | 231 TransportSecurityState::DomainState domain_state; |
| 228 if (!state.GetDomainState(hostname, true /* SNI ok */, &domain_state)) | 232 if (!state.GetDomainState(hostname, true /* SNI ok */, &domain_state)) |
| 229 return false; | 233 return false; |
| 230 | 234 |
| 231 return (domain_state.static_spki_hashes.size() > 0 || | 235 return (domain_state.static_pkp.spki_hashes.size() > 0 || |
| 232 domain_state.bad_static_spki_hashes.size() > 0 || | 236 domain_state.static_pkp.bad_spki_hashes.size() > 0 || |
| 233 domain_state.dynamic_spki_hashes.size() > 0) && | 237 domain_state.dynamic_pkp.spki_hashes.size() > 0) && |
| 234 !domain_state.ShouldUpgradeToSSL(); | 238 !domain_state.ShouldUpgradeToSSL(); |
| 235 } | 239 } |
| 236 | 240 |
| 237 TEST_F(TransportSecurityStateTest, Preloaded) { | 241 TEST_F(TransportSecurityStateTest, Preloaded) { |
| 238 TransportSecurityState state; | 242 TransportSecurityState state; |
| 239 TransportSecurityState::DomainState domain_state; | 243 TransportSecurityState::DomainState domain_state; |
| 240 | 244 |
| 241 // We do more extensive checks for the first domain. | 245 // We do more extensive checks for the first domain. |
| 242 EXPECT_TRUE(state.GetDomainState("www.paypal.com", true, &domain_state)); | 246 EXPECT_TRUE(state.GetDomainState("www.paypal.com", true, &domain_state)); |
| 243 EXPECT_EQ(domain_state.upgrade_mode, | 247 EXPECT_EQ(domain_state.static_sts.upgrade_mode, |
| 244 TransportSecurityState::DomainState::MODE_FORCE_HTTPS); | 248 TransportSecurityState::DomainState::MODE_FORCE_HTTPS); |
| 245 EXPECT_FALSE(domain_state.sts_include_subdomains); | 249 EXPECT_FALSE(domain_state.static_sts.include_subdomains); |
| 246 EXPECT_FALSE(domain_state.pkp_include_subdomains); | 250 EXPECT_FALSE(domain_state.static_pkp.include_subdomains); |
| 247 | 251 |
| 248 EXPECT_TRUE(HasState("paypal.com")); | 252 EXPECT_TRUE(HasState("paypal.com")); |
| 249 EXPECT_FALSE(HasState("www2.paypal.com")); | 253 EXPECT_FALSE(HasState("www2.paypal.com")); |
| 250 EXPECT_FALSE(HasState("www2.paypal.com")); | 254 EXPECT_FALSE(HasState("www2.paypal.com")); |
| 251 | 255 |
| 252 // Google hosts: | 256 // Google hosts: |
| 253 | 257 |
| 254 EXPECT_TRUE(ShouldRedirect("chrome.google.com")); | 258 EXPECT_TRUE(ShouldRedirect("chrome.google.com")); |
| 255 EXPECT_TRUE(ShouldRedirect("checkout.google.com")); | 259 EXPECT_TRUE(ShouldRedirect("checkout.google.com")); |
| 256 EXPECT_TRUE(ShouldRedirect("wallet.google.com")); | 260 EXPECT_TRUE(ShouldRedirect("wallet.google.com")); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 EXPECT_TRUE(ShouldRedirect("foo.simon.butcher.name")); | 399 EXPECT_TRUE(ShouldRedirect("foo.simon.butcher.name")); |
| 396 | 400 |
| 397 EXPECT_TRUE(ShouldRedirect("linx.net")); | 401 EXPECT_TRUE(ShouldRedirect("linx.net")); |
| 398 EXPECT_TRUE(ShouldRedirect("foo.linx.net")); | 402 EXPECT_TRUE(ShouldRedirect("foo.linx.net")); |
| 399 | 403 |
| 400 EXPECT_TRUE(ShouldRedirect("dropcam.com")); | 404 EXPECT_TRUE(ShouldRedirect("dropcam.com")); |
| 401 EXPECT_TRUE(ShouldRedirect("www.dropcam.com")); | 405 EXPECT_TRUE(ShouldRedirect("www.dropcam.com")); |
| 402 EXPECT_FALSE(HasState("foo.dropcam.com")); | 406 EXPECT_FALSE(HasState("foo.dropcam.com")); |
| 403 | 407 |
| 404 EXPECT_TRUE(state.GetDomainState("torproject.org", false, &domain_state)); | 408 EXPECT_TRUE(state.GetDomainState("torproject.org", false, &domain_state)); |
| 405 EXPECT_FALSE(domain_state.static_spki_hashes.empty()); | 409 EXPECT_FALSE(domain_state.static_pkp.spki_hashes.empty()); |
| 406 EXPECT_TRUE(state.GetDomainState("www.torproject.org", false, | 410 EXPECT_TRUE(state.GetDomainState("www.torproject.org", false, |
| 407 &domain_state)); | 411 &domain_state)); |
| 408 EXPECT_FALSE(domain_state.static_spki_hashes.empty()); | 412 EXPECT_FALSE(domain_state.static_pkp.spki_hashes.empty()); |
| 409 EXPECT_TRUE(state.GetDomainState("check.torproject.org", false, | 413 EXPECT_TRUE(state.GetDomainState("check.torproject.org", false, |
| 410 &domain_state)); | 414 &domain_state)); |
| 411 EXPECT_FALSE(domain_state.static_spki_hashes.empty()); | 415 EXPECT_FALSE(domain_state.static_pkp.spki_hashes.empty()); |
| 412 EXPECT_TRUE(state.GetDomainState("blog.torproject.org", false, | 416 EXPECT_TRUE(state.GetDomainState("blog.torproject.org", false, |
| 413 &domain_state)); | 417 &domain_state)); |
| 414 EXPECT_FALSE(domain_state.static_spki_hashes.empty()); | 418 EXPECT_FALSE(domain_state.static_pkp.spki_hashes.empty()); |
| 415 EXPECT_TRUE(ShouldRedirect("ebanking.indovinabank.com.vn")); | 419 EXPECT_TRUE(ShouldRedirect("ebanking.indovinabank.com.vn")); |
| 416 EXPECT_TRUE(ShouldRedirect("foo.ebanking.indovinabank.com.vn")); | 420 EXPECT_TRUE(ShouldRedirect("foo.ebanking.indovinabank.com.vn")); |
| 417 | 421 |
| 418 EXPECT_TRUE(ShouldRedirect("epoxate.com")); | 422 EXPECT_TRUE(ShouldRedirect("epoxate.com")); |
| 419 EXPECT_FALSE(HasState("foo.epoxate.com")); | 423 EXPECT_FALSE(HasState("foo.epoxate.com")); |
| 420 | 424 |
| 421 EXPECT_TRUE(HasPublicKeyPins("torproject.org")); | 425 EXPECT_TRUE(HasPublicKeyPins("torproject.org")); |
| 422 EXPECT_TRUE(HasPublicKeyPins("www.torproject.org")); | 426 EXPECT_TRUE(HasPublicKeyPins("www.torproject.org")); |
| 423 EXPECT_TRUE(HasPublicKeyPins("check.torproject.org")); | 427 EXPECT_TRUE(HasPublicKeyPins("check.torproject.org")); |
| 424 EXPECT_TRUE(HasPublicKeyPins("blog.torproject.org")); | 428 EXPECT_TRUE(HasPublicKeyPins("blog.torproject.org")); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 | 617 |
| 614 TEST_F(TransportSecurityStateTest, OverrideBuiltins) { | 618 TEST_F(TransportSecurityStateTest, OverrideBuiltins) { |
| 615 EXPECT_TRUE(HasPublicKeyPins("google.com")); | 619 EXPECT_TRUE(HasPublicKeyPins("google.com")); |
| 616 EXPECT_FALSE(ShouldRedirect("google.com")); | 620 EXPECT_FALSE(ShouldRedirect("google.com")); |
| 617 EXPECT_FALSE(ShouldRedirect("www.google.com")); | 621 EXPECT_FALSE(ShouldRedirect("www.google.com")); |
| 618 | 622 |
| 619 TransportSecurityState state; | 623 TransportSecurityState state; |
| 620 TransportSecurityState::DomainState domain_state; | 624 TransportSecurityState::DomainState domain_state; |
| 621 const base::Time current_time(base::Time::Now()); | 625 const base::Time current_time(base::Time::Now()); |
| 622 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); | 626 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); |
| 623 domain_state.upgrade_expiry = expiry; | 627 domain_state.dynamic_sts.expiry = expiry; |
| 624 EnableHost(&state, "www.google.com", domain_state); | 628 EnableHost(&state, "www.google.com", domain_state); |
| 625 | 629 |
| 626 EXPECT_TRUE(state.GetDomainState("www.google.com", true, &domain_state)); | 630 EXPECT_TRUE(state.GetDomainState("www.google.com", true, &domain_state)); |
| 627 } | 631 } |
| 628 | 632 |
| 629 TEST_F(TransportSecurityStateTest, GooglePinnedProperties) { | 633 TEST_F(TransportSecurityStateTest, GooglePinnedProperties) { |
| 630 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( | 634 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( |
| 631 "www.example.com", true)); | 635 "www.example.com", true)); |
| 632 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( | 636 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( |
| 633 "www.paypal.com", true)); | 637 "www.paypal.com", true)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 // Expect to fail for SNI hosts when not searching the SNI list: | 687 // Expect to fail for SNI hosts when not searching the SNI list: |
| 684 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( | 688 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( |
| 685 "gmail.com", false)); | 689 "gmail.com", false)); |
| 686 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( | 690 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( |
| 687 "googlegroups.com", false)); | 691 "googlegroups.com", false)); |
| 688 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( | 692 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( |
| 689 "www.googlegroups.com", false)); | 693 "www.googlegroups.com", false)); |
| 690 } | 694 } |
| 691 | 695 |
| 692 } // namespace net | 696 } // namespace net |
| OLD | NEW |