1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SSL_CHROME_SSL_HOST_STATE_DELEGATE_H_
6 #define CHROME_BROWSER_SSL_CHROME_SSL_HOST_STATE_DELEGATE_H_
8 #include "base/gtest_prod_util.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/time.h"
11 #include "content/public/browser/ssl_host_state_delegate.h"
17 class DictionaryValue
;
20 // Tracks whether the user has allowed a certificate error exception for a
21 // specific site, SSL fingerprint, and error. Based on command-line flags and
22 // experimental group, remembers this decision either until end-of-session or
23 // for a particular length of time.
24 class ChromeSSLHostStateDelegate
: public content::SSLHostStateDelegate
{
26 explicit ChromeSSLHostStateDelegate(Profile
* profile
);
27 ~ChromeSSLHostStateDelegate() override
;
29 // SSLHostStateDelegate:
30 void AllowCert(const std::string
& host
,
31 const net::X509Certificate
& cert
,
32 net::CertStatus error
) override
;
33 void Clear() override
;
34 CertJudgment
QueryPolicy(const std::string
& host
,
35 const net::X509Certificate
& cert
,
36 net::CertStatus error
,
37 bool* expired_previous_decision
) override
;
38 void HostRanInsecureContent(const std::string
& host
, int pid
) override
;
39 bool DidHostRunInsecureContent(const std::string
& host
,
40 int pid
) const override
;
42 // Revokes all SSL certificate error allow exceptions made by the user for
43 // |host| in the given Profile.
44 void RevokeUserAllowExceptions(const std::string
& host
) override
;
46 // RevokeUserAllowExceptionsHard is the same as RevokeUserAllowExceptions but
47 // additionally may close idle connections in the process. This should be used
48 // *only* for rare events, such as a user controlled button, as it may be very
49 // disruptive to the networking stack.
50 virtual void RevokeUserAllowExceptionsHard(const std::string
& host
);
52 // Returns whether the user has allowed a certificate error exception for
53 // |host|. This does not mean that *all* certificate errors are allowed, just
54 // that there exists an exception. To see if a particular certificate and
55 // error combination exception is allowed, use QueryPolicy().
56 bool HasAllowException(const std::string
& host
) const override
;
59 // SetClock takes ownership of the passed in clock.
60 void SetClock(scoped_ptr
<base::Clock
> clock
);
63 FRIEND_TEST_ALL_PREFIXES(ForgetInstantlySSLHostStateDelegateTest
,
64 MakeAndForgetException
);
65 FRIEND_TEST_ALL_PREFIXES(RememberSSLHostStateDelegateTest
, AfterRestart
);
66 FRIEND_TEST_ALL_PREFIXES(RememberSSLHostStateDelegateTest
,
69 // Used to specify whether new content setting entries should be created if
70 // they don't already exist when querying the user's settings.
71 enum CreateDictionaryEntriesDisposition
{
72 CREATE_DICTIONARY_ENTRIES
,
73 DO_NOT_CREATE_DICTIONARY_ENTRIES
76 // Specifies whether user SSL error decisions should be forgetten at the end
77 // of this current session (the old style of remembering decisions), or
78 // whether they should be remembered across session restarts for a specified
79 // length of time, deteremined by
80 // |default_ssl_cert_decision_expiration_delta_|.
81 enum RememberSSLExceptionDecisionsDisposition
{
82 FORGET_SSL_EXCEPTION_DECISIONS_AT_SESSION_END
,
83 REMEMBER_SSL_EXCEPTION_DECISIONS_FOR_DELTA
86 // Returns a dictionary of certificate fingerprints and errors that have been
87 // allowed as exceptions by the user.
89 // |dict| specifies the user's full exceptions dictionary for a specific site
90 // in their content settings. Must be retrieved directly from a website
91 // setting in the the profile's HostContentSettingsMap.
93 // If |create_entries| specifies CreateDictionaryEntries, then
94 // GetValidCertDecisionsDict will create a new set of entries within the
95 // dictionary if they do not already exist. Otherwise will fail and return if
96 // NULL if they do not exist.
98 // |expired_previous_decision| is set to true if there had been a previous
99 // decision made by the user but it has expired. Otherwise it is set to false.
100 base::DictionaryValue
* GetValidCertDecisionsDict(
101 base::DictionaryValue
* dict
,
102 CreateDictionaryEntriesDisposition create_entries
,
103 bool* expired_previous_decision
);
105 scoped_ptr
<base::Clock
> clock_
;
106 RememberSSLExceptionDecisionsDisposition should_remember_ssl_decisions_
;
107 base::TimeDelta default_ssl_cert_decision_expiration_delta_
;
110 // A BrokenHostEntry is a pair of (host, process_id) that indicates the host
111 // contains insecure content in that renderer process.
112 typedef std::pair
<std::string
, int> BrokenHostEntry
;
114 // Hosts which have been contaminated with insecure content in the
115 // specified process. Note that insecure content can travel between
116 // same-origin frames in one processs but cannot jump between processes.
117 std::set
<BrokenHostEntry
> ran_insecure_content_hosts_
;
119 // This is a GUID to mark this unique session. Whenever a certificate decision
120 // expiration is set, the GUID is saved as well so Chrome can tell if it was
121 // last set during the current session. This is used by the
122 // FORGET_SSL_EXCEPTION_DECISIONS_AT_SESSION_END experimental group to
123 // determine if the expired_previous_decision bit should be set on queries.
125 // Why not just iterate over the set of current extensions and mark them all
126 // as expired when the session starts, rather than storing a GUID for the
127 // current session? Glad you asked! Unfortunately, content settings does not
128 // currently support iterating over all current *compound* content setting
129 // values (iteration only works for simple content settings). While this could
130 // be added, it would be a fair amount of work for what amounts to a temporary
131 // measurement problem, so it's not worth the complexity.
133 // TODO(jww): This is only used by the default and disable groups of the
134 // certificate memory decisions experiment to tell if a decision has expired
135 // since the last session. Since this is only used for UMA purposes, this
136 // should be removed after the experiment has finished, and a call to Clear()
137 // should be added to the constructor and destructor for members of the
138 // FORGET_SSL_EXCEPTION_DECISIONS_AT_SESSION_END groups. See
139 // https://crbug.com/418631 for more details.
140 const std::string current_expiration_guid_
;
142 DISALLOW_COPY_AND_ASSIGN(ChromeSSLHostStateDelegate
);
145 #endif // CHROME_BROWSER_SSL_CHROME_SSL_HOST_STATE_DELEGATE_H_