OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/ssl/ssl_host_state.h" | 5 #include "content/browser/ssl/ssl_host_state.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "content/public/browser/browser_context.h" | 9 #include "content/public/browser/browser_context.h" |
10 #include "content/public/browser/ssl_host_state_delegate.h" | |
11 #include "net/http/http_transaction_factory.h" | |
12 #include "net/url_request/url_request_context.h" | |
13 #include "net/url_request/url_request_context_getter.h" | |
10 | 14 |
11 const char kKeyName[] = "content_ssl_host_state"; | 15 const char kKeyName[] = "content_ssl_host_state"; |
12 | 16 |
13 namespace content { | 17 namespace content { |
14 | 18 |
15 SSLHostState* SSLHostState::GetFor(BrowserContext* context) { | 19 SSLHostState* SSLHostState::GetFor(BrowserContext* context) { |
16 SSLHostState* rv = static_cast<SSLHostState*>(context->GetUserData(kKeyName)); | 20 SSLHostState* rv = static_cast<SSLHostState*>(context->GetUserData(kKeyName)); |
17 if (!rv) { | 21 if (!rv) { |
18 rv = new SSLHostState(); | 22 rv = new SSLHostState(); |
19 context->SetUserData(kKeyName, rv); | 23 rv->delegate_ = context->GetSSLHostStateDelegate(); |
24 // |context| may be NULL, implementing the default storage strategy. | |
25 if (context) | |
benm (inactive)
2014/12/10 15:01:42
should this check go up above? If context might be
jww
2014/12/10 23:20:06
Good catch, although this code was significantly r
| |
26 context->SetUserData(kKeyName, rv); | |
20 } | 27 } |
21 return rv; | 28 return rv; |
22 } | 29 } |
23 | 30 |
24 SSLHostState::SSLHostState() { | 31 SSLHostState::SSLHostState() { |
25 } | 32 } |
26 | 33 |
27 SSLHostState::~SSLHostState() { | 34 SSLHostState::~SSLHostState() { |
28 } | 35 } |
29 | 36 |
30 void SSLHostState::HostRanInsecureContent(const std::string& host, int pid) { | 37 void SSLHostState::HostRanInsecureContent(const std::string& host, int pid) { |
31 DCHECK(CalledOnValidThread()); | 38 DCHECK(CalledOnValidThread()); |
32 ran_insecure_content_hosts_.insert(BrokenHostEntry(host, pid)); | 39 ran_insecure_content_hosts_.insert(BrokenHostEntry(host, pid)); |
33 } | 40 } |
34 | 41 |
35 bool SSLHostState::DidHostRunInsecureContent(const std::string& host, | 42 bool SSLHostState::DidHostRunInsecureContent(const std::string& host, |
36 int pid) const { | 43 int pid) const { |
37 DCHECK(CalledOnValidThread()); | 44 DCHECK(CalledOnValidThread()); |
38 return !!ran_insecure_content_hosts_.count(BrokenHostEntry(host, pid)); | 45 return !!ran_insecure_content_hosts_.count(BrokenHostEntry(host, pid)); |
39 } | 46 } |
40 | 47 |
41 void SSLHostState::DenyCertForHost(net::X509Certificate* cert, | 48 void SSLHostState::DenyCertForHost(net::X509Certificate* cert, |
42 const std::string& host, | 49 const std::string& host, |
43 net::CertStatus error) { | 50 net::CertStatus error) { |
44 DCHECK(CalledOnValidThread()); | 51 DCHECK(CalledOnValidThread()); |
45 | 52 |
46 cert_policy_for_host_[host].Deny(cert, error); | 53 if (!delegate_) |
54 return; | |
55 | |
56 delegate_->DenyCert(host, cert, error); | |
47 } | 57 } |
48 | 58 |
49 void SSLHostState::AllowCertForHost(net::X509Certificate* cert, | 59 void SSLHostState::AllowCertForHost(net::X509Certificate* cert, |
50 const std::string& host, | 60 const std::string& host, |
51 net::CertStatus error) { | 61 net::CertStatus error) { |
52 DCHECK(CalledOnValidThread()); | 62 DCHECK(CalledOnValidThread()); |
53 | 63 |
54 cert_policy_for_host_[host].Allow(cert, error); | 64 if (!delegate_) |
65 return; | |
66 | |
67 delegate_->AllowCert(host, cert, error); | |
68 } | |
69 | |
70 void SSLHostState::RevokeAllowAndDenyPreferences(const std::string& host) { | |
71 DCHECK(CalledOnValidThread()); | |
72 | |
73 if (!delegate_) | |
74 return; | |
75 | |
76 // TODO(jww): This will revoke all of the decisions in the browser context. | |
77 // However, the networking stack actually keeps track of its own list of | |
78 // exceptions per-HttpNetworkTransaction in the SSLConfig structure (see the | |
79 // allowed_bad_certs Vector in net/ssl/ssl_config.h). This dual-tracking of | |
80 // exceptions introduces a problem where the browser context can revoke a | |
81 // certificate, but if a transaction reuses a cached version of the SSLConfig | |
82 // (probably from a pooled socket), it may bypass the intestitial layer. | |
83 // | |
84 // Over time, the cached versions should expire and it should converge on | |
85 // showing the interstitial. We probably need to | |
86 // introduce into the networking stack a way revoke SSLConfig's | |
87 // allowed_bad_certs lists per socket. | |
88 delegate_->RevokeAllowAndDenyPreferences(host); | |
89 } | |
90 | |
91 bool SSLHostState::HasAllowedOrDeniedCert(const std::string& host) { | |
92 DCHECK(CalledOnValidThread()); | |
93 | |
94 if (!delegate_) | |
95 return false; | |
96 | |
97 return delegate_->HasAllowedOrDeniedCert(host); | |
55 } | 98 } |
56 | 99 |
57 void SSLHostState::Clear() { | 100 void SSLHostState::Clear() { |
58 DCHECK(CalledOnValidThread()); | 101 if (!delegate_) |
102 return; | |
59 | 103 |
60 cert_policy_for_host_.clear(); | 104 delegate_->Clear(); |
61 } | 105 } |
62 | 106 |
63 net::CertPolicy::Judgment SSLHostState::QueryPolicy(net::X509Certificate* cert, | 107 net::CertPolicy::Judgment SSLHostState::QueryPolicy(net::X509Certificate* cert, |
64 const std::string& host, | 108 const std::string& host, |
65 net::CertStatus error) { | 109 net::CertStatus error) { |
66 DCHECK(CalledOnValidThread()); | 110 DCHECK(CalledOnValidThread()); |
67 | 111 |
68 return cert_policy_for_host_[host].Check(cert, error); | 112 if (!delegate_) |
113 return net::CertPolicy::Judgment::UNKNOWN; | |
114 | |
115 return delegate_->QueryPolicy(host, cert, error); | |
69 } | 116 } |
70 | 117 |
71 } // namespace content | 118 } // namespace content |
OLD | NEW |