blob: 65a187bf77baf9f4028eb4bf8d29c17496b0c104 [file] [log] [blame]
[email protected]fecef222012-01-05 02:26:151// Copyright (c) 2012 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
[email protected]536fd0b2013-03-14 17:41:575#include "net/http/transport_security_state.h"
[email protected]5f15ed62011-11-02 15:07:086
[email protected]fecef222012-01-05 02:26:157#include <algorithm>
8#include <string>
[email protected]ede03212012-09-07 12:52:269#include <vector>
[email protected]fecef222012-01-05 02:26:1510
[email protected]5f15ed62011-11-02 15:07:0811#include "base/base64.h"
[email protected]57999812013-02-24 05:40:5212#include "base/files/file_path.h"
[email protected]5f15ed62011-11-02 15:07:0813#include "base/sha1.h"
[email protected]d069c11a2013-04-13 00:01:5514#include "base/strings/string_piece.h"
[email protected]ede03212012-09-07 12:52:2615#include "crypto/sha2.h"
[email protected]66d9b6e32012-03-22 03:04:3216#include "net/base/net_errors.h"
17#include "net/base/net_log.h"
[email protected]66d9b6e32012-03-22 03:04:3218#include "net/base/test_completion_callback.h"
[email protected]42fdb452012-11-01 12:44:4019#include "net/base/test_data_directory.h"
[email protected]6e7845ae2013-03-29 21:48:1120#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]fecef222012-01-05 02:26:1526#include "net/http/http_util.h"
[email protected]536fd0b2013-03-14 17:41:5727#include "net/ssl/ssl_info.h"
[email protected]6e7845ae2013-03-29 21:48:1128#include "net/test/cert_test_util.h"
[email protected]326e6792009-12-11 21:04:4229#include "testing/gtest/include/gtest/gtest.h"
30
[email protected]06256e52011-09-29 15:08:4831#if defined(USE_OPENSSL)
32#include "crypto/openssl_util.h"
33#else
34#include "crypto/nss_util.h"
35#endif
36
[email protected]2fc4c212010-03-10 18:59:0637namespace net {
38
[email protected]326e6792009-12-11 21:04:4239class TransportSecurityStateTest : public testing::Test {
[email protected]06256e52011-09-29 15:08:4840 virtual void SetUp() {
[email protected]54356432011-10-05 21:49:4241#if defined(USE_OPENSSL)
[email protected]06256e52011-09-29 15:08:4842 crypto::EnsureOpenSSLInit();
[email protected]54356432011-10-05 21:49:4243#else
44 crypto::EnsureNSSInit();
[email protected]06256e52011-09-29 15:08:4845#endif
46 }
[email protected]474f079e2013-03-02 19:11:2047
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]326e6792009-12-11 21:04:4265};
66
[email protected]326e6792009-12-11 21:04:4267TEST_F(TransportSecurityStateTest, SimpleMatches) {
[email protected]f43b89f32012-05-01 19:39:4868 TransportSecurityState state;
[email protected]2fc4c212010-03-10 18:59:0669 TransportSecurityState::DomainState domain_state;
[email protected]326e6792009-12-11 21:04:4270 const base::Time current_time(base::Time::Now());
71 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000);
72
[email protected]f43b89f32012-05-01 19:39:4873 EXPECT_FALSE(state.GetDomainState("yahoo.com", true, &domain_state));
[email protected]474f079e2013-03-02 19:11:2074 bool include_subdomains = false;
75 state.AddHSTS("yahoo.com", expiry, include_subdomains);
[email protected]f43b89f32012-05-01 19:39:4876 EXPECT_TRUE(state.GetDomainState("yahoo.com", true, &domain_state));
[email protected]326e6792009-12-11 21:04:4277}
78
79TEST_F(TransportSecurityStateTest, MatchesCase1) {
[email protected]f43b89f32012-05-01 19:39:4880 TransportSecurityState state;
[email protected]2fc4c212010-03-10 18:59:0681 TransportSecurityState::DomainState domain_state;
[email protected]326e6792009-12-11 21:04:4282 const base::Time current_time(base::Time::Now());
83 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000);
84
[email protected]f43b89f32012-05-01 19:39:4885 EXPECT_FALSE(state.GetDomainState("yahoo.com", true, &domain_state));
[email protected]474f079e2013-03-02 19:11:2086 bool include_subdomains = false;
87 state.AddHSTS("YAhoo.coM", expiry, include_subdomains);
[email protected]f43b89f32012-05-01 19:39:4888 EXPECT_TRUE(state.GetDomainState("yahoo.com", true, &domain_state));
[email protected]326e6792009-12-11 21:04:4289}
90
91TEST_F(TransportSecurityStateTest, MatchesCase2) {
[email protected]f43b89f32012-05-01 19:39:4892 TransportSecurityState state;
[email protected]2fc4c212010-03-10 18:59:0693 TransportSecurityState::DomainState domain_state;
[email protected]326e6792009-12-11 21:04:4294 const base::Time current_time(base::Time::Now());
95 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000);
96
[email protected]f43b89f32012-05-01 19:39:4897 EXPECT_FALSE(state.GetDomainState("YAhoo.coM", true, &domain_state));
[email protected]474f079e2013-03-02 19:11:2098 bool include_subdomains = false;
99 state.AddHSTS("yahoo.com", expiry, include_subdomains);
[email protected]f43b89f32012-05-01 19:39:48100 EXPECT_TRUE(state.GetDomainState("YAhoo.coM", true, &domain_state));
[email protected]326e6792009-12-11 21:04:42101}
102
103TEST_F(TransportSecurityStateTest, SubdomainMatches) {
[email protected]f43b89f32012-05-01 19:39:48104 TransportSecurityState state;
[email protected]2fc4c212010-03-10 18:59:06105 TransportSecurityState::DomainState domain_state;
[email protected]326e6792009-12-11 21:04:42106 const base::Time current_time(base::Time::Now());
107 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000);
108
[email protected]f43b89f32012-05-01 19:39:48109 EXPECT_FALSE(state.GetDomainState("yahoo.com", true, &domain_state));
[email protected]474f079e2013-03-02 19:11:20110 bool include_subdomains = true;
111 state.AddHSTS("yahoo.com", expiry, include_subdomains);
[email protected]f43b89f32012-05-01 19:39:48112 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]326e6792009-12-11 21:04:42118}
119
[email protected]474f079e2013-03-02 19:11:20120TEST_F(TransportSecurityStateTest, DeleteAllDynamicDataSince) {
[email protected]f43b89f32012-05-01 19:39:48121 TransportSecurityState state;
[email protected]2fc4c212010-03-10 18:59:06122 TransportSecurityState::DomainState domain_state;
[email protected]4d0d8082010-02-23 01:03:10123 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]f43b89f32012-05-01 19:39:48127 EXPECT_FALSE(state.GetDomainState("yahoo.com", true, &domain_state));
[email protected]474f079e2013-03-02 19:11:20128 bool include_subdomains = false;
129 state.AddHSTS("yahoo.com", expiry, include_subdomains);
[email protected]4d0d8082010-02-23 01:03:10130
[email protected]474f079e2013-03-02 19:11:20131 state.DeleteAllDynamicDataSince(expiry);
[email protected]f43b89f32012-05-01 19:39:48132 EXPECT_TRUE(state.GetDomainState("yahoo.com", true, &domain_state));
[email protected]474f079e2013-03-02 19:11:20133 state.DeleteAllDynamicDataSince(older);
[email protected]f43b89f32012-05-01 19:39:48134 EXPECT_FALSE(state.GetDomainState("yahoo.com", true, &domain_state));
[email protected]4d0d8082010-02-23 01:03:10135}
136
[email protected]474f079e2013-03-02 19:11:20137TEST_F(TransportSecurityStateTest, DeleteDynamicDataForHost) {
[email protected]f43b89f32012-05-01 19:39:48138 TransportSecurityState state;
[email protected]f060be32011-02-17 17:20:28139 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]474f079e2013-03-02 19:11:20142 bool include_subdomains = false;
143 state.AddHSTS("yahoo.com", expiry, include_subdomains);
[email protected]f060be32011-02-17 17:20:28144
[email protected]f43b89f32012-05-01 19:39:48145 EXPECT_TRUE(state.GetDomainState("yahoo.com", true, &domain_state));
146 EXPECT_FALSE(state.GetDomainState("example.com", true, &domain_state));
[email protected]474f079e2013-03-02 19:11:20147 EXPECT_TRUE(state.DeleteDynamicDataForHost("yahoo.com"));
[email protected]f43b89f32012-05-01 19:39:48148 EXPECT_FALSE(state.GetDomainState("yahoo.com", true, &domain_state));
[email protected]4d0d8082010-02-23 01:03:10149}
150
[email protected]2fc4c212010-03-10 18:59:06151TEST_F(TransportSecurityStateTest, IsPreloaded) {
[email protected]9f972ec2013-04-10 20:24:36152 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]2fc4c212010-03-10 18:59:06158
[email protected]f43b89f32012-05-01 19:39:48159 TransportSecurityState state;
[email protected]aa904432011-04-21 00:07:16160 TransportSecurityState::DomainState domain_state;
[email protected]f43b89f32012-05-01 19:39:48161
[email protected]474f079e2013-03-02 19:11:20162 EXPECT_FALSE(GetStaticDomainState(&state, paypal, true, &domain_state));
163 EXPECT_TRUE(GetStaticDomainState(&state, www_paypal, true, &domain_state));
[email protected]aa904432011-04-21 00:07:16164 EXPECT_FALSE(domain_state.include_subdomains);
[email protected]474f079e2013-03-02 19:11:20165 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]2fc4c212010-03-10 18:59:06169}
170
[email protected]dc694c32011-11-29 20:00:49171TEST_F(TransportSecurityStateTest, PreloadedDomainSet) {
[email protected]f43b89f32012-05-01 19:39:48172 TransportSecurityState state;
[email protected]dc694c32011-11-29 20:00:49173 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]f43b89f32012-05-01 19:39:48177 EXPECT_TRUE(state.GetDomainState("market.android.com", true, &domain_state));
[email protected]dc694c32011-11-29 20:00:49178 EXPECT_EQ(domain_state.domain, "market.android.com");
[email protected]f43b89f32012-05-01 19:39:48179 EXPECT_TRUE(state.GetDomainState("sub.market.android.com", true,
180 &domain_state));
[email protected]dc694c32011-11-29 20:00:49181 EXPECT_EQ(domain_state.domain, "market.android.com");
182}
183
184static bool ShouldRedirect(const char* hostname) {
[email protected]f43b89f32012-05-01 19:39:48185 TransportSecurityState state;
[email protected]dc694c32011-11-29 20:00:49186 TransportSecurityState::DomainState domain_state;
[email protected]f43b89f32012-05-01 19:39:48187 return state.GetDomainState(hostname, true /* SNI ok */, &domain_state) &&
[email protected]843329e2013-01-22 22:06:09188 domain_state.ShouldUpgradeToSSL();
[email protected]dc694c32011-11-29 20:00:49189}
190
[email protected]f43b89f32012-05-01 19:39:48191static bool HasState(const char* hostname) {
192 TransportSecurityState state;
[email protected]dc694c32011-11-29 20:00:49193 TransportSecurityState::DomainState domain_state;
[email protected]f43b89f32012-05-01 19:39:48194 return state.GetDomainState(hostname, true /* SNI ok */, &domain_state);
[email protected]dc694c32011-11-29 20:00:49195}
196
[email protected]843329e2013-01-22 22:06:09197static bool HasPublicKeyPins(const char* hostname, bool sni_enabled) {
[email protected]f43b89f32012-05-01 19:39:48198 TransportSecurityState state;
[email protected]dc694c32011-11-29 20:00:49199 TransportSecurityState::DomainState domain_state;
[email protected]f43b89f32012-05-01 19:39:48200 if (!state.GetDomainState(hostname, sni_enabled, &domain_state))
201 return false;
202
[email protected]843329e2013-01-22 22:06:09203 return domain_state.HasPublicKeyPins();
[email protected]f43b89f32012-05-01 19:39:48204}
205
[email protected]843329e2013-01-22 22:06:09206static bool HasPublicKeyPins(const char* hostname) {
207 return HasPublicKeyPins(hostname, true);
[email protected]dc694c32011-11-29 20:00:49208}
209
210static bool OnlyPinning(const char *hostname) {
[email protected]f43b89f32012-05-01 19:39:48211 TransportSecurityState state;
[email protected]dc694c32011-11-29 20:00:49212 TransportSecurityState::DomainState domain_state;
[email protected]f43b89f32012-05-01 19:39:48213 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]843329e2013-01-22 22:06:09219 !domain_state.ShouldUpgradeToSSL();
[email protected]dc694c32011-11-29 20:00:49220}
221
[email protected]2fc4c212010-03-10 18:59:06222TEST_F(TransportSecurityStateTest, Preloaded) {
[email protected]f43b89f32012-05-01 19:39:48223 TransportSecurityState state;
[email protected]2fc4c212010-03-10 18:59:06224 TransportSecurityState::DomainState domain_state;
[email protected]dc694c32011-11-29 20:00:49225
226 // We do more extensive checks for the first domain.
[email protected]f43b89f32012-05-01 19:39:48227 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]2fc4c212010-03-10 18:59:06230 EXPECT_FALSE(domain_state.include_subdomains);
[email protected]f091469f2010-05-05 21:05:28231
[email protected]dc694c32011-11-29 20:00:49232 EXPECT_FALSE(HasState("paypal.com"));
233 EXPECT_FALSE(HasState("www2.paypal.com"));
[email protected]fecef222012-01-05 02:26:15234 EXPECT_FALSE(HasState("www2.paypal.com"));
[email protected]edbc4f92011-09-27 21:04:49235
[email protected]dc694c32011-11-29 20:00:49236 // Google hosts:
[email protected]edbc4f92011-09-27 21:04:49237
[email protected]dc694c32011-11-29 20:00:49238 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]d100467b2012-02-10 22:01:21256 EXPECT_TRUE(ShouldRedirect("groups.google.com"));
[email protected]b9480af02012-02-22 19:55:01257 EXPECT_TRUE(ShouldRedirect("apis.google.com"));
[email protected]25b882a2012-03-05 20:44:15258 EXPECT_FALSE(ShouldRedirect("chart.apis.google.com"));
[email protected]dc694c32011-11-29 20:00:49259 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]bee76312011-03-17 18:35:35268
[email protected]dc694c32011-11-29 20:00:49269 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]b4adfdf02011-03-18 20:54:43286
[email protected]dc694c32011-11-29 20:00:49287 // Tests for domains that don't work without SNI.
[email protected]f43b89f32012-05-01 19:39:48288 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]bef90f32011-05-13 19:25:25295
[email protected]dc694c32011-11-29 20:00:49296 // Other hosts:
[email protected]edbc4f92011-09-27 21:04:49297
[email protected]dc694c32011-11-29 20:00:49298 EXPECT_TRUE(ShouldRedirect("aladdinschools.appspot.com"));
[email protected]4e7075a2011-05-16 17:44:06299
[email protected]dc694c32011-11-29 20:00:49300 EXPECT_TRUE(ShouldRedirect("ottospora.nl"));
301 EXPECT_TRUE(ShouldRedirect("www.ottospora.nl"));
[email protected]edbc4f92011-09-27 21:04:49302
[email protected]dc694c32011-11-29 20:00:49303 EXPECT_TRUE(ShouldRedirect("www.paycheckrecords.com"));
[email protected]edbc4f92011-09-27 21:04:49304
[email protected]dc694c32011-11-29 20:00:49305 EXPECT_TRUE(ShouldRedirect("lastpass.com"));
306 EXPECT_TRUE(ShouldRedirect("www.lastpass.com"));
307 EXPECT_FALSE(HasState("blog.lastpass.com"));
[email protected]edbc4f92011-09-27 21:04:49308
[email protected]dc694c32011-11-29 20:00:49309 EXPECT_TRUE(ShouldRedirect("keyerror.com"));
310 EXPECT_TRUE(ShouldRedirect("www.keyerror.com"));
[email protected]edbc4f92011-09-27 21:04:49311
[email protected]dc694c32011-11-29 20:00:49312 EXPECT_TRUE(ShouldRedirect("entropia.de"));
313 EXPECT_TRUE(ShouldRedirect("www.entropia.de"));
314 EXPECT_FALSE(HasState("foo.entropia.de"));
[email protected]edbc4f92011-09-27 21:04:49315
[email protected]dc694c32011-11-29 20:00:49316 EXPECT_TRUE(ShouldRedirect("www.elanex.biz"));
317 EXPECT_FALSE(HasState("elanex.biz"));
318 EXPECT_FALSE(HasState("foo.elanex.biz"));
[email protected]edbc4f92011-09-27 21:04:49319
[email protected]dc694c32011-11-29 20:00:49320 EXPECT_TRUE(ShouldRedirect("sunshinepress.org"));
321 EXPECT_TRUE(ShouldRedirect("www.sunshinepress.org"));
322 EXPECT_TRUE(ShouldRedirect("a.b.sunshinepress.org"));
[email protected]0526e7a2011-05-19 16:49:40323
[email protected]dc694c32011-11-29 20:00:49324 EXPECT_TRUE(ShouldRedirect("www.noisebridge.net"));
325 EXPECT_FALSE(HasState("noisebridge.net"));
326 EXPECT_FALSE(HasState("foo.noisebridge.net"));
[email protected]edbc4f92011-09-27 21:04:49327
[email protected]dc694c32011-11-29 20:00:49328 EXPECT_TRUE(ShouldRedirect("neg9.org"));
329 EXPECT_FALSE(HasState("www.neg9.org"));
[email protected]edbc4f92011-09-27 21:04:49330
[email protected]dc694c32011-11-29 20:00:49331 EXPECT_TRUE(ShouldRedirect("riseup.net"));
332 EXPECT_TRUE(ShouldRedirect("foo.riseup.net"));
[email protected]edbc4f92011-09-27 21:04:49333
[email protected]dc694c32011-11-29 20:00:49334 EXPECT_TRUE(ShouldRedirect("factor.cc"));
335 EXPECT_FALSE(HasState("www.factor.cc"));
[email protected]edbc4f92011-09-27 21:04:49336
[email protected]dc694c32011-11-29 20:00:49337 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]edbc4f92011-09-27 21:04:49342
[email protected]dc694c32011-11-29 20:00:49343 EXPECT_TRUE(ShouldRedirect("romab.com"));
344 EXPECT_TRUE(ShouldRedirect("www.romab.com"));
345 EXPECT_TRUE(ShouldRedirect("foo.romab.com"));
[email protected]5287d0092011-05-30 19:19:36346
[email protected]dc694c32011-11-29 20:00:49347 EXPECT_TRUE(ShouldRedirect("logentries.com"));
348 EXPECT_TRUE(ShouldRedirect("www.logentries.com"));
349 EXPECT_FALSE(HasState("foo.logentries.com"));
[email protected]7179d2f42011-09-07 21:08:40350
[email protected]dc694c32011-11-29 20:00:49351 EXPECT_TRUE(ShouldRedirect("stripe.com"));
352 EXPECT_TRUE(ShouldRedirect("foo.stripe.com"));
[email protected]edbc4f92011-09-27 21:04:49353
[email protected]dc694c32011-11-29 20:00:49354 EXPECT_TRUE(ShouldRedirect("cloudsecurityalliance.org"));
355 EXPECT_TRUE(ShouldRedirect("foo.cloudsecurityalliance.org"));
[email protected]d43846e2011-09-09 19:21:23356
[email protected]dc694c32011-11-29 20:00:49357 EXPECT_TRUE(ShouldRedirect("login.sapo.pt"));
358 EXPECT_TRUE(ShouldRedirect("foo.login.sapo.pt"));
[email protected]e59d0fa2011-09-16 13:19:08359
[email protected]dc694c32011-11-29 20:00:49360 EXPECT_TRUE(ShouldRedirect("mattmccutchen.net"));
361 EXPECT_TRUE(ShouldRedirect("foo.mattmccutchen.net"));
[email protected]edbc4f92011-09-27 21:04:49362
[email protected]dc694c32011-11-29 20:00:49363 EXPECT_TRUE(ShouldRedirect("betnet.fr"));
364 EXPECT_TRUE(ShouldRedirect("foo.betnet.fr"));
[email protected]edbc4f92011-09-27 21:04:49365
[email protected]dc694c32011-11-29 20:00:49366 EXPECT_TRUE(ShouldRedirect("uprotect.it"));
367 EXPECT_TRUE(ShouldRedirect("foo.uprotect.it"));
[email protected]e0a18fe2011-10-12 14:26:05368
[email protected]dc694c32011-11-29 20:00:49369 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]f43b89f32012-05-01 19:39:48388 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]dc694c32011-11-29 20:00:49399 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]843329e2013-01-22 22:06:09405 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]dc694c32011-11-29 20:00:49409 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]dc694c32011-11-29 20:00:49418 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]7ccf34e2011-10-04 18:29:29430
[email protected]e004c4072011-12-28 15:08:19431 EXPECT_TRUE(ShouldRedirect("pixi.me"));
432 EXPECT_TRUE(ShouldRedirect("www.pixi.me"));
433
[email protected]736c1db2012-02-24 17:21:39434 EXPECT_TRUE(ShouldRedirect("grepular.com"));
435 EXPECT_TRUE(ShouldRedirect("www.grepular.com"));
436
[email protected]aaf17d572012-03-06 15:54:19437 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]15a43f82013-01-15 22:51:55451 EXPECT_FALSE(ShouldRedirect("foo.crypto.cat"));
[email protected]aaf17d572012-03-06 15:54:19452
[email protected]37204972012-03-09 20:43:00453 EXPECT_TRUE(ShouldRedirect("bigshinylock.minazo.net"));
454 EXPECT_TRUE(ShouldRedirect("foo.bigshinylock.minazo.net"));
455
[email protected]2a886d32012-03-12 21:33:12456 EXPECT_TRUE(ShouldRedirect("crate.io"));
457 EXPECT_TRUE(ShouldRedirect("foo.crate.io"));
458
[email protected]843329e2013-01-22 22:06:09459 EXPECT_TRUE(HasPublicKeyPins("www.twitter.com"));
[email protected]2fc4c212010-03-10 18:59:06460}
461
[email protected]442845a2010-09-01 16:57:33462TEST_F(TransportSecurityStateTest, LongNames) {
[email protected]f43b89f32012-05-01 19:39:48463 TransportSecurityState state;
[email protected]442845a2010-09-01 16:57:33464 const char kLongName[] =
465 "lookupByWaveIdHashAndWaveIdIdAndWaveIdDomainAndWaveletIdIdAnd"
466 "WaveletIdDomainAndBlipBlipid";
467 TransportSecurityState::DomainState domain_state;
468 // Just checks that we don't hit a NOTREACHED.
[email protected]f43b89f32012-05-01 19:39:48469 EXPECT_FALSE(state.GetDomainState(kLongName, true, &domain_state));
[email protected]381e8852011-04-14 14:30:58470}
471
[email protected]938d6a32011-04-25 21:09:38472TEST_F(TransportSecurityStateTest, BuiltinCertPins) {
[email protected]f43b89f32012-05-01 19:39:48473 TransportSecurityState state;
[email protected]938d6a32011-04-25 21:09:38474 TransportSecurityState::DomainState domain_state;
[email protected]f43b89f32012-05-01 19:39:48475
476 EXPECT_TRUE(state.GetDomainState("chrome.google.com", true, &domain_state));
[email protected]843329e2013-01-22 22:06:09477 EXPECT_TRUE(HasPublicKeyPins("chrome.google.com"));
[email protected]f43b89f32012-05-01 19:39:48478
[email protected]ede03212012-09-07 12:52:26479 HashValueVector hashes;
[email protected]f43b89f32012-05-01 19:39:48480 // Checks that a built-in list does exist.
[email protected]843329e2013-01-22 22:06:09481 EXPECT_FALSE(domain_state.CheckPublicKeyPins(hashes));
482 EXPECT_FALSE(HasPublicKeyPins("www.paypal.com"));
[email protected]6a571112011-04-28 23:00:03483
[email protected]843329e2013-01-22 22:06:09484 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]627d03cc2011-10-19 18:36:22504
[email protected]843329e2013-01-22 22:06:09505 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]7ccf34e2011-10-04 18:29:29509
[email protected]3f0bc942011-11-09 20:05:13510 // Disabled in order to help track down pinning failures --agl
[email protected]843329e2013-01-22 22:06:09511 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]dee9ae92011-04-26 03:58:30522}
523
[email protected]5f15ed62011-11-02 15:07:08524static bool AddHash(const std::string& type_and_base64,
[email protected]ede03212012-09-07 12:52:26525 HashValueVector* out) {
526 HashValue hash;
[email protected]6ed72be2013-01-08 22:07:33527 if (!hash.FromString(type_and_base64))
[email protected]ede03212012-09-07 12:52:26528 return false;
529
530 out->push_back(hash);
531 return true;
[email protected]5f15ed62011-11-02 15:07:08532}
533
534TEST_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]ede03212012-09-07 12:52:26553 HashValueVector good_hashes, bad_hashes;
[email protected]5f15ed62011-11-02 15:07:08554
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]f43b89f32012-05-01 19:39:48562 TransportSecurityState state;
[email protected]5f15ed62011-11-02 15:07:08563 TransportSecurityState::DomainState domain_state;
[email protected]f43b89f32012-05-01 19:39:48564 EXPECT_TRUE(state.GetDomainState("plus.google.com", true, &domain_state));
[email protected]843329e2013-01-22 22:06:09565 EXPECT_TRUE(domain_state.HasPublicKeyPins());
[email protected]5f15ed62011-11-02 15:07:08566
[email protected]843329e2013-01-22 22:06:09567 EXPECT_TRUE(domain_state.CheckPublicKeyPins(good_hashes));
568 EXPECT_FALSE(domain_state.CheckPublicKeyPins(bad_hashes));
[email protected]5f15ed62011-11-02 15:07:08569}
570
571TEST_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]ede03212012-09-07 12:52:26589 HashValueVector good_hashes, bad_hashes;
[email protected]5f15ed62011-11-02 15:07:08590
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]f43b89f32012-05-01 19:39:48598 TransportSecurityState state;
[email protected]5f15ed62011-11-02 15:07:08599 TransportSecurityState::DomainState domain_state;
[email protected]f43b89f32012-05-01 19:39:48600 EXPECT_TRUE(state.GetDomainState("blog.torproject.org", true, &domain_state));
[email protected]843329e2013-01-22 22:06:09601 EXPECT_TRUE(domain_state.HasPublicKeyPins());
[email protected]5f15ed62011-11-02 15:07:08602
[email protected]843329e2013-01-22 22:06:09603 EXPECT_TRUE(domain_state.CheckPublicKeyPins(good_hashes));
604 EXPECT_FALSE(domain_state.CheckPublicKeyPins(bad_hashes));
[email protected]5f15ed62011-11-02 15:07:08605}
606
[email protected]ede03212012-09-07 12:52:26607TEST_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]843329e2013-01-22 22:06:09630 EXPECT_TRUE(domain_state.HasPublicKeyPins());
[email protected]ede03212012-09-07 12:52:26631
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]843329e2013-01-22 22:06:09643 EXPECT_TRUE(domain_state.CheckPublicKeyPins(validated_chain));
[email protected]ede03212012-09-07 12:52:26644
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]843329e2013-01-22 22:06:09650 EXPECT_FALSE(domain_state.CheckPublicKeyPins(validated_chain));
[email protected]ede03212012-09-07 12:52:26651
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]843329e2013-01-22 22:06:09657 EXPECT_TRUE(domain_state.CheckPublicKeyPins(validated_chain));
[email protected]ede03212012-09-07 12:52:26658
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]843329e2013-01-22 22:06:09664 EXPECT_FALSE(domain_state.CheckPublicKeyPins(validated_chain));
[email protected]ede03212012-09-07 12:52:26665
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]843329e2013-01-22 22:06:09671 EXPECT_TRUE(domain_state.CheckPublicKeyPins(validated_chain));
[email protected]ede03212012-09-07 12:52:26672
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]843329e2013-01-22 22:06:09678 EXPECT_FALSE(domain_state.CheckPublicKeyPins(validated_chain));
[email protected]ede03212012-09-07 12:52:26679
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]843329e2013-01-22 22:06:09688 EXPECT_TRUE(domain_state.CheckPublicKeyPins(validated_chain));
[email protected]ede03212012-09-07 12:52:26689
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]843329e2013-01-22 22:06:09698 EXPECT_FALSE(domain_state.CheckPublicKeyPins(validated_chain));
[email protected]ede03212012-09-07 12:52:26699}
700
[email protected]dee9ae92011-04-26 03:58:30701TEST_F(TransportSecurityStateTest, OptionalHSTSCertPins) {
[email protected]f43b89f32012-05-01 19:39:48702 TransportSecurityState state;
[email protected]dee9ae92011-04-26 03:58:30703 TransportSecurityState::DomainState domain_state;
[email protected]f43b89f32012-05-01 19:39:48704
[email protected]dc694c32011-11-29 20:00:49705 EXPECT_FALSE(ShouldRedirect("www.google-analytics.com"));
[email protected]938d6a32011-04-25 21:09:38706
[email protected]843329e2013-01-22 22:06:09707 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]d7cf831a2011-05-02 22:18:48727}
728
[email protected]55cb21182011-05-09 19:55:00729TEST_F(TransportSecurityStateTest, OverrideBuiltins) {
[email protected]843329e2013-01-22 22:06:09730 EXPECT_TRUE(HasPublicKeyPins("google.com"));
[email protected]dc694c32011-11-29 20:00:49731 EXPECT_FALSE(ShouldRedirect("google.com"));
732 EXPECT_FALSE(ShouldRedirect("www.google.com"));
733
[email protected]f43b89f32012-05-01 19:39:48734 TransportSecurityState state;
[email protected]55cb21182011-05-09 19:55:00735 TransportSecurityState::DomainState domain_state;
[email protected]55cb21182011-05-09 19:55:00736 const base::Time current_time(base::Time::Now());
737 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000);
[email protected]f43b89f32012-05-01 19:39:48738 domain_state.upgrade_expiry = expiry;
[email protected]474f079e2013-03-02 19:11:20739 EnableHost(&state, "www.google.com", domain_state);
[email protected]55cb21182011-05-09 19:55:00740
[email protected]f43b89f32012-05-01 19:39:48741 EXPECT_TRUE(state.GetDomainState("www.google.com", true, &domain_state));
[email protected]55cb21182011-05-09 19:55:00742}
743
[email protected]ae780c82011-09-20 19:39:06744static 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
755static 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
771static 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]cb8d2812011-10-15 05:07:07776TEST_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]2fc4c212010-03-10 18:59:06839} // namespace net