| 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, |
| 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( |
| 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 bool ShouldUpgradeToSSL(const std::string& host); | 293 bool ShouldUpgradeToSSL(const std::string& host); |
| 262 bool CheckPublicKeyPins(const HostPortPair& host_port_pair, | 294 bool CheckPublicKeyPins(const HostPortPair& host_port_pair, |
| 263 bool is_issued_by_known_root, | 295 bool is_issued_by_known_root, |
| 264 const HashValueVector& hashes, | 296 const HashValueVector& hashes, |
| 265 const X509Certificate* served_certificate_chain, | 297 const X509Certificate* served_certificate_chain, |
| 266 const X509Certificate* validated_certificate_chain, | 298 const X509Certificate* validated_certificate_chain, |
| 267 const PublicKeyPinReportStatus report_status, | 299 const PublicKeyPinReportStatus report_status, |
| 268 std::string* failure_log); | 300 std::string* failure_log); |
| 269 bool HasPublicKeyPins(const std::string& host); | 301 bool HasPublicKeyPins(const std::string& host); |
| 270 | 302 |
| 303 // Returns true if connections to |host|, using the validated certificate |
| 304 // |validated_certificate_chain|, are expected to be accompanied with |
| 305 // valid Certificate Transparency information that complies with the |
| 306 // connection's CTPolicyEnforcer. |
| 307 // |
| 308 // The behavior may be further be altered by setting a RequireCTDelegate |
| 309 // via |SetRequireCTDelegate()|. |
| 310 bool ShouldRequireCT(const std::string& host, |
| 311 const X509Certificate* validated_certificate_chain, |
| 312 const HashValueVector& hashes); |
| 313 |
| 271 // Assign a |Delegate| for persisting the transport security state. If | 314 // Assign a |Delegate| for persisting the transport security state. If |
| 272 // |NULL|, state will not be persisted. The caller retains | 315 // |NULL|, state will not be persisted. The caller retains |
| 273 // ownership of |delegate|. | 316 // ownership of |delegate|. |
| 274 // Note: This is only used for serializing/deserializing the | 317 // Note: This is only used for serializing/deserializing the |
| 275 // TransportSecurityState. | 318 // TransportSecurityState. |
| 276 void SetDelegate(Delegate* delegate); | 319 void SetDelegate(Delegate* delegate); |
| 277 | 320 |
| 278 void SetReportSender(ReportSenderInterface* report_sender); | 321 void SetReportSender(ReportSenderInterface* report_sender); |
| 279 | 322 |
| 280 void SetExpectCTReporter(ExpectCTReporter* expect_ct_reporter); | 323 void SetExpectCTReporter(ExpectCTReporter* expect_ct_reporter); |
| 281 | 324 |
| 325 // Assigns a delegate responsible for determining whether or not a |
| 326 // connection to a given host should require Certificate Transparency |
| 327 // information that complies with the CT policy provided by a |
| 328 // CTPolicyEnforcer. |
| 329 // If nullptr, no delegate will be consulted. |
| 330 // The caller retains ownership of the |delegate|, and must persist for |
| 331 // the lifetime of this object or until called with nullptr, whichever |
| 332 // occurs first. |
| 333 void SetRequireCTDelegate(RequireCTDelegate* delegate); |
| 334 |
| 282 // Clears all dynamic data (e.g. HSTS and HPKP data). | 335 // Clears all dynamic data (e.g. HSTS and HPKP data). |
| 283 // | 336 // |
| 284 // Does NOT persist changes using the Delegate, as this function is only | 337 // Does NOT persist changes using the Delegate, as this function is only |
| 285 // used to clear any dynamic data prior to re-loading it from a file. | 338 // used to clear any dynamic data prior to re-loading it from a file. |
| 286 // Note: This is only used for serializing/deserializing the | 339 // Note: This is only used for serializing/deserializing the |
| 287 // TransportSecurityState. | 340 // TransportSecurityState. |
| 288 void ClearDynamicData(); | 341 void ClearDynamicData(); |
| 289 | 342 |
| 290 // Inserts |state| into |enabled_sts_hosts_| under the key |hashed_host|. | 343 // Inserts |state| into |enabled_sts_hosts_| under the key |hashed_host|. |
| 291 // |hashed_host| is already in the internal representation. | 344 // |hashed_host| is already in the internal representation. |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 ExpectStapleState* expect_staple_result) const; | 529 ExpectStapleState* expect_staple_result) const; |
| 477 | 530 |
| 478 // The sets of hosts that have enabled TransportSecurity. |domain| will always | 531 // The sets of hosts that have enabled TransportSecurity. |domain| will always |
| 479 // be empty for a STSState or PKPState in these maps; the domain | 532 // be empty for a STSState or PKPState in these maps; the domain |
| 480 // comes from the map keys instead. In addition, |upgrade_mode| in the | 533 // comes from the map keys instead. In addition, |upgrade_mode| in the |
| 481 // STSState is never MODE_DEFAULT and |HasPublicKeyPins| in the PKPState | 534 // STSState is never MODE_DEFAULT and |HasPublicKeyPins| in the PKPState |
| 482 // always returns true. | 535 // always returns true. |
| 483 STSStateMap enabled_sts_hosts_; | 536 STSStateMap enabled_sts_hosts_; |
| 484 PKPStateMap enabled_pkp_hosts_; | 537 PKPStateMap enabled_pkp_hosts_; |
| 485 | 538 |
| 486 Delegate* delegate_; | 539 Delegate* delegate_ = nullptr; |
| 487 | 540 |
| 488 ReportSenderInterface* report_sender_; | 541 ReportSenderInterface* report_sender_ = nullptr; |
| 489 | 542 |
| 490 // True if static pins should be used. | 543 // True if static pins should be used. |
| 491 bool enable_static_pins_; | 544 bool enable_static_pins_; |
| 492 | 545 |
| 493 // True if static expect-CT state should be used. | 546 // True if static expect-CT state should be used. |
| 494 bool enable_static_expect_ct_; | 547 bool enable_static_expect_ct_; |
| 495 | 548 |
| 496 // True if static expect-staple state should be used. | 549 // True if static expect-staple state should be used. |
| 497 bool enable_static_expect_staple_; | 550 bool enable_static_expect_staple_; |
| 498 | 551 |
| 499 ExpectCTReporter* expect_ct_reporter_; | 552 ExpectCTReporter* expect_ct_reporter_ = nullptr; |
| 553 |
| 554 RequireCTDelegate* require_ct_delegate_ = nullptr; |
| 500 | 555 |
| 501 // Keeps track of reports that have been sent recently for | 556 // Keeps track of reports that have been sent recently for |
| 502 // rate-limiting. | 557 // rate-limiting. |
| 503 ExpiringCache<std::string, bool, base::TimeTicks, std::less<base::TimeTicks>> | 558 ExpiringCache<std::string, bool, base::TimeTicks, std::less<base::TimeTicks>> |
| 504 sent_reports_cache_; | 559 sent_reports_cache_; |
| 505 | 560 |
| 506 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); | 561 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); |
| 507 }; | 562 }; |
| 508 | 563 |
| 509 } // namespace net | 564 } // namespace net |
| 510 | 565 |
| 511 #endif // NET_HTTP_TRANSPORT_SECURITY_STATE_H_ | 566 #endif // NET_HTTP_TRANSPORT_SECURITY_STATE_H_ |
| OLD | NEW |