| 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 NET_EXPORT DomainState { |
| 55 public: |
| 56 enum UpgradeMode { |
| 57 // These numbers must match those in hsts_view.js, function modeToString. |
| 58 MODE_FORCE_HTTPS = 0, |
| 59 MODE_DEFAULT = 1, |
| 60 }; |
| 61 |
| 62 DomainState(); |
| 63 ~DomainState(); |
| 64 |
| 65 // Parses |value| as a Public-Key-Pins header. If successful, returns true |
| 66 // and updates the |dynamic_spki_hashes| and |dynamic_spki_hashes_expiry| |
| 67 // fields; otherwise, returns false without updating any fields. |
| 68 // Interprets the max-age directive relative to |now|. |
| 69 bool ParsePinsHeader(const base::Time& now, |
| 70 const std::string& value, |
| 71 const SSLInfo& ssl_info); |
| 72 |
| 73 // Parses |value| as a Strict-Transport-Security header. If successful, |
| 74 // returns true and updates the |upgrade_mode|, |upgrade_expiry| and |
| 75 // |include_subdomains| fields; otherwise, returns false without updating |
| 76 // any fields. Interprets the max-age directive relative to |now|. |
| 77 bool ParseSTSHeader(const base::Time& now, const std::string& value); |
| 78 |
| 79 // Takes a set of SubjectPublicKeyInfo |hashes| and returns true if: |
| 80 // 1) |bad_static_spki_hashes| does not intersect |hashes|; AND |
| 81 // 2) Both |static_spki_hashes| and |dynamic_spki_hashes| are empty |
| 82 // or at least one of them intersects |hashes|. |
| 83 // |
| 84 // |{dynamic,static}_spki_hashes| contain trustworthy public key hashes, |
| 85 // any one of which is sufficient to validate the certificate chain in |
| 86 // question. The public keys could be of a root CA, intermediate CA, or |
| 87 // leaf certificate, depending on the security vs. disaster recovery |
| 88 // tradeoff selected. (Pinning only to leaf certifiates increases |
| 89 // security because you no longer trust any CAs, but it hampers disaster |
| 90 // recovery because you can't just get a new certificate signed by the |
| 91 // CA.) |
| 92 // |
| 93 // |bad_static_spki_hashes| contains public keys that we don't want to |
| 94 // trust. |
| 95 bool IsChainOfPublicKeysPermitted(const FingerprintVector& hashes) const; |
| 96 |
| 97 // Returns true if any of the FingerprintVectors |static_spki_hashes|, |
| 98 // |bad_static_spki_hashes|, or |dynamic_spki_hashes| contains any |
| 99 // items. |
| 100 bool HasPins() const; |
| 101 |
| 102 // ShouldRedirectHTTPToHTTPS returns true iff, given the |mode| of this |
| 103 // DomainState, HTTP requests should be internally redirected to HTTPS. |
| 104 bool ShouldRedirectHTTPToHTTPS() const; |
| 105 |
| 106 bool Equals(const DomainState& other) const; |
| 107 |
| 108 UpgradeMode upgrade_mode; |
| 109 |
| 110 // The absolute time (UTC) when this DomainState was first created. |
| 111 // |
| 112 // Static entries do not have a created time. |
| 113 base::Time created; |
| 114 |
| 115 // The absolute time (UTC) when the |upgrade_mode|, if set to |
| 116 // UPGRADE_ALWAYS, downgrades to UPGRADE_NEVER. |
| 117 base::Time upgrade_expiry; |
| 118 |
| 119 // Are subdomains subject to this DomainState? |
| 120 // |
| 121 // TODO(palmer): Decide if we should have separate |pin_subdomains| and |
| 122 // |upgrade_subdomains|. Alternately, and perhaps better, is to separate |
| 123 // DomainState into UpgradeState and PinState (requiring also changing the |
| 124 // serialization format?). |
| 125 bool include_subdomains; |
| 126 |
| 127 // Optional; hashes of static pinned SubjectPublicKeyInfos. Unless both |
| 128 // are empty, at least one of |static_spki_hashes| and |
| 129 // |dynamic_spki_hashes| MUST intersect with the set of SPKIs in the TLS |
| 130 // server's certificate chain. |
| 131 // |
| 132 // |dynamic_spki_hashes| take precedence over |static_spki_hashes|. |
| 133 // That is, |IsChainOfPublicKeysPermitted| first checks dynamic pins and |
| 134 // then checks static pins. |
| 135 FingerprintVector static_spki_hashes; |
| 136 |
| 137 // Optional; hashes of dynamically pinned SubjectPublicKeyInfos. |
| 138 FingerprintVector dynamic_spki_hashes; |
| 139 |
| 140 // The absolute time (UTC) when the |dynamic_spki_hashes| expire. |
| 141 base::Time dynamic_spki_hashes_expiry; |
| 142 |
| 143 // Optional; hashes of static known-bad SubjectPublicKeyInfos which |
| 144 // MUST NOT intersect with the set of SPKIs in the TLS server's |
| 145 // certificate chain. |
| 146 FingerprintVector bad_static_spki_hashes; |
| 147 |
| 148 // The following members are not valid when stored in |enabled_hosts_|: |
| 149 |
| 150 // The domain which matched during a search for this DomainState entry. |
| 151 // Updated by |GetDomainState| and |GetStaticDomainState|. |
| 152 std::string domain; |
| 153 }; |
| 154 |
| 155 class Iterator { |
| 156 public: |
| 157 explicit Iterator(const TransportSecurityState& state) |
| 158 : iterator_(state.enabled_hosts_.begin()), |
| 159 end_(state.enabled_hosts_.end()) { |
| 160 } |
| 161 ~Iterator() {} |
| 162 |
| 163 bool HasNext() const { return iterator_ != end_; } |
| 164 void Advance() { ++iterator_; } |
| 165 const std::string& hostname() const { return iterator_->first; } |
| 166 const DomainState& domain_state() const { return iterator_->second; } |
| 167 |
| 168 private: |
| 169 std::map<std::string, DomainState>::const_iterator iterator_; |
| 170 std::map<std::string, DomainState>::const_iterator end_; |
| 171 }; |
| 172 |
| 173 // Assign a |Delegate| for persisting the transport security state. If |
| 174 // |NULL|, state will not be persisted. Caller owns |delegate|. |
| 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 // |
| 223 | 199 // If |host| matches both an exact entry and is a subdomain of another |
| 224 // Returns |true| if |value| parses as a valid *-Transport-Security | 200 // entry, the exact match determines the return value. |
| 225 // header value. The values of max-age and and includeSubDomains are | 201 // |
| 226 // returned in |max_age| and |include_subdomains|, respectively. The out | 202 // Note that this method is not const because it opportunistically removes |
| 227 // parameters are not modified if the function returns |false|. | 203 // entries that have expired. |
| 228 static bool ParseHeader(const std::string& value, | 204 bool GetDomainState(const std::string& host, |
| 229 int* max_age, | 205 bool sni_enabled, |
| 230 bool* include_subdomains); | 206 DomainState* result); |
| 231 | 207 |
| 232 // ParseSidePin attempts to parse a side pin from |side_info| which signs the | 208 // 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 | 209 // |host|. |
| 234 // sign their public key with a key that is offline but still controlled by | 210 // |
| 235 // them. If successful, the hash of the public key used to sign |leaf_spki| | 211 // |GetStaticDomainState| is identical to |GetDomainState| except that it |
| 236 // is put into |out_pub_key_hash|. | 212 // searches only the statically-defined transport security state, ignoring |
| 237 static bool ParseSidePin(const base::StringPiece& leaf_spki, | 213 // all dynamically-added DomainStates. |
| 238 const base::StringPiece& side_info, | 214 // |
| 239 FingerprintVector* out_pub_key_hash); | 215 // If |sni_enabled| is true, searches the static pins defined for |
| 240 | 216 // SNI-using hosts as well as the rest of the pins. |
| 241 bool Serialise(std::string* output); | 217 // |
| 242 // Existing non-preloaded entries are cleared and repopulated from the | 218 // If |host| matches both an exact entry and is a subdomain of another |
| 243 // passed JSON string. | 219 // entry, the exact match determines the return value. |
| 244 bool LoadEntries(const std::string& state, bool* dirty); | 220 // |
| 221 // Note that this method is not const because it opportunistically removes |
| 222 // entries that have expired. |
| 223 bool GetStaticDomainState(const std::string& host, |
| 224 bool sni_enabled, |
| 225 DomainState* result); |
| 226 |
| 227 // Removed all DomainState records. |
| 228 void Clear() { enabled_hosts_.clear(); } |
| 229 |
| 230 // Inserts |state| into |enabled_hosts_| under the key |hashed_host|. |
| 231 // |hashed_host| is already in the internal representation |
| 232 // HashHost(CanonicalizeHost(host)); thus, most callers will use |
| 233 // |EnableHost|. |
| 234 void AddOrUpdateEnabledHosts(std::string hashed_host, |
| 235 const DomainState& state); |
| 236 |
| 237 // Inserts |state| into |forced_hosts_| under the key |hashed_host|. |
| 238 // |hashed_host| is already in the internal representation |
| 239 // HashHost(CanonicalizeHost(host)); thus, most callers will use |
| 240 // |EnableHost|. |
| 241 void AddOrUpdateForcedHosts(std::string hashed_host, |
| 242 const DomainState& state); |
| 243 |
| 244 // Returns true iff we have any static public key pins for the |host| and |
| 245 // iff its set of required pins is the set we expect for Google |
| 246 // properties. |
| 247 // |
| 248 // If |sni_enabled| is true, searches the static pins defined for |
| 249 // SNI-using hosts as well as the rest of the pins. |
| 250 // |
| 251 // If |host| matches both an exact entry and is a subdomain of another |
| 252 // entry, the exact match determines the return value. |
| 253 static bool IsGooglePinnedProperty(const std::string& host, |
| 254 bool sni_enabled); |
| 255 |
| 256 // Decodes a pin string |value| (e.g. "sha1/hvfkN/qlp/zhXR3cuerq6jd2Z7g="). |
| 257 // If parsing succeeded, updates |*out| and returns true; otherwise returns |
| 258 // false without updating |*out|. |
| 259 static bool ParsePin(const std::string& value, Fingerprint* out); |
| 245 | 260 |
| 246 // The maximum number of seconds for which we'll cache an HSTS request. | 261 // The maximum number of seconds for which we'll cache an HSTS request. |
| 247 static const long int kMaxHSTSAgeSecs; | 262 static const long int kMaxHSTSAgeSecs; |
| 248 | 263 |
| 264 // Converts |hostname| from dotted form ("www.google.com") to the form |
| 265 // used in DNS: "\x03www\x06google\x03com", lowercases that, and returns |
| 266 // the result. |
| 267 static std::string CanonicalizeHost(const std::string& hostname); |
| 268 |
| 269 // Send an UMA report on pin validation failure, if the host is in a |
| 270 // statically-defined list of domains. |
| 271 // |
| 272 // TODO(palmer): This doesn't really belong here, and should be moved into |
| 273 // the exactly one call site. This requires unifying |struct HSTSPreload| |
| 274 // (an implementation detail of this class) with a more generic |
| 275 // representation of first-class DomainStates, and exposing the preloads |
| 276 // to the caller with |GetStaticDomainState|. |
| 277 static void ReportUMAOnPinFailure(const std::string& host); |
| 278 |
| 249 private: | 279 private: |
| 250 FRIEND_TEST_ALL_PREFIXES(TransportSecurityStateTest, IsPreloaded); | 280 // If a Delegate is present, notify it that the internal state has |
| 251 | 281 // changed. |
| 252 // If we have a callback configured, call it to let our serialiser know that | |
| 253 // our state is dirty. | |
| 254 void DirtyNotify(); | 282 void DirtyNotify(); |
| 255 bool IsPreloadedSTS(const std::string& canonicalized_host, | 283 |
| 256 bool sni_available, | 284 // 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_; | 285 std::map<std::string, DomainState> enabled_hosts_; |
| 268 | 286 |
| 269 // These hosts are extra rules to treat as built-in, passed in the | 287 // Extra entries, provided by the user at run-time, to treat as if they |
| 270 // constructor (typically originating from the command line). | 288 // were static. |
| 271 std::map<std::string, DomainState> forced_hosts_; | 289 std::map<std::string, DomainState> forced_hosts_; |
| 272 | 290 |
| 273 // Our delegate who gets notified when we are dirtied, or NULL. | |
| 274 Delegate* delegate_; | 291 Delegate* delegate_; |
| 275 | 292 |
| 276 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); | 293 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); |
| 277 }; | 294 }; |
| 278 | 295 |
| 279 } // namespace net | 296 } // namespace net |
| 280 | 297 |
| 281 #endif // NET_BASE_TRANSPORT_SECURITY_STATE_H_ | 298 #endif // NET_BASE_TRANSPORT_SECURITY_STATE_H_ |
| OLD | NEW |