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_HTTP_TRANSPORT_SECURITY_STATE_H_ | 5 #ifndef NET_HTTP_TRANSPORT_SECURITY_STATE_H_ |
6 #define NET_HTTP_TRANSPORT_SECURITY_STATE_H_ | 6 #define NET_HTTP_TRANSPORT_SECURITY_STATE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 public: | 54 public: |
55 enum UpgradeMode { | 55 enum UpgradeMode { |
56 // These numbers must match those in hsts_view.js, function modeToString. | 56 // These numbers must match those in hsts_view.js, function modeToString. |
57 MODE_FORCE_HTTPS = 0, | 57 MODE_FORCE_HTTPS = 0, |
58 MODE_DEFAULT = 1, | 58 MODE_DEFAULT = 1, |
59 }; | 59 }; |
60 | 60 |
61 DomainState(); | 61 DomainState(); |
62 ~DomainState(); | 62 ~DomainState(); |
63 | 63 |
64 struct STSState { | |
65 // The absolute time (UTC) when the |upgrade_mode| (and other state) was | |
66 // observed. | |
67 base::Time last_observed; | |
68 | |
69 // The absolute time (UTC) when the |upgrade_mode|, if set to | |
70 // UPGRADE_ALWAYS, downgrades to UPGRADE_NEVER. | |
71 base::Time expiry; | |
72 | |
73 UpgradeMode upgrade_mode; | |
74 | |
75 // Are subdomains subject to this policy state? | |
76 bool include_subdomains; | |
77 }; | |
78 | |
79 struct PKPState { | |
80 // The absolute time (UTC) when the |spki_hashes| (and other state) were | |
81 // observed. | |
82 base::Time last_observed; | |
83 | |
84 // The absolute time (UTC) when the |spki_hashes| expire. | |
85 base::Time expiry; | |
86 | |
87 // Optional; hashes of pinned SubjectPublicKeyInfos. | |
88 HashValueVector spki_hashes; | |
89 | |
90 // Optional; hashes of static known-bad SubjectPublicKeyInfos which MUST | |
91 // NOT intersect with the set of SPKIs in the TLS server's certificate | |
92 // chain. | |
93 HashValueVector bad_spki_hashes; | |
94 | |
95 // Are subdomains subject to this policy state? | |
96 bool include_subdomains; | |
97 }; | |
98 | |
64 // Takes a set of SubjectPublicKeyInfo |hashes| and returns true if: | 99 // Takes a set of SubjectPublicKeyInfo |hashes| and returns true if: |
65 // 1) |bad_static_spki_hashes| does not intersect |hashes|; AND | 100 // 1) |bad_static_spki_hashes| does not intersect |hashes|; AND |
66 // 2) Both |static_spki_hashes| and |dynamic_spki_hashes| are empty | 101 // 2) Both |static_spki_hashes| and |dynamic_spki_hashes| are empty |
67 // or at least one of them intersects |hashes|. | 102 // or at least one of them intersects |hashes|. |
68 // | 103 // |
69 // |{dynamic,static}_spki_hashes| contain trustworthy public key hashes, | 104 // |{dynamic,static}_spki_hashes| contain trustworthy public key hashes, |
70 // any one of which is sufficient to validate the certificate chain in | 105 // any one of which is sufficient to validate the certificate chain in |
71 // question. The public keys could be of a root CA, intermediate CA, or | 106 // question. The public keys could be of a root CA, intermediate CA, or |
72 // leaf certificate, depending on the security vs. disaster recovery | 107 // leaf certificate, depending on the security vs. disaster recovery |
73 // tradeoff selected. (Pinning only to leaf certifiates increases | 108 // tradeoff selected. (Pinning only to leaf certifiates increases |
(...skipping 12 matching lines...) Expand all Loading... | |
86 | 121 |
87 // ShouldUpgradeToSSL returns true iff, given the |mode| of this | 122 // ShouldUpgradeToSSL returns true iff, given the |mode| of this |
88 // DomainState, HTTP requests should be internally redirected to HTTPS | 123 // DomainState, HTTP requests should be internally redirected to HTTPS |
89 // (also if the "ws" WebSocket request should be upgraded to "wss") | 124 // (also if the "ws" WebSocket request should be upgraded to "wss") |
90 bool ShouldUpgradeToSSL() const; | 125 bool ShouldUpgradeToSSL() const; |
91 | 126 |
92 // ShouldSSLErrorsBeFatal returns true iff HTTPS errors should cause | 127 // ShouldSSLErrorsBeFatal returns true iff HTTPS errors should cause |
93 // hard-fail behavior (e.g. if HSTS is set for the domain) | 128 // hard-fail behavior (e.g. if HSTS is set for the domain) |
94 bool ShouldSSLErrorsBeFatal() const; | 129 bool ShouldSSLErrorsBeFatal() const; |
95 | 130 |
96 UpgradeMode upgrade_mode; | 131 STSState sts; |
97 | 132 PKPState pkp; |
98 // The absolute time (UTC) when the |upgrade_mode| was observed. | |
99 // | |
100 // TODO(palmer): Perhaps static entries should have an "observed" time. | |
101 base::Time sts_observed; | |
102 | |
103 // The absolute time (UTC) when the |dynamic_spki_hashes| (and other | |
104 // |dynamic_*| state) were observed. | |
105 // | |
106 // TODO(palmer): Perhaps static entries should have an "observed" time. | |
107 base::Time pkp_observed; | |
108 | |
109 // The absolute time (UTC) when the |upgrade_mode|, if set to | |
110 // UPGRADE_ALWAYS, downgrades to UPGRADE_NEVER. | |
111 base::Time upgrade_expiry; | |
112 | |
113 // Are subdomains subject to this DomainState, for the purposes of | |
114 // upgrading to HTTPS? | |
115 bool sts_include_subdomains; | |
116 | |
117 // Are subdomains subject to this DomainState, for the purposes of | |
118 // Pin Validation? | |
119 bool pkp_include_subdomains; | |
120 | |
121 // Optional; hashes of static pinned SubjectPublicKeyInfos. Unless both | |
122 // are empty, at least one of |static_spki_hashes| and | |
123 // |dynamic_spki_hashes| MUST intersect with the set of SPKIs in the TLS | |
124 // server's certificate chain. | |
125 // | |
126 // |dynamic_spki_hashes| take precedence over |static_spki_hashes|. | |
127 // That is, |IsChainOfPublicKeysPermitted| first checks dynamic pins and | |
128 // then checks static pins. | |
129 HashValueVector static_spki_hashes; | |
130 | |
131 // Optional; hashes of dynamically pinned SubjectPublicKeyInfos. | |
132 HashValueVector dynamic_spki_hashes; | |
133 | |
134 // The absolute time (UTC) when the |dynamic_spki_hashes| expire. | |
135 base::Time dynamic_spki_hashes_expiry; | |
136 | |
137 // Optional; hashes of static known-bad SubjectPublicKeyInfos which | |
138 // MUST NOT intersect with the set of SPKIs in the TLS server's | |
139 // certificate chain. | |
140 HashValueVector bad_static_spki_hashes; | |
141 | 133 |
142 // The following members are not valid when stored in |enabled_hosts_|: | 134 // The following members are not valid when stored in |enabled_hosts_|: |
143 | 135 |
144 // The domain which matched during a search for this DomainState entry. | 136 // The domain which matched during a search for this DomainState entry. |
145 // Updated by |GetDomainState|, |GetDynamicDomainState|, and | 137 // Updated by |GetDynamicDomainState| and |GetStaticDomainState|. |
146 // |GetStaticDomainState|. | |
147 std::string domain; | 138 std::string domain; |
Ryan Sleevi
2014/04/08 20:29:11
Should this be migrated into the STS and PKP state
| |
148 }; | 139 }; |
149 | 140 |
150 class NET_EXPORT Iterator { | 141 class NET_EXPORT Iterator { |
151 public: | 142 public: |
152 explicit Iterator(const TransportSecurityState& state); | 143 explicit Iterator(const TransportSecurityState& state); |
153 ~Iterator(); | 144 ~Iterator(); |
154 | 145 |
155 bool HasNext() const { return iterator_ != end_; } | 146 bool HasNext() const { return iterator_ != end_; } |
156 void Advance() { ++iterator_; } | 147 void Advance() { ++iterator_; } |
157 const std::string& hostname() const { return iterator_->first; } | 148 const std::string& hostname() const { return iterator_->first; } |
158 const DomainState& domain_state() const { return iterator_->second; } | 149 const DomainState& domain_state() const { return iterator_->second; } |
159 | 150 |
160 private: | 151 private: |
161 std::map<std::string, DomainState>::const_iterator iterator_; | 152 std::map<std::string, DomainState>::const_iterator iterator_; |
162 std::map<std::string, DomainState>::const_iterator end_; | 153 std::map<std::string, DomainState>::const_iterator end_; |
163 }; | 154 }; |
164 | 155 |
156 // TODO(palmer): Document this. | |
157 bool ShouldSSLErrorsBeFatal(const std::string& host, bool sni_enabled) const; | |
158 | |
159 // TODO(palmer): Document this. | |
160 bool ShouldUpgradeToSSL(const std::string& host, bool sni_enabled) const; | |
161 | |
162 // TODO(palmer): Document this. | |
163 bool CheckPublicKeyPins(const std::string& host, | |
164 bool sni_enabled, | |
165 const HashValueVector& hashes) const; | |
166 | |
167 // TODO(palmer): Document this. | |
168 bool HasPublicKeyPins(const std::string& host, bool sni_enabled) const; | |
169 | |
165 // Assign a |Delegate| for persisting the transport security state. If | 170 // Assign a |Delegate| for persisting the transport security state. If |
166 // |NULL|, state will not be persisted. The caller retains | 171 // |NULL|, state will not be persisted. The caller retains |
167 // ownership of |delegate|. | 172 // ownership of |delegate|. |
168 // Note: This is only used for serializing/deserializing the | 173 // Note: This is only used for serializing/deserializing the |
169 // TransportSecurityState. | 174 // TransportSecurityState. |
170 void SetDelegate(Delegate* delegate); | 175 void SetDelegate(Delegate* delegate); |
171 | 176 |
172 // Clears all dynamic data (e.g. HSTS and HPKP data). | 177 // Clears all dynamic data (e.g. HSTS and HPKP data). |
173 // | 178 // |
174 // Does NOT persist changes using the Delegate, as this function is only | 179 // Does NOT persist changes using the Delegate, as this function is only |
(...skipping 30 matching lines...) Expand all Loading... | |
205 // |host|. | 210 // |host|. |
206 // | 211 // |
207 // If |sni_enabled| is true, searches the static pins defined for | 212 // If |sni_enabled| is true, searches the static pins defined for |
208 // SNI-using hosts as well as the rest of the pins. | 213 // SNI-using hosts as well as the rest of the pins. |
209 // | 214 // |
210 // If |host| matches both an exact entry and is a subdomain of another | 215 // If |host| matches both an exact entry and is a subdomain of another |
211 // entry, the exact match determines the return value. | 216 // entry, the exact match determines the return value. |
212 // | 217 // |
213 // Note that this method is not const because it opportunistically removes | 218 // Note that this method is not const because it opportunistically removes |
214 // entries that have expired. | 219 // entries that have expired. |
215 bool GetDomainState(const std::string& host, | 220 bool GetStaticDomainState(const std::string& host, |
216 bool sni_enabled, | 221 bool sni_enabled, |
217 DomainState* result); | 222 DomainState* result); |
223 bool GetDynamicDomainState(const std::string& host, DomainState* result); | |
218 | 224 |
219 // Processes an HSTS header value from the host, adding entries to | 225 // Processes an HSTS header value from the host, adding entries to |
220 // dynamic state if necessary. | 226 // dynamic state if necessary. |
221 bool AddHSTSHeader(const std::string& host, const std::string& value); | 227 bool AddHSTSHeader(const std::string& host, const std::string& value); |
222 | 228 |
223 // Processes an HPKP header value from the host, adding entries to | 229 // Processes an HPKP header value from the host, adding entries to |
224 // dynamic state if necessary. ssl_info is used to check that | 230 // dynamic state if necessary. ssl_info is used to check that |
225 // the specified pins overlap with the certificate chain. | 231 // the specified pins overlap with the certificate chain. |
226 bool AddHPKPHeader(const std::string& host, const std::string& value, | 232 bool AddHPKPHeader(const std::string& host, const std::string& value, |
227 const SSLInfo& ssl_info); | 233 const SSLInfo& ssl_info); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 // state for the |host|, including static entries. | 299 // state for the |host|, including static entries. |
294 // | 300 // |
295 // The new state for |host| is persisted using the Delegate (if any). | 301 // The new state for |host| is persisted using the Delegate (if any). |
296 void EnableHost(const std::string& host, const DomainState& state); | 302 void EnableHost(const std::string& host, const DomainState& state); |
297 | 303 |
298 // Converts |hostname| from dotted form ("www.google.com") to the form | 304 // Converts |hostname| from dotted form ("www.google.com") to the form |
299 // used in DNS: "\x03www\x06google\x03com", lowercases that, and returns | 305 // used in DNS: "\x03www\x06google\x03com", lowercases that, and returns |
300 // the result. | 306 // the result. |
301 static std::string CanonicalizeHost(const std::string& hostname); | 307 static std::string CanonicalizeHost(const std::string& hostname); |
302 | 308 |
303 // Returns true and updates |*result| iff there is a static DomainState for | |
304 // |host|. | |
305 // | |
306 // |GetStaticDomainState| is identical to |GetDomainState| except that it | |
307 // searches only the statically-defined transport security state, ignoring | |
308 // all dynamically-added DomainStates. | |
309 // | |
310 // If |sni_enabled| is true, searches the static pins defined for | |
311 // SNI-using hosts as well as the rest of the pins. | |
312 // | |
313 // If |host| matches both an exact entry and is a subdomain of another | |
314 // entry, the exact match determines the return value. | |
315 // | |
316 // Note that this method is not const because it opportunistically removes | |
317 // entries that have expired. | |
318 bool GetStaticDomainState(const std::string& host, | |
319 bool sni_enabled, | |
320 DomainState* result); | |
321 | |
322 // Returns true and updates |*result| iff there is a dynamic DomainState for | |
323 // |host|. | |
324 // | |
325 // |GetDynamicDomainState| is identical to |GetDomainState| except that it | |
326 // searches only the dynamically-added transport security state, ignoring | |
327 // all statically-defined DomainStates. | |
328 // | |
329 // If |host| matches both an exact entry and is a subdomain of another | |
330 // entry, the exact match determines the return value. | |
331 // | |
332 // Note that this method is not const because it opportunistically removes | |
333 // entries that have expired. | |
334 bool GetDynamicDomainState(const std::string& host, DomainState* result); | |
335 | |
336 // The set of hosts that have enabled TransportSecurity. | 309 // The set of hosts that have enabled TransportSecurity. |
337 DomainStateMap enabled_hosts_; | 310 DomainStateMap enabled_hosts_; |
338 | 311 |
339 Delegate* delegate_; | 312 Delegate* delegate_; |
340 | 313 |
341 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); | 314 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); |
342 }; | 315 }; |
343 | 316 |
344 } // namespace net | 317 } // namespace net |
345 | 318 |
346 #endif // NET_HTTP_TRANSPORT_SECURITY_STATE_H_ | 319 #endif // NET_HTTP_TRANSPORT_SECURITY_STATE_H_ |
OLD | NEW |