summaryrefslogtreecommitdiffstats
path: root/content/browser/ssl/ssl_host_state.cc
blob: 15edabbfd11c5da07c794d55f7a2e322adba44f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/ssl/ssl_host_state.h"

#include "base/logging.h"
#include "base/lazy_instance.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/ssl_host_state_delegate.h"
#include "net/http/http_transaction_factory.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"

const char kKeyName[] = "content_ssl_host_state";

namespace content {

SSLHostState* SSLHostState::GetFor(BrowserContext* context) {
  SSLHostState* rv = static_cast<SSLHostState*>(context->GetUserData(kKeyName));
  if (!rv) {
    rv = new SSLHostState();
    rv->delegate_ = context->GetSSLHostStateDelegate();
    // |context| may be NULL, implementing the default storage strategy.
    if (context)
      context->SetUserData(kKeyName, rv);
  }
  return rv;
}

SSLHostState::SSLHostState() {
}

SSLHostState::~SSLHostState() {
}

void SSLHostState::HostRanInsecureContent(const std::string& host, int pid) {
  DCHECK(CalledOnValidThread());
  ran_insecure_content_hosts_.insert(BrokenHostEntry(host, pid));
}

bool SSLHostState::DidHostRunInsecureContent(const std::string& host,
                                             int pid) const {
  DCHECK(CalledOnValidThread());
  return !!ran_insecure_content_hosts_.count(BrokenHostEntry(host, pid));
}

void SSLHostState::DenyCertForHost(net::X509Certificate* cert,
                                   const std::string& host,
                                   net::CertStatus error) {
  DCHECK(CalledOnValidThread());

  if (!delegate_)
    return;

  delegate_->DenyCert(host, cert, error);
}

void SSLHostState::AllowCertForHost(net::X509Certificate* cert,
                                    const std::string& host,
                                    net::CertStatus error) {
  DCHECK(CalledOnValidThread());

  if (!delegate_)
    return;

  delegate_->AllowCert(host, cert, error);
}

void SSLHostState::RevokeAllowAndDenyPreferences(const std::string& host) {
  DCHECK(CalledOnValidThread());

  if (!delegate_)
    return;

  // TODO(jww): This will revoke all of the decisions in the browser context.
  // However, the networking stack actually keeps track of its own list of
  // exceptions per-HttpNetworkTransaction in the SSLConfig structure (see the
  // allowed_bad_certs Vector in net/ssl/ssl_config.h). This dual-tracking of
  // exceptions introduces a problem where the browser context can revoke a
  // certificate, but if a transaction reuses a cached version of the SSLConfig
  // (probably from a pooled socket), it may bypass the intestitial layer.
  //
  // Over time, the cached versions should expire and it should converge on
  // showing the interstitial. We probably need to
  // introduce into the networking stack a way revoke SSLConfig's
  // allowed_bad_certs lists per socket.
  delegate_->RevokeAllowAndDenyPreferences(host);
}

bool SSLHostState::HasAllowedOrDeniedCert(const std::string& host) {
  DCHECK(CalledOnValidThread());

  if (!delegate_)
    return false;

  return delegate_->HasAllowedOrDeniedCert(host);
}

void SSLHostState::Clear() {
  if (!delegate_)
    return;

  delegate_->Clear();
}

net::CertPolicy::Judgment SSLHostState::QueryPolicy(net::X509Certificate* cert,
                                                    const std::string& host,
                                                    net::CertStatus error) {
  DCHECK(CalledOnValidThread());

  if (!delegate_)
    return net::CertPolicy::Judgment::UNKNOWN;

  return delegate_->QueryPolicy(host, cert, error);
}

}  // namespace content