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_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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 class NET_EXPORT Delegate { | 46 class NET_EXPORT Delegate { |
| 47 public: | 47 public: |
| 48 // This function may not block and may be called with internal locks held. | 48 // This function may not block and may be called with internal locks held. |
| 49 // Thus it must not reenter the TransportSecurityState object. | 49 // Thus it must not reenter the TransportSecurityState object. |
| 50 virtual void StateIsDirty(TransportSecurityState* state) = 0; | 50 virtual void StateIsDirty(TransportSecurityState* state) = 0; |
| 51 | 51 |
| 52 protected: | 52 protected: |
| 53 virtual ~Delegate() {} | 53 virtual ~Delegate() {} |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 class NET_EXPORT RequireCTDelegate { | |
| 57 public: | |
| 58 // Provides a capability for altering the default handling of Certificate | |
| 59 // Transparency information, allowing it to be always required for some | |
| 60 // hosts, for some hosts to be opted out of the default policy, or | |
| 61 // allowing the TransportSecurityState to apply the default security | |
| 62 // policies. | |
| 63 enum class CTRequirementLevel { | |
| 64 // The host is required to always supply Certificate Transparency | |
| 65 // information that complies with the CT policy. | |
| 66 REQUIRED, | |
| 67 | |
| 68 // The host is explicitly not required to supply Certificate | |
| 69 // Transparency information that complies with the CT policy. | |
| 70 NOT_REQUIRED, | |
| 71 | |
| 72 // The delegate makes no statements, positive or negative, about | |
| 73 // requiring the host to supply Certificate Transparency information, | |
| 74 // allowing the default behaviour to happen. | |
| 75 DEFAULT, | |
|
davidben
2016/06/22 21:44:59
To confirm, the reason DEFAULT is a notion is beca
Ryan Sleevi
2016/06/22 22:07:39
Yes (or eventually the CertVerifier)
| |
| 76 }; | |
| 77 | |
| 78 // Called by the TransportSecurityState, allows the Delegate to override | |
| 79 // the default handling of Certificate Transparency requirements, if | |
| 80 // desired. | |
| 81 virtual CTRequirementLevel IsCTRequiredForHost( | |
|
davidben
2016/06/22 21:44:59
Nit: A little weird to have an IsFoo function retu
Ryan Sleevi
2016/06/22 22:07:39
It's just a tri-state bool ;)
( http://thedailywt
| |
| 82 const std::string& hostname) = 0; | |
| 83 | |
| 84 protected: | |
| 85 virtual ~RequireCTDelegate() = default; | |
| 86 }; | |
| 87 | |
| 56 // A STSState describes the strict transport security state (required | 88 // A STSState describes the strict transport security state (required |
| 57 // upgrade to HTTPS). | 89 // upgrade to HTTPS). |
| 58 class NET_EXPORT STSState { | 90 class NET_EXPORT STSState { |
| 59 public: | 91 public: |
| 60 enum UpgradeMode { | 92 enum UpgradeMode { |
| 61 // These numbers must match those in hsts_view.js, function modeToString. | 93 // These numbers must match those in hsts_view.js, function modeToString. |
| 62 MODE_FORCE_HTTPS = 0, | 94 MODE_FORCE_HTTPS = 0, |
| 63 MODE_DEFAULT = 1, | 95 MODE_DEFAULT = 1, |
| 64 }; | 96 }; |
| 65 | 97 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 bool ShouldUpgradeToSSL(const std::string& host); | 285 bool ShouldUpgradeToSSL(const std::string& host); |
| 254 bool CheckPublicKeyPins(const HostPortPair& host_port_pair, | 286 bool CheckPublicKeyPins(const HostPortPair& host_port_pair, |
| 255 bool is_issued_by_known_root, | 287 bool is_issued_by_known_root, |
| 256 const HashValueVector& hashes, | 288 const HashValueVector& hashes, |
| 257 const X509Certificate* served_certificate_chain, | 289 const X509Certificate* served_certificate_chain, |
| 258 const X509Certificate* validated_certificate_chain, | 290 const X509Certificate* validated_certificate_chain, |
| 259 const PublicKeyPinReportStatus report_status, | 291 const PublicKeyPinReportStatus report_status, |
| 260 std::string* failure_log); | 292 std::string* failure_log); |
| 261 bool HasPublicKeyPins(const std::string& host); | 293 bool HasPublicKeyPins(const std::string& host); |
| 262 | 294 |
| 295 // Returns true if connections to |host|, using the validated certificate | |
| 296 // |validated_certificate_chain|, are expected to be accompanied with | |
| 297 // valid Certificate Transparency information that complies with the | |
| 298 // connection's CTPolicyEnforcer. | |
| 299 // | |
| 300 // The behavior may be further be altered by setting a RequireCTDelegate | |
| 301 // via |SetRequireCTDelegate()|. | |
| 302 bool ShouldRequireCT(const std::string& host, | |
| 303 const X509Certificate* validated_certificate_chain, | |
| 304 const HashValueVector& hashes); | |
| 305 | |
| 263 // Assign a |Delegate| for persisting the transport security state. If | 306 // Assign a |Delegate| for persisting the transport security state. If |
| 264 // |NULL|, state will not be persisted. The caller retains | 307 // |NULL|, state will not be persisted. The caller retains |
| 265 // ownership of |delegate|. | 308 // ownership of |delegate|. |
| 266 // Note: This is only used for serializing/deserializing the | 309 // Note: This is only used for serializing/deserializing the |
| 267 // TransportSecurityState. | 310 // TransportSecurityState. |
| 268 void SetDelegate(Delegate* delegate); | 311 void SetDelegate(Delegate* delegate); |
| 269 | 312 |
| 270 void SetReportSender(ReportSenderInterface* report_sender); | 313 void SetReportSender(ReportSenderInterface* report_sender); |
| 271 | 314 |
| 272 void SetExpectCTReporter(ExpectCTReporter* expect_ct_reporter); | 315 void SetExpectCTReporter(ExpectCTReporter* expect_ct_reporter); |
| 273 | 316 |
| 317 // Assigns a delegate responsible for determining whether or not a | |
| 318 // connection to a given host should require Certificate Transparency | |
| 319 // information that complies with the CT policy provided by a | |
| 320 // CTPolicyEnforcer. | |
| 321 // If nullptr, no delegate will be consulted. | |
| 322 // The caller retains ownership of the |delegate|, and must persist for | |
| 323 // the lifetime of this object or until called with nullptr, whichever | |
| 324 // occurs first. | |
| 325 void SetRequireCTDelegate(RequireCTDelegate* delegate); | |
| 326 | |
| 274 // Clears all dynamic data (e.g. HSTS and HPKP data). | 327 // Clears all dynamic data (e.g. HSTS and HPKP data). |
| 275 // | 328 // |
| 276 // Does NOT persist changes using the Delegate, as this function is only | 329 // Does NOT persist changes using the Delegate, as this function is only |
| 277 // used to clear any dynamic data prior to re-loading it from a file. | 330 // used to clear any dynamic data prior to re-loading it from a file. |
| 278 // Note: This is only used for serializing/deserializing the | 331 // Note: This is only used for serializing/deserializing the |
| 279 // TransportSecurityState. | 332 // TransportSecurityState. |
| 280 void ClearDynamicData(); | 333 void ClearDynamicData(); |
| 281 | 334 |
| 282 // Inserts |state| into |enabled_sts_hosts_| under the key |hashed_host|. | 335 // Inserts |state| into |enabled_sts_hosts_| under the key |hashed_host|. |
| 283 // |hashed_host| is already in the internal representation. | 336 // |hashed_host| is already in the internal representation. |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 ExpectStapleState* expect_staple_result) const; | 521 ExpectStapleState* expect_staple_result) const; |
| 469 | 522 |
| 470 // The sets of hosts that have enabled TransportSecurity. |domain| will always | 523 // The sets of hosts that have enabled TransportSecurity. |domain| will always |
| 471 // be empty for a STSState or PKPState in these maps; the domain | 524 // be empty for a STSState or PKPState in these maps; the domain |
| 472 // comes from the map keys instead. In addition, |upgrade_mode| in the | 525 // comes from the map keys instead. In addition, |upgrade_mode| in the |
| 473 // STSState is never MODE_DEFAULT and |HasPublicKeyPins| in the PKPState | 526 // STSState is never MODE_DEFAULT and |HasPublicKeyPins| in the PKPState |
| 474 // always returns true. | 527 // always returns true. |
| 475 STSStateMap enabled_sts_hosts_; | 528 STSStateMap enabled_sts_hosts_; |
| 476 PKPStateMap enabled_pkp_hosts_; | 529 PKPStateMap enabled_pkp_hosts_; |
| 477 | 530 |
| 478 Delegate* delegate_; | 531 Delegate* delegate_ = nullptr; |
| 479 | 532 |
| 480 ReportSenderInterface* report_sender_; | 533 ReportSenderInterface* report_sender_ = nullptr; |
| 481 | 534 |
| 482 // True if static pins should be used. | 535 // True if static pins should be used. |
| 483 bool enable_static_pins_; | 536 bool enable_static_pins_; |
|
davidben
2016/06/22 21:44:59
Why make the pointers = nullptr while the bools ar
Ryan Sleevi
2016/06/22 22:07:39
I haven't seen any clear guidance in any of the st
| |
| 484 | 537 |
| 485 // True if static expect-CT state should be used. | 538 // True if static expect-CT state should be used. |
| 486 bool enable_static_expect_ct_; | 539 bool enable_static_expect_ct_; |
| 487 | 540 |
| 488 // True if static expect-staple state should be used. | 541 // True if static expect-staple state should be used. |
| 489 bool enable_static_expect_staple_; | 542 bool enable_static_expect_staple_; |
| 490 | 543 |
| 491 ExpectCTReporter* expect_ct_reporter_; | 544 ExpectCTReporter* expect_ct_reporter_ = nullptr; |
| 545 | |
| 546 RequireCTDelegate* require_ct_delegate_ = nullptr; | |
| 492 | 547 |
| 493 // Keeps track of reports that have been sent recently for | 548 // Keeps track of reports that have been sent recently for |
| 494 // rate-limiting. | 549 // rate-limiting. |
| 495 ExpiringCache<std::string, bool, base::TimeTicks, std::less<base::TimeTicks>> | 550 ExpiringCache<std::string, bool, base::TimeTicks, std::less<base::TimeTicks>> |
| 496 sent_reports_cache_; | 551 sent_reports_cache_; |
| 497 | 552 |
| 498 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); | 553 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); |
| 499 }; | 554 }; |
| 500 | 555 |
| 501 } // namespace net | 556 } // namespace net |
| 502 | 557 |
| 503 #endif // NET_HTTP_TRANSPORT_SECURITY_STATE_H_ | 558 #endif // NET_HTTP_TRANSPORT_SECURITY_STATE_H_ |
| OLD | NEW |