blob: 05ea015accd5ee37e386c35426e1359c18f56f74 [file] [log] [blame]
[email protected]b7f9fb22011-04-09 20:28:471// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]326e6792009-12-11 21:04:422// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "net/base/transport_security_state.h"
[email protected]5f15ed62011-11-02 15:07:086
7#include "base/base64.h"
8#include "base/sha1.h"
9#include "base/string_piece.h"
[email protected]326e6792009-12-11 21:04:4210#include "testing/gtest/include/gtest/gtest.h"
11
[email protected]06256e52011-09-29 15:08:4812#if defined(USE_OPENSSL)
13#include "crypto/openssl_util.h"
14#else
15#include "crypto/nss_util.h"
16#endif
17
[email protected]2fc4c212010-03-10 18:59:0618namespace net {
19
[email protected]326e6792009-12-11 21:04:4220class TransportSecurityStateTest : public testing::Test {
[email protected]06256e52011-09-29 15:08:4821 virtual void SetUp() {
[email protected]54356432011-10-05 21:49:4222#if defined(USE_OPENSSL)
[email protected]06256e52011-09-29 15:08:4823 crypto::EnsureOpenSSLInit();
[email protected]54356432011-10-05 21:49:4224#else
25 crypto::EnsureNSSInit();
[email protected]06256e52011-09-29 15:08:4826#endif
27 }
[email protected]326e6792009-12-11 21:04:4228};
29
30TEST_F(TransportSecurityStateTest, BogusHeaders) {
31 int max_age = 42;
32 bool include_subdomains = false;
33
[email protected]2fc4c212010-03-10 18:59:0634 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4235 "", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0636 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4237 " ", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0638 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4239 "abc", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0640 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4241 " abc", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0642 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4243 " abc ", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0644 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4245 "max-age", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0646 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4247 " max-age", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0648 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4249 " max-age ", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0650 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4251 "max-age=", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0652 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4253 " max-age=", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0654 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4255 " max-age =", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0656 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4257 " max-age= ", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0658 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4259 " max-age = ", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0660 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4261 " max-age = xy", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0662 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4263 " max-age = 3488a923", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0664 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4265 "max-age=3488a923 ", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0666 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4267 "max-ag=3488923", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0668 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4269 "max-aged=3488923", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0670 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4271 "max-age==3488923", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0672 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4273 "amax-age=3488923", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0674 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4275 "max-age=-3488923", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0676 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4277 "max-age=3488923;", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0678 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4279 "max-age=3488923 e", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0680 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4281 "max-age=3488923 includesubdomain", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0682 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4283 "max-age=3488923includesubdomains", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0684 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4285 "max-age=3488923=includesubdomains", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0686 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4287 "max-age=3488923 includesubdomainx", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0688 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4289 "max-age=3488923 includesubdomain=", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0690 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4291 "max-age=3488923 includesubdomain=true", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0692 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4293 "max-age=3488923 includesubdomainsx", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0694 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4295 "max-age=3488923 includesubdomains x", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0696 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4297 "max-age=34889.23 includesubdomains", &max_age, &include_subdomains));
[email protected]2fc4c212010-03-10 18:59:0698 EXPECT_FALSE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:4299 "max-age=34889 includesubdomains", &max_age, &include_subdomains));
100
101 EXPECT_EQ(max_age, 42);
102 EXPECT_FALSE(include_subdomains);
103}
104
105TEST_F(TransportSecurityStateTest, ValidHeaders) {
106 int max_age = 42;
107 bool include_subdomains = true;
108
[email protected]2fc4c212010-03-10 18:59:06109 EXPECT_TRUE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:42110 "max-age=243", &max_age, &include_subdomains));
111 EXPECT_EQ(max_age, 243);
112 EXPECT_FALSE(include_subdomains);
113
[email protected]2fc4c212010-03-10 18:59:06114 EXPECT_TRUE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:42115 " Max-agE = 567", &max_age, &include_subdomains));
116 EXPECT_EQ(max_age, 567);
117 EXPECT_FALSE(include_subdomains);
118
[email protected]2fc4c212010-03-10 18:59:06119 EXPECT_TRUE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:42120 " mAx-aGe = 890 ", &max_age, &include_subdomains));
121 EXPECT_EQ(max_age, 890);
122 EXPECT_FALSE(include_subdomains);
123
[email protected]2fc4c212010-03-10 18:59:06124 EXPECT_TRUE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:42125 "max-age=123;incLudesUbdOmains", &max_age, &include_subdomains));
126 EXPECT_EQ(max_age, 123);
127 EXPECT_TRUE(include_subdomains);
128
[email protected]2fc4c212010-03-10 18:59:06129 EXPECT_TRUE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:42130 "max-age=394082; incLudesUbdOmains", &max_age, &include_subdomains));
131 EXPECT_EQ(max_age, 394082);
132 EXPECT_TRUE(include_subdomains);
133
[email protected]2fc4c212010-03-10 18:59:06134 EXPECT_TRUE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:42135 "max-age=39408299 ;incLudesUbdOmains", &max_age, &include_subdomains));
[email protected]337a4052010-11-30 15:09:33136 EXPECT_EQ(max_age,
137 std::min(TransportSecurityState::kMaxHSTSAgeSecs, 39408299l));
[email protected]326e6792009-12-11 21:04:42138 EXPECT_TRUE(include_subdomains);
139
[email protected]2fc4c212010-03-10 18:59:06140 EXPECT_TRUE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:42141 "max-age=394082038 ; incLudesUbdOmains", &max_age, &include_subdomains));
[email protected]337a4052010-11-30 15:09:33142 EXPECT_EQ(max_age,
143 std::min(TransportSecurityState::kMaxHSTSAgeSecs, 394082038l));
[email protected]326e6792009-12-11 21:04:42144 EXPECT_TRUE(include_subdomains);
145
[email protected]2fc4c212010-03-10 18:59:06146 EXPECT_TRUE(TransportSecurityState::ParseHeader(
[email protected]326e6792009-12-11 21:04:42147 " max-age=0 ; incLudesUbdOmains ", &max_age, &include_subdomains));
148 EXPECT_EQ(max_age, 0);
149 EXPECT_TRUE(include_subdomains);
[email protected]337a4052010-11-30 15:09:33150
151 EXPECT_TRUE(TransportSecurityState::ParseHeader(
152 " max-age=999999999999999999999999999999999999999999999 ;"
153 " incLudesUbdOmains ",
154 &max_age, &include_subdomains));
155 EXPECT_EQ(max_age, TransportSecurityState::kMaxHSTSAgeSecs);
156 EXPECT_TRUE(include_subdomains);
[email protected]326e6792009-12-11 21:04:42157}
158
159TEST_F(TransportSecurityStateTest, SimpleMatches) {
[email protected]edbc4f92011-09-27 21:04:49160 TransportSecurityState state("");
[email protected]2fc4c212010-03-10 18:59:06161 TransportSecurityState::DomainState domain_state;
[email protected]326e6792009-12-11 21:04:42162 const base::Time current_time(base::Time::Now());
163 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000);
164
[email protected]edbc4f92011-09-27 21:04:49165 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "yahoo.com", true));
[email protected]326e6792009-12-11 21:04:42166 domain_state.expiry = expiry;
[email protected]edbc4f92011-09-27 21:04:49167 state.EnableHost("yahoo.com", domain_state);
168 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "yahoo.com", true));
[email protected]326e6792009-12-11 21:04:42169}
170
171TEST_F(TransportSecurityStateTest, MatchesCase1) {
[email protected]edbc4f92011-09-27 21:04:49172 TransportSecurityState state("");
[email protected]2fc4c212010-03-10 18:59:06173 TransportSecurityState::DomainState domain_state;
[email protected]326e6792009-12-11 21:04:42174 const base::Time current_time(base::Time::Now());
175 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000);
176
[email protected]edbc4f92011-09-27 21:04:49177 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "yahoo.com", true));
[email protected]326e6792009-12-11 21:04:42178 domain_state.expiry = expiry;
[email protected]edbc4f92011-09-27 21:04:49179 state.EnableHost("YAhoo.coM", domain_state);
180 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "yahoo.com", true));
[email protected]326e6792009-12-11 21:04:42181}
182
183TEST_F(TransportSecurityStateTest, MatchesCase2) {
[email protected]edbc4f92011-09-27 21:04:49184 TransportSecurityState state("");
[email protected]2fc4c212010-03-10 18:59:06185 TransportSecurityState::DomainState domain_state;
[email protected]326e6792009-12-11 21:04:42186 const base::Time current_time(base::Time::Now());
187 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000);
188
[email protected]edbc4f92011-09-27 21:04:49189 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "YAhoo.coM", true));
[email protected]326e6792009-12-11 21:04:42190 domain_state.expiry = expiry;
[email protected]edbc4f92011-09-27 21:04:49191 state.EnableHost("yahoo.com", domain_state);
192 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "YAhoo.coM", true));
[email protected]326e6792009-12-11 21:04:42193}
194
195TEST_F(TransportSecurityStateTest, SubdomainMatches) {
[email protected]edbc4f92011-09-27 21:04:49196 TransportSecurityState state("");
[email protected]2fc4c212010-03-10 18:59:06197 TransportSecurityState::DomainState domain_state;
[email protected]326e6792009-12-11 21:04:42198 const base::Time current_time(base::Time::Now());
199 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000);
200
[email protected]edbc4f92011-09-27 21:04:49201 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "yahoo.com", true));
[email protected]326e6792009-12-11 21:04:42202 domain_state.expiry = expiry;
203 domain_state.include_subdomains = true;
[email protected]edbc4f92011-09-27 21:04:49204 state.EnableHost("yahoo.com", domain_state);
205 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "yahoo.com", true));
206 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "foo.yahoo.com", true));
207 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
208 "foo.bar.yahoo.com",
209 true));
210 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
211 "foo.bar.baz.yahoo.com",
212 true));
213 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "com", true));
[email protected]326e6792009-12-11 21:04:42214}
215
216TEST_F(TransportSecurityStateTest, Serialise1) {
[email protected]edbc4f92011-09-27 21:04:49217 TransportSecurityState state("");
[email protected]326e6792009-12-11 21:04:42218 std::string output;
[email protected]4d0d8082010-02-23 01:03:10219 bool dirty;
[email protected]edbc4f92011-09-27 21:04:49220 state.Serialise(&output);
221 EXPECT_TRUE(state.LoadEntries(output, &dirty));
[email protected]4d0d8082010-02-23 01:03:10222 EXPECT_FALSE(dirty);
[email protected]326e6792009-12-11 21:04:42223}
224
225TEST_F(TransportSecurityStateTest, Serialise2) {
[email protected]edbc4f92011-09-27 21:04:49226 TransportSecurityState state("");
[email protected]2fc4c212010-03-10 18:59:06227 TransportSecurityState::DomainState domain_state;
[email protected]326e6792009-12-11 21:04:42228 const base::Time current_time(base::Time::Now());
229 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000);
230
[email protected]edbc4f92011-09-27 21:04:49231 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "yahoo.com", true));
[email protected]2fc4c212010-03-10 18:59:06232 domain_state.mode = TransportSecurityState::DomainState::MODE_STRICT;
[email protected]326e6792009-12-11 21:04:42233 domain_state.expiry = expiry;
234 domain_state.include_subdomains = true;
[email protected]edbc4f92011-09-27 21:04:49235 state.EnableHost("yahoo.com", domain_state);
[email protected]326e6792009-12-11 21:04:42236
237 std::string output;
[email protected]4d0d8082010-02-23 01:03:10238 bool dirty;
[email protected]edbc4f92011-09-27 21:04:49239 state.Serialise(&output);
240 EXPECT_TRUE(state.LoadEntries(output, &dirty));
[email protected]326e6792009-12-11 21:04:42241
[email protected]edbc4f92011-09-27 21:04:49242 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "yahoo.com", true));
[email protected]2fc4c212010-03-10 18:59:06243 EXPECT_EQ(domain_state.mode, TransportSecurityState::DomainState::MODE_STRICT);
[email protected]edbc4f92011-09-27 21:04:49244 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "foo.yahoo.com", true));
[email protected]2fc4c212010-03-10 18:59:06245 EXPECT_EQ(domain_state.mode, TransportSecurityState::DomainState::MODE_STRICT);
[email protected]edbc4f92011-09-27 21:04:49246 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
247 "foo.bar.yahoo.com",
248 true));
[email protected]2fc4c212010-03-10 18:59:06249 EXPECT_EQ(domain_state.mode, TransportSecurityState::DomainState::MODE_STRICT);
[email protected]edbc4f92011-09-27 21:04:49250 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
251 "foo.bar.baz.yahoo.com",
252 true));
[email protected]b7f9fb22011-04-09 20:28:47253 EXPECT_EQ(domain_state.mode, TransportSecurityState::DomainState::MODE_STRICT);
[email protected]edbc4f92011-09-27 21:04:49254 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "com", true));
[email protected]326e6792009-12-11 21:04:42255}
256
[email protected]4d0d8082010-02-23 01:03:10257TEST_F(TransportSecurityStateTest, DeleteSince) {
[email protected]edbc4f92011-09-27 21:04:49258 TransportSecurityState state("");
[email protected]2fc4c212010-03-10 18:59:06259 TransportSecurityState::DomainState domain_state;
[email protected]4d0d8082010-02-23 01:03:10260 const base::Time current_time(base::Time::Now());
261 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000);
262 const base::Time older = current_time - base::TimeDelta::FromSeconds(1000);
263
[email protected]edbc4f92011-09-27 21:04:49264 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "yahoo.com", true));
[email protected]2fc4c212010-03-10 18:59:06265 domain_state.mode = TransportSecurityState::DomainState::MODE_STRICT;
[email protected]4d0d8082010-02-23 01:03:10266 domain_state.expiry = expiry;
[email protected]edbc4f92011-09-27 21:04:49267 state.EnableHost("yahoo.com", domain_state);
[email protected]4d0d8082010-02-23 01:03:10268
[email protected]edbc4f92011-09-27 21:04:49269 state.DeleteSince(expiry);
270 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "yahoo.com", true));
271 state.DeleteSince(older);
272 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "yahoo.com", true));
[email protected]4d0d8082010-02-23 01:03:10273}
274
[email protected]f060be32011-02-17 17:20:28275TEST_F(TransportSecurityStateTest, DeleteHost) {
[email protected]edbc4f92011-09-27 21:04:49276 TransportSecurityState state("");
[email protected]f060be32011-02-17 17:20:28277 TransportSecurityState::DomainState domain_state;
278 const base::Time current_time(base::Time::Now());
279 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000);
280 domain_state.mode = TransportSecurityState::DomainState::MODE_STRICT;
281 domain_state.expiry = expiry;
[email protected]edbc4f92011-09-27 21:04:49282 state.EnableHost("yahoo.com", domain_state);
[email protected]f060be32011-02-17 17:20:28283
[email protected]edbc4f92011-09-27 21:04:49284 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "yahoo.com", true));
285 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "example.com", true));
286 EXPECT_TRUE(state.DeleteHost("yahoo.com"));
287 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "yahoo.com", true));
[email protected]f060be32011-02-17 17:20:28288}
289
[email protected]4d0d8082010-02-23 01:03:10290TEST_F(TransportSecurityStateTest, SerialiseOld) {
[email protected]edbc4f92011-09-27 21:04:49291 TransportSecurityState state("");
[email protected]4d0d8082010-02-23 01:03:10292 // This is an old-style piece of transport state JSON, which has no creation
293 // date.
294 std::string output =
295 "{ "
[email protected]edbc4f92011-09-27 21:04:49296 "\"NiyD+3J1r6z1wjl2n1ALBu94Zj9OsEAMo0kCN8js0Uk=\": {"
297 "\"expiry\": 1266815027.983453, "
298 "\"include_subdomains\": false, "
299 "\"mode\": \"strict\" "
300 "}"
[email protected]4d0d8082010-02-23 01:03:10301 "}";
302 bool dirty;
[email protected]edbc4f92011-09-27 21:04:49303 EXPECT_TRUE(state.LoadEntries(output, &dirty));
[email protected]4d0d8082010-02-23 01:03:10304 EXPECT_TRUE(dirty);
305}
306
[email protected]2fc4c212010-03-10 18:59:06307TEST_F(TransportSecurityStateTest, IsPreloaded) {
[email protected]edbc4f92011-09-27 21:04:49308 TransportSecurityState state("");
[email protected]d7cf831a2011-05-02 22:18:48309
[email protected]2fc4c212010-03-10 18:59:06310 const std::string paypal =
[email protected]f060be32011-02-17 17:20:28311 TransportSecurityState::CanonicalizeHost("paypal.com");
[email protected]2fc4c212010-03-10 18:59:06312 const std::string www_paypal =
[email protected]f060be32011-02-17 17:20:28313 TransportSecurityState::CanonicalizeHost("www.paypal.com");
[email protected]2fc4c212010-03-10 18:59:06314 const std::string a_www_paypal =
[email protected]f060be32011-02-17 17:20:28315 TransportSecurityState::CanonicalizeHost("a.www.paypal.com");
[email protected]2fc4c212010-03-10 18:59:06316 const std::string abc_paypal =
[email protected]f060be32011-02-17 17:20:28317 TransportSecurityState::CanonicalizeHost("a.b.c.paypal.com");
[email protected]2fc4c212010-03-10 18:59:06318 const std::string example =
[email protected]f060be32011-02-17 17:20:28319 TransportSecurityState::CanonicalizeHost("example.com");
[email protected]2fc4c212010-03-10 18:59:06320 const std::string aypal =
[email protected]f060be32011-02-17 17:20:28321 TransportSecurityState::CanonicalizeHost("aypal.com");
[email protected]2fc4c212010-03-10 18:59:06322
[email protected]aa904432011-04-21 00:07:16323 TransportSecurityState::DomainState domain_state;
[email protected]edbc4f92011-09-27 21:04:49324 EXPECT_FALSE(state.IsPreloadedSTS(paypal, true, &domain_state));
325 EXPECT_TRUE(state.IsPreloadedSTS(www_paypal, true, &domain_state));
[email protected]aa904432011-04-21 00:07:16326 EXPECT_FALSE(domain_state.include_subdomains);
[email protected]edbc4f92011-09-27 21:04:49327 EXPECT_FALSE(state.IsPreloadedSTS(a_www_paypal, true, &domain_state));
328 EXPECT_FALSE(state.IsPreloadedSTS(abc_paypal, true, &domain_state));
329 EXPECT_FALSE(state.IsPreloadedSTS(example, true, &domain_state));
330 EXPECT_FALSE(state.IsPreloadedSTS(aypal, true, &domain_state));
[email protected]2fc4c212010-03-10 18:59:06331}
332
333TEST_F(TransportSecurityStateTest, Preloaded) {
[email protected]edbc4f92011-09-27 21:04:49334 TransportSecurityState state("");
[email protected]2fc4c212010-03-10 18:59:06335 TransportSecurityState::DomainState domain_state;
[email protected]edbc4f92011-09-27 21:04:49336 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "paypal.com", true));
337 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "www.paypal.com", true));
[email protected]2fc4c212010-03-10 18:59:06338 EXPECT_EQ(domain_state.mode,
339 TransportSecurityState::DomainState::MODE_STRICT);
[email protected]f060be32011-02-17 17:20:28340 EXPECT_TRUE(domain_state.preloaded);
[email protected]2fc4c212010-03-10 18:59:06341 EXPECT_FALSE(domain_state.include_subdomains);
[email protected]edbc4f92011-09-27 21:04:49342 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "www2.paypal.com", true));
343 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
344 "a.www.paypal.com",
345 true));
[email protected]f091469f2010-05-05 21:05:28346
[email protected]edbc4f92011-09-27 21:04:49347 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "elanex.biz", true));
348 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "www.elanex.biz", true));
[email protected]f091469f2010-05-05 21:05:28349 EXPECT_EQ(domain_state.mode,
350 TransportSecurityState::DomainState::MODE_STRICT);
[email protected]edbc4f92011-09-27 21:04:49351 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "foo.elanex.biz", true));
352 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
353 "a.foo.elanex.biz",
[email protected]b7f9fb22011-04-09 20:28:47354 true));
[email protected]edbc4f92011-09-27 21:04:49355
356 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
357 "sunshinepress.org",
358 true));
[email protected]0ae0f3e2010-07-26 18:16:31359 EXPECT_EQ(domain_state.mode,
360 TransportSecurityState::DomainState::MODE_STRICT);
[email protected]edbc4f92011-09-27 21:04:49361 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
362 "www.sunshinepress.org",
363 true));
364 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
365 "a.b.sunshinepress.org",
366 true));
367
368 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
369 "www.noisebridge.net",
370 true));
371 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
372 "noisebridge.net",
[email protected]b7f9fb22011-04-09 20:28:47373 true));
[email protected]edbc4f92011-09-27 21:04:49374 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
375 "foo.noisebridge.net",
[email protected]b7f9fb22011-04-09 20:28:47376 true));
[email protected]bee76312011-03-17 18:35:35377
[email protected]edbc4f92011-09-27 21:04:49378 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "neg9.org", true));
379 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "www.neg9.org", true));
[email protected]b4adfdf02011-03-18 20:54:43380
[email protected]edbc4f92011-09-27 21:04:49381 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "riseup.net", true));
382 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "foo.riseup.net", true));
[email protected]abaeacb2011-03-21 13:43:17383
[email protected]edbc4f92011-09-27 21:04:49384 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "factor.cc", true));
385 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "www.factor.cc", true));
[email protected]88ec4442011-03-21 13:49:14386
[email protected]edbc4f92011-09-27 21:04:49387 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
388 "members.mayfirst.org",
389 true));
390 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
391 "support.mayfirst.org",
392 true));
393 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "id.mayfirst.org", true));
394 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
395 "lists.mayfirst.org",
396 true));
397 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
398 "www.mayfirst.org",
[email protected]b7f9fb22011-04-09 20:28:47399 true));
400
[email protected]edbc4f92011-09-27 21:04:49401 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
402 "splendidbacon.com",
403 true));
404 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
405 "www.splendidbacon.com",
406 true));
407 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
408 "foo.splendidbacon.com",
409 true));
[email protected]b7f9fb22011-04-09 20:28:47410
[email protected]edbc4f92011-09-27 21:04:49411 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
412 "chrome.google.com",
413 true));
414 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
415 "checkout.google.com",
416 true));
417 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
418 "health.google.com",
419 true));
420 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
421 "aladdinschools.appspot.com",
422 true));
423 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "ottospora.nl", true));
424 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "www.ottospora.nl", true));
[email protected]b7f9fb22011-04-09 20:28:47425
[email protected]edbc4f92011-09-27 21:04:49426 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "docs.google.com", true));
427 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "sites.google.com", true));
428 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "drive.google.com", true));
429 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
430 "spreadsheets.google.com",
431 true));
432 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
433 "appengine.google.com",
434 true));
435
436 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
437 "www.paycheckrecords.com",
438 true));
439 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
440 "market.android.com",
441 true));
[email protected]aa904432011-04-21 00:07:16442 // The domain wasn't being set, leading to a blank string in the
443 // chrome://net-internals/#hsts UI. So test that.
444 EXPECT_EQ(domain_state.domain, "market.android.com");
[email protected]edbc4f92011-09-27 21:04:49445 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
446 "sub.market.android.com",
447 true));
[email protected]aa904432011-04-21 00:07:16448 EXPECT_EQ(domain_state.domain, "market.android.com");
[email protected]b7f9fb22011-04-09 20:28:47449
[email protected]edbc4f92011-09-27 21:04:49450 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "lastpass.com", true));
451 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "www.lastpass.com", true));
452 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
453 "blog.lastpass.com",
[email protected]6a571112011-04-28 23:00:03454 true));
455
[email protected]edbc4f92011-09-27 21:04:49456 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "keyerror.com", true));
457 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "www.keyerror.com", true));
[email protected]6a571112011-04-28 23:00:03458
[email protected]edbc4f92011-09-27 21:04:49459 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
460 "encrypted.google.com",
461 true));
462 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
463 "accounts.google.com",
464 true));
465 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
466 "profiles.google.com",
467 true));
468 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "mail.google.com", true));
469 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
470 "chatenabled.mail.google.com",
471 true));
472 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
473 "talkgadget.google.com",
474 true));
475 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
476 "hostedtalkgadget.google.com",
477 true));
478 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "talk.google.com", true));
479 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "plus.google.com", true));
[email protected]627d03cc2011-10-19 18:36:22480 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "groups.google.com", true));
[email protected]edbc4f92011-09-27 21:04:49481
482 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "entropia.de", true));
483 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "www.entropia.de", true));
484 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "foo.entropia.de", true));
485
486 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
487 "ssl.google-analytics.com",
488 true));
489
490 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "www.google.com", true));
491 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "google.com", true));
492 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "www.youtube.com", true));
493 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "youtube.com", true));
494 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "i.ytimg.com", true));
495 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "ytimg.com", true));
496 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
497 "googleusercontent.com",
498 true));
499 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
500 "www.googleusercontent.com",
501 true));
502 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
503 "www.google-analytics.com",
504 true));
505 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
506 "google-analytics.com",
507 true));
508 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "googleapis.com", true));
509 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
510 "googleadservices.com",
511 true));
512 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "googlecode.com", true));
513 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "appspot.com", true));
514 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
515 "googlesyndication.com",
516 true));
517 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "doubleclick.net", true));
518 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
519 "googlegroups.com",
520 true));
521
522 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "gmail.com", true));
523 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "www.gmail.com", true));
524 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "m.gmail.com", true));
525 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "googlemail.com", true));
526 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
527 "www.googlemail.com",
528 true));
529 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
530 "m.googlemail.com",
531 true));
532 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "gmail.com", false));
533 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "www.gmail.com", false));
534 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "m.gmail.com", false));
535 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "googlemail.com", false));
536 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
[email protected]b7f9fb22011-04-09 20:28:47537 "www.googlemail.com",
[email protected]229f8fda2011-05-04 21:03:05538 false));
[email protected]edbc4f92011-09-27 21:04:49539 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
540 "m.googlemail.com",
[email protected]c6bf6512011-05-05 15:00:13541 false));
[email protected]0a86afa2011-10-14 00:54:51542 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
543 "www.googleplex.com",
544 true));
[email protected]bef90f32011-05-13 19:25:25545
[email protected]edbc4f92011-09-27 21:04:49546 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "romab.com", false));
547 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "www.romab.com", false));
548 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "foo.romab.com", false));
549
550 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "logentries.com", false));
551 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
552 "www.logentries.com",
553 false));
554 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
555 "foo.logentries.com",
[email protected]bef90f32011-05-13 19:25:25556 false));
[email protected]4e7075a2011-05-16 17:44:06557
[email protected]edbc4f92011-09-27 21:04:49558 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "stripe.com", false));
559 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "foo.stripe.com", false));
560
561 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
562 "cloudsecurityalliance.org",
563 false));
564 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
565 "foo.cloudsecurityalliance.org",
566 false));
567
568 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
569 "login.sapo.pt",
570 false));
571 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
572 "foo.login.sapo.pt",
573 false));
574
575 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
576 "mattmccutchen.net",
577 false));
578 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
579 "foo.mattmccutchen.net",
580 false));
581
582 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
583 "betnet.fr",
584 false));
585 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
586 "foo.betnet.fr",
587 false));
588
589 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
590 "uprotect.it",
591 false));
592 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
593 "foo.uprotect.it",
594 false));
595
596 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
597 "squareup.com",
598 false));
599 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
600 "foo.squareup.com",
[email protected]4e7075a2011-05-16 17:44:06601 false));
[email protected]0526e7a2011-05-19 16:49:40602
[email protected]edbc4f92011-09-27 21:04:49603 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
604 "cert.se",
605 false));
606 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
607 "foo.cert.se",
608 false));
609
610 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
611 "crypto.is",
612 false));
613 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
614 "foo.crypto.is",
615 false));
616
617 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
618 "simon.butcher.name",
619 false));
620 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
621 "foo.simon.butcher.name",
622 false));
623
624 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
625 "linx.net",
626 false));
627 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
628 "foo.linx.net",
629 false));
630
631 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
632 "dropcam.com",
633 false));
634 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
[email protected]da0e0252011-10-12 16:52:53635 "www.dropcam.com",
[email protected]edbc4f92011-09-27 21:04:49636 false));
[email protected]da0e0252011-10-12 16:52:53637 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
638 "foo.dropcam.com",
639 false));
[email protected]edbc4f92011-09-27 21:04:49640
641 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
642 "ebanking.indovinabank.com.vn",
643 false));
644 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
645 "foo.ebanking.indovinabank.com.vn",
646 false));
647
648 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
649 "epoxate.com",
650 false));
651 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
652 "foo.epoxate.com",
[email protected]0526e7a2011-05-19 16:49:40653 false));
[email protected]5287d0092011-05-30 19:19:36654
[email protected]edbc4f92011-09-27 21:04:49655 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
656 "torproject.org",
657 false));
[email protected]7179d2f42011-09-07 21:08:40658 EXPECT_TRUE(domain_state.public_key_hashes.size() != 0);
[email protected]edbc4f92011-09-27 21:04:49659 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
660 "www.torproject.org",
661 false));
[email protected]7179d2f42011-09-07 21:08:40662 EXPECT_TRUE(domain_state.public_key_hashes.size() != 0);
[email protected]edbc4f92011-09-27 21:04:49663 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
664 "check.torproject.org",
665 false));
[email protected]7179d2f42011-09-07 21:08:40666 EXPECT_TRUE(domain_state.public_key_hashes.size() != 0);
[email protected]edbc4f92011-09-27 21:04:49667 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
668 "blog.torproject.org",
669 false));
[email protected]7179d2f42011-09-07 21:08:40670 EXPECT_TRUE(domain_state.public_key_hashes.size() != 0);
671
[email protected]edbc4f92011-09-27 21:04:49672 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
673 "foo.torproject.org",
[email protected]d43846e2011-09-09 19:21:23674 false));
[email protected]edbc4f92011-09-27 21:04:49675
676 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
677 "www.moneybookers.com",
678 false));
679 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
[email protected]d43846e2011-09-09 19:21:23680 "moneybookers.com",
681 false));
682
[email protected]edbc4f92011-09-27 21:04:49683 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
684 "ledgerscope.net",
685 false));
686 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
687 "www.ledgerscope.net",
688 false));
689 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
690 "status.ledgerscope.net",
[email protected]e59d0fa2011-09-16 13:19:08691 false));
692
[email protected]edbc4f92011-09-27 21:04:49693 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
694 "kyps.net",
695 false));
696 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
697 "www.kyps.net",
698 false));
699 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
700 "foo.kyps.net",
[email protected]e59d0fa2011-09-16 13:19:08701 false));
[email protected]edbc4f92011-09-27 21:04:49702
703 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
704 "foo.app.recurly.com",
705 false));
706 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
707 "foo.api.recurly.com",
708 false));
709
710 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
711 "greplin.com",
712 false));
713 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
714 "www.greplin.com",
715 false));
716 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
717 "foo.greplin.com",
[email protected]e59d0fa2011-09-16 13:19:08718 false));
[email protected]94fb7aec2011-09-29 22:20:19719 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
720 "luneta.nearbuysystems.com",
721 false));
722 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
723 "foo.luneta.nearbuysystems.com",
724 false));
[email protected]e0a18fe2011-10-12 14:26:05725 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
726 "ubertt.org",
727 false));
728 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
729 "foo.ubertt.org",
730 false));
731
[email protected]7ccf34e2011-10-04 18:29:29732
733#if defined(OS_CHROMEOS)
734 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
735 "twitter.com",
736 false));
737#else
738 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
739 "twitter.com",
740 false));
741#endif
[email protected]2fc4c212010-03-10 18:59:06742}
743
[email protected]442845a2010-09-01 16:57:33744TEST_F(TransportSecurityStateTest, LongNames) {
[email protected]edbc4f92011-09-27 21:04:49745 TransportSecurityState state("");
[email protected]442845a2010-09-01 16:57:33746 const char kLongName[] =
747 "lookupByWaveIdHashAndWaveIdIdAndWaveIdDomainAndWaveletIdIdAnd"
748 "WaveletIdDomainAndBlipBlipid";
749 TransportSecurityState::DomainState domain_state;
750 // Just checks that we don't hit a NOTREACHED.
[email protected]edbc4f92011-09-27 21:04:49751 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, kLongName, true));
[email protected]442845a2010-09-01 16:57:33752}
753
[email protected]381e8852011-04-14 14:30:58754TEST_F(TransportSecurityStateTest, PublicKeyHashes) {
[email protected]edbc4f92011-09-27 21:04:49755 TransportSecurityState state("");
[email protected]381e8852011-04-14 14:30:58756 TransportSecurityState::DomainState domain_state;
[email protected]edbc4f92011-09-27 21:04:49757 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "example.com", false));
[email protected]381e8852011-04-14 14:30:58758 std::vector<SHA1Fingerprint> hashes;
759 EXPECT_TRUE(domain_state.IsChainOfPublicKeysPermitted(hashes));
760
761 SHA1Fingerprint hash;
762 memset(hash.data, '1', sizeof(hash.data));
763 domain_state.public_key_hashes.push_back(hash);
764
765 EXPECT_FALSE(domain_state.IsChainOfPublicKeysPermitted(hashes));
766 hashes.push_back(hash);
767 EXPECT_TRUE(domain_state.IsChainOfPublicKeysPermitted(hashes));
768 hashes[0].data[0] = '2';
769 EXPECT_FALSE(domain_state.IsChainOfPublicKeysPermitted(hashes));
770
771 const base::Time current_time(base::Time::Now());
772 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000);
773 domain_state.expiry = expiry;
[email protected]edbc4f92011-09-27 21:04:49774 state.EnableHost("example.com", domain_state);
[email protected]381e8852011-04-14 14:30:58775 std::string ser;
[email protected]edbc4f92011-09-27 21:04:49776 EXPECT_TRUE(state.Serialise(&ser));
[email protected]381e8852011-04-14 14:30:58777 bool dirty;
[email protected]edbc4f92011-09-27 21:04:49778 EXPECT_TRUE(state.LoadEntries(ser, &dirty));
779 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "example.com", false));
[email protected]381e8852011-04-14 14:30:58780 EXPECT_EQ(1u, domain_state.public_key_hashes.size());
781 EXPECT_TRUE(0 == memcmp(domain_state.public_key_hashes[0].data, hash.data,
782 sizeof(hash.data)));
783}
784
[email protected]938d6a32011-04-25 21:09:38785TEST_F(TransportSecurityStateTest, BuiltinCertPins) {
[email protected]edbc4f92011-09-27 21:04:49786 TransportSecurityState state("");
[email protected]938d6a32011-04-25 21:09:38787 TransportSecurityState::DomainState domain_state;
[email protected]edbc4f92011-09-27 21:04:49788 EXPECT_TRUE(state.IsEnabledForHost(&domain_state,
789 "chrome.google.com",
790 true));
791 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "chrome.google.com", true));
[email protected]938d6a32011-04-25 21:09:38792 std::vector<SHA1Fingerprint> hashes;
793 // This essential checks that a built-in list does exist.
794 EXPECT_FALSE(domain_state.IsChainOfPublicKeysPermitted(hashes));
[email protected]edbc4f92011-09-27 21:04:49795 EXPECT_FALSE(state.HasPinsForHost(&domain_state, "www.paypal.com", true));
[email protected]6a571112011-04-28 23:00:03796
[email protected]edbc4f92011-09-27 21:04:49797 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "docs.google.com", true));
798 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "1.docs.google.com", true));
799 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "sites.google.com", true));
800 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "drive.google.com", true));
801 EXPECT_TRUE(state.HasPinsForHost(&domain_state,
802 "spreadsheets.google.com",
803 true));
804 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "health.google.com", true));
805 EXPECT_TRUE(state.HasPinsForHost(&domain_state,
806 "checkout.google.com",
807 true));
808 EXPECT_TRUE(state.HasPinsForHost(&domain_state,
809 "appengine.google.com",
810 true));
811 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "market.android.com", true));
812 EXPECT_TRUE(state.HasPinsForHost(&domain_state,
813 "encrypted.google.com",
814 true));
815 EXPECT_TRUE(state.HasPinsForHost(&domain_state,
816 "accounts.google.com",
817 true));
818 EXPECT_TRUE(state.HasPinsForHost(&domain_state,
819 "profiles.google.com",
820 true));
821 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "mail.google.com", true));
822 EXPECT_TRUE(state.HasPinsForHost(&domain_state,
823 "chatenabled.mail.google.com",
824 true));
825 EXPECT_TRUE(state.HasPinsForHost(&domain_state,
826 "talkgadget.google.com",
827 true));
828 EXPECT_TRUE(state.HasPinsForHost(&domain_state,
829 "hostedtalkgadget.google.com",
830 true));
831 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "talk.google.com", true));
832 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "plus.google.com", true));
[email protected]627d03cc2011-10-19 18:36:22833 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "groups.google.com", true));
834
[email protected]edbc4f92011-09-27 21:04:49835 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "ssl.gstatic.com", true));
836 EXPECT_FALSE(state.HasPinsForHost(&domain_state, "www.gstatic.com", true));
837 EXPECT_TRUE(state.HasPinsForHost(&domain_state,
838 "ssl.google-analytics.com",
839 true));
[email protected]0a86afa2011-10-14 00:54:51840 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "www.googleplex.com", true));
[email protected]7ccf34e2011-10-04 18:29:29841
842 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "twitter.com", true));
843 EXPECT_FALSE(state.HasPinsForHost(&domain_state, "foo.twitter.com", true));
844 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "www.twitter.com", true));
845 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "api.twitter.com", true));
846 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "oauth.twitter.com", true));
847 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "mobile.twitter.com", true));
848 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "dev.twitter.com", true));
849 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "business.twitter.com", true));
[email protected]8f8146f2011-10-12 16:36:09850#if 0
851 // Disabled in order to help track down pinning failures --agl
[email protected]7ccf34e2011-10-04 18:29:29852 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "platform.twitter.com", true));
853 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "si0.twimg.com", true));
854 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "twimg0-a.akamaihd.net", true));
[email protected]8f8146f2011-10-12 16:36:09855#endif
[email protected]dee9ae92011-04-26 03:58:30856}
857
[email protected]5f15ed62011-11-02 15:07:08858static bool AddHash(const std::string& type_and_base64,
859 std::vector<SHA1Fingerprint>* out) {
860 std::string hash_str;
861 if (type_and_base64.find("sha1/") == 0 &&
862 base::Base64Decode(type_and_base64.substr(5, type_and_base64.size() - 5),
863 &hash_str) &&
864 hash_str.size() == base::kSHA1Length) {
865 SHA1Fingerprint hash;
866 memcpy(hash.data, hash_str.data(), sizeof(hash.data));
867 out->push_back(hash);
868 return true;
869 }
870 return false;
871}
872
873TEST_F(TransportSecurityStateTest, PinValidationWithRejectedCerts) {
874 // kGoodPath is plus.google.com via Google Internet Authority.
875 static const char* kGoodPath[] = {
876 "sha1/4BjDjn8v2lWeUFQnqSs0BgbIcrU=",
877 "sha1/QMVAHW+MuvCLAO3vse6H0AWzuc0=",
878 "sha1/SOZo+SvSspXXR9gjIBBPM5iQn9Q=",
879 NULL,
880 };
881
882 // kBadPath is plus.google.com via Trustcenter, which contains a required
883 // certificate (Equifax root), but also an excluded certificate
884 // (Trustcenter).
885 static const char* kBadPath[] = {
886 "sha1/4BjDjn8v2lWeUFQnqSs0BgbIcrU=",
887 "sha1/gzuEEAB/bkqdQS3EIjk2by7lW+k=",
888 "sha1/SOZo+SvSspXXR9gjIBBPM5iQn9Q=",
889 NULL,
890 };
891
892 std::vector<net::SHA1Fingerprint> good_hashes, bad_hashes;
893
894 for (size_t i = 0; kGoodPath[i]; i++) {
895 EXPECT_TRUE(AddHash(kGoodPath[i], &good_hashes));
896 }
897 for (size_t i = 0; kBadPath[i]; i++) {
898 EXPECT_TRUE(AddHash(kBadPath[i], &bad_hashes));
899 }
900
901 TransportSecurityState state("");
902 TransportSecurityState::DomainState domain_state;
903 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "plus.google.com", true));
904
905 EXPECT_TRUE(domain_state.IsChainOfPublicKeysPermitted(good_hashes));
906 EXPECT_FALSE(domain_state.IsChainOfPublicKeysPermitted(bad_hashes));
907}
908
909TEST_F(TransportSecurityStateTest, PinValidationWithoutRejectedCerts) {
910 // kGoodPath is blog.torproject.org.
911 static const char* kGoodPath[] = {
912 "sha1/m9lHYJYke9k0GtVZ+bXSQYE8nDI=",
913 "sha1/o5OZxATDsgmwgcIfIWIneMJ0jkw=",
914 "sha1/wHqYaI2J+6sFZAwRfap9ZbjKzE4=",
915 NULL,
916 };
917
918 // kBadPath is plus.google.com via Trustcenter, which is utterly wrong for
919 // torproject.org.
920 static const char* kBadPath[] = {
921 "sha1/4BjDjn8v2lWeUFQnqSs0BgbIcrU=",
922 "sha1/gzuEEAB/bkqdQS3EIjk2by7lW+k=",
923 "sha1/SOZo+SvSspXXR9gjIBBPM5iQn9Q=",
924 NULL,
925 };
926
927 std::vector<net::SHA1Fingerprint> good_hashes, bad_hashes;
928
929 for (size_t i = 0; kGoodPath[i]; i++) {
930 EXPECT_TRUE(AddHash(kGoodPath[i], &good_hashes));
931 }
932 for (size_t i = 0; kBadPath[i]; i++) {
933 EXPECT_TRUE(AddHash(kBadPath[i], &bad_hashes));
934 }
935
936 TransportSecurityState state("");
937 TransportSecurityState::DomainState domain_state;
938 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "blog.torproject.org", true));
939
940 EXPECT_TRUE(domain_state.IsChainOfPublicKeysPermitted(good_hashes));
941 EXPECT_FALSE(domain_state.IsChainOfPublicKeysPermitted(bad_hashes));
942}
943
[email protected]dee9ae92011-04-26 03:58:30944TEST_F(TransportSecurityStateTest, OptionalHSTSCertPins) {
[email protected]edbc4f92011-09-27 21:04:49945 TransportSecurityState state("");
[email protected]dee9ae92011-04-26 03:58:30946 TransportSecurityState::DomainState domain_state;
[email protected]edbc4f92011-09-27 21:04:49947 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
948 "www.google-analytics.com",
949 false));
950 EXPECT_FALSE(state.IsEnabledForHost(&domain_state,
951 "www.google-analytics.com",
952 true));
953 EXPECT_FALSE(state.HasPinsForHost(&domain_state,
[email protected]dee9ae92011-04-26 03:58:30954 "www.google-analytics.com",
[email protected]edbc4f92011-09-27 21:04:49955 false));
956 EXPECT_TRUE(state.HasPinsForHost(&domain_state,
957 "www.google-analytics.com",
958 true));
959 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "google.com", true));
960 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "www.google.com", true));
961 EXPECT_TRUE(state.HasPinsForHost(&domain_state,
962 "mail-attachment.googleusercontent.com",
963 true));
964 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "www.youtube.com", true));
965 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "i.ytimg.com", true));
966 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "googleapis.com", true));
967 EXPECT_TRUE(state.HasPinsForHost(&domain_state,
968 "ajax.googleapis.com",
969 true));
970 EXPECT_TRUE(state.HasPinsForHost(&domain_state,
971 "googleadservices.com",
972 true));
973 EXPECT_TRUE(state.HasPinsForHost(&domain_state,
974 "pagead2.googleadservices.com",
975 true));
976 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "googlecode.com", true));
977 EXPECT_TRUE(state.HasPinsForHost(&domain_state,
978 "kibbles.googlecode.com",
979 true));
980 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "appspot.com", true));
981 EXPECT_TRUE(state.HasPinsForHost(&domain_state,
982 "googlesyndication.com",
983 true));
984 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "doubleclick.net", true));
985 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "ad.doubleclick.net", true));
986 EXPECT_FALSE(state.HasPinsForHost(&domain_state,
987 "learn.doubleclick.net",
[email protected]dee9ae92011-04-26 03:58:30988 true));
[email protected]edbc4f92011-09-27 21:04:49989 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "a.googlegroups.com", true));
990 EXPECT_FALSE(state.HasPinsForHost(&domain_state,
991 "a.googlegroups.com",
992 false));
[email protected]938d6a32011-04-25 21:09:38993}
994
[email protected]d7cf831a2011-05-02 22:18:48995TEST_F(TransportSecurityStateTest, ForcePreloads) {
996 // This is a docs.google.com override.
997 std::string preload("{"
[email protected]edbc4f92011-09-27 21:04:49998 "\"4AGT3lHihuMSd5rUj7B4u6At0jlSH3HFePovjPR+oLE=\": {"
999 "\"created\": 0.0,"
1000 "\"expiry\": 2000000000.0,"
1001 "\"include_subdomains\": false,"
1002 "\"mode\": \"none\""
1003 "}}");
[email protected]d7cf831a2011-05-02 22:18:481004
[email protected]edbc4f92011-09-27 21:04:491005 TransportSecurityState state(preload);
[email protected]d7cf831a2011-05-02 22:18:481006 TransportSecurityState::DomainState domain_state;
[email protected]edbc4f92011-09-27 21:04:491007 EXPECT_FALSE(state.HasPinsForHost(&domain_state, "docs.google.com", true));
1008 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "docs.google.com", true));
[email protected]d7cf831a2011-05-02 22:18:481009}
1010
[email protected]55cb21182011-05-09 19:55:001011TEST_F(TransportSecurityStateTest, OverrideBuiltins) {
[email protected]edbc4f92011-09-27 21:04:491012 TransportSecurityState state("");
[email protected]55cb21182011-05-09 19:55:001013 TransportSecurityState::DomainState domain_state;
[email protected]edbc4f92011-09-27 21:04:491014 EXPECT_TRUE(state.HasPinsForHost(&domain_state, "google.com", true));
1015 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "google.com", true));
1016 EXPECT_FALSE(state.IsEnabledForHost(&domain_state, "www.google.com", true));
[email protected]55cb21182011-05-09 19:55:001017
1018 domain_state = TransportSecurityState::DomainState();
1019 const base::Time current_time(base::Time::Now());
1020 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000);
1021 domain_state.expiry = expiry;
[email protected]edbc4f92011-09-27 21:04:491022 state.EnableHost("www.google.com", domain_state);
[email protected]55cb21182011-05-09 19:55:001023
[email protected]edbc4f92011-09-27 21:04:491024 EXPECT_TRUE(state.IsEnabledForHost(&domain_state, "www.google.com", true));
[email protected]55cb21182011-05-09 19:55:001025}
1026
[email protected]ae780c82011-09-20 19:39:061027static const uint8 kSidePinLeafSPKI[] = {
1028 0x30, 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
1029 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48, 0x02, 0x41, 0x00, 0xe4,
1030 0x1d, 0xcc, 0xf2, 0x92, 0xe7, 0x7a, 0xc6, 0x36, 0xf7, 0x1a, 0x62, 0x31, 0x7d,
1031 0x37, 0xea, 0x0d, 0xa2, 0xa8, 0x12, 0x2b, 0xc2, 0x1c, 0x82, 0x3e, 0xa5, 0x70,
1032 0x4a, 0x83, 0x5d, 0x9b, 0x84, 0x82, 0x70, 0xa4, 0x88, 0x98, 0x98, 0x41, 0x29,
1033 0x31, 0xcb, 0x6e, 0x2a, 0x54, 0x65, 0x14, 0x60, 0xcc, 0x00, 0xe8, 0x10, 0x30,
1034 0x0a, 0x4a, 0xd1, 0xa7, 0x52, 0xfe, 0x2d, 0x31, 0x2a, 0x1d, 0x0d, 0x02, 0x03,
1035 0x01, 0x00, 0x01,
1036};
1037
1038static const uint8 kSidePinInfo[] = {
1039 0x01, 0x00, 0x53, 0x50, 0x49, 0x4e, 0xa0, 0x00, 0x03, 0x00, 0x53, 0x49, 0x47,
1040 0x00, 0x50, 0x55, 0x42, 0x4b, 0x41, 0x4c, 0x47, 0x4f, 0x47, 0x00, 0x41, 0x00,
1041 0x04, 0x00, 0x30, 0x45, 0x02, 0x21, 0x00, 0xfb, 0x26, 0xd5, 0xe8, 0x76, 0x35,
1042 0x96, 0x6d, 0x91, 0x9b, 0x5b, 0x27, 0xe6, 0x09, 0x1c, 0x7b, 0x6c, 0xcd, 0xc8,
1043 0x10, 0x25, 0x95, 0xc0, 0xa5, 0xf6, 0x6c, 0x6f, 0xfb, 0x59, 0x1e, 0x2d, 0xf4,
1044 0x02, 0x20, 0x33, 0x0a, 0xf8, 0x8b, 0x3e, 0xc4, 0xca, 0x75, 0x28, 0xdf, 0x5f,
1045 0xab, 0xe4, 0x46, 0xa0, 0xdd, 0x2d, 0xe5, 0xad, 0xc3, 0x81, 0x44, 0x70, 0xb2,
1046 0x10, 0x87, 0xe8, 0xc3, 0xd6, 0x6e, 0x12, 0x5d, 0x04, 0x67, 0x0b, 0x7d, 0xf2,
1047 0x99, 0x75, 0x57, 0x99, 0x3a, 0x98, 0xf8, 0xe4, 0xdf, 0x79, 0xdf, 0x8e, 0x02,
1048 0x2c, 0xbe, 0xd8, 0xfd, 0x75, 0x80, 0x18, 0xb1, 0x6f, 0x43, 0xd9, 0x8a, 0x79,
1049 0xc3, 0x6e, 0x18, 0xdf, 0x79, 0xc0, 0x59, 0xab, 0xd6, 0x77, 0x37, 0x6a, 0x94,
1050 0x5a, 0x7e, 0xfb, 0xa9, 0xc5, 0x54, 0x14, 0x3a, 0x7b, 0x97, 0x17, 0x2a, 0xb6,
1051 0x1e, 0x59, 0x4f, 0x2f, 0xb1, 0x15, 0x1a, 0x34, 0x50, 0x32, 0x35, 0x36,
1052};
1053
1054static const uint8 kSidePinExpectedHash[20] = {
1055 0xb5, 0x91, 0x66, 0x47, 0x43, 0x16, 0x62, 0x86, 0xd4, 0x1e, 0x5d, 0x36, 0xe1,
1056 0xc4, 0x09, 0x3d, 0x2d, 0x1d, 0xea, 0x1e,
1057};
1058
1059TEST_F(TransportSecurityStateTest, ParseSidePins) {
[email protected]ae780c82011-09-20 19:39:061060
1061 base::StringPiece leaf_spki(reinterpret_cast<const char*>(kSidePinLeafSPKI),
1062 sizeof(kSidePinLeafSPKI));
1063 base::StringPiece side_info(reinterpret_cast<const char*>(kSidePinInfo),
1064 sizeof(kSidePinInfo));
1065
1066 std::vector<SHA1Fingerprint> pub_key_hashes;
1067 EXPECT_TRUE(TransportSecurityState::ParseSidePin(
1068 leaf_spki, side_info, &pub_key_hashes));
1069 ASSERT_EQ(1u, pub_key_hashes.size());
1070 EXPECT_TRUE(0 == memcmp(pub_key_hashes[0].data, kSidePinExpectedHash,
1071 sizeof(kSidePinExpectedHash)));
1072}
1073
1074TEST_F(TransportSecurityStateTest, ParseSidePinsFailsWithBadData) {
[email protected]ae780c82011-09-20 19:39:061075
1076 uint8 leaf_spki_copy[sizeof(kSidePinLeafSPKI)];
1077 memcpy(leaf_spki_copy, kSidePinLeafSPKI, sizeof(leaf_spki_copy));
1078
1079 uint8 side_info_copy[sizeof(kSidePinInfo)];
1080 memcpy(side_info_copy, kSidePinInfo, sizeof(kSidePinInfo));
1081
1082 base::StringPiece leaf_spki(reinterpret_cast<const char*>(leaf_spki_copy),
1083 sizeof(leaf_spki_copy));
1084 base::StringPiece side_info(reinterpret_cast<const char*>(side_info_copy),
1085 sizeof(side_info_copy));
1086 std::vector<SHA1Fingerprint> pub_key_hashes;
1087
1088 // Tweak |leaf_spki| and expect a failure.
1089 leaf_spki_copy[10] ^= 1;
1090 EXPECT_FALSE(TransportSecurityState::ParseSidePin(
1091 leaf_spki, side_info, &pub_key_hashes));
1092 ASSERT_EQ(0u, pub_key_hashes.size());
1093
1094 // Undo the change to |leaf_spki| and tweak |side_info|.
1095 leaf_spki_copy[10] ^= 1;
1096 side_info_copy[30] ^= 1;
1097 EXPECT_FALSE(TransportSecurityState::ParseSidePin(
1098 leaf_spki, side_info, &pub_key_hashes));
1099 ASSERT_EQ(0u, pub_key_hashes.size());
1100}
1101
1102TEST_F(TransportSecurityStateTest, DISABLED_ParseSidePinsFuzz) {
1103 // Disabled because it's too slow for normal tests. Run manually when
1104 // changing the underlying code.
1105
[email protected]ae780c82011-09-20 19:39:061106 base::StringPiece leaf_spki(reinterpret_cast<const char*>(kSidePinLeafSPKI),
1107 sizeof(kSidePinLeafSPKI));
1108 uint8 side_info_copy[sizeof(kSidePinInfo)];
1109 base::StringPiece side_info(reinterpret_cast<const char*>(side_info_copy),
1110 sizeof(side_info_copy));
1111 std::vector<SHA1Fingerprint> pub_key_hashes;
1112 static const size_t bit_length = sizeof(kSidePinInfo) * 8;
1113
1114 for (size_t bit_to_flip = 0; bit_to_flip < bit_length; bit_to_flip++) {
1115 memcpy(side_info_copy, kSidePinInfo, sizeof(kSidePinInfo));
1116
1117 size_t byte = bit_to_flip >> 3;
1118 size_t bit = bit_to_flip & 7;
1119 side_info_copy[byte] ^= (1 << bit);
1120
1121 EXPECT_FALSE(TransportSecurityState::ParseSidePin(
1122 leaf_spki, side_info, &pub_key_hashes));
1123 ASSERT_EQ(0u, pub_key_hashes.size());
1124 }
1125}
1126
[email protected]cb8d2812011-10-15 05:07:071127TEST_F(TransportSecurityStateTest, GooglePinnedProperties) {
1128 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty(
1129 "www.example.com", true));
1130 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty(
1131 "www.paypal.com", true));
1132 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty(
1133 "mail.twitter.com", true));
1134 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty(
1135 "www.google.com.int", true));
1136 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty(
1137 "jottit.com", true));
1138 // learn.doubleclick.net has a more specific match than
1139 // *.doubleclick.com, and has 0 or NULL for its required certs.
1140 // This test ensures that the exact-match-preferred behavior
1141 // works.
1142 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty(
1143 "learn.doubleclick.net", true));
1144
1145 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty(
1146 "encrypted.google.com", true));
1147 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty(
1148 "mail.google.com", true));
1149 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty(
1150 "accounts.google.com", true));
1151 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty(
1152 "doubleclick.net", true));
1153 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty(
1154 "ad.doubleclick.net", true));
1155 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty(
1156 "youtube.com", true));
1157 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty(
1158 "www.profiles.google.com", true));
1159 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty(
1160 "checkout.google.com", true));
1161 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty(
1162 "googleadservices.com", true));
1163
1164 // Test with sni_enabled false:
1165 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty(
1166 "www.example.com", false));
1167 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty(
1168 "www.paypal.com", false));
1169 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty(
1170 "checkout.google.com", false));
1171 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty(
1172 "googleadservices.com", false));
1173
1174 // Test some SNI hosts:
1175 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty(
1176 "gmail.com", true));
1177 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty(
1178 "googlegroups.com", true));
1179 EXPECT_TRUE(TransportSecurityState::IsGooglePinnedProperty(
1180 "www.googlegroups.com", true));
1181 // Expect to fail for SNI hosts when not searching the SNI list:
1182 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty(
1183 "gmail.com", false));
1184 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty(
1185 "googlegroups.com", false));
1186 EXPECT_FALSE(TransportSecurityState::IsGooglePinnedProperty(
1187 "www.googlegroups.com", false));
1188}
1189
[email protected]2fc4c212010-03-10 18:59:061190} // namespace net