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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 const DomainState& domain_state() const { return iterator_->second; } | 152 const DomainState& domain_state() const { return iterator_->second; } |
153 | 153 |
154 private: | 154 private: |
155 std::map<std::string, DomainState>::const_iterator iterator_; | 155 std::map<std::string, DomainState>::const_iterator iterator_; |
156 std::map<std::string, DomainState>::const_iterator end_; | 156 std::map<std::string, DomainState>::const_iterator end_; |
157 }; | 157 }; |
158 | 158 |
159 // These functions search for static and dynamic DomainStates, and invoke the | 159 // These functions search for static and dynamic DomainStates, and invoke the |
160 // functions of the same name on them. These functions are the primary public | 160 // functions of the same name on them. These functions are the primary public |
161 // interface; direct access to DomainStates is best left to tests. | 161 // interface; direct access to DomainStates is best left to tests. |
162 bool ShouldSSLErrorsBeFatal(const std::string& host, bool sni_enabled); | 162 bool ShouldSSLErrorsBeFatal(const std::string& host); |
163 bool ShouldUpgradeToSSL(const std::string& host, bool sni_enabled); | 163 bool ShouldUpgradeToSSL(const std::string& host); |
164 bool CheckPublicKeyPins(const std::string& host, | 164 bool CheckPublicKeyPins(const std::string& host, |
165 bool sni_enabled, | |
166 bool is_issued_by_known_root, | 165 bool is_issued_by_known_root, |
167 const HashValueVector& hashes, | 166 const HashValueVector& hashes, |
168 std::string* failure_log); | 167 std::string* failure_log); |
169 bool HasPublicKeyPins(const std::string& host, bool sni_enabled); | 168 bool HasPublicKeyPins(const std::string& host); |
170 | 169 |
171 // Assign a |Delegate| for persisting the transport security state. If | 170 // Assign a |Delegate| for persisting the transport security state. If |
172 // |NULL|, state will not be persisted. The caller retains | 171 // |NULL|, state will not be persisted. The caller retains |
173 // ownership of |delegate|. | 172 // ownership of |delegate|. |
174 // Note: This is only used for serializing/deserializing the | 173 // Note: This is only used for serializing/deserializing the |
175 // TransportSecurityState. | 174 // TransportSecurityState. |
176 void SetDelegate(Delegate* delegate); | 175 void SetDelegate(Delegate* delegate); |
177 | 176 |
178 // Clears all dynamic data (e.g. HSTS and HPKP data). | 177 // Clears all dynamic data (e.g. HSTS and HPKP data). |
179 // | 178 // |
(...skipping 23 matching lines...) Expand all Loading... |
203 // not delete static (i.e. preloaded) data. Returns true iff an entry | 202 // not delete static (i.e. preloaded) data. Returns true iff an entry |
204 // was deleted. | 203 // was deleted. |
205 // | 204 // |
206 // If an entry is deleted, the new state will be persisted through | 205 // If an entry is deleted, the new state will be persisted through |
207 // the Delegate (if any). | 206 // the Delegate (if any). |
208 bool DeleteDynamicDataForHost(const std::string& host); | 207 bool DeleteDynamicDataForHost(const std::string& host); |
209 | 208 |
210 // Returns true and updates |*result| iff there is a static (built-in) | 209 // Returns true and updates |*result| iff there is a static (built-in) |
211 // DomainState for |host|. | 210 // DomainState for |host|. |
212 // | 211 // |
213 // If |sni_enabled| is true, searches the static pins defined for SNI-using | |
214 // hosts as well as the rest of the pins. | |
215 // | |
216 // If |host| matches both an exact entry and is a subdomain of another entry, | 212 // If |host| matches both an exact entry and is a subdomain of another entry, |
217 // the exact match determines the return value. | 213 // the exact match determines the return value. |
218 // | 214 // |
219 // Note that this method is not const because it opportunistically removes | 215 // Note that this method is not const because it opportunistically removes |
220 // entries that have expired. | 216 // entries that have expired. |
221 bool GetStaticDomainState(const std::string& host, | 217 bool GetStaticDomainState(const std::string& host, DomainState* result) const; |
222 bool sni_enabled, | |
223 DomainState* result) const; | |
224 | 218 |
225 // Returns true and updates |*result| iff there is a dynamic DomainState | 219 // Returns true and updates |*result| iff there is a dynamic DomainState |
226 // (learned from HSTS or HPKP headers, or set by the user, or other means) for | 220 // (learned from HSTS or HPKP headers, or set by the user, or other means) for |
227 // |host|. | 221 // |host|. |
228 // | 222 // |
229 // If |host| matches both an exact entry and is a subdomain of another entry, | 223 // If |host| matches both an exact entry and is a subdomain of another entry, |
230 // the exact match determines the return value. | 224 // the exact match determines the return value. |
231 // | 225 // |
232 // Note that this method is not const because it opportunistically removes | 226 // Note that this method is not const because it opportunistically removes |
233 // entries that have expired. | 227 // entries that have expired. |
(...skipping 16 matching lines...) Expand all Loading... |
250 | 244 |
251 // Adds explicitly-specified data as if it was processed from an | 245 // Adds explicitly-specified data as if it was processed from an |
252 // HPKP header (used for net-internals and unit tests). | 246 // HPKP header (used for net-internals and unit tests). |
253 bool AddHPKP(const std::string& host, const base::Time& expiry, | 247 bool AddHPKP(const std::string& host, const base::Time& expiry, |
254 bool include_subdomains, const HashValueVector& hashes); | 248 bool include_subdomains, const HashValueVector& hashes); |
255 | 249 |
256 // Returns true iff we have any static public key pins for the |host| and | 250 // Returns true iff we have any static public key pins for the |host| and |
257 // iff its set of required pins is the set we expect for Google | 251 // iff its set of required pins is the set we expect for Google |
258 // properties. | 252 // properties. |
259 // | 253 // |
260 // If |sni_enabled| is true, searches the static pins defined for | |
261 // SNI-using hosts as well as the rest of the pins. | |
262 // | |
263 // If |host| matches both an exact entry and is a subdomain of another | 254 // If |host| matches both an exact entry and is a subdomain of another |
264 // entry, the exact match determines the return value. | 255 // entry, the exact match determines the return value. |
265 static bool IsGooglePinnedProperty(const std::string& host, | 256 static bool IsGooglePinnedProperty(const std::string& host); |
266 bool sni_enabled); | |
267 | 257 |
268 // The maximum number of seconds for which we'll cache an HSTS request. | 258 // The maximum number of seconds for which we'll cache an HSTS request. |
269 static const long int kMaxHSTSAgeSecs; | 259 static const long int kMaxHSTSAgeSecs; |
270 | 260 |
271 private: | 261 private: |
272 friend class TransportSecurityStateTest; | 262 friend class TransportSecurityStateTest; |
273 FRIEND_TEST_ALL_PREFIXES(HttpSecurityHeadersTest, UpdateDynamicPKPOnly); | 263 FRIEND_TEST_ALL_PREFIXES(HttpSecurityHeadersTest, UpdateDynamicPKPOnly); |
274 FRIEND_TEST_ALL_PREFIXES(HttpSecurityHeadersTest, UpdateDynamicPKPMaxAge0); | 264 FRIEND_TEST_ALL_PREFIXES(HttpSecurityHeadersTest, UpdateDynamicPKPMaxAge0); |
275 FRIEND_TEST_ALL_PREFIXES(HttpSecurityHeadersTest, NoClobberPins); | 265 FRIEND_TEST_ALL_PREFIXES(HttpSecurityHeadersTest, NoClobberPins); |
276 | 266 |
277 typedef std::map<std::string, DomainState> DomainStateMap; | 267 typedef std::map<std::string, DomainState> DomainStateMap; |
278 | 268 |
279 // Send an UMA report on pin validation failure, if the host is in a | 269 // Send an UMA report on pin validation failure, if the host is in a |
280 // statically-defined list of domains. | 270 // statically-defined list of domains. |
281 // | 271 // |
282 // TODO(palmer): This doesn't really belong here, and should be moved into | 272 // TODO(palmer): This doesn't really belong here, and should be moved into |
283 // the exactly one call site. This requires unifying |struct HSTSPreload| | 273 // the exactly one call site. This requires unifying |struct HSTSPreload| |
284 // (an implementation detail of this class) with a more generic | 274 // (an implementation detail of this class) with a more generic |
285 // representation of first-class DomainStates, and exposing the preloads | 275 // representation of first-class DomainStates, and exposing the preloads |
286 // to the caller with |GetStaticDomainState|. | 276 // to the caller with |GetStaticDomainState|. |
287 static void ReportUMAOnPinFailure(const std::string& host); | 277 static void ReportUMAOnPinFailure(const std::string& host); |
288 | 278 |
289 // IsBuildTimely returns true if the current build is new enough ensure that | 279 // IsBuildTimely returns true if the current build is new enough ensure that |
290 // built in security information (i.e. HSTS preloading and pinning | 280 // built in security information (i.e. HSTS preloading and pinning |
291 // information) is timely. | 281 // information) is timely. |
292 static bool IsBuildTimely(); | 282 static bool IsBuildTimely(); |
293 | 283 |
294 // Helper method for actually checking pins. | 284 // Helper method for actually checking pins. |
295 bool CheckPublicKeyPinsImpl(const std::string& host, | 285 bool CheckPublicKeyPinsImpl(const std::string& host, |
296 bool sni_enabled, | |
297 const HashValueVector& hashes, | 286 const HashValueVector& hashes, |
298 std::string* failure_log); | 287 std::string* failure_log); |
299 | 288 |
300 // If a Delegate is present, notify it that the internal state has | 289 // If a Delegate is present, notify it that the internal state has |
301 // changed. | 290 // changed. |
302 void DirtyNotify(); | 291 void DirtyNotify(); |
303 | 292 |
304 // Enable TransportSecurity for |host|. |state| supercedes any previous | 293 // Enable TransportSecurity for |host|. |state| supercedes any previous |
305 // state for the |host|, including static entries. | 294 // state for the |host|, including static entries. |
306 // | 295 // |
(...skipping 12 matching lines...) Expand all Loading... |
319 | 308 |
320 // True if static pins should be used. | 309 // True if static pins should be used. |
321 bool enable_static_pins_; | 310 bool enable_static_pins_; |
322 | 311 |
323 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); | 312 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); |
324 }; | 313 }; |
325 | 314 |
326 } // namespace net | 315 } // namespace net |
327 | 316 |
328 #endif // NET_HTTP_TRANSPORT_SECURITY_STATE_H_ | 317 #endif // NET_HTTP_TRANSPORT_SECURITY_STATE_H_ |
OLD | NEW |