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