| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 class NET_EXPORT Delegate { | 42 class NET_EXPORT Delegate { |
| 43 public: | 43 public: |
| 44 // This function may not block and may be called with internal locks held. | 44 // This function may not block and may be called with internal locks held. |
| 45 // Thus it must not reenter the TransportSecurityState object. | 45 // Thus it must not reenter the TransportSecurityState object. |
| 46 virtual void StateIsDirty(TransportSecurityState* state) = 0; | 46 virtual void StateIsDirty(TransportSecurityState* state) = 0; |
| 47 | 47 |
| 48 protected: | 48 protected: |
| 49 virtual ~Delegate() {} | 49 virtual ~Delegate() {} |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 class NET_EXPORT RequireCTDelegate { |
| 53 public: |
| 54 // Provides a capability for altering the default handling of Certificate |
| 55 // Transparency information, allowing it to be always required for some |
| 56 // hosts, for some hosts to be opted out of the default policy, or |
| 57 // allowing the TransportSecurityState to apply the default security |
| 58 // policies. |
| 59 enum class CTRequirementLevel { |
| 60 // The host is required to always supply Certificate Transparency |
| 61 // information that complies with the CT policy. |
| 62 REQUIRED, |
| 63 |
| 64 // The host is explicitly not required to supply Certificate |
| 65 // Transparency information that complies with the CT policy. |
| 66 NOT_REQUIRED, |
| 67 |
| 68 // The delegate makes no statements, positive or negative, about |
| 69 // requiring the host to supply Certificate Transparency information, |
| 70 // allowing the default behaviour to happen. |
| 71 DEFAULT, |
| 72 }; |
| 73 |
| 74 // Called by the TransportSecurityState, allows the Delegate to override |
| 75 // the default handling of Certificate Transparency requirements, if |
| 76 // desired. |
| 77 virtual CTRequirementLevel IsCTRequiredForHost( |
| 78 const std::string& hostname) = 0; |
| 79 |
| 80 protected: |
| 81 virtual ~RequireCTDelegate() = default; |
| 82 }; |
| 83 |
| 52 // A STSState describes the strict transport security state (required | 84 // A STSState describes the strict transport security state (required |
| 53 // upgrade to HTTPS). | 85 // upgrade to HTTPS). |
| 54 class NET_EXPORT STSState { | 86 class NET_EXPORT STSState { |
| 55 public: | 87 public: |
| 56 enum UpgradeMode { | 88 enum UpgradeMode { |
| 57 // These numbers must match those in hsts_view.js, function modeToString. | 89 // These numbers must match those in hsts_view.js, function modeToString. |
| 58 MODE_FORCE_HTTPS = 0, | 90 MODE_FORCE_HTTPS = 0, |
| 59 MODE_DEFAULT = 1, | 91 MODE_DEFAULT = 1, |
| 60 }; | 92 }; |
| 61 | 93 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 PKPStatus CheckPublicKeyPins( | 296 PKPStatus CheckPublicKeyPins( |
| 265 const HostPortPair& host_port_pair, | 297 const HostPortPair& host_port_pair, |
| 266 bool is_issued_by_known_root, | 298 bool is_issued_by_known_root, |
| 267 const HashValueVector& hashes, | 299 const HashValueVector& hashes, |
| 268 const X509Certificate* served_certificate_chain, | 300 const X509Certificate* served_certificate_chain, |
| 269 const X509Certificate* validated_certificate_chain, | 301 const X509Certificate* validated_certificate_chain, |
| 270 const PublicKeyPinReportStatus report_status, | 302 const PublicKeyPinReportStatus report_status, |
| 271 std::string* failure_log); | 303 std::string* failure_log); |
| 272 bool HasPublicKeyPins(const std::string& host); | 304 bool HasPublicKeyPins(const std::string& host); |
| 273 | 305 |
| 306 // Returns true if connections to |host|, using the validated certificate |
| 307 // |validated_certificate_chain|, are expected to be accompanied with |
| 308 // valid Certificate Transparency information that complies with the |
| 309 // connection's CTPolicyEnforcer. |
| 310 // |
| 311 // The behavior may be further be altered by setting a RequireCTDelegate |
| 312 // via |SetRequireCTDelegate()|. |
| 313 bool ShouldRequireCT(const std::string& host, |
| 314 const X509Certificate* validated_certificate_chain, |
| 315 const HashValueVector& hashes); |
| 316 |
| 274 // Assign a |Delegate| for persisting the transport security state. If | 317 // Assign a |Delegate| for persisting the transport security state. If |
| 275 // |NULL|, state will not be persisted. The caller retains | 318 // |NULL|, state will not be persisted. The caller retains |
| 276 // ownership of |delegate|. | 319 // ownership of |delegate|. |
| 277 // Note: This is only used for serializing/deserializing the | 320 // Note: This is only used for serializing/deserializing the |
| 278 // TransportSecurityState. | 321 // TransportSecurityState. |
| 279 void SetDelegate(Delegate* delegate); | 322 void SetDelegate(Delegate* delegate); |
| 280 | 323 |
| 281 void SetReportSender(ReportSenderInterface* report_sender); | 324 void SetReportSender(ReportSenderInterface* report_sender); |
| 282 | 325 |
| 283 void SetExpectCTReporter(ExpectCTReporter* expect_ct_reporter); | 326 void SetExpectCTReporter(ExpectCTReporter* expect_ct_reporter); |
| 284 | 327 |
| 328 // Assigns a delegate responsible for determining whether or not a |
| 329 // connection to a given host should require Certificate Transparency |
| 330 // information that complies with the CT policy provided by a |
| 331 // CTPolicyEnforcer. |
| 332 // If nullptr, no delegate will be consulted. |
| 333 // The caller retains ownership of the |delegate|, and must persist for |
| 334 // the lifetime of this object or until called with nullptr, whichever |
| 335 // occurs first. |
| 336 void SetRequireCTDelegate(RequireCTDelegate* delegate); |
| 337 |
| 285 // Clears all dynamic data (e.g. HSTS and HPKP data). | 338 // Clears all dynamic data (e.g. HSTS and HPKP data). |
| 286 // | 339 // |
| 287 // Does NOT persist changes using the Delegate, as this function is only | 340 // Does NOT persist changes using the Delegate, as this function is only |
| 288 // used to clear any dynamic data prior to re-loading it from a file. | 341 // used to clear any dynamic data prior to re-loading it from a file. |
| 289 // Note: This is only used for serializing/deserializing the | 342 // Note: This is only used for serializing/deserializing the |
| 290 // TransportSecurityState. | 343 // TransportSecurityState. |
| 291 void ClearDynamicData(); | 344 void ClearDynamicData(); |
| 292 | 345 |
| 293 // Inserts |state| into |enabled_sts_hosts_| under the key |hashed_host|. | 346 // Inserts |state| into |enabled_sts_hosts_| under the key |hashed_host|. |
| 294 // |hashed_host| is already in the internal representation. | 347 // |hashed_host| is already in the internal representation. |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 ExpectStapleState* expect_staple_result) const; | 532 ExpectStapleState* expect_staple_result) const; |
| 480 | 533 |
| 481 // The sets of hosts that have enabled TransportSecurity. |domain| will always | 534 // The sets of hosts that have enabled TransportSecurity. |domain| will always |
| 482 // be empty for a STSState or PKPState in these maps; the domain | 535 // be empty for a STSState or PKPState in these maps; the domain |
| 483 // comes from the map keys instead. In addition, |upgrade_mode| in the | 536 // comes from the map keys instead. In addition, |upgrade_mode| in the |
| 484 // STSState is never MODE_DEFAULT and |HasPublicKeyPins| in the PKPState | 537 // STSState is never MODE_DEFAULT and |HasPublicKeyPins| in the PKPState |
| 485 // always returns true. | 538 // always returns true. |
| 486 STSStateMap enabled_sts_hosts_; | 539 STSStateMap enabled_sts_hosts_; |
| 487 PKPStateMap enabled_pkp_hosts_; | 540 PKPStateMap enabled_pkp_hosts_; |
| 488 | 541 |
| 489 Delegate* delegate_; | 542 Delegate* delegate_ = nullptr; |
| 490 | 543 |
| 491 ReportSenderInterface* report_sender_; | 544 ReportSenderInterface* report_sender_ = nullptr; |
| 492 | 545 |
| 493 // True if static pins should be used. | 546 // True if static pins should be used. |
| 494 bool enable_static_pins_; | 547 bool enable_static_pins_; |
| 495 | 548 |
| 496 // True if static expect-CT state should be used. | 549 // True if static expect-CT state should be used. |
| 497 bool enable_static_expect_ct_; | 550 bool enable_static_expect_ct_; |
| 498 | 551 |
| 499 // True if static expect-staple state should be used. | 552 // True if static expect-staple state should be used. |
| 500 bool enable_static_expect_staple_; | 553 bool enable_static_expect_staple_; |
| 501 | 554 |
| 502 ExpectCTReporter* expect_ct_reporter_; | 555 ExpectCTReporter* expect_ct_reporter_ = nullptr; |
| 556 |
| 557 RequireCTDelegate* require_ct_delegate_ = nullptr; |
| 503 | 558 |
| 504 // Keeps track of reports that have been sent recently for | 559 // Keeps track of reports that have been sent recently for |
| 505 // rate-limiting. | 560 // rate-limiting. |
| 506 ExpiringCache<std::string, bool, base::TimeTicks, std::less<base::TimeTicks>> | 561 ExpiringCache<std::string, bool, base::TimeTicks, std::less<base::TimeTicks>> |
| 507 sent_reports_cache_; | 562 sent_reports_cache_; |
| 508 | 563 |
| 509 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); | 564 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); |
| 510 }; | 565 }; |
| 511 | 566 |
| 512 } // namespace net | 567 } // namespace net |
| 513 | 568 |
| 514 #endif // NET_HTTP_TRANSPORT_SECURITY_STATE_H_ | 569 #endif // NET_HTTP_TRANSPORT_SECURITY_STATE_H_ |
| OLD | NEW |