Chromium Code Reviews| 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 <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.h" | 16 #include "base/time.h" |
| 17 #include "net/base/net_export.h" | 17 #include "net/base/net_export.h" |
| 18 #include "net/base/x509_certificate.h" | 18 #include "net/base/x509_certificate.h" |
| 19 #include "net/base/x509_cert_types.h" | 19 #include "net/base/x509_cert_types.h" |
| 20 | 20 |
| 21 namespace net { | 21 namespace net { |
| 22 | 22 |
| 23 class SSLInfo; | 23 class SSLInfo; |
| 24 | 24 |
| 25 typedef std::vector<SHA1Fingerprint> FingerprintVector; | 25 // In the future there will be a generic Fingerprint type, with at least two |
| 26 // implementations: SHA1 and SHA256. See http://crbug.com/117914. Until that | |
| 27 // work is done (in a separate patch) this typedef bridges the gap. | |
| 28 typedef SHA1Fingerprint Fingerprint; | |
| 26 | 29 |
| 27 // TransportSecurityState | 30 typedef std::vector<Fingerprint> FingerprintVector; |
| 31 | |
| 32 // Tracks which hosts have enabled strict transport security and/or public | |
| 33 // key pins. | |
| 28 // | 34 // |
| 29 // Tracks which hosts have enabled *-Transport-Security. This object manages | 35 // This object manages the in-memory store. Register a Delegate |
| 30 // the in-memory store. A separate object must register itself with this object | 36 // with |SetDelegate| to persist the state to disk. |
| 31 // in order to persist the state to disk. | 37 // |
| 38 // HTTP strict transport security (HSTS) is defined in | |
| 39 // http://tools.ietf.org/html/draft-ietf-websec-strict-transport-sec-04, and | |
| 40 // HTTP-based dynamic public key pinning (HPKP) is defined in | |
| 41 // http://tools.ietf.org/html/draft-ietf-websec-key-pinning-01. | |
| 32 class NET_EXPORT TransportSecurityState | 42 class NET_EXPORT TransportSecurityState |
| 33 : NON_EXPORTED_BASE(public base::NonThreadSafe) { | 43 : NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| 34 public: | 44 public: |
| 35 // If non-empty, |hsts_hosts| is a JSON-formatted string to treat as if it | 45 // The caller owns |delegate|. |
| 36 // were a built-in entry (same format as persisted metadata in the | 46 TransportSecurityState(TransportSecurityState::Delegate* delegate) |
|
agl
2012/03/20 22:12:59
explicit
palmer
2012/03/22 16:39:00
Done.
| |
| 37 // TransportSecurityState file). | 47 : delegate_(delegate); |
|
Ryan Sleevi
2012/03/15 03:51:15
This belongs in the .cc file.
palmer
2012/03/19 23:37:52
Done.
| |
| 38 explicit TransportSecurityState(const std::string& hsts_hosts); | 48 |
| 39 ~TransportSecurityState(); | 49 ~TransportSecurityState(); |
| 40 | 50 |
| 41 // A DomainState is the information that we persist about a given domain. | 51 // A DomainState describes the transport security state (required upgrade |
| 42 struct NET_EXPORT DomainState { | 52 // to HTTPS, and/or any public key pins). |
| 43 enum Mode { | 53 class NET_EXPORT DomainState { |
|
Ryan Sleevi
2012/03/15 03:51:15
Are you sure you need to NET_EXPORT this? My under
palmer
2012/03/19 23:37:52
Done.
| |
| 44 // Strict mode implies: | 54 enum UpgradeMode { |
|
Ryan Sleevi
2012/03/15 03:51:15
nit: Missing public
public:
enum UpgradeMode {
palmer
2012/03/19 23:37:52
Done.
| |
| 45 // * We generate internal redirects from HTTP -> HTTPS. | 55 MODE_DEFAULT, |
| 46 // * Certificate issues are fatal. | 56 MODE_FORCE_HTTPS, |
| 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 }; | 57 }; |
| 59 | 58 |
| 60 DomainState(); | 59 DomainState(); |
| 61 ~DomainState(); | 60 ~DomainState(); |
| 62 | 61 |
| 62 // Parses |value| as a Public-Key-Pins header. If successful, returns true | |
| 63 // and updates the |dynamic_spki_hashes| and |dynamic_spki_hashes_expiry| | |
| 64 // fields; otherwise, returns false without updating any fields. | |
| 65 bool ParsePinsHeader(const std::string& value, const SSLInfo& ssl_info); | |
| 66 | |
| 67 // Parses |value| as a Strict-Transport-Security header. If successful, | |
| 68 // returns true and updates the |upgrade_mode|, |upgrade_expiry| and | |
| 69 // |include_subdomains| fields; otherwise, returns false without updating | |
| 70 // any fields. | |
| 71 bool ParseSTSHeader(const std::string& value); | |
|
Ryan Sleevi
2012/03/15 03:51:15
ParsePinsHeader and ParseSTSHeader both seem like
palmer
2012/03/19 23:37:52
Well, the implementations of these two functions l
| |
| 72 | |
| 63 // Takes a set of SubjectPublicKeyInfo |hashes| and returns true if: | 73 // Takes a set of SubjectPublicKeyInfo |hashes| and returns true if: |
| 64 // 1) |bad_preloaded_spki_hashes| does not intersect |hashes|; AND | 74 // 1) |bad_static_spki_hashes| does not intersect |hashes|; AND |
| 65 // 2) Both |preloaded_spki_hashes| and |dynamic_spki_hashes| are empty | 75 // 2) Both |static_spki_hashes| and |dynamic_spki_hashes| are empty |
| 66 // or at least one of them intersects |hashes|. | 76 // or at least one of them intersects |hashes|. |
| 67 // | 77 // |
| 68 // |{dynamic,preloaded}_spki_hashes| contain trustworthy public key | 78 // |{dynamic,static}_spki_hashes| contain trustworthy public key hashes, |
| 69 // hashes, any one of which is sufficient to validate the certificate | 79 // any one of which is sufficient to validate the certificate chain in |
| 70 // chain in question. The public keys could be of a root CA, intermediate | 80 // question. The public keys could be of a root CA, intermediate CA, or |
| 71 // CA, or leaf certificate, depending on the security vs. disaster | 81 // leaf certificate, depending on the security vs. disaster recovery |
| 72 // recovery tradeoff selected. (Pinning only to leaf certifiates increases | 82 // tradeoff selected. (Pinning only to leaf certifiates increases |
| 73 // security because you no longer trust any CAs, but it hampers disaster | 83 // 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 | 84 // recovery because you can't just get a new certificate signed by the |
| 75 // CA.) | 85 // CA.) |
| 76 // | 86 // |
| 77 // |bad_preloaded_spki_hashes| contains public keys that we don't want to | 87 // |bad_static_spki_hashes| contains public keys that we don't want to |
| 78 // trust. | 88 // trust. |
| 79 bool IsChainOfPublicKeysPermitted(const FingerprintVector& hashes); | 89 bool IsChainOfPublicKeysPermitted(const FingerprintVector& hashes) const; |
| 80 | 90 |
| 81 // Returns true if |this| describes a more strict policy than |other|. | 91 // Returns true if any of the FingerprintVectors |static_spki_hashes|, |
| 82 // Used to see if a dynamic DomainState should override a preloaded one. | 92 // |bad_static_spki_hashes|, or |dynamic_spki_hashes| contains any |
| 83 bool IsMoreStrict(const DomainState& other); | 93 // items. |
| 94 bool HasPins() const; | |
| 84 | 95 |
| 85 // ShouldRedirectHTTPToHTTPS returns true iff, given the |mode| of this | 96 // ShouldRedirectHTTPToHTTPS returns true iff, given the |mode| of this |
| 86 // DomainState, HTTP requests should be internally redirected to HTTPS. | 97 // DomainState, HTTP requests should be internally redirected to HTTPS. |
| 87 bool ShouldRedirectHTTPToHTTPS() const; | 98 bool ShouldRedirectHTTPToHTTPS() const; |
| 88 | 99 |
| 89 Mode mode; | 100 UpgradeMode upgrade_mode; |
|
Ryan Sleevi
2012/03/15 03:51:15
DomainState is meant to be immutable after creatio
palmer
2012/03/19 23:37:52
Making them private would require at least getters
| |
| 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 | 101 |
| 94 // Optional; hashes of preloaded "pinned" SubjectPublicKeyInfos. Unless | 102 // The absolute time (UTC) when this DomainState was first created. |
| 95 // both are empty, at least one of |preloaded_spki_hashes| and | 103 // |
| 104 // Static entries do not have a created time. | |
| 105 base::Time created; | |
| 106 | |
| 107 // The absolute time (UTC) when the |upgrade_mode|, if set to | |
| 108 // UPGRADE_ALWAYS, downgrades to UPGRADE_NEVER. | |
| 109 base::Time upgrade_expiry; | |
| 110 | |
| 111 // Are subdomains subject to this DomainState? | |
| 112 // | |
| 113 // TODO(palmer): Decide if we should have separate |pin_subdomains| and | |
| 114 // |upgrade_subdomains|. Alternately, and perhaps better, is to separate | |
| 115 // DomainState into UpgradeState and PinState (requiring also changing the | |
| 116 // serialization format?). | |
| 117 bool include_subdomains; | |
| 118 | |
| 119 // Optional; hashes of static pinned SubjectPublicKeyInfos. Unless both | |
| 120 // are empty, at least one of |static_spki_hashes| and | |
| 96 // |dynamic_spki_hashes| MUST intersect with the set of SPKIs in the TLS | 121 // |dynamic_spki_hashes| MUST intersect with the set of SPKIs in the TLS |
| 97 // server's certificate chain. | 122 // server's certificate chain. |
| 98 // | 123 // |
| 99 // |dynamic_spki_hashes| take precedence over |preloaded_spki_hashes|. | 124 // |dynamic_spki_hashes| take precedence over |static_spki_hashes|. |
| 100 // That is, when performing pin validation, first check dynamic and then | 125 // That is, |IsChainOfPublicKeysPermitted| first checks dynamic pins and |
| 101 // check preloaded. | 126 // then checks static pins. |
| 102 FingerprintVector preloaded_spki_hashes; | 127 FingerprintVector static_spki_hashes; |
| 103 | 128 |
| 104 // Optional; hashes of dynamically pinned SubjectPublicKeyInfos. (They | 129 // Optional; hashes of dynamically pinned SubjectPublicKeyInfos. |
| 105 // could be set e.g. by an HTTP header or by a superfluous certificate.) | |
| 106 FingerprintVector dynamic_spki_hashes; | 130 FingerprintVector dynamic_spki_hashes; |
| 107 | 131 |
| 108 // The absolute time (UTC) when the |dynamic_spki_hashes| expire. | 132 // The absolute time (UTC) when the |dynamic_spki_hashes| expire. |
| 109 base::Time dynamic_spki_hashes_expiry; | 133 base::Time dynamic_spki_hashes_expiry; |
| 110 | 134 |
| 111 // The max-age directive of the Public-Key-Pins header as parsed. Do not | 135 // Optional; hashes of static known-bad SubjectPublicKeyInfos which |
| 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 | 136 // MUST NOT intersect with the set of SPKIs in the TLS server's |
| 118 // certificate chain. | 137 // certificate chain. |
| 119 FingerprintVector bad_preloaded_spki_hashes; | 138 FingerprintVector bad_static_spki_hashes; |
| 120 | 139 |
| 121 // The following members are not valid when stored in |enabled_hosts_|. | 140 // The following members are not valid when stored in |enabled_hosts_|: |
| 122 bool preloaded; // is this a preloaded entry? | 141 |
| 123 std::string domain; // the domain which matched | 142 // The domain which matched during a search for this DomainState entry. |
| 143 // Updated by |GetDomainState| and |GetStaticDomainState|. | |
| 144 std::string domain; | |
| 145 }; | |
| 146 | |
| 147 class Iterator { | |
| 148 public: | |
| 149 Iterator(const TransportSecurityState& state) | |
| 150 : iterator_(state.enabled_hosts_.begin()), | |
| 151 end_(state.enabled_hosts_.end()); | |
| 152 ~Iterator(); | |
| 153 | |
| 154 bool HasNext() const { return iterator_ != end_; } | |
| 155 void Advance() { ++iterator_; } | |
| 156 const std::pair<std::string, DomainState>& GetDomainState() { | |
| 157 return *iterator_; | |
| 158 } | |
| 159 | |
| 160 private: | |
| 161 std::map<std::string, DomainState>::const_iterator iterator_; | |
|
Ryan Sleevi
2012/03/15 03:51:15
Can you cheat with a typedef here (more aptly, put
palmer
2012/03/19 23:37:52
I'm not sure what you mean. TSS is a class; what d
| |
| 162 std::map<std::string, DomainState>::const_iterator end_; | |
| 124 }; | 163 }; |
| 125 | 164 |
| 126 class Delegate { | 165 class Delegate { |
| 127 public: | 166 public: |
| 128 // This function may not block and may be called with internal locks held. | 167 // This function may not block and may be called with internal locks held. |
| 129 // Thus it must not reenter the TransportSecurityState object. | 168 // Thus it must not reenter the TransportSecurityState object. |
| 130 virtual void StateIsDirty(TransportSecurityState* state) = 0; | 169 virtual void StateIsDirty(TransportSecurityState* state) = 0; |
| 131 | 170 |
| 132 protected: | 171 protected: |
| 133 virtual ~Delegate() {} | 172 virtual ~Delegate() {} |
| 134 }; | 173 }; |
| 135 | 174 |
| 136 void SetDelegate(Delegate* delegate); | 175 void SetDelegate(Delegate* delegate); |
| 137 | 176 |
| 138 // Enable TransportSecurity for |host|. | 177 // Enable TransportSecurity for |host|. |state| supercedes any previous |
| 178 // state for the |host|, including static entries. | |
| 179 // | |
| 180 // The new state for |host| is persisted using the Delegate (if any). | |
| 139 void EnableHost(const std::string& host, const DomainState& state); | 181 void EnableHost(const std::string& host, const DomainState& state); |
| 140 | 182 |
| 141 // Delete any entry for |host|. If |host| doesn't have an exact entry then no | 183 // 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. | 184 // no action is taken. Does not delete static entries. Returns true iff an |
| 185 // entry was deleted. | |
| 186 // | |
| 187 // The new state for |host| is persisted using the Delegate (if any). | |
| 143 bool DeleteHost(const std::string& host); | 188 bool DeleteHost(const std::string& host); |
| 144 | 189 |
| 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. | 190 // Deletes all records created since a given time. |
| 215 void DeleteSince(const base::Time& time); | 191 void DeleteSince(const base::Time& time); |
| 216 | 192 |
| 217 // Parses |value| as a Public-Key-Pins header. If successful, returns |true| | 193 // Returns true and updates |*result| iff there is a DomainState for |
| 218 // and updates the |dynamic_spki_hashes| and |dynamic_spki_hashes_expiry| | 194 // |host|. |
| 219 // fields of |*state|; otherwise, returns |false| without updating |*state|. | 195 // |
| 220 static bool ParsePinsHeader(const std::string& value, | 196 // If |sni_enabled| is true, searches the static pins defined for |
| 221 const SSLInfo& ssl_info, | 197 // SNI-using hosts as well as the rest of the pins. |
| 222 DomainState* state); | 198 // |
| 199 // If |host| matches both an exact entry and is a subdomain of another | |
| 200 // entry, the exact match determines the return value. | |
| 201 bool GetDomainState(const std::string& host, | |
| 202 bool sni_enabled, | |
| 203 DomainState* result) const; | |
| 223 | 204 |
| 224 // Returns |true| if |value| parses as a valid *-Transport-Security | 205 // Returns true and updates |*result| iff there is a static DomainState for |
| 225 // header value. The values of max-age and and includeSubDomains are | 206 // |host|. |
| 226 // returned in |max_age| and |include_subdomains|, respectively. The out | 207 // |
| 227 // parameters are not modified if the function returns |false|. | 208 // |GetStaticDomainState| is identical to |GetDomainState| except that it |
| 228 static bool ParseHeader(const std::string& value, | 209 // searches only the statically-defined transport security state, ignoring |
| 229 int* max_age, | 210 // all dynamically-added DomainStates. |
| 230 bool* include_subdomains); | 211 // |
| 212 // If |sni_enabled| is true, searches the static pins defined for | |
| 213 // SNI-using hosts as well as the rest of the pins. | |
| 214 // | |
| 215 // If |host| matches both an exact entry and is a subdomain of another | |
| 216 // entry, the exact match determines the return value. | |
| 217 bool GetStaticDomainState(const std::string& host, | |
| 218 bool sni_enabled, | |
| 219 DomainState* result) const; | |
| 231 | 220 |
| 232 // ParseSidePin attempts to parse a side pin from |side_info| which signs the | 221 // Returns true iff we have any static public key pins for the |host| and |
| 233 // SubjectPublicKeyInfo in |leaf_spki|. A side pin is a way for a site to | 222 // iff its set of required pins is the set we expect for Google |
| 234 // sign their public key with a key that is offline but still controlled by | 223 // properties. |
| 235 // them. If successful, the hash of the public key used to sign |leaf_spki| | 224 // |
| 236 // is put into |out_pub_key_hash|. | 225 // If |sni_enabled| is true, searches the static pins defined for |
| 237 static bool ParseSidePin(const base::StringPiece& leaf_spki, | 226 // SNI-using hosts as well as the rest of the pins. |
| 238 const base::StringPiece& side_info, | 227 // |
| 239 FingerprintVector* out_pub_key_hash); | 228 // If |host| matches both an exact entry and is a subdomain of another |
| 229 // entry, the exact match determines the return value. | |
| 230 static bool IsGooglePinnedProperty(const std::string& host, | |
| 231 bool sni_enabled); | |
| 240 | 232 |
| 241 bool Serialise(std::string* output); | 233 // Decodes a pin string |value| (e.g. "sha1/hvfkN/qlp/zhXR3cuerq6jd2Z7g="). |
| 242 // Existing non-preloaded entries are cleared and repopulated from the | 234 // If parsing succeeded, updates |*out| and returns true; otherwise returns |
| 243 // passed JSON string. | 235 // false without updating |*out|. |
| 244 bool LoadEntries(const std::string& state, bool* dirty); | 236 static bool ParsePin(const std::string& value, Fingerprint* out); |
|
Ryan Sleevi
2012/03/15 03:51:15
See above comments about HTTP header parsing above
| |
| 245 | 237 |
| 246 // The maximum number of seconds for which we'll cache an HSTS request. | 238 // The maximum number of seconds for which we'll cache an HSTS request. |
| 247 static const long int kMaxHSTSAgeSecs; | 239 static const long int kMaxHSTSAgeSecs; |
| 248 | 240 |
| 241 // Converts |hostname| from dotted form ("www.google.com") to the form | |
| 242 // used in DNS: "\x03www\x06google\x03com", lowercases that, and returns | |
| 243 // the result. | |
| 244 static std::string CanonicalizeHost(const std::string& hostname); | |
| 245 | |
| 249 private: | 246 private: |
| 250 FRIEND_TEST_ALL_PREFIXES(TransportSecurityStateTest, IsPreloaded); | 247 // If we have a Delegate, call its |StateIsDirty| function. |
| 248 void DirtyNotify(); | |
| 251 | 249 |
| 252 // If we have a callback configured, call it to let our serialiser know that | 250 // The set of hosts that have enabled TransportSecurity. |
| 253 // our state is dirty. | |
| 254 void DirtyNotify(); | |
| 255 bool IsPreloadedSTS(const std::string& canonicalized_host, | |
| 256 bool sni_available, | |
| 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_; | 251 std::map<std::string, DomainState> enabled_hosts_; |
| 268 | 252 |
| 269 // These hosts are extra rules to treat as built-in, passed in the | 253 // Extra entries, provided by the user at run-time, to treat as if they |
| 270 // constructor (typically originating from the command line). | 254 // were static. |
| 271 std::map<std::string, DomainState> forced_hosts_; | 255 std::map<std::string, DomainState> forced_hosts_; |
| 272 | 256 |
| 273 // Our delegate who gets notified when we are dirtied, or NULL. | |
| 274 Delegate* delegate_; | 257 Delegate* delegate_; |
| 275 | 258 |
| 276 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); | 259 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); |
| 277 }; | 260 }; |
| 278 | 261 |
| 279 } // namespace net | 262 } // namespace net |
| 280 | 263 |
| 281 #endif // NET_BASE_TRANSPORT_SECURITY_STATE_H_ | 264 #endif // NET_BASE_TRANSPORT_SECURITY_STATE_H_ |
| OLD | NEW |