OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_SSL_CHROME_SSL_HOST_STATE_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_SSL_CHROME_SSL_HOST_STATE_DELEGATE_H_ |
6 #define CHROME_BROWSER_SSL_CHROME_SSL_HOST_STATE_DELEGATE_H_ | 6 #define CHROME_BROWSER_SSL_CHROME_SSL_HOST_STATE_DELEGATE_H_ |
7 | 7 |
8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "content/public/browser/ssl_host_state_delegate.h" | 11 #include "content/public/browser/ssl_host_state_delegate.h" |
12 | 12 |
13 class Profile; | 13 class Profile; |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 class Clock; | 16 class Clock; |
17 class DictionaryValue; | 17 class DictionaryValue; |
18 } // namespace base | 18 } // namespace base |
19 | 19 |
20 // Implementation of the tracking of user decisions on SSL errors for sites. | 20 // Tracks whether the user has allowed a certificate error exception for a |
21 // Tracks if the user has allowed, denied, or not seen an exception for the | 21 // specific site, SSL fingerprint, and error. Based on command-line flags and |
22 // specified site, SSL fingerprint, and error. If the user makes a decision, | 22 // experimental group, remembers this decision either until end-of-session or |
23 // stores the decision until either the session ends or for a length of time | 23 // for a particular length of time. |
24 // (across session restarts), based on command line flags. | |
25 class ChromeSSLHostStateDelegate : public content::SSLHostStateDelegate { | 24 class ChromeSSLHostStateDelegate : public content::SSLHostStateDelegate { |
26 public: | 25 public: |
27 explicit ChromeSSLHostStateDelegate(Profile* profile); | 26 explicit ChromeSSLHostStateDelegate(Profile* profile); |
28 virtual ~ChromeSSLHostStateDelegate(); | 27 virtual ~ChromeSSLHostStateDelegate(); |
29 | 28 |
30 // SSLHostStateDelegate: | 29 // SSLHostStateDelegate: |
31 virtual void DenyCert(const std::string& host, | |
32 const net::X509Certificate& cert, | |
33 net::CertStatus error) OVERRIDE; | |
34 virtual void AllowCert(const std::string& host, | 30 virtual void AllowCert(const std::string& host, |
35 const net::X509Certificate& cert, | 31 const net::X509Certificate& cert, |
36 net::CertStatus error) OVERRIDE; | 32 net::CertStatus error) OVERRIDE; |
37 virtual void Clear() OVERRIDE; | 33 virtual void Clear() OVERRIDE; |
38 virtual net::CertPolicy::Judgment QueryPolicy( | 34 virtual CertJudgment QueryPolicy(const std::string& host, |
39 const std::string& host, | 35 const net::X509Certificate& cert, |
40 const net::X509Certificate& cert, | 36 net::CertStatus error, |
41 net::CertStatus error, | 37 bool* expired_previous_decision) OVERRIDE; |
42 bool* expired_previous_decision) OVERRIDE; | |
43 virtual void HostRanInsecureContent(const std::string& host, | 38 virtual void HostRanInsecureContent(const std::string& host, |
44 int pid) OVERRIDE; | 39 int pid) OVERRIDE; |
45 virtual bool DidHostRunInsecureContent(const std::string& host, | 40 virtual bool DidHostRunInsecureContent(const std::string& host, |
46 int pid) const OVERRIDE; | 41 int pid) const OVERRIDE; |
47 | 42 |
48 // ChromeSSLHostStateDelegate implementation: | 43 // Revokes all SSL certificate error allow exceptions made by the user for |
49 // Revoke all user decisions for |host| in the given Profile. The | 44 // |host| in the given Profile. |
50 // RevokeUserDecisionsHard version may close idle connections in the process. | 45 virtual void RevokeUserAllowExceptions(const std::string& host); |
51 // This version should be used *only* for rare events, such as a user | |
52 // controlled button, as it may be very disruptive to the networking stack. | |
53 virtual void RevokeUserDecisions(const std::string& host); | |
54 virtual void RevokeUserDecisionsHard(const std::string& host); | |
55 | 46 |
56 // Returns true if any decisions has been recorded for |host| for the given | 47 // RevokeUserAllowExceptionsHard is the same as RevokeUserAllowExceptions but |
57 // Profile, otherwise false. | 48 // additionally may close idle connections in the process. This should be used |
58 virtual bool HasUserDecision(const std::string& host) const; | 49 // *only* for rare events, such as a user controlled button, as it may be very |
| 50 // disruptive to the networking stack. |
| 51 virtual void RevokeUserAllowExceptionsHard(const std::string& host); |
| 52 |
| 53 // Returns whether the user has allowed a certificate error exception for |
| 54 // |host|. This does not mean that *all* certificate errors are allowed, just |
| 55 // that there exists an exception. To see if a particular certificate and |
| 56 // error combination exception is allowed, use QueryPolicy(). |
| 57 virtual bool HasAllowException(const std::string& host) const; |
59 | 58 |
60 protected: | 59 protected: |
61 // SetClock takes ownership of the passed in clock. | 60 // SetClock takes ownership of the passed in clock. |
62 void SetClock(scoped_ptr<base::Clock> clock); | 61 void SetClock(scoped_ptr<base::Clock> clock); |
63 | 62 |
64 private: | 63 private: |
65 FRIEND_TEST_ALL_PREFIXES(ForgetInstantlySSLHostStateDelegateTest, | 64 FRIEND_TEST_ALL_PREFIXES(ForgetInstantlySSLHostStateDelegateTest, |
66 MakeAndForgetException); | 65 MakeAndForgetException); |
67 FRIEND_TEST_ALL_PREFIXES(RememberSSLHostStateDelegateTest, AfterRestart); | 66 FRIEND_TEST_ALL_PREFIXES(RememberSSLHostStateDelegateTest, AfterRestart); |
68 FRIEND_TEST_ALL_PREFIXES(RememberSSLHostStateDelegateTest, | 67 FRIEND_TEST_ALL_PREFIXES(RememberSSLHostStateDelegateTest, |
69 QueryPolicyExpired); | 68 QueryPolicyExpired); |
70 | 69 |
71 // Used to specify whether new content setting entries should be created if | 70 // Used to specify whether new content setting entries should be created if |
72 // they don't already exist when querying the user's settings. | 71 // they don't already exist when querying the user's settings. |
73 enum CreateDictionaryEntriesDisposition { | 72 enum CreateDictionaryEntriesDisposition { |
74 CREATE_DICTIONARY_ENTRIES, | 73 CREATE_DICTIONARY_ENTRIES, |
75 DO_NOT_CREATE_DICTIONARY_ENTRIES | 74 DO_NOT_CREATE_DICTIONARY_ENTRIES |
76 }; | 75 }; |
77 | 76 |
78 // Specifies whether user SSL error decisions should be forgetten at the end | 77 // Specifies whether user SSL error decisions should be forgetten at the end |
79 // of this current session (the old style of remembering decisions), or | 78 // of this current session (the old style of remembering decisions), or |
80 // whether they should be remembered across session restarts for a specified | 79 // whether they should be remembered across session restarts for a specified |
81 // length of time, deteremined by | 80 // length of time, deteremined by |
82 // |default_ssl_cert_decision_expiration_delta_|. | 81 // |default_ssl_cert_decision_expiration_delta_|. |
83 enum RememberSSLExceptionDecisionsDisposition { | 82 enum RememberSSLExceptionDecisionsDisposition { |
84 FORGET_SSL_EXCEPTION_DECISIONS_AT_SESSION_END, | 83 FORGET_SSL_EXCEPTION_DECISIONS_AT_SESSION_END, |
85 REMEMBER_SSL_EXCEPTION_DECISIONS_FOR_DELTA | 84 REMEMBER_SSL_EXCEPTION_DECISIONS_FOR_DELTA |
86 }; | 85 }; |
87 | 86 |
88 // Modify the user's content settings to specify a judgement made for a | 87 // Returns a dictionary of certificate fingerprints and errors that have been |
89 // specific site and certificate, where |url| is the site in question, |cert| | 88 // allowed as exceptions by the user. |
90 // is the certificate with an error, |error| is the error in the certificate, | |
91 // and |judgement| is the user decision to be recorded. | |
92 void ChangeCertPolicy(const std::string& host, | |
93 const net::X509Certificate& cert, | |
94 net::CertStatus error, | |
95 net::CertPolicy::Judgment judgment); | |
96 | |
97 // Query the content settings to retrieve a dictionary of certificate | |
98 // fingerprints and errors of certificates to user decisions, as set by | |
99 // ChangeCertPolicy. Returns NULL on a failure. | |
100 // | 89 // |
101 // |dict| specifies the user's full exceptions dictionary for a specific site | 90 // |dict| specifies the user's full exceptions dictionary for a specific site |
102 // in their content settings. Must be retrieved directly from a website | 91 // in their content settings. Must be retrieved directly from a website |
103 // setting in the the profile's HostContentSettingsMap. | 92 // setting in the the profile's HostContentSettingsMap. |
104 // | 93 // |
105 // If |create_entries| specifies CreateDictionaryEntries, then | 94 // If |create_entries| specifies CreateDictionaryEntries, then |
106 // GetValidCertDecisionsDict will create a new set of entries within the | 95 // GetValidCertDecisionsDict will create a new set of entries within the |
107 // dictionary if they do not already exist. Otherwise will fail and return if | 96 // dictionary if they do not already exist. Otherwise will fail and return if |
108 // NULL if they do not exist. | 97 // NULL if they do not exist. |
109 // | 98 // |
(...skipping 15 matching lines...) Expand all Loading... |
125 | 114 |
126 // Hosts which have been contaminated with insecure content in the | 115 // Hosts which have been contaminated with insecure content in the |
127 // specified process. Note that insecure content can travel between | 116 // specified process. Note that insecure content can travel between |
128 // same-origin frames in one processs but cannot jump between processes. | 117 // same-origin frames in one processs but cannot jump between processes. |
129 std::set<BrokenHostEntry> ran_insecure_content_hosts_; | 118 std::set<BrokenHostEntry> ran_insecure_content_hosts_; |
130 | 119 |
131 DISALLOW_COPY_AND_ASSIGN(ChromeSSLHostStateDelegate); | 120 DISALLOW_COPY_AND_ASSIGN(ChromeSSLHostStateDelegate); |
132 }; | 121 }; |
133 | 122 |
134 #endif // CHROME_BROWSER_SSL_CHROME_SSL_HOST_STATE_DELEGATE_H_ | 123 #endif // CHROME_BROWSER_SSL_CHROME_SSL_HOST_STATE_DELEGATE_H_ |
OLD | NEW |