[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 5 | #include "net/http/transport_security_state.h" |
[email protected] | 5f15ed6 | 2011-11-02 15:07:08 | [diff] [blame] | 6 | |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | #include <string> |
[email protected] | ede0321 | 2012-09-07 12:52:26 | [diff] [blame] | 9 | #include <vector> |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 10 | |
[email protected] | 5f15ed6 | 2011-11-02 15:07:08 | [diff] [blame] | 11 | #include "base/base64.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 12 | #include "base/files/file_path.h" |
[email protected] | 5f15ed6 | 2011-11-02 15:07:08 | [diff] [blame] | 13 | #include "base/sha1.h" |
[email protected] | d069c11a | 2013-04-13 00:01:55 | [diff] [blame^] | 14 | #include "base/strings/string_piece.h" |
[email protected] | ede0321 | 2012-09-07 12:52:26 | [diff] [blame] | 15 | #include "crypto/sha2.h" |
[email protected] | 66d9b6e3 | 2012-03-22 03:04:32 | [diff] [blame] | 16 | #include "net/base/net_errors.h" |
| 17 | #include "net/base/net_log.h" |
[email protected] | 66d9b6e3 | 2012-03-22 03:04:32 | [diff] [blame] | 18 | #include "net/base/test_completion_callback.h" |
[email protected] | 42fdb45 | 2012-11-01 12:44:40 | [diff] [blame] | 19 | #include "net/base/test_data_directory.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 20 | #include "net/cert/asn1_util.h" |
| 21 | #include "net/cert/cert_verifier.h" |
| 22 | #include "net/cert/cert_verify_result.h" |
| 23 | #include "net/cert/test_root_certs.h" |
| 24 | #include "net/cert/x509_cert_types.h" |
| 25 | #include "net/cert/x509_certificate.h" |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 26 | #include "net/http/http_util.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 27 | #include "net/ssl/ssl_info.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 28 | #include "net/test/cert_test_util.h" |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 29 | #include "testing/gtest/include/gtest/gtest.h" |
| 30 | |
[email protected] | 06256e5 | 2011-09-29 15:08:48 | [diff] [blame] | 31 | #if defined(USE_OPENSSL) |
| 32 | #include "crypto/openssl_util.h" |
| 33 | #else |
| 34 | #include "crypto/nss_util.h" |
| 35 | #endif |
| 36 | |
[email protected] | 2fc4c21 | 2010-03-10 18:59:06 | [diff] [blame] | 37 | namespace net { |
| 38 | |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 39 | class TransportSecurityStateTest : public testing::Test { |
[email protected] | 06256e5 | 2011-09-29 15:08:48 | [diff] [blame] | 40 | virtual void SetUp() { |
[email protected] | 5435643 | 2011-10-05 21:49:42 | [diff] [blame] | 41 | #if defined(USE_OPENSSL) |
[email protected] | 06256e5 | 2011-09-29 15:08:48 | [diff] [blame] | 42 | crypto::EnsureOpenSSLInit(); |
[email protected] | 5435643 | 2011-10-05 21:49:42 | [diff] [blame] | 43 | #else |
| 44 | crypto::EnsureNSSInit(); |
[email protected] | 06256e5 | 2011-09-29 15:08:48 | [diff] [blame] | 45 | #endif |
| 46 | } |
[email protected] | 474f079e | 2013-03-02 19:11:20 | [diff] [blame] | 47 | |
| 48 | protected: |
| 49 | std::string CanonicalizeHost(const std::string& host) { |
| 50 | return TransportSecurityState::CanonicalizeHost(host); |
| 51 | } |
| 52 | |
| 53 | bool GetStaticDomainState(TransportSecurityState* state, |
| 54 | const std::string& host, |
| 55 | bool sni_enabled, |
| 56 | TransportSecurityState::DomainState* result) { |
| 57 | return state->GetStaticDomainState(host, sni_enabled, result); |
| 58 | } |
| 59 | |
| 60 | void EnableHost(TransportSecurityState* state, |
| 61 | const std::string& host, |
| 62 | const TransportSecurityState::DomainState& domain_state) { |
| 63 | return state->EnableHost(host, domain_state); |
| 64 | } |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 65 | }; |
| 66 | |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 67 | TEST_F(TransportSecurityStateTest, SimpleMatches) { |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 68 | TransportSecurityState state; |
[email protected] | 2fc4c21 | 2010-03-10 18:59:06 | [diff] [blame] | 69 | TransportSecurityState::DomainState domain_state; |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 70 | const base::Time current_time(base::Time::Now()); |
| 71 | const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); |
| 72 | |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 73 | EXPECT_FALSE(state.GetDomainState("yahoo.com", true, &domain_state)); |
[email protected] | 474f079e | 2013-03-02 19:11:20 | [diff] [blame] | 74 | bool include_subdomains = false; |
| 75 | state.AddHSTS("yahoo.com", expiry, include_subdomains); |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 76 | EXPECT_TRUE(state.GetDomainState("yahoo.com", true, &domain_state)); |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | TEST_F(TransportSecurityStateTest, MatchesCase1) { |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 80 | TransportSecurityState state; |
[email protected] | 2fc4c21 | 2010-03-10 18:59:06 | [diff] [blame] | 81 | TransportSecurityState::DomainState domain_state; |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 82 | const base::Time current_time(base::Time::Now()); |
| 83 | const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); |
| 84 | |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 85 | EXPECT_FALSE(state.GetDomainState("yahoo.com", true, &domain_state)); |
[email protected] | 474f079e | 2013-03-02 19:11:20 | [diff] [blame] | 86 | bool include_subdomains = false; |
| 87 | state.AddHSTS("YAhoo.coM", expiry, include_subdomains); |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 88 | EXPECT_TRUE(state.GetDomainState("yahoo.com", true, &domain_state)); |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | TEST_F(TransportSecurityStateTest, MatchesCase2) { |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 92 | TransportSecurityState state; |
[email protected] | 2fc4c21 | 2010-03-10 18:59:06 | [diff] [blame] | 93 | TransportSecurityState::DomainState domain_state; |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 94 | const base::Time current_time(base::Time::Now()); |
| 95 | const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); |
| 96 | |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 97 | EXPECT_FALSE(state.GetDomainState("YAhoo.coM", true, &domain_state)); |
[email protected] | 474f079e | 2013-03-02 19:11:20 | [diff] [blame] | 98 | bool include_subdomains = false; |
| 99 | state.AddHSTS("yahoo.com", expiry, include_subdomains); |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 100 | EXPECT_TRUE(state.GetDomainState("YAhoo.coM", true, &domain_state)); |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | TEST_F(TransportSecurityStateTest, SubdomainMatches) { |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 104 | TransportSecurityState state; |
[email protected] | 2fc4c21 | 2010-03-10 18:59:06 | [diff] [blame] | 105 | TransportSecurityState::DomainState domain_state; |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 106 | const base::Time current_time(base::Time::Now()); |
| 107 | const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); |
| 108 | |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 109 | EXPECT_FALSE(state.GetDomainState("yahoo.com", true, &domain_state)); |
[email protected] | 474f079e | 2013-03-02 19:11:20 | [diff] [blame] | 110 | bool include_subdomains = true; |
| 111 | state.AddHSTS("yahoo.com", expiry, include_subdomains); |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 112 | EXPECT_TRUE(state.GetDomainState("yahoo.com", true, &domain_state)); |
| 113 | EXPECT_TRUE(state.GetDomainState("foo.yahoo.com", true, &domain_state)); |
| 114 | EXPECT_TRUE(state.GetDomainState("foo.bar.yahoo.com", true, &domain_state)); |
| 115 | EXPECT_TRUE(state.GetDomainState("foo.bar.baz.yahoo.com", true, |
| 116 | &domain_state)); |
| 117 | EXPECT_FALSE(state.GetDomainState("com", true, &domain_state)); |
[email protected] | 326e679 | 2009-12-11 21:04:42 | [diff] [blame] | 118 | } |
| 119 | |
[email protected] | 474f079e | 2013-03-02 19:11:20 | [diff] [blame] | 120 | TEST_F(TransportSecurityStateTest, DeleteAllDynamicDataSince) { |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 121 | TransportSecurityState state; |
[email protected] | 2fc4c21 | 2010-03-10 18:59:06 | [diff] [blame] | 122 | TransportSecurityState::DomainState domain_state; |
[email protected] | 4d0d808 | 2010-02-23 01:03:10 | [diff] [blame] | 123 | const base::Time current_time(base::Time::Now()); |
| 124 | const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); |
| 125 | const base::Time older = current_time - base::TimeDelta::FromSeconds(1000); |
| 126 | |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 127 | EXPECT_FALSE(state.GetDomainState("yahoo.com", true, &domain_state)); |
[email protected] | 474f079e | 2013-03-02 19:11:20 | [diff] [blame] | 128 | bool include_subdomains = false; |
| 129 | state.AddHSTS("yahoo.com", expiry, include_subdomains); |
[email protected] | 4d0d808 | 2010-02-23 01:03:10 | [diff] [blame] | 130 | |
[email protected] | 474f079e | 2013-03-02 19:11:20 | [diff] [blame] | 131 | state.DeleteAllDynamicDataSince(expiry); |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 132 | EXPECT_TRUE(state.GetDomainState("yahoo.com", true, &domain_state)); |
[email protected] | 474f079e | 2013-03-02 19:11:20 | [diff] [blame] | 133 | state.DeleteAllDynamicDataSince(older); |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 134 | EXPECT_FALSE(state.GetDomainState("yahoo.com", true, &domain_state)); |
[email protected] | 4d0d808 | 2010-02-23 01:03:10 | [diff] [blame] | 135 | } |
| 136 | |
[email protected] | 474f079e | 2013-03-02 19:11:20 | [diff] [blame] | 137 | TEST_F(TransportSecurityStateTest, DeleteDynamicDataForHost) { |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 138 | TransportSecurityState state; |
[email protected] | f060be3 | 2011-02-17 17:20:28 | [diff] [blame] | 139 | TransportSecurityState::DomainState domain_state; |
| 140 | const base::Time current_time(base::Time::Now()); |
| 141 | const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); |
[email protected] | 474f079e | 2013-03-02 19:11:20 | [diff] [blame] | 142 | bool include_subdomains = false; |
| 143 | state.AddHSTS("yahoo.com", expiry, include_subdomains); |
[email protected] | f060be3 | 2011-02-17 17:20:28 | [diff] [blame] | 144 | |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 145 | EXPECT_TRUE(state.GetDomainState("yahoo.com", true, &domain_state)); |
| 146 | EXPECT_FALSE(state.GetDomainState("example.com", true, &domain_state)); |
[email protected] | 474f079e | 2013-03-02 19:11:20 | [diff] [blame] | 147 | EXPECT_TRUE(state.DeleteDynamicDataForHost("yahoo.com")); |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 148 | EXPECT_FALSE(state.GetDomainState("yahoo.com", true, &domain_state)); |
[email protected] | 4d0d808 | 2010-02-23 01:03:10 | [diff] [blame] | 149 | } |
| 150 | |
[email protected] | 2fc4c21 | 2010-03-10 18:59:06 | [diff] [blame] | 151 | TEST_F(TransportSecurityStateTest, IsPreloaded) { |
[email protected] | 9f972ec | 2013-04-10 20:24:36 | [diff] [blame] | 152 | const std::string paypal = CanonicalizeHost("paypal.com"); |
| 153 | const std::string www_paypal = CanonicalizeHost("www.paypal.com"); |
| 154 | const std::string a_www_paypal = CanonicalizeHost("a.www.paypal.com"); |
| 155 | const std::string abc_paypal = CanonicalizeHost("a.b.c.paypal.com"); |
| 156 | const std::string example = CanonicalizeHost("example.com"); |
| 157 | const std::string aypal = CanonicalizeHost("aypal.com"); |
[email protected] | 2fc4c21 | 2010-03-10 18:59:06 | [diff] [blame] | 158 | |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 159 | TransportSecurityState state; |
[email protected] | aa90443 | 2011-04-21 00:07:16 | [diff] [blame] | 160 | TransportSecurityState::DomainState domain_state; |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 161 | |
[email protected] | 474f079e | 2013-03-02 19:11:20 | [diff] [blame] | 162 | EXPECT_FALSE(GetStaticDomainState(&state, paypal, true, &domain_state)); |
| 163 | EXPECT_TRUE(GetStaticDomainState(&state, www_paypal, true, &domain_state)); |
[email protected] | aa90443 | 2011-04-21 00:07:16 | [diff] [blame] | 164 | EXPECT_FALSE(domain_state.include_subdomains); |
[email protected] | 474f079e | 2013-03-02 19:11:20 | [diff] [blame] | 165 | EXPECT_FALSE(GetStaticDomainState(&state, a_www_paypal, true, &domain_state)); |
| 166 | EXPECT_FALSE(GetStaticDomainState(&state, abc_paypal, true, &domain_state)); |
| 167 | EXPECT_FALSE(GetStaticDomainState(&state, example, true, &domain_state)); |
| 168 | EXPECT_FALSE(GetStaticDomainState(&state, aypal, true, &domain_state)); |
[email protected] | 2fc4c21 | 2010-03-10 18:59:06 | [diff] [blame] | 169 | } |
| 170 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 171 | TEST_F(TransportSecurityStateTest, PreloadedDomainSet) { |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 172 | TransportSecurityState state; |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 173 | TransportSecurityState::DomainState domain_state; |
| 174 | |
| 175 | // The domain wasn't being set, leading to a blank string in the |
| 176 | // chrome://net-internals/#hsts UI. So test that. |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 177 | EXPECT_TRUE(state.GetDomainState("market.android.com", true, &domain_state)); |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 178 | EXPECT_EQ(domain_state.domain, "market.android.com"); |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 179 | EXPECT_TRUE(state.GetDomainState("sub.market.android.com", true, |
| 180 | &domain_state)); |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 181 | EXPECT_EQ(domain_state.domain, "market.android.com"); |
| 182 | } |
| 183 | |
| 184 | static bool ShouldRedirect(const char* hostname) { |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 185 | TransportSecurityState state; |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 186 | TransportSecurityState::DomainState domain_state; |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 187 | return state.GetDomainState(hostname, true /* SNI ok */, &domain_state) && |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 188 | domain_state.ShouldUpgradeToSSL(); |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 189 | } |
| 190 | |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 191 | static bool HasState(const char* hostname) { |
| 192 | TransportSecurityState state; |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 193 | TransportSecurityState::DomainState domain_state; |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 194 | return state.GetDomainState(hostname, true /* SNI ok */, &domain_state); |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 195 | } |
| 196 | |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 197 | static bool HasPublicKeyPins(const char* hostname, bool sni_enabled) { |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 198 | TransportSecurityState state; |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 199 | TransportSecurityState::DomainState domain_state; |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 200 | if (!state.GetDomainState(hostname, sni_enabled, &domain_state)) |
| 201 | return false; |
| 202 | |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 203 | return domain_state.HasPublicKeyPins(); |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 204 | } |
| 205 | |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 206 | static bool HasPublicKeyPins(const char* hostname) { |
| 207 | return HasPublicKeyPins(hostname, true); |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | static bool OnlyPinning(const char *hostname) { |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 211 | TransportSecurityState state; |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 212 | TransportSecurityState::DomainState domain_state; |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 213 | if (!state.GetDomainState(hostname, true /* SNI ok */, &domain_state)) |
| 214 | return false; |
| 215 | |
| 216 | return (domain_state.static_spki_hashes.size() > 0 || |
| 217 | domain_state.bad_static_spki_hashes.size() > 0 || |
| 218 | domain_state.dynamic_spki_hashes.size() > 0) && |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 219 | !domain_state.ShouldUpgradeToSSL(); |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 220 | } |
| 221 | |
[email protected] | 2fc4c21 | 2010-03-10 18:59:06 | [diff] [blame] | 222 | TEST_F(TransportSecurityStateTest, Preloaded) { |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 223 | TransportSecurityState state; |
[email protected] | 2fc4c21 | 2010-03-10 18:59:06 | [diff] [blame] | 224 | TransportSecurityState::DomainState domain_state; |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 225 | |
| 226 | // We do more extensive checks for the first domain. |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 227 | EXPECT_TRUE(state.GetDomainState("www.paypal.com", true, &domain_state)); |
| 228 | EXPECT_EQ(domain_state.upgrade_mode, |
| 229 | TransportSecurityState::DomainState::MODE_FORCE_HTTPS); |
[email protected] | 2fc4c21 | 2010-03-10 18:59:06 | [diff] [blame] | 230 | EXPECT_FALSE(domain_state.include_subdomains); |
[email protected] | f091469f | 2010-05-05 21:05:28 | [diff] [blame] | 231 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 232 | EXPECT_FALSE(HasState("paypal.com")); |
| 233 | EXPECT_FALSE(HasState("www2.paypal.com")); |
[email protected] | fecef22 | 2012-01-05 02:26:15 | [diff] [blame] | 234 | EXPECT_FALSE(HasState("www2.paypal.com")); |
[email protected] | edbc4f9 | 2011-09-27 21:04:49 | [diff] [blame] | 235 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 236 | // Google hosts: |
[email protected] | edbc4f9 | 2011-09-27 21:04:49 | [diff] [blame] | 237 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 238 | EXPECT_TRUE(ShouldRedirect("chrome.google.com")); |
| 239 | EXPECT_TRUE(ShouldRedirect("checkout.google.com")); |
| 240 | EXPECT_TRUE(ShouldRedirect("health.google.com")); |
| 241 | EXPECT_TRUE(ShouldRedirect("docs.google.com")); |
| 242 | EXPECT_TRUE(ShouldRedirect("sites.google.com")); |
| 243 | EXPECT_TRUE(ShouldRedirect("drive.google.com")); |
| 244 | EXPECT_TRUE(ShouldRedirect("spreadsheets.google.com")); |
| 245 | EXPECT_TRUE(ShouldRedirect("appengine.google.com")); |
| 246 | EXPECT_TRUE(ShouldRedirect("market.android.com")); |
| 247 | EXPECT_TRUE(ShouldRedirect("encrypted.google.com")); |
| 248 | EXPECT_TRUE(ShouldRedirect("accounts.google.com")); |
| 249 | EXPECT_TRUE(ShouldRedirect("profiles.google.com")); |
| 250 | EXPECT_TRUE(ShouldRedirect("mail.google.com")); |
| 251 | EXPECT_TRUE(ShouldRedirect("chatenabled.mail.google.com")); |
| 252 | EXPECT_TRUE(ShouldRedirect("talkgadget.google.com")); |
| 253 | EXPECT_TRUE(ShouldRedirect("hostedtalkgadget.google.com")); |
| 254 | EXPECT_TRUE(ShouldRedirect("talk.google.com")); |
| 255 | EXPECT_TRUE(ShouldRedirect("plus.google.com")); |
[email protected] | d100467b | 2012-02-10 22:01:21 | [diff] [blame] | 256 | EXPECT_TRUE(ShouldRedirect("groups.google.com")); |
[email protected] | b9480af0 | 2012-02-22 19:55:01 | [diff] [blame] | 257 | EXPECT_TRUE(ShouldRedirect("apis.google.com")); |
[email protected] | 25b882a | 2012-03-05 20:44:15 | [diff] [blame] | 258 | EXPECT_FALSE(ShouldRedirect("chart.apis.google.com")); |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 259 | EXPECT_TRUE(ShouldRedirect("ssl.google-analytics.com")); |
| 260 | EXPECT_TRUE(ShouldRedirect("gmail.com")); |
| 261 | EXPECT_TRUE(ShouldRedirect("www.gmail.com")); |
| 262 | EXPECT_TRUE(ShouldRedirect("googlemail.com")); |
| 263 | EXPECT_TRUE(ShouldRedirect("www.googlemail.com")); |
| 264 | EXPECT_TRUE(ShouldRedirect("googleplex.com")); |
| 265 | EXPECT_TRUE(ShouldRedirect("www.googleplex.com")); |
| 266 | EXPECT_FALSE(HasState("m.gmail.com")); |
| 267 | EXPECT_FALSE(HasState("m.googlemail.com")); |
[email protected] | bee7631 | 2011-03-17 18:35:35 | [diff] [blame] | 268 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 269 | EXPECT_TRUE(OnlyPinning("www.google.com")); |
| 270 | EXPECT_TRUE(OnlyPinning("foo.google.com")); |
| 271 | EXPECT_TRUE(OnlyPinning("google.com")); |
| 272 | EXPECT_TRUE(OnlyPinning("www.youtube.com")); |
| 273 | EXPECT_TRUE(OnlyPinning("youtube.com")); |
| 274 | EXPECT_TRUE(OnlyPinning("i.ytimg.com")); |
| 275 | EXPECT_TRUE(OnlyPinning("ytimg.com")); |
| 276 | EXPECT_TRUE(OnlyPinning("googleusercontent.com")); |
| 277 | EXPECT_TRUE(OnlyPinning("www.googleusercontent.com")); |
| 278 | EXPECT_TRUE(OnlyPinning("www.google-analytics.com")); |
| 279 | EXPECT_TRUE(OnlyPinning("googleapis.com")); |
| 280 | EXPECT_TRUE(OnlyPinning("googleadservices.com")); |
| 281 | EXPECT_TRUE(OnlyPinning("googlecode.com")); |
| 282 | EXPECT_TRUE(OnlyPinning("appspot.com")); |
| 283 | EXPECT_TRUE(OnlyPinning("googlesyndication.com")); |
| 284 | EXPECT_TRUE(OnlyPinning("doubleclick.net")); |
| 285 | EXPECT_TRUE(OnlyPinning("googlegroups.com")); |
[email protected] | b4adfdf0 | 2011-03-18 20:54:43 | [diff] [blame] | 286 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 287 | // Tests for domains that don't work without SNI. |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 288 | EXPECT_FALSE(state.GetDomainState("gmail.com", false, &domain_state)); |
| 289 | EXPECT_FALSE(state.GetDomainState("www.gmail.com", false, &domain_state)); |
| 290 | EXPECT_FALSE(state.GetDomainState("m.gmail.com", false, &domain_state)); |
| 291 | EXPECT_FALSE(state.GetDomainState("googlemail.com", false, &domain_state)); |
| 292 | EXPECT_FALSE(state.GetDomainState("www.googlemail.com", false, |
| 293 | &domain_state)); |
| 294 | EXPECT_FALSE(state.GetDomainState("m.googlemail.com", false, &domain_state)); |
[email protected] | bef90f3 | 2011-05-13 19:25:25 | [diff] [blame] | 295 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 296 | // Other hosts: |
[email protected] | edbc4f9 | 2011-09-27 21:04:49 | [diff] [blame] | 297 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 298 | EXPECT_TRUE(ShouldRedirect("aladdinschools.appspot.com")); |
[email protected] | 4e7075a | 2011-05-16 17:44:06 | [diff] [blame] | 299 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 300 | EXPECT_TRUE(ShouldRedirect("ottospora.nl")); |
| 301 | EXPECT_TRUE(ShouldRedirect("www.ottospora.nl")); |
[email protected] | edbc4f9 | 2011-09-27 21:04:49 | [diff] [blame] | 302 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 303 | EXPECT_TRUE(ShouldRedirect("www.paycheckrecords.com")); |
[email protected] | edbc4f9 | 2011-09-27 21:04:49 | [diff] [blame] | 304 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 305 | EXPECT_TRUE(ShouldRedirect("lastpass.com")); |
| 306 | EXPECT_TRUE(ShouldRedirect("www.lastpass.com")); |
| 307 | EXPECT_FALSE(HasState("blog.lastpass.com")); |
[email protected] | edbc4f9 | 2011-09-27 21:04:49 | [diff] [blame] | 308 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 309 | EXPECT_TRUE(ShouldRedirect("keyerror.com")); |
| 310 | EXPECT_TRUE(ShouldRedirect("www.keyerror.com")); |
[email protected] | edbc4f9 | 2011-09-27 21:04:49 | [diff] [blame] | 311 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 312 | EXPECT_TRUE(ShouldRedirect("entropia.de")); |
| 313 | EXPECT_TRUE(ShouldRedirect("www.entropia.de")); |
| 314 | EXPECT_FALSE(HasState("foo.entropia.de")); |
[email protected] | edbc4f9 | 2011-09-27 21:04:49 | [diff] [blame] | 315 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 316 | EXPECT_TRUE(ShouldRedirect("www.elanex.biz")); |
| 317 | EXPECT_FALSE(HasState("elanex.biz")); |
| 318 | EXPECT_FALSE(HasState("foo.elanex.biz")); |
[email protected] | edbc4f9 | 2011-09-27 21:04:49 | [diff] [blame] | 319 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 320 | EXPECT_TRUE(ShouldRedirect("sunshinepress.org")); |
| 321 | EXPECT_TRUE(ShouldRedirect("www.sunshinepress.org")); |
| 322 | EXPECT_TRUE(ShouldRedirect("a.b.sunshinepress.org")); |
[email protected] | 0526e7a | 2011-05-19 16:49:40 | [diff] [blame] | 323 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 324 | EXPECT_TRUE(ShouldRedirect("www.noisebridge.net")); |
| 325 | EXPECT_FALSE(HasState("noisebridge.net")); |
| 326 | EXPECT_FALSE(HasState("foo.noisebridge.net")); |
[email protected] | edbc4f9 | 2011-09-27 21:04:49 | [diff] [blame] | 327 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 328 | EXPECT_TRUE(ShouldRedirect("neg9.org")); |
| 329 | EXPECT_FALSE(HasState("www.neg9.org")); |
[email protected] | edbc4f9 | 2011-09-27 21:04:49 | [diff] [blame] | 330 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 331 | EXPECT_TRUE(ShouldRedirect("riseup.net")); |
| 332 | EXPECT_TRUE(ShouldRedirect("foo.riseup.net")); |
[email protected] | edbc4f9 | 2011-09-27 21:04:49 | [diff] [blame] | 333 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 334 | EXPECT_TRUE(ShouldRedirect("factor.cc")); |
| 335 | EXPECT_FALSE(HasState("www.factor.cc")); |
[email protected] | edbc4f9 | 2011-09-27 21:04:49 | [diff] [blame] | 336 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 337 | EXPECT_TRUE(ShouldRedirect("members.mayfirst.org")); |
| 338 | EXPECT_TRUE(ShouldRedirect("support.mayfirst.org")); |
| 339 | EXPECT_TRUE(ShouldRedirect("id.mayfirst.org")); |
| 340 | EXPECT_TRUE(ShouldRedirect("lists.mayfirst.org")); |
| 341 | EXPECT_FALSE(HasState("www.mayfirst.org")); |
[email protected] | edbc4f9 | 2011-09-27 21:04:49 | [diff] [blame] | 342 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 343 | EXPECT_TRUE(ShouldRedirect("romab.com")); |
| 344 | EXPECT_TRUE(ShouldRedirect("www.romab.com")); |
| 345 | EXPECT_TRUE(ShouldRedirect("foo.romab.com")); |
[email protected] | 5287d009 | 2011-05-30 19:19:36 | [diff] [blame] | 346 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 347 | EXPECT_TRUE(ShouldRedirect("logentries.com")); |
| 348 | EXPECT_TRUE(ShouldRedirect("www.logentries.com")); |
| 349 | EXPECT_FALSE(HasState("foo.logentries.com")); |
[email protected] | 7179d2f4 | 2011-09-07 21:08:40 | [diff] [blame] | 350 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 351 | EXPECT_TRUE(ShouldRedirect("stripe.com")); |
| 352 | EXPECT_TRUE(ShouldRedirect("foo.stripe.com")); |
[email protected] | edbc4f9 | 2011-09-27 21:04:49 | [diff] [blame] | 353 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 354 | EXPECT_TRUE(ShouldRedirect("cloudsecurityalliance.org")); |
| 355 | EXPECT_TRUE(ShouldRedirect("foo.cloudsecurityalliance.org")); |
[email protected] | d43846e | 2011-09-09 19:21:23 | [diff] [blame] | 356 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 357 | EXPECT_TRUE(ShouldRedirect("login.sapo.pt")); |
| 358 | EXPECT_TRUE(ShouldRedirect("foo.login.sapo.pt")); |
[email protected] | e59d0fa | 2011-09-16 13:19:08 | [diff] [blame] | 359 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 360 | EXPECT_TRUE(ShouldRedirect("mattmccutchen.net")); |
| 361 | EXPECT_TRUE(ShouldRedirect("foo.mattmccutchen.net")); |
[email protected] | edbc4f9 | 2011-09-27 21:04:49 | [diff] [blame] | 362 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 363 | EXPECT_TRUE(ShouldRedirect("betnet.fr")); |
| 364 | EXPECT_TRUE(ShouldRedirect("foo.betnet.fr")); |
[email protected] | edbc4f9 | 2011-09-27 21:04:49 | [diff] [blame] | 365 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 366 | EXPECT_TRUE(ShouldRedirect("uprotect.it")); |
| 367 | EXPECT_TRUE(ShouldRedirect("foo.uprotect.it")); |
[email protected] | e0a18fe | 2011-10-12 14:26:05 | [diff] [blame] | 368 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 369 | EXPECT_TRUE(ShouldRedirect("squareup.com")); |
| 370 | EXPECT_FALSE(HasState("foo.squareup.com")); |
| 371 | |
| 372 | EXPECT_TRUE(ShouldRedirect("cert.se")); |
| 373 | EXPECT_TRUE(ShouldRedirect("foo.cert.se")); |
| 374 | |
| 375 | EXPECT_TRUE(ShouldRedirect("crypto.is")); |
| 376 | EXPECT_TRUE(ShouldRedirect("foo.crypto.is")); |
| 377 | |
| 378 | EXPECT_TRUE(ShouldRedirect("simon.butcher.name")); |
| 379 | EXPECT_TRUE(ShouldRedirect("foo.simon.butcher.name")); |
| 380 | |
| 381 | EXPECT_TRUE(ShouldRedirect("linx.net")); |
| 382 | EXPECT_TRUE(ShouldRedirect("foo.linx.net")); |
| 383 | |
| 384 | EXPECT_TRUE(ShouldRedirect("dropcam.com")); |
| 385 | EXPECT_TRUE(ShouldRedirect("www.dropcam.com")); |
| 386 | EXPECT_FALSE(HasState("foo.dropcam.com")); |
| 387 | |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 388 | EXPECT_TRUE(state.GetDomainState("torproject.org", false, &domain_state)); |
| 389 | EXPECT_FALSE(domain_state.static_spki_hashes.empty()); |
| 390 | EXPECT_TRUE(state.GetDomainState("www.torproject.org", false, |
| 391 | &domain_state)); |
| 392 | EXPECT_FALSE(domain_state.static_spki_hashes.empty()); |
| 393 | EXPECT_TRUE(state.GetDomainState("check.torproject.org", false, |
| 394 | &domain_state)); |
| 395 | EXPECT_FALSE(domain_state.static_spki_hashes.empty()); |
| 396 | EXPECT_TRUE(state.GetDomainState("blog.torproject.org", false, |
| 397 | &domain_state)); |
| 398 | EXPECT_FALSE(domain_state.static_spki_hashes.empty()); |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 399 | EXPECT_TRUE(ShouldRedirect("ebanking.indovinabank.com.vn")); |
| 400 | EXPECT_TRUE(ShouldRedirect("foo.ebanking.indovinabank.com.vn")); |
| 401 | |
| 402 | EXPECT_TRUE(ShouldRedirect("epoxate.com")); |
| 403 | EXPECT_FALSE(HasState("foo.epoxate.com")); |
| 404 | |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 405 | EXPECT_TRUE(HasPublicKeyPins("torproject.org")); |
| 406 | EXPECT_TRUE(HasPublicKeyPins("www.torproject.org")); |
| 407 | EXPECT_TRUE(HasPublicKeyPins("check.torproject.org")); |
| 408 | EXPECT_TRUE(HasPublicKeyPins("blog.torproject.org")); |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 409 | EXPECT_FALSE(HasState("foo.torproject.org")); |
| 410 | |
| 411 | EXPECT_TRUE(ShouldRedirect("www.moneybookers.com")); |
| 412 | EXPECT_FALSE(HasState("moneybookers.com")); |
| 413 | |
| 414 | EXPECT_TRUE(ShouldRedirect("ledgerscope.net")); |
| 415 | EXPECT_TRUE(ShouldRedirect("www.ledgerscope.net")); |
| 416 | EXPECT_FALSE(HasState("status.ledgerscope.net")); |
| 417 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 418 | EXPECT_TRUE(ShouldRedirect("foo.app.recurly.com")); |
| 419 | EXPECT_TRUE(ShouldRedirect("foo.api.recurly.com")); |
| 420 | |
| 421 | EXPECT_TRUE(ShouldRedirect("greplin.com")); |
| 422 | EXPECT_TRUE(ShouldRedirect("www.greplin.com")); |
| 423 | EXPECT_FALSE(HasState("foo.greplin.com")); |
| 424 | |
| 425 | EXPECT_TRUE(ShouldRedirect("luneta.nearbuysystems.com")); |
| 426 | EXPECT_TRUE(ShouldRedirect("foo.luneta.nearbuysystems.com")); |
| 427 | |
| 428 | EXPECT_TRUE(ShouldRedirect("ubertt.org")); |
| 429 | EXPECT_TRUE(ShouldRedirect("foo.ubertt.org")); |
[email protected] | 7ccf34e | 2011-10-04 18:29:29 | [diff] [blame] | 430 | |
[email protected] | e004c407 | 2011-12-28 15:08:19 | [diff] [blame] | 431 | EXPECT_TRUE(ShouldRedirect("pixi.me")); |
| 432 | EXPECT_TRUE(ShouldRedirect("www.pixi.me")); |
| 433 | |
[email protected] | 736c1db | 2012-02-24 17:21:39 | [diff] [blame] | 434 | EXPECT_TRUE(ShouldRedirect("grepular.com")); |
| 435 | EXPECT_TRUE(ShouldRedirect("www.grepular.com")); |
| 436 | |
[email protected] | aaf17d57 | 2012-03-06 15:54:19 | [diff] [blame] | 437 | EXPECT_TRUE(ShouldRedirect("mydigipass.com")); |
| 438 | EXPECT_FALSE(ShouldRedirect("foo.mydigipass.com")); |
| 439 | EXPECT_TRUE(ShouldRedirect("www.mydigipass.com")); |
| 440 | EXPECT_FALSE(ShouldRedirect("foo.www.mydigipass.com")); |
| 441 | EXPECT_TRUE(ShouldRedirect("developer.mydigipass.com")); |
| 442 | EXPECT_FALSE(ShouldRedirect("foo.developer.mydigipass.com")); |
| 443 | EXPECT_TRUE(ShouldRedirect("www.developer.mydigipass.com")); |
| 444 | EXPECT_FALSE(ShouldRedirect("foo.www.developer.mydigipass.com")); |
| 445 | EXPECT_TRUE(ShouldRedirect("sandbox.mydigipass.com")); |
| 446 | EXPECT_FALSE(ShouldRedirect("foo.sandbox.mydigipass.com")); |
| 447 | EXPECT_TRUE(ShouldRedirect("www.sandbox.mydigipass.com")); |
| 448 | EXPECT_FALSE(ShouldRedirect("foo.www.sandbox.mydigipass.com")); |
| 449 | |
| 450 | EXPECT_TRUE(ShouldRedirect("crypto.cat")); |
[email protected] | 15a43f8 | 2013-01-15 22:51:55 | [diff] [blame] | 451 | EXPECT_FALSE(ShouldRedirect("foo.crypto.cat")); |
[email protected] | aaf17d57 | 2012-03-06 15:54:19 | [diff] [blame] | 452 | |
[email protected] | 3720497 | 2012-03-09 20:43:00 | [diff] [blame] | 453 | EXPECT_TRUE(ShouldRedirect("bigshinylock.minazo.net")); |
| 454 | EXPECT_TRUE(ShouldRedirect("foo.bigshinylock.minazo.net")); |
| 455 | |
[email protected] | 2a886d3 | 2012-03-12 21:33:12 | [diff] [blame] | 456 | EXPECT_TRUE(ShouldRedirect("crate.io")); |
| 457 | EXPECT_TRUE(ShouldRedirect("foo.crate.io")); |
| 458 | |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 459 | EXPECT_TRUE(HasPublicKeyPins("www.twitter.com")); |
[email protected] | 2fc4c21 | 2010-03-10 18:59:06 | [diff] [blame] | 460 | } |
| 461 | |
[email protected] | 442845a | 2010-09-01 16:57:33 | [diff] [blame] | 462 | TEST_F(TransportSecurityStateTest, LongNames) { |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 463 | TransportSecurityState state; |
[email protected] | 442845a | 2010-09-01 16:57:33 | [diff] [blame] | 464 | const char kLongName[] = |
| 465 | "lookupByWaveIdHashAndWaveIdIdAndWaveIdDomainAndWaveletIdIdAnd" |
| 466 | "WaveletIdDomainAndBlipBlipid"; |
| 467 | TransportSecurityState::DomainState domain_state; |
| 468 | // Just checks that we don't hit a NOTREACHED. |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 469 | EXPECT_FALSE(state.GetDomainState(kLongName, true, &domain_state)); |
[email protected] | 381e885 | 2011-04-14 14:30:58 | [diff] [blame] | 470 | } |
| 471 | |
[email protected] | 938d6a3 | 2011-04-25 21:09:38 | [diff] [blame] | 472 | TEST_F(TransportSecurityStateTest, BuiltinCertPins) { |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 473 | TransportSecurityState state; |
[email protected] | 938d6a3 | 2011-04-25 21:09:38 | [diff] [blame] | 474 | TransportSecurityState::DomainState domain_state; |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 475 | |
| 476 | EXPECT_TRUE(state.GetDomainState("chrome.google.com", true, &domain_state)); |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 477 | EXPECT_TRUE(HasPublicKeyPins("chrome.google.com")); |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 478 | |
[email protected] | ede0321 | 2012-09-07 12:52:26 | [diff] [blame] | 479 | HashValueVector hashes; |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 480 | // Checks that a built-in list does exist. |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 481 | EXPECT_FALSE(domain_state.CheckPublicKeyPins(hashes)); |
| 482 | EXPECT_FALSE(HasPublicKeyPins("www.paypal.com")); |
[email protected] | 6a57111 | 2011-04-28 23:00:03 | [diff] [blame] | 483 | |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 484 | EXPECT_TRUE(HasPublicKeyPins("docs.google.com")); |
| 485 | EXPECT_TRUE(HasPublicKeyPins("1.docs.google.com")); |
| 486 | EXPECT_TRUE(HasPublicKeyPins("sites.google.com")); |
| 487 | EXPECT_TRUE(HasPublicKeyPins("drive.google.com")); |
| 488 | EXPECT_TRUE(HasPublicKeyPins("spreadsheets.google.com")); |
| 489 | EXPECT_TRUE(HasPublicKeyPins("health.google.com")); |
| 490 | EXPECT_TRUE(HasPublicKeyPins("checkout.google.com")); |
| 491 | EXPECT_TRUE(HasPublicKeyPins("appengine.google.com")); |
| 492 | EXPECT_TRUE(HasPublicKeyPins("market.android.com")); |
| 493 | EXPECT_TRUE(HasPublicKeyPins("encrypted.google.com")); |
| 494 | EXPECT_TRUE(HasPublicKeyPins("accounts.google.com")); |
| 495 | EXPECT_TRUE(HasPublicKeyPins("profiles.google.com")); |
| 496 | EXPECT_TRUE(HasPublicKeyPins("mail.google.com")); |
| 497 | EXPECT_TRUE(HasPublicKeyPins("chatenabled.mail.google.com")); |
| 498 | EXPECT_TRUE(HasPublicKeyPins("talkgadget.google.com")); |
| 499 | EXPECT_TRUE(HasPublicKeyPins("hostedtalkgadget.google.com")); |
| 500 | EXPECT_TRUE(HasPublicKeyPins("talk.google.com")); |
| 501 | EXPECT_TRUE(HasPublicKeyPins("plus.google.com")); |
| 502 | EXPECT_TRUE(HasPublicKeyPins("groups.google.com")); |
| 503 | EXPECT_TRUE(HasPublicKeyPins("apis.google.com")); |
[email protected] | 627d03cc | 2011-10-19 18:36:22 | [diff] [blame] | 504 | |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 505 | EXPECT_TRUE(HasPublicKeyPins("ssl.gstatic.com")); |
| 506 | EXPECT_FALSE(HasPublicKeyPins("www.gstatic.com")); |
| 507 | EXPECT_TRUE(HasPublicKeyPins("ssl.google-analytics.com")); |
| 508 | EXPECT_TRUE(HasPublicKeyPins("www.googleplex.com")); |
[email protected] | 7ccf34e | 2011-10-04 18:29:29 | [diff] [blame] | 509 | |
[email protected] | 3f0bc94 | 2011-11-09 20:05:13 | [diff] [blame] | 510 | // Disabled in order to help track down pinning failures --agl |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 511 | EXPECT_TRUE(HasPublicKeyPins("twitter.com")); |
| 512 | EXPECT_FALSE(HasPublicKeyPins("foo.twitter.com")); |
| 513 | EXPECT_TRUE(HasPublicKeyPins("www.twitter.com")); |
| 514 | EXPECT_TRUE(HasPublicKeyPins("api.twitter.com")); |
| 515 | EXPECT_TRUE(HasPublicKeyPins("oauth.twitter.com")); |
| 516 | EXPECT_TRUE(HasPublicKeyPins("mobile.twitter.com")); |
| 517 | EXPECT_TRUE(HasPublicKeyPins("dev.twitter.com")); |
| 518 | EXPECT_TRUE(HasPublicKeyPins("business.twitter.com")); |
| 519 | EXPECT_TRUE(HasPublicKeyPins("platform.twitter.com")); |
| 520 | EXPECT_TRUE(HasPublicKeyPins("si0.twimg.com")); |
| 521 | EXPECT_TRUE(HasPublicKeyPins("twimg0-a.akamaihd.net")); |
[email protected] | dee9ae9 | 2011-04-26 03:58:30 | [diff] [blame] | 522 | } |
| 523 | |
[email protected] | 5f15ed6 | 2011-11-02 15:07:08 | [diff] [blame] | 524 | static bool AddHash(const std::string& type_and_base64, |
[email protected] | ede0321 | 2012-09-07 12:52:26 | [diff] [blame] | 525 | HashValueVector* out) { |
| 526 | HashValue hash; |
[email protected] | 6ed72be | 2013-01-08 22:07:33 | [diff] [blame] | 527 | if (!hash.FromString(type_and_base64)) |
[email protected] | ede0321 | 2012-09-07 12:52:26 | [diff] [blame] | 528 | return false; |
| 529 | |
| 530 | out->push_back(hash); |
| 531 | return true; |
[email protected] | 5f15ed6 | 2011-11-02 15:07:08 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | TEST_F(TransportSecurityStateTest, PinValidationWithRejectedCerts) { |
| 535 | // kGoodPath is plus.google.com via Google Internet Authority. |
| 536 | static const char* kGoodPath[] = { |
| 537 | "sha1/4BjDjn8v2lWeUFQnqSs0BgbIcrU=", |
| 538 | "sha1/QMVAHW+MuvCLAO3vse6H0AWzuc0=", |
| 539 | "sha1/SOZo+SvSspXXR9gjIBBPM5iQn9Q=", |
| 540 | NULL, |
| 541 | }; |
| 542 | |
| 543 | // kBadPath is plus.google.com via Trustcenter, which contains a required |
| 544 | // certificate (Equifax root), but also an excluded certificate |
| 545 | // (Trustcenter). |
| 546 | static const char* kBadPath[] = { |
| 547 | "sha1/4BjDjn8v2lWeUFQnqSs0BgbIcrU=", |
| 548 | "sha1/gzuEEAB/bkqdQS3EIjk2by7lW+k=", |
| 549 | "sha1/SOZo+SvSspXXR9gjIBBPM5iQn9Q=", |
| 550 | NULL, |
| 551 | }; |
| 552 | |
[email protected] | ede0321 | 2012-09-07 12:52:26 | [diff] [blame] | 553 | HashValueVector good_hashes, bad_hashes; |
[email protected] | 5f15ed6 | 2011-11-02 15:07:08 | [diff] [blame] | 554 | |
| 555 | for (size_t i = 0; kGoodPath[i]; i++) { |
| 556 | EXPECT_TRUE(AddHash(kGoodPath[i], &good_hashes)); |
| 557 | } |
| 558 | for (size_t i = 0; kBadPath[i]; i++) { |
| 559 | EXPECT_TRUE(AddHash(kBadPath[i], &bad_hashes)); |
| 560 | } |
| 561 | |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 562 | TransportSecurityState state; |
[email protected] | 5f15ed6 | 2011-11-02 15:07:08 | [diff] [blame] | 563 | TransportSecurityState::DomainState domain_state; |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 564 | EXPECT_TRUE(state.GetDomainState("plus.google.com", true, &domain_state)); |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 565 | EXPECT_TRUE(domain_state.HasPublicKeyPins()); |
[email protected] | 5f15ed6 | 2011-11-02 15:07:08 | [diff] [blame] | 566 | |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 567 | EXPECT_TRUE(domain_state.CheckPublicKeyPins(good_hashes)); |
| 568 | EXPECT_FALSE(domain_state.CheckPublicKeyPins(bad_hashes)); |
[email protected] | 5f15ed6 | 2011-11-02 15:07:08 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | TEST_F(TransportSecurityStateTest, PinValidationWithoutRejectedCerts) { |
| 572 | // kGoodPath is blog.torproject.org. |
| 573 | static const char* kGoodPath[] = { |
| 574 | "sha1/m9lHYJYke9k0GtVZ+bXSQYE8nDI=", |
| 575 | "sha1/o5OZxATDsgmwgcIfIWIneMJ0jkw=", |
| 576 | "sha1/wHqYaI2J+6sFZAwRfap9ZbjKzE4=", |
| 577 | NULL, |
| 578 | }; |
| 579 | |
| 580 | // kBadPath is plus.google.com via Trustcenter, which is utterly wrong for |
| 581 | // torproject.org. |
| 582 | static const char* kBadPath[] = { |
| 583 | "sha1/4BjDjn8v2lWeUFQnqSs0BgbIcrU=", |
| 584 | "sha1/gzuEEAB/bkqdQS3EIjk2by7lW+k=", |
| 585 | "sha1/SOZo+SvSspXXR9gjIBBPM5iQn9Q=", |
| 586 | NULL, |
| 587 | }; |
| 588 | |
[email protected] | ede0321 | 2012-09-07 12:52:26 | [diff] [blame] | 589 | HashValueVector good_hashes, bad_hashes; |
[email protected] | 5f15ed6 | 2011-11-02 15:07:08 | [diff] [blame] | 590 | |
| 591 | for (size_t i = 0; kGoodPath[i]; i++) { |
| 592 | EXPECT_TRUE(AddHash(kGoodPath[i], &good_hashes)); |
| 593 | } |
| 594 | for (size_t i = 0; kBadPath[i]; i++) { |
| 595 | EXPECT_TRUE(AddHash(kBadPath[i], &bad_hashes)); |
| 596 | } |
| 597 | |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 598 | TransportSecurityState state; |
[email protected] | 5f15ed6 | 2011-11-02 15:07:08 | [diff] [blame] | 599 | TransportSecurityState::DomainState domain_state; |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 600 | EXPECT_TRUE(state.GetDomainState("blog.torproject.org", true, &domain_state)); |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 601 | EXPECT_TRUE(domain_state.HasPublicKeyPins()); |
[email protected] | 5f15ed6 | 2011-11-02 15:07:08 | [diff] [blame] | 602 | |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 603 | EXPECT_TRUE(domain_state.CheckPublicKeyPins(good_hashes)); |
| 604 | EXPECT_FALSE(domain_state.CheckPublicKeyPins(bad_hashes)); |
[email protected] | 5f15ed6 | 2011-11-02 15:07:08 | [diff] [blame] | 605 | } |
| 606 | |
[email protected] | ede0321 | 2012-09-07 12:52:26 | [diff] [blame] | 607 | TEST_F(TransportSecurityStateTest, PinValidationWithRejectedCertsMixedHashes) { |
| 608 | static const char* ee_sha1 = "sha1/4BjDjn8v2lWeUFQnqSs0BgbIcrU="; |
| 609 | static const char* ee_sha256 = |
| 610 | "sha256/sRJBQqWhpaKIGcc1NA7/jJ4vgWj+47oYfyU7waOS1+I="; |
| 611 | static const char* google_1024_sha1 = "sha1/QMVAHW+MuvCLAO3vse6H0AWzuc0="; |
| 612 | static const char* google_1024_sha256 = |
| 613 | "sha256/trlUMquuV/4CDLK3T0+fkXPIxwivyecyrOIyeQR8bQU="; |
| 614 | static const char* equifax_sha1 = "sha1/SOZo+SvSspXXR9gjIBBPM5iQn9Q="; |
| 615 | static const char* equifax_sha256 = |
| 616 | "sha256//1aAzXOlcD2gSBegdf1GJQanNQbEuBoVg+9UlHjSZHY="; |
| 617 | static const char* trustcenter_sha1 = "sha1/gzuEEAB/bkqdQS3EIjk2by7lW+k="; |
| 618 | static const char* trustcenter_sha256 = |
| 619 | "sha256/Dq58KIA4NMLsboWMLU8/aTREzaAGEFW+EtUule8dd/M="; |
| 620 | |
| 621 | // Good chains for plus.google.com chain up through google_1024_sha{1,256} |
| 622 | // to equifax_sha{1,256}. Bad chains chain up to Equifax through |
| 623 | // trustcenter_sha{1,256}, which is a blacklisted key. Even though Equifax |
| 624 | // and Google1024 are known-good, the blacklistedness of Trustcenter |
| 625 | // should override and cause pin validation failure. |
| 626 | |
| 627 | TransportSecurityState state; |
| 628 | TransportSecurityState::DomainState domain_state; |
| 629 | EXPECT_TRUE(state.GetDomainState("plus.google.com", true, &domain_state)); |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 630 | EXPECT_TRUE(domain_state.HasPublicKeyPins()); |
[email protected] | ede0321 | 2012-09-07 12:52:26 | [diff] [blame] | 631 | |
| 632 | // The statically-defined pins are all SHA-1, so we add some SHA-256 pins |
| 633 | // manually: |
| 634 | EXPECT_TRUE(AddHash(google_1024_sha256, &domain_state.static_spki_hashes)); |
| 635 | EXPECT_TRUE(AddHash(trustcenter_sha256, |
| 636 | &domain_state.bad_static_spki_hashes)); |
| 637 | |
| 638 | // Try an all-good SHA1 chain. |
| 639 | HashValueVector validated_chain; |
| 640 | EXPECT_TRUE(AddHash(ee_sha1, &validated_chain)); |
| 641 | EXPECT_TRUE(AddHash(google_1024_sha1, &validated_chain)); |
| 642 | EXPECT_TRUE(AddHash(equifax_sha1, &validated_chain)); |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 643 | EXPECT_TRUE(domain_state.CheckPublicKeyPins(validated_chain)); |
[email protected] | ede0321 | 2012-09-07 12:52:26 | [diff] [blame] | 644 | |
| 645 | // Try an all-bad SHA1 chain. |
| 646 | validated_chain.clear(); |
| 647 | EXPECT_TRUE(AddHash(ee_sha1, &validated_chain)); |
| 648 | EXPECT_TRUE(AddHash(trustcenter_sha1, &validated_chain)); |
| 649 | EXPECT_TRUE(AddHash(equifax_sha1, &validated_chain)); |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 650 | EXPECT_FALSE(domain_state.CheckPublicKeyPins(validated_chain)); |
[email protected] | ede0321 | 2012-09-07 12:52:26 | [diff] [blame] | 651 | |
| 652 | // Try an all-good SHA-256 chain. |
| 653 | validated_chain.clear(); |
| 654 | EXPECT_TRUE(AddHash(ee_sha256, &validated_chain)); |
| 655 | EXPECT_TRUE(AddHash(google_1024_sha256, &validated_chain)); |
| 656 | EXPECT_TRUE(AddHash(equifax_sha256, &validated_chain)); |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 657 | EXPECT_TRUE(domain_state.CheckPublicKeyPins(validated_chain)); |
[email protected] | ede0321 | 2012-09-07 12:52:26 | [diff] [blame] | 658 | |
| 659 | // Try an all-bad SHA-256 chain. |
| 660 | validated_chain.clear(); |
| 661 | EXPECT_TRUE(AddHash(ee_sha256, &validated_chain)); |
| 662 | EXPECT_TRUE(AddHash(trustcenter_sha256, &validated_chain)); |
| 663 | EXPECT_TRUE(AddHash(equifax_sha256, &validated_chain)); |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 664 | EXPECT_FALSE(domain_state.CheckPublicKeyPins(validated_chain)); |
[email protected] | ede0321 | 2012-09-07 12:52:26 | [diff] [blame] | 665 | |
| 666 | // Try a mixed-hash good chain. |
| 667 | validated_chain.clear(); |
| 668 | EXPECT_TRUE(AddHash(ee_sha256, &validated_chain)); |
| 669 | EXPECT_TRUE(AddHash(google_1024_sha1, &validated_chain)); |
| 670 | EXPECT_TRUE(AddHash(equifax_sha256, &validated_chain)); |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 671 | EXPECT_TRUE(domain_state.CheckPublicKeyPins(validated_chain)); |
[email protected] | ede0321 | 2012-09-07 12:52:26 | [diff] [blame] | 672 | |
| 673 | // Try a mixed-hash bad chain. |
| 674 | validated_chain.clear(); |
| 675 | EXPECT_TRUE(AddHash(ee_sha1, &validated_chain)); |
| 676 | EXPECT_TRUE(AddHash(trustcenter_sha256, &validated_chain)); |
| 677 | EXPECT_TRUE(AddHash(equifax_sha1, &validated_chain)); |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 678 | EXPECT_FALSE(domain_state.CheckPublicKeyPins(validated_chain)); |
[email protected] | ede0321 | 2012-09-07 12:52:26 | [diff] [blame] | 679 | |
| 680 | // Try a chain with all good hashes. |
| 681 | validated_chain.clear(); |
| 682 | EXPECT_TRUE(AddHash(ee_sha1, &validated_chain)); |
| 683 | EXPECT_TRUE(AddHash(google_1024_sha1, &validated_chain)); |
| 684 | EXPECT_TRUE(AddHash(equifax_sha1, &validated_chain)); |
| 685 | EXPECT_TRUE(AddHash(ee_sha256, &validated_chain)); |
| 686 | EXPECT_TRUE(AddHash(google_1024_sha256, &validated_chain)); |
| 687 | EXPECT_TRUE(AddHash(equifax_sha256, &validated_chain)); |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 688 | EXPECT_TRUE(domain_state.CheckPublicKeyPins(validated_chain)); |
[email protected] | ede0321 | 2012-09-07 12:52:26 | [diff] [blame] | 689 | |
| 690 | // Try a chain with all bad hashes. |
| 691 | validated_chain.clear(); |
| 692 | EXPECT_TRUE(AddHash(ee_sha1, &validated_chain)); |
| 693 | EXPECT_TRUE(AddHash(trustcenter_sha1, &validated_chain)); |
| 694 | EXPECT_TRUE(AddHash(equifax_sha1, &validated_chain)); |
| 695 | EXPECT_TRUE(AddHash(ee_sha256, &validated_chain)); |
| 696 | EXPECT_TRUE(AddHash(trustcenter_sha256, &validated_chain)); |
| 697 | EXPECT_TRUE(AddHash(equifax_sha256, &validated_chain)); |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 698 | EXPECT_FALSE(domain_state.CheckPublicKeyPins(validated_chain)); |
[email protected] | ede0321 | 2012-09-07 12:52:26 | [diff] [blame] | 699 | } |
| 700 | |
[email protected] | dee9ae9 | 2011-04-26 03:58:30 | [diff] [blame] | 701 | TEST_F(TransportSecurityStateTest, OptionalHSTSCertPins) { |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 702 | TransportSecurityState state; |
[email protected] | dee9ae9 | 2011-04-26 03:58:30 | [diff] [blame] | 703 | TransportSecurityState::DomainState domain_state; |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 704 | |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 705 | EXPECT_FALSE(ShouldRedirect("www.google-analytics.com")); |
[email protected] | 938d6a3 | 2011-04-25 21:09:38 | [diff] [blame] | 706 | |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 707 | EXPECT_FALSE(HasPublicKeyPins("www.google-analytics.com", false)); |
| 708 | EXPECT_TRUE(HasPublicKeyPins("www.google-analytics.com")); |
| 709 | EXPECT_TRUE(HasPublicKeyPins("google.com")); |
| 710 | EXPECT_TRUE(HasPublicKeyPins("www.google.com")); |
| 711 | EXPECT_TRUE(HasPublicKeyPins("mail-attachment.googleusercontent.com")); |
| 712 | EXPECT_TRUE(HasPublicKeyPins("www.youtube.com")); |
| 713 | EXPECT_TRUE(HasPublicKeyPins("i.ytimg.com")); |
| 714 | EXPECT_TRUE(HasPublicKeyPins("googleapis.com")); |
| 715 | EXPECT_TRUE(HasPublicKeyPins("ajax.googleapis.com")); |
| 716 | EXPECT_TRUE(HasPublicKeyPins("googleadservices.com")); |
| 717 | EXPECT_TRUE(HasPublicKeyPins("pagead2.googleadservices.com")); |
| 718 | EXPECT_TRUE(HasPublicKeyPins("googlecode.com")); |
| 719 | EXPECT_TRUE(HasPublicKeyPins("kibbles.googlecode.com")); |
| 720 | EXPECT_TRUE(HasPublicKeyPins("appspot.com")); |
| 721 | EXPECT_TRUE(HasPublicKeyPins("googlesyndication.com")); |
| 722 | EXPECT_TRUE(HasPublicKeyPins("doubleclick.net")); |
| 723 | EXPECT_TRUE(HasPublicKeyPins("ad.doubleclick.net")); |
| 724 | EXPECT_FALSE(HasPublicKeyPins("learn.doubleclick.net")); |
| 725 | EXPECT_TRUE(HasPublicKeyPins("a.googlegroups.com")); |
| 726 | EXPECT_FALSE(HasPublicKeyPins("a.googlegroups.com", false)); |
[email protected] | d7cf831a | 2011-05-02 22:18:48 | [diff] [blame] | 727 | } |
| 728 | |
[email protected] | 55cb2118 | 2011-05-09 19:55:00 | [diff] [blame] | 729 | TEST_F(TransportSecurityStateTest, OverrideBuiltins) { |
[email protected] | 843329e | 2013-01-22 22:06:09 | [diff] [blame] | 730 | EXPECT_TRUE(HasPublicKeyPins("google.com")); |
[email protected] | dc694c3 | 2011-11-29 20:00:49 | [diff] [blame] | 731 | EXPECT_FALSE(ShouldRedirect("google.com")); |
| 732 | EXPECT_FALSE(ShouldRedirect("www.google.com")); |
| 733 | |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 734 | TransportSecurityState state; |
[email protected] | 55cb2118 | 2011-05-09 19:55:00 | [diff] [blame] | 735 | TransportSecurityState::DomainState domain_state; |
[email protected] | 55cb2118 | 2011-05-09 19:55:00 | [diff] [blame] | 736 | const base::Time current_time(base::Time::Now()); |
| 737 | const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 738 | domain_state.upgrade_expiry = expiry; |
[email protected] | 474f079e | 2013-03-02 19:11:20 | [diff] [blame] | 739 | EnableHost(&state, "www.google.com", domain_state); |
[email protected] | 55cb2118 | 2011-05-09 19:55:00 | [diff] [blame] | 740 | |
[email protected] | f43b89f3 | 2012-05-01 19:39:48 | [diff] [blame] | 741 | EXPECT_TRUE(state.GetDomainState("www.google.com", true, &domain_state)); |
[email protected] | 55cb2118 | 2011-05-09 19:55:00 | [diff] [blame] | 742 | } |
| 743 | |
[email protected] | ae780c8 | 2011-09-20 19:39:06 | [diff] [blame] | 744 | static const uint8 kSidePinLeafSPKI[] = { |
| 745 | 0x30, 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, |
| 746 | 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48, 0x02, 0x41, 0x00, 0xe4, |
| 747 | 0x1d, 0xcc, 0xf2, 0x92, 0xe7, 0x7a, 0xc6, 0x36, 0xf7, 0x1a, 0x62, 0x31, 0x7d, |
| 748 | 0x37, 0xea, 0x0d, 0xa2, 0xa8, 0x12, 0x2b, 0xc2, 0x1c, 0x82, 0x3e, 0xa5, 0x70, |
| 749 | 0x4a, 0x83, 0x5d, 0x9b, 0x84, 0x82, 0x70, 0xa4, 0x88, 0x98, 0x98, 0x41, 0x29, |
| 750 | 0x31, 0xcb, 0x6e, 0x2a, 0x54, 0x65, 0x14, 0x60, 0xcc, 0x00, 0xe8, 0x10, 0x30, |
| 751 | 0x0a, 0x4a, 0xd1, 0xa7, 0x52, 0xfe, 0x2d, 0x31, 0x2a, 0x1d, 0x0d, 0x02, 0x03, |
| 752 | 0x01, 0x00, 0x01, |
| 753 | }; |
| 754 | |
| 755 | static const uint8 kSidePinInfo[] = { |
| 756 | 0x01, 0x00, 0x53, 0x50, 0x49, 0x4e, 0xa0, 0x00, 0x03, 0x00, 0x53, 0x49, 0x47, |
| 757 | 0x00, 0x50, 0x55, 0x42, 0x4b, 0x41, 0x4c, 0x47, 0x4f, 0x47, 0x00, 0x41, 0x00, |
| 758 | 0x04, 0x00, 0x30, 0x45, 0x02, 0x21, 0x00, 0xfb, 0x26, 0xd5, 0xe8, 0x76, 0x35, |
| 759 | 0x96, 0x6d, 0x91, 0x9b, 0x5b, 0x27, 0xe6, 0x09, 0x1c, 0x7b, 0x6c, 0xcd, 0xc8, |
| 760 | 0x10, 0x25, 0x95, 0xc0, 0xa5, 0xf6, 0x6c, 0x6f, 0xfb, 0x59, 0x1e, 0x2d, 0xf4, |
| 761 | 0x02, 0x20, 0x33, 0x0a, 0xf8, 0x8b, 0x3e, 0xc4, 0xca, 0x75, 0x28, 0xdf, 0x5f, |
| 762 | 0xab, 0xe4, 0x46, 0xa0, 0xdd, 0x2d, 0xe5, 0xad, 0xc3, 0x81, 0x44, 0x70, 0xb2, |
| 763 | 0x10, 0x87, 0xe8, 0xc3, 0xd6, 0x6e, 0x12, 0x5d, 0x04, 0x67, 0x0b, 0x7d, 0xf2, |
| 764 | 0x99, 0x75, 0x57, 0x99, 0x3a, 0x98, 0xf8, 0xe4, 0xdf, 0x79, 0xdf, 0x8e, 0x02, |
| 765 | 0x2c, 0xbe, 0xd8, 0xfd, 0x75, 0x80, 0x18, 0xb1, 0x6f, 0x43, 0xd9, 0x8a, 0x79, |
| 766 | 0xc3, 0x6e, 0x18, 0xdf, 0x79, 0xc0, 0x59, 0xab, 0xd6, 0x77, 0x37, 0x6a, 0x94, |
| 767 | 0x5a, 0x7e, 0xfb, 0xa9, 0xc5, 0x54, 0x14, 0x3a, 0x7b, 0x97, 0x17, 0x2a, 0xb6, |
| 768 | 0x1e, 0x59, 0x4f, 0x2f, 0xb1, 0x15, 0x1a, 0x34, 0x50, 0x32, 0x35, 0x36, |
| 769 | }; |
| 770 | |
| 771 | static const uint8 kSidePinExpectedHash[20] = { |
| 772 | 0xb5, 0x91, 0x66, 0x47, 0x43, 0x16, 0x62, 0x86, 0xd4, 0x1e, 0x5d, 0x36, 0xe1, |
| 773 | 0xc4, 0x09, 0x3d, 0x2d, 0x1d, 0xea, 0x1e, |
| 774 | }; |
| 775 | |
[email protected] | cb8d281 | 2011-10-15 05:07:07 | [diff] [blame] | 776 | TEST_F(TransportSecurityStateTest, GooglePinnedProperties) { |
| 777 | EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( |
| 778 | "www.example.com", true)); |
| 779 | EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( |
| 780 | "www.paypal.com", true)); |
| 781 | EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( |
| 782 | "mail.twitter.com", true)); |
| 783 | EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( |
| 784 | "www.google.com.int", true)); |
| 785 | EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( |
| 786 | "jottit.com", true)); |
| 787 | // learn.doubleclick.net has a more specific match than |
| 788 | // *.doubleclick.com, and has 0 or NULL for its required certs. |
| 789 | // This test ensures that the exact-match-preferred behavior |
| 790 | // works. |
| 791 | EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( |
| 792 | "learn.doubleclick.net", true)); |
| 793 | |
| 794 | EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( |
| 795 | "encrypted.google.com", true)); |
| 796 | EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( |
| 797 | "mail.google.com", true)); |
| 798 | EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( |
| 799 | "accounts.google.com", true)); |
| 800 | EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( |
| 801 | "doubleclick.net", true)); |
| 802 | EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( |
| 803 | "ad.doubleclick.net", true)); |
| 804 | EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( |
| 805 | "youtube.com", true)); |
| 806 | EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( |
| 807 | "www.profiles.google.com", true)); |
| 808 | EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( |
| 809 | "checkout.google.com", true)); |
| 810 | EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( |
| 811 | "googleadservices.com", true)); |
| 812 | |
| 813 | // Test with sni_enabled false: |
| 814 | EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( |
| 815 | "www.example.com", false)); |
| 816 | EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( |
| 817 | "www.paypal.com", false)); |
| 818 | EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( |
| 819 | "checkout.google.com", false)); |
| 820 | EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( |
| 821 | "googleadservices.com", false)); |
| 822 | |
| 823 | // Test some SNI hosts: |
| 824 | EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( |
| 825 | "gmail.com", true)); |
| 826 | EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( |
| 827 | "googlegroups.com", true)); |
| 828 | EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty( |
| 829 | "www.googlegroups.com", true)); |
| 830 | // Expect to fail for SNI hosts when not searching the SNI list: |
| 831 | EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( |
| 832 | "gmail.com", false)); |
| 833 | EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( |
| 834 | "googlegroups.com", false)); |
| 835 | EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty( |
| 836 | "www.googlegroups.com", false)); |
| 837 | } |
| 838 | |
[email protected] | 2fc4c21 | 2010-03-10 18:59:06 | [diff] [blame] | 839 | } // namespace net |