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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/threading/non_thread_safe.h" | 15 #include "base/threading/non_thread_safe.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "net/base/net_export.h" | 17 #include "net/base/net_export.h" |
18 #include "net/cert/x509_cert_types.h" | 18 #include "net/cert/x509_cert_types.h" |
19 #include "net/cert/x509_certificate.h" | 19 #include "net/cert/x509_certificate.h" |
| 20 #include "url/gurl.h" |
20 | 21 |
21 namespace net { | 22 namespace net { |
22 | 23 |
23 class SSLInfo; | 24 class SSLInfo; |
24 | 25 |
25 // Tracks which hosts have enabled strict transport security and/or public | 26 // Tracks which hosts have enabled strict transport security and/or public |
26 // key pins. | 27 // key pins. |
27 // | 28 // |
28 // This object manages the in-memory store. Register a Delegate with | 29 // This object manages the in-memory store. Register a Delegate with |
29 // |SetDelegate| to persist the state to disk. | 30 // |SetDelegate| to persist the state to disk. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // chain. | 124 // chain. |
124 HashValueVector bad_spki_hashes; | 125 HashValueVector bad_spki_hashes; |
125 | 126 |
126 // Are subdomains subject to this policy state? | 127 // Are subdomains subject to this policy state? |
127 bool include_subdomains; | 128 bool include_subdomains; |
128 | 129 |
129 // The domain which matched during a search for this DomainState entry. | 130 // The domain which matched during a search for this DomainState entry. |
130 // Updated by |GetDynamicPKPState| and |GetStaticDomainState|. | 131 // Updated by |GetDynamicPKPState| and |GetStaticDomainState|. |
131 std::string domain; | 132 std::string domain; |
132 | 133 |
| 134 // An optional URI indicating where reports should be |
| 135 // sent when this pin is violated, or empty when omitted. |
| 136 GURL report_uri; |
| 137 |
133 // Takes a set of SubjectPublicKeyInfo |hashes| and returns true if: | 138 // Takes a set of SubjectPublicKeyInfo |hashes| and returns true if: |
134 // 1) |bad_static_spki_hashes| does not intersect |hashes|; AND | 139 // 1) |bad_static_spki_hashes| does not intersect |hashes|; AND |
135 // 2) Both |static_spki_hashes| and |dynamic_spki_hashes| are empty | 140 // 2) Both |static_spki_hashes| and |dynamic_spki_hashes| are empty |
136 // or at least one of them intersects |hashes|. | 141 // or at least one of them intersects |hashes|. |
137 // | 142 // |
138 // |{dynamic,static}_spki_hashes| contain trustworthy public key hashes, | 143 // |{dynamic,static}_spki_hashes| contain trustworthy public key hashes, |
139 // any one of which is sufficient to validate the certificate chain in | 144 // any one of which is sufficient to validate the certificate chain in |
140 // question. The public keys could be of a root CA, intermediate CA, or | 145 // question. The public keys could be of a root CA, intermediate CA, or |
141 // leaf certificate, depending on the security vs. disaster recovery | 146 // leaf certificate, depending on the security vs. disaster recovery |
142 // tradeoff selected. (Pinning only to leaf certifiates increases | 147 // tradeoff selected. (Pinning only to leaf certifiates increases |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 // HSTS header (used for net-internals and unit tests). | 266 // HSTS header (used for net-internals and unit tests). |
262 void AddHSTS(const std::string& host, | 267 void AddHSTS(const std::string& host, |
263 const base::Time& expiry, | 268 const base::Time& expiry, |
264 bool include_subdomains); | 269 bool include_subdomains); |
265 | 270 |
266 // Adds explicitly-specified data as if it was processed from an | 271 // Adds explicitly-specified data as if it was processed from an |
267 // HPKP header (used for net-internals and unit tests). | 272 // HPKP header (used for net-internals and unit tests). |
268 void AddHPKP(const std::string& host, | 273 void AddHPKP(const std::string& host, |
269 const base::Time& expiry, | 274 const base::Time& expiry, |
270 bool include_subdomains, | 275 bool include_subdomains, |
271 const HashValueVector& hashes); | 276 const HashValueVector& hashes, |
| 277 const GURL& report_uri); |
272 | 278 |
273 // Returns true iff we have any static public key pins for the |host| and | 279 // Returns true iff we have any static public key pins for the |host| and |
274 // iff its set of required pins is the set we expect for Google | 280 // iff its set of required pins is the set we expect for Google |
275 // properties. | 281 // properties. |
276 // | 282 // |
277 // If |host| matches both an exact entry and is a subdomain of another | 283 // If |host| matches both an exact entry and is a subdomain of another |
278 // entry, the exact match determines the return value. | 284 // entry, the exact match determines the return value. |
279 static bool IsGooglePinnedProperty(const std::string& host); | 285 static bool IsGooglePinnedProperty(const std::string& host); |
280 | 286 |
281 // The maximum number of seconds for which we'll cache an HSTS request. | 287 // The maximum number of seconds for which we'll cache an HSTS request. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 void AddHSTSInternal(const std::string& host, | 324 void AddHSTSInternal(const std::string& host, |
319 STSState::UpgradeMode upgrade_mode, | 325 STSState::UpgradeMode upgrade_mode, |
320 const base::Time& expiry, | 326 const base::Time& expiry, |
321 bool include_subdomains); | 327 bool include_subdomains); |
322 | 328 |
323 // Adds HPKP state to |host|. | 329 // Adds HPKP state to |host|. |
324 void AddHPKPInternal(const std::string& host, | 330 void AddHPKPInternal(const std::string& host, |
325 const base::Time& last_observed, | 331 const base::Time& last_observed, |
326 const base::Time& expiry, | 332 const base::Time& expiry, |
327 bool include_subdomains, | 333 bool include_subdomains, |
328 const HashValueVector& hashes); | 334 const HashValueVector& hashes, |
| 335 const GURL& report_uri); |
329 | 336 |
330 // Enable TransportSecurity for |host|. |state| supercedes any previous | 337 // Enable TransportSecurity for |host|. |state| supercedes any previous |
331 // state for the |host|, including static entries. | 338 // state for the |host|, including static entries. |
332 // | 339 // |
333 // The new state for |host| is persisted using the Delegate (if any). | 340 // The new state for |host| is persisted using the Delegate (if any). |
334 void EnableSTSHost(const std::string& host, const STSState& state); | 341 void EnableSTSHost(const std::string& host, const STSState& state); |
335 void EnablePKPHost(const std::string& host, const PKPState& state); | 342 void EnablePKPHost(const std::string& host, const PKPState& state); |
336 | 343 |
337 // The sets of hosts that have enabled TransportSecurity. |domain| will always | 344 // The sets of hosts that have enabled TransportSecurity. |domain| will always |
338 // be empty for a STSState or PKPState in these maps; the domain | 345 // be empty for a STSState or PKPState in these maps; the domain |
339 // comes from the map keys instead. In addition, |upgrade_mode| in the | 346 // comes from the map keys instead. In addition, |upgrade_mode| in the |
340 // STSState is never MODE_DEFAULT and |HasPublicKeyPins| in the PKPState | 347 // STSState is never MODE_DEFAULT and |HasPublicKeyPins| in the PKPState |
341 // always returns true. | 348 // always returns true. |
342 STSStateMap enabled_sts_hosts_; | 349 STSStateMap enabled_sts_hosts_; |
343 PKPStateMap enabled_pkp_hosts_; | 350 PKPStateMap enabled_pkp_hosts_; |
344 | 351 |
345 Delegate* delegate_; | 352 Delegate* delegate_; |
346 | 353 |
347 // True if static pins should be used. | 354 // True if static pins should be used. |
348 bool enable_static_pins_; | 355 bool enable_static_pins_; |
349 | 356 |
350 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); | 357 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); |
351 }; | 358 }; |
352 | 359 |
353 } // namespace net | 360 } // namespace net |
354 | 361 |
355 #endif // NET_HTTP_TRANSPORT_SECURITY_STATE_H_ | 362 #endif // NET_HTTP_TRANSPORT_SECURITY_STATE_H_ |
OLD | NEW |