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 #ifndef NET_BASE_TRANSPORT_SECURITY_STATE_H_ | 5 #ifndef NET_BASE_TRANSPORT_SECURITY_STATE_H_ |
6 #define NET_BASE_TRANSPORT_SECURITY_STATE_H_ | 6 #define NET_BASE_TRANSPORT_SECURITY_STATE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
14 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
15 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
16 #include "base/time.h" | 17 #include "base/time.h" |
17 #include "net/base/net_export.h" | 18 #include "net/base/net_export.h" |
18 #include "net/base/x509_certificate.h" | 19 #include "net/base/x509_certificate.h" |
19 #include "net/base/x509_cert_types.h" | 20 #include "net/base/x509_cert_types.h" |
20 | 21 |
21 namespace net { | 22 namespace net { |
22 | 23 |
23 class SSLInfo; | 24 class SSLInfo; |
24 | 25 |
25 typedef std::vector<SHA1Fingerprint> FingerprintVector; | 26 // Tracks which hosts have enabled strict transport security and/or public |
26 | 27 // key pins. |
27 // TransportSecurityState | |
28 // | 28 // |
29 // Tracks which hosts have enabled *-Transport-Security. This object manages | 29 // This object manages the in-memory store. Register a Delegate with |
30 // the in-memory store. A separate object must register itself with this object | 30 // |SetDelegate| to persist the state to disk. |
31 // in order to persist the state to disk. | 31 // |
32 // HTTP strict transport security (HSTS) is defined in | |
33 // http://tools.ietf.org/html/ietf-websec-strict-transport-sec, and | |
34 // HTTP-based dynamic public key pinning (HPKP) is defined in | |
35 // http://tools.ietf.org/html/ietf-websec-key-pinning. | |
32 class NET_EXPORT TransportSecurityState | 36 class NET_EXPORT TransportSecurityState |
33 : NON_EXPORTED_BASE(public base::NonThreadSafe) { | 37 : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
34 public: | 38 public: |
35 // If non-empty, |hsts_hosts| is a JSON-formatted string to treat as if it | |
36 // were a built-in entry (same format as persisted metadata in the | |
37 // TransportSecurityState file). | |
38 explicit TransportSecurityState(const std::string& hsts_hosts); | |
39 ~TransportSecurityState(); | |
40 | |
41 // A DomainState is the information that we persist about a given domain. | |
42 struct NET_EXPORT DomainState { | |
43 enum Mode { | |
44 // Strict mode implies: | |
45 // * We generate internal redirects from HTTP -> HTTPS. | |
46 // * Certificate issues are fatal. | |
47 MODE_STRICT = 0, | |
48 // This used to be opportunistic HTTPS, but we removed support. | |
49 MODE_OPPORTUNISTIC_REMOVED = 1, | |
50 // SPDY_ONLY (aka X-Bodge-Transport-Security) is a hopefully temporary | |
51 // measure. It implies: | |
52 // * We'll request HTTP URLs over HTTPS iff we have SPDY support. | |
53 // * Certificate issues are fatal. | |
54 MODE_SPDY_ONLY = 2, | |
55 // Pinning means there are no HTTP -> HTTPS redirects, however certificate | |
56 // issues are still fatal and there may be public key pins. | |
57 MODE_PINNING_ONLY = 3, | |
58 }; | |
59 | |
60 DomainState(); | |
61 ~DomainState(); | |
62 | |
63 // Takes a set of SubjectPublicKeyInfo |hashes| and returns true if: | |
64 // 1) |bad_preloaded_spki_hashes| does not intersect |hashes|; AND | |
65 // 2) Both |preloaded_spki_hashes| and |dynamic_spki_hashes| are empty | |
66 // or at least one of them intersects |hashes|. | |
67 // | |
68 // |{dynamic,preloaded}_spki_hashes| contain trustworthy public key | |
69 // hashes, any one of which is sufficient to validate the certificate | |
70 // chain in question. The public keys could be of a root CA, intermediate | |
71 // CA, or leaf certificate, depending on the security vs. disaster | |
72 // recovery tradeoff selected. (Pinning only to leaf certifiates increases | |
73 // security because you no longer trust any CAs, but it hampers disaster | |
74 // recovery because you can't just get a new certificate signed by the | |
75 // CA.) | |
76 // | |
77 // |bad_preloaded_spki_hashes| contains public keys that we don't want to | |
78 // trust. | |
79 bool IsChainOfPublicKeysPermitted(const FingerprintVector& hashes); | |
80 | |
81 // Returns true if |this| describes a more strict policy than |other|. | |
82 // Used to see if a dynamic DomainState should override a preloaded one. | |
83 bool IsMoreStrict(const DomainState& other); | |
84 | |
85 // ShouldRedirectHTTPToHTTPS returns true iff, given the |mode| of this | |
86 // DomainState, HTTP requests should be internally redirected to HTTPS. | |
87 bool ShouldRedirectHTTPToHTTPS() const; | |
88 | |
89 Mode mode; | |
90 base::Time created; // when this host entry was first created | |
91 base::Time expiry; // the absolute time (UTC) when this record expires | |
92 bool include_subdomains; // subdomains included? | |
93 | |
94 // Optional; hashes of preloaded "pinned" SubjectPublicKeyInfos. Unless | |
95 // both are empty, at least one of |preloaded_spki_hashes| and | |
96 // |dynamic_spki_hashes| MUST intersect with the set of SPKIs in the TLS | |
97 // server's certificate chain. | |
98 // | |
99 // |dynamic_spki_hashes| take precedence over |preloaded_spki_hashes|. | |
100 // That is, when performing pin validation, first check dynamic and then | |
101 // check preloaded. | |
102 FingerprintVector preloaded_spki_hashes; | |
103 | |
104 // Optional; hashes of dynamically pinned SubjectPublicKeyInfos. (They | |
105 // could be set e.g. by an HTTP header or by a superfluous certificate.) | |
106 FingerprintVector dynamic_spki_hashes; | |
107 | |
108 // The absolute time (UTC) when the |dynamic_spki_hashes| expire. | |
109 base::Time dynamic_spki_hashes_expiry; | |
110 | |
111 // The max-age directive of the Public-Key-Pins header as parsed. Do not | |
112 // persist this; it is only for testing. TODO(palmer): Therefore, get rid | |
113 // of it and find a better way to test. | |
114 int max_age; | |
115 | |
116 // Optional; hashes of preloaded known-bad SubjectPublicKeyInfos which | |
117 // MUST NOT intersect with the set of SPKIs in the TLS server's | |
118 // certificate chain. | |
119 FingerprintVector bad_preloaded_spki_hashes; | |
120 | |
121 // The following members are not valid when stored in |enabled_hosts_|. | |
122 bool preloaded; // is this a preloaded entry? | |
123 std::string domain; // the domain which matched | |
124 }; | |
125 | |
126 class Delegate { | 39 class Delegate { |
127 public: | 40 public: |
128 // This function may not block and may be called with internal locks held. | 41 // This function may not block and may be called with internal locks held. |
129 // Thus it must not reenter the TransportSecurityState object. | 42 // Thus it must not reenter the TransportSecurityState object. |
130 virtual void StateIsDirty(TransportSecurityState* state) = 0; | 43 virtual void StateIsDirty(TransportSecurityState* state) = 0; |
131 | 44 |
132 protected: | 45 protected: |
133 virtual ~Delegate() {} | 46 virtual ~Delegate() {} |
134 }; | 47 }; |
135 | 48 |
49 TransportSecurityState(); | |
50 ~TransportSecurityState(); | |
51 | |
52 // A DomainState describes the transport security state (required upgrade | |
53 // to HTTPS, and/or any public key pins). | |
54 class DomainState { | |
55 public: | |
56 enum UpgradeMode { | |
57 MODE_DEFAULT, | |
58 MODE_FORCE_HTTPS, | |
59 }; | |
60 | |
61 DomainState(); | |
62 ~DomainState(); | |
63 | |
64 // Parses |value| as a Public-Key-Pins header. If successful, returns true | |
65 // and updates the |dynamic_spki_hashes| and |dynamic_spki_hashes_expiry| | |
66 // fields; otherwise, returns false without updating any fields. | |
67 // Interprets the max-age directive relative to |now|. | |
68 bool ParsePinsHeader(const base::Time& now, | |
69 const std::string& value, | |
70 const SSLInfo& ssl_info); | |
71 | |
72 // Parses |value| as a Strict-Transport-Security header. If successful, | |
73 // returns true and updates the |upgrade_mode|, |upgrade_expiry| and | |
74 // |include_subdomains| fields; otherwise, returns false without updating | |
75 // any fields. Interprets the max-age directive relative to |now|. | |
76 bool ParseSTSHeader(const base::Time& now, const std::string& value); | |
77 | |
78 // Takes a set of SubjectPublicKeyInfo |hashes| and returns true if: | |
79 // 1) |bad_static_spki_hashes| does not intersect |hashes|; AND | |
80 // 2) Both |static_spki_hashes| and |dynamic_spki_hashes| are empty | |
81 // or at least one of them intersects |hashes|. | |
82 // | |
83 // |{dynamic,static}_spki_hashes| contain trustworthy public key hashes, | |
84 // any one of which is sufficient to validate the certificate chain in | |
85 // question. The public keys could be of a root CA, intermediate CA, or | |
86 // leaf certificate, depending on the security vs. disaster recovery | |
87 // tradeoff selected. (Pinning only to leaf certifiates increases | |
88 // security because you no longer trust any CAs, but it hampers disaster | |
89 // recovery because you can't just get a new certificate signed by the | |
90 // CA.) | |
91 // | |
92 // |bad_static_spki_hashes| contains public keys that we don't want to | |
93 // trust. | |
94 bool IsChainOfPublicKeysPermitted(const FingerprintVector& hashes) const; | |
95 | |
96 // Returns true if any of the FingerprintVectors |static_spki_hashes|, | |
97 // |bad_static_spki_hashes|, or |dynamic_spki_hashes| contains any | |
98 // items. | |
99 bool HasPins() const; | |
100 | |
101 // ShouldRedirectHTTPToHTTPS returns true iff, given the |mode| of this | |
102 // DomainState, HTTP requests should be internally redirected to HTTPS. | |
103 bool ShouldRedirectHTTPToHTTPS() const; | |
104 | |
105 UpgradeMode upgrade_mode; | |
106 | |
107 // The absolute time (UTC) when this DomainState was first created. | |
108 // | |
109 // Static entries do not have a created time. | |
110 base::Time created; | |
111 | |
112 // The absolute time (UTC) when the |upgrade_mode|, if set to | |
113 // UPGRADE_ALWAYS, downgrades to UPGRADE_NEVER. | |
114 base::Time upgrade_expiry; | |
115 | |
116 // Are subdomains subject to this DomainState? | |
117 // | |
118 // TODO(palmer): Decide if we should have separate |pin_subdomains| and | |
119 // |upgrade_subdomains|. Alternately, and perhaps better, is to separate | |
120 // DomainState into UpgradeState and PinState (requiring also changing the | |
121 // serialization format?). | |
122 bool include_subdomains; | |
123 | |
124 // Optional; hashes of static pinned SubjectPublicKeyInfos. Unless both | |
125 // are empty, at least one of |static_spki_hashes| and | |
126 // |dynamic_spki_hashes| MUST intersect with the set of SPKIs in the TLS | |
127 // server's certificate chain. | |
128 // | |
129 // |dynamic_spki_hashes| take precedence over |static_spki_hashes|. | |
130 // That is, |IsChainOfPublicKeysPermitted| first checks dynamic pins and | |
131 // then checks static pins. | |
132 FingerprintVector static_spki_hashes; | |
133 | |
134 // Optional; hashes of dynamically pinned SubjectPublicKeyInfos. | |
135 FingerprintVector dynamic_spki_hashes; | |
136 | |
137 // The absolute time (UTC) when the |dynamic_spki_hashes| expire. | |
138 base::Time dynamic_spki_hashes_expiry; | |
139 | |
140 // Optional; hashes of static known-bad SubjectPublicKeyInfos which | |
141 // MUST NOT intersect with the set of SPKIs in the TLS server's | |
142 // certificate chain. | |
143 FingerprintVector bad_static_spki_hashes; | |
144 | |
145 // The following members are not valid when stored in |enabled_hosts_|: | |
146 | |
147 // The domain which matched during a search for this DomainState entry. | |
148 // Updated by |GetDomainState| and |GetStaticDomainState|. | |
149 std::string domain; | |
150 }; | |
151 | |
152 class Iterator { | |
153 public: | |
154 explicit Iterator(const TransportSecurityState& state) | |
155 : iterator_(state.enabled_hosts_.begin()), | |
156 end_(state.enabled_hosts_.end()) { } | |
Ryan Sleevi
2012/04/26 19:21:12
nit: } on a new line, as per
http://google-stylegu
palmer
2012/04/27 23:52:34
Done.
| |
157 ~Iterator() { } | |
Ryan Sleevi
2012/04/26 19:21:12
nit: { } -> {}
palmer
2012/04/27 23:52:34
Done.
| |
158 | |
159 bool HasNext() const { return iterator_ != end_; } | |
160 void Advance() { ++iterator_; } | |
161 const std::string& hostname() const { return iterator_->first; } | |
162 const DomainState& domain_state() const { return iterator_->second; } | |
163 | |
164 private: | |
165 std::map<std::string, DomainState>::const_iterator iterator_; | |
166 std::map<std::string, DomainState>::const_iterator end_; | |
167 }; | |
168 | |
169 // Assign a |Delegate| for persisting the transport security state. If | |
170 // |NULL|, state will not be persisted. Caller owns |delegate|. | |
136 void SetDelegate(Delegate* delegate); | 171 void SetDelegate(Delegate* delegate); |
137 | 172 |
138 // Enable TransportSecurity for |host|. | 173 // Enable TransportSecurity for |host|. |state| supercedes any previous |
174 // state for the |host|, including static entries. | |
175 // | |
176 // The new state for |host| is persisted using the Delegate (if any). | |
139 void EnableHost(const std::string& host, const DomainState& state); | 177 void EnableHost(const std::string& host, const DomainState& state); |
140 | 178 |
141 // Delete any entry for |host|. If |host| doesn't have an exact entry then no | 179 // Delete any entry for |host|. If |host| doesn't have an exact entry then |
142 // action is taken. Returns true iff an entry was deleted. | 180 // no action is taken. Does not delete static entries. Returns true iff an |
181 // entry was deleted. | |
182 // | |
183 // The new state for |host| is persisted using the Delegate (if any). | |
143 bool DeleteHost(const std::string& host); | 184 bool DeleteHost(const std::string& host); |
144 | 185 |
145 // Returns true if |host| has TransportSecurity enabled. Before operating | |
146 // on this result, consult |result->mode|, as the expected behavior of | |
147 // TransportSecurity can significantly differ based on mode. | |
148 // | |
149 // If |sni_available| is true, searches the preloads defined for SNI-using | |
150 // hosts as well as the usual preload list. | |
151 // | |
152 // Note that |*result| is always overwritten on every call. | |
153 // TODO(palmer): Only update |*result| on success. | |
154 bool GetDomainState(DomainState* result, | |
155 const std::string& host, | |
156 bool sni_available); | |
157 | |
158 // Returns true if there are any certificates pinned for |host|. | |
159 // If so, updates the |preloaded_spki_hashes|, |dynamic_spki_hashes|, and | |
160 // |bad_preloaded_spki_hashes| fields of |*result| with the pins. | |
161 // | |
162 // Note that |*result| is always overwritten on every call, regardless of | |
163 // whether or not pins are enabled. | |
164 // | |
165 // If |sni_available| is true, searches the preloads defined for SNI-using | |
166 // hosts as well as the usual preload list. | |
167 // | |
168 // TODO(palmer): Only update |*result| if pins exist. | |
169 bool HasPinsForHost(DomainState* result, | |
170 const std::string& host, | |
171 bool sni_available); | |
172 | |
173 // Returns true and updates |*result| if there is any |DomainState| | |
174 // metadata for |host| in the local TransportSecurityState database; | |
175 // returns false otherwise. TODO(palmer): Unlike the other | |
176 // TransportSecurityState lookup functions in this class (e.g | |
177 // |HasPinsForHost|, |GetDomainState|), |*result| is updated iff metadata | |
178 // is found. The other functions are buggy and will be fixed to behave | |
179 // like this one. | |
180 // | |
181 // If |sni_available| is true, searches the preloads defined for SNI-using | |
182 // hosts as well as the usual preload list. | |
183 bool HasMetadata(DomainState* result, | |
184 const std::string& host, | |
185 bool sni_available); | |
186 | |
187 // Returns true if we have a preloaded certificate pin for the |host| and if | |
188 // its set of required certificates is the set we expect for Google | |
189 // properties. | |
190 // | |
191 // If |sni_available| is true, searches the preloads defined for SNI-using | |
192 // hosts as well as the usual preload list. | |
193 // | |
194 // Note that like HasMetadata, if |host| matches both an exact entry and is a | |
195 // subdomain of another entry, the exact match determines the return value. | |
196 static bool IsGooglePinnedProperty(const std::string& host, | |
197 bool sni_available); | |
198 | |
199 // Reports UMA statistics upon public key pin failure. Reports only down to | |
200 // the second-level domain of |host| (e.g. google.com if |host| is | |
201 // mail.google.com), and only if |host| is a preloaded STS host. | |
202 static void ReportUMAOnPinFailure(const std::string& host); | |
203 | |
204 // Parses |cert|'s Subject Public Key Info structure, hashes it, and writes | |
205 // the hash into |spki_hash|. Returns true on parse success, false on | |
206 // failure. | |
207 static bool GetPublicKeyHash(const X509Certificate& cert, | |
208 SHA1Fingerprint* spki_hash); | |
209 | |
210 // Decodes a pin string |value| (e.g. "sha1/hvfkN/qlp/zhXR3cuerq6jd2Z7g=") | |
211 // and populates |out|. | |
212 static bool ParsePin(const std::string& value, SHA1Fingerprint* out); | |
213 | |
214 // Deletes all records created since a given time. | 186 // Deletes all records created since a given time. |
215 void DeleteSince(const base::Time& time); | 187 void DeleteSince(const base::Time& time); |
216 | 188 |
217 // Parses |value| as a Public-Key-Pins header. If successful, returns |true| | 189 // Returns true and updates |*result| iff there is a DomainState for |
218 // and updates the |dynamic_spki_hashes| and |dynamic_spki_hashes_expiry| | 190 // |host|. |
219 // fields of |*state|; otherwise, returns |false| without updating |*state|. | 191 // |
220 static bool ParsePinsHeader(const std::string& value, | 192 // If |sni_enabled| is true, searches the static pins defined for |
221 const SSLInfo& ssl_info, | 193 // SNI-using hosts as well as the rest of the pins. |
222 DomainState* state); | 194 // |
223 | 195 // If |host| matches both an exact entry and is a subdomain of another |
224 // Returns |true| if |value| parses as a valid *-Transport-Security | 196 // entry, the exact match determines the return value. |
225 // header value. The values of max-age and and includeSubDomains are | 197 // |
226 // returned in |max_age| and |include_subdomains|, respectively. The out | 198 // Note that this method is not const because it opportunistically removes |
227 // parameters are not modified if the function returns |false|. | 199 // entries that have expired. |
228 static bool ParseHeader(const std::string& value, | 200 bool GetDomainState(const std::string& host, |
229 int* max_age, | 201 bool sni_enabled, |
230 bool* include_subdomains); | 202 DomainState* result); |
231 | 203 |
232 // ParseSidePin attempts to parse a side pin from |side_info| which signs the | 204 // Returns true and updates |*result| iff there is a static DomainState for |
233 // SubjectPublicKeyInfo in |leaf_spki|. A side pin is a way for a site to | 205 // |host|. |
234 // sign their public key with a key that is offline but still controlled by | 206 // |
235 // them. If successful, the hash of the public key used to sign |leaf_spki| | 207 // |GetStaticDomainState| is identical to |GetDomainState| except that it |
236 // is put into |out_pub_key_hash|. | 208 // searches only the statically-defined transport security state, ignoring |
237 static bool ParseSidePin(const base::StringPiece& leaf_spki, | 209 // all dynamically-added DomainStates. |
238 const base::StringPiece& side_info, | 210 // |
239 FingerprintVector* out_pub_key_hash); | 211 // If |sni_enabled| is true, searches the static pins defined for |
240 | 212 // SNI-using hosts as well as the rest of the pins. |
241 bool Serialise(std::string* output); | 213 // |
242 // Existing non-preloaded entries are cleared and repopulated from the | 214 // If |host| matches both an exact entry and is a subdomain of another |
243 // passed JSON string. | 215 // entry, the exact match determines the return value. |
244 bool LoadEntries(const std::string& state, bool* dirty); | 216 // |
217 // Note that this method is not const because it opportunistically removes | |
218 // entries that have expired. | |
219 bool GetStaticDomainState(const std::string& host, | |
220 bool sni_enabled, | |
221 DomainState* result); | |
222 | |
223 // Removed all DomainState records. | |
224 void Clear() { enabled_hosts_.clear(); } | |
225 | |
226 // Returns the map of hosts that have DomainState entries. The keys of the | |
227 // map are HashHost(CanonicalizeHost(hostname)). | |
228 // | |
229 // NOTE: Normally, clients will not use this directly; most clients should | |
230 // use |GetDomainState|, |GetStaticDomainState|, |EnableHost|, | |
231 // |DeleteHost|, and |DeleteSince|. | |
232 std::map<std::string, DomainState>& GetEnabledHosts() { | |
Ryan Sleevi
2012/04/26 19:21:12
I would much rather you expose an API that allows
palmer
2012/04/27 23:52:34
Done.
| |
233 return enabled_hosts_; | |
234 } | |
235 | |
236 // Returns the map of hosts that have forced DomainState entries. The keys | |
237 // of the map are HashHost(CanonicalizeHost(hostname)). | |
238 // | |
239 // NOTE: Normally, clients will not use this directly; most clients should | |
240 // use |GetDomainState|, |GetStaticDomainState|, |EnableHost|, | |
241 // |DeleteHost|, and |DeleteSince|. | |
242 std::map<std::string, DomainState>& GetForcedHosts() { | |
243 return forced_hosts_; | |
244 } | |
245 | |
246 // Returns true iff we have any static public key pins for the |host| and | |
247 // iff its set of required pins is the set we expect for Google | |
248 // properties. | |
249 // | |
250 // If |sni_enabled| is true, searches the static pins defined for | |
251 // SNI-using hosts as well as the rest of the pins. | |
252 // | |
253 // If |host| matches both an exact entry and is a subdomain of another | |
254 // entry, the exact match determines the return value. | |
255 static bool IsGooglePinnedProperty(const std::string& host, | |
256 bool sni_enabled); | |
257 | |
258 // Decodes a pin string |value| (e.g. "sha1/hvfkN/qlp/zhXR3cuerq6jd2Z7g="). | |
259 // If parsing succeeded, updates |*out| and returns true; otherwise returns | |
260 // false without updating |*out|. | |
261 static bool ParsePin(const std::string& value, Fingerprint* out); | |
245 | 262 |
246 // The maximum number of seconds for which we'll cache an HSTS request. | 263 // The maximum number of seconds for which we'll cache an HSTS request. |
247 static const long int kMaxHSTSAgeSecs; | 264 static const long int kMaxHSTSAgeSecs; |
248 | 265 |
266 // Converts |hostname| from dotted form ("www.google.com") to the form | |
267 // used in DNS: "\x03www\x06google\x03com", lowercases that, and returns | |
268 // the result. | |
269 static std::string CanonicalizeHost(const std::string& hostname); | |
270 | |
271 // Send an UMA report on pin validation failure, if the host is in a | |
272 // statically-defined list of domains. | |
273 // | |
274 // TODO(palmer): This doesn't really belong here, and should be moved into | |
275 // the exactly one call site. This requires unifying |struct HSTSPreload| | |
276 // (an implementation detail of this class) with a more generic | |
277 // representation of first-class DomainStates, and exposing the preloads | |
278 // to the caller with |GetStaticDomainState|. | |
279 static void ReportUMAOnPinFailure(const std::string& host); | |
280 | |
249 private: | 281 private: |
250 FRIEND_TEST_ALL_PREFIXES(TransportSecurityStateTest, IsPreloaded); | 282 // If a Delegate is present, notify it that the internal state has |
251 | 283 // changed. |
252 // If we have a callback configured, call it to let our serialiser know that | |
253 // our state is dirty. | |
254 void DirtyNotify(); | 284 void DirtyNotify(); |
255 bool IsPreloadedSTS(const std::string& canonicalized_host, | 285 |
256 bool sni_available, | 286 // The set of hosts that have enabled TransportSecurity. |
257 DomainState* out); | |
258 | |
259 static std::string CanonicalizeHost(const std::string& host); | |
260 static bool Deserialise(const std::string& state, | |
261 bool* dirty, | |
262 std::map<std::string, DomainState>* out); | |
263 | |
264 // The set of hosts that have enabled TransportSecurity. The keys here | |
265 // are SHA256(DNSForm(domain)) where DNSForm converts from dotted form | |
266 // ('www.google.com') to the form used in DNS: "\x03www\x06google\x03com" | |
267 std::map<std::string, DomainState> enabled_hosts_; | 287 std::map<std::string, DomainState> enabled_hosts_; |
268 | 288 |
269 // These hosts are extra rules to treat as built-in, passed in the | 289 // Extra entries, provided by the user at run-time, to treat as if they |
270 // constructor (typically originating from the command line). | 290 // were static. |
271 std::map<std::string, DomainState> forced_hosts_; | 291 std::map<std::string, DomainState> forced_hosts_; |
272 | 292 |
273 // Our delegate who gets notified when we are dirtied, or NULL. | |
274 Delegate* delegate_; | 293 Delegate* delegate_; |
275 | 294 |
276 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); | 295 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); |
277 }; | 296 }; |
278 | 297 |
279 } // namespace net | 298 } // namespace net |
280 | 299 |
281 #endif // NET_BASE_TRANSPORT_SECURITY_STATE_H_ | 300 #endif // NET_BASE_TRANSPORT_SECURITY_STATE_H_ |
OLD | NEW |