| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 bool HasNext() const { return iterator_ != end_; } | 100 bool HasNext() const { return iterator_ != end_; } |
| 101 void Advance() { ++iterator_; } | 101 void Advance() { ++iterator_; } |
| 102 const std::string& hostname() const { return iterator_->first; } | 102 const std::string& hostname() const { return iterator_->first; } |
| 103 const STSState& domain_state() const { return iterator_->second; } | 103 const STSState& domain_state() const { return iterator_->second; } |
| 104 | 104 |
| 105 private: | 105 private: |
| 106 std::map<std::string, STSState>::const_iterator iterator_; | 106 std::map<std::string, STSState>::const_iterator iterator_; |
| 107 std::map<std::string, STSState>::const_iterator end_; | 107 std::map<std::string, STSState>::const_iterator end_; |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 // PKPStatus describes the result of a pinning check. |
| 111 enum class PKPStatus { |
| 112 // Pinning was enabled and the necessary pins were not present. |
| 113 VIOLATED, |
| 114 |
| 115 // Pinning was not enabled, or pinning was enabled and the certificate |
| 116 // satisfied the pins. |
| 117 OK, |
| 118 |
| 119 // Pinning was enabled and the certificate did not satisfy the pins, but the |
| 120 // violation was ignored due to local policy, such as a local trust anchor. |
| 121 BYPASSED, |
| 122 }; |
| 123 |
| 110 // A PKPState describes the public key pinning state. | 124 // A PKPState describes the public key pinning state. |
| 111 class NET_EXPORT PKPState { | 125 class NET_EXPORT PKPState { |
| 112 public: | 126 public: |
| 113 PKPState(); | 127 PKPState(); |
| 114 PKPState(const PKPState& other); | 128 PKPState(const PKPState& other); |
| 115 ~PKPState(); | 129 ~PKPState(); |
| 116 | 130 |
| 117 // The absolute time (UTC) when the |spki_hashes| (and other state) were | 131 // The absolute time (UTC) when the |spki_hashes| (and other state) were |
| 118 // observed. | 132 // observed. |
| 119 base::Time last_observed; | 133 base::Time last_observed; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 TransportSecurityState(); | 266 TransportSecurityState(); |
| 253 ~TransportSecurityState(); | 267 ~TransportSecurityState(); |
| 254 | 268 |
| 255 // These functions search for static and dynamic STS and PKP states, and | 269 // These functions search for static and dynamic STS and PKP states, and |
| 256 // invoke the functions of the same name on them. These functions are the | 270 // invoke the functions of the same name on them. These functions are the |
| 257 // primary public interface; direct access to STS and PKP states is best | 271 // primary public interface; direct access to STS and PKP states is best |
| 258 // left to tests. The caller needs to handle the optional pinning override | 272 // left to tests. The caller needs to handle the optional pinning override |
| 259 // when is_issued_by_known_root is false. | 273 // when is_issued_by_known_root is false. |
| 260 bool ShouldSSLErrorsBeFatal(const std::string& host); | 274 bool ShouldSSLErrorsBeFatal(const std::string& host); |
| 261 bool ShouldUpgradeToSSL(const std::string& host); | 275 bool ShouldUpgradeToSSL(const std::string& host); |
| 262 bool CheckPublicKeyPins(const HostPortPair& host_port_pair, | 276 PKPStatus CheckPublicKeyPins( |
| 263 bool is_issued_by_known_root, | 277 const HostPortPair& host_port_pair, |
| 264 const HashValueVector& hashes, | 278 bool is_issued_by_known_root, |
| 265 const X509Certificate* served_certificate_chain, | 279 const HashValueVector& hashes, |
| 266 const X509Certificate* validated_certificate_chain, | 280 const X509Certificate* served_certificate_chain, |
| 267 const PublicKeyPinReportStatus report_status, | 281 const X509Certificate* validated_certificate_chain, |
| 268 std::string* failure_log); | 282 const PublicKeyPinReportStatus report_status, |
| 283 std::string* failure_log); |
| 269 bool HasPublicKeyPins(const std::string& host); | 284 bool HasPublicKeyPins(const std::string& host); |
| 270 | 285 |
| 271 // Assign a |Delegate| for persisting the transport security state. If | 286 // Assign a |Delegate| for persisting the transport security state. If |
| 272 // |NULL|, state will not be persisted. The caller retains | 287 // |NULL|, state will not be persisted. The caller retains |
| 273 // ownership of |delegate|. | 288 // ownership of |delegate|. |
| 274 // Note: This is only used for serializing/deserializing the | 289 // Note: This is only used for serializing/deserializing the |
| 275 // TransportSecurityState. | 290 // TransportSecurityState. |
| 276 void SetDelegate(Delegate* delegate); | 291 void SetDelegate(Delegate* delegate); |
| 277 | 292 |
| 278 void SetReportSender(ReportSenderInterface* report_sender); | 293 void SetReportSender(ReportSenderInterface* report_sender); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 // representation of first-class DomainStates, and exposing the preloads | 419 // representation of first-class DomainStates, and exposing the preloads |
| 405 // to the caller with |GetStaticDomainState|. | 420 // to the caller with |GetStaticDomainState|. |
| 406 static void ReportUMAOnPinFailure(const std::string& host); | 421 static void ReportUMAOnPinFailure(const std::string& host); |
| 407 | 422 |
| 408 // IsBuildTimely returns true if the current build is new enough ensure that | 423 // IsBuildTimely returns true if the current build is new enough ensure that |
| 409 // built in security information (i.e. HSTS preloading and pinning | 424 // built in security information (i.e. HSTS preloading and pinning |
| 410 // information) is timely. | 425 // information) is timely. |
| 411 static bool IsBuildTimely(); | 426 static bool IsBuildTimely(); |
| 412 | 427 |
| 413 // Helper method for actually checking pins. | 428 // Helper method for actually checking pins. |
| 414 bool CheckPublicKeyPinsImpl( | 429 PKPStatus CheckPublicKeyPinsImpl( |
| 415 const HostPortPair& host_port_pair, | 430 const HostPortPair& host_port_pair, |
| 416 bool is_issued_by_known_root, | 431 bool is_issued_by_known_root, |
| 417 const HashValueVector& hashes, | 432 const HashValueVector& hashes, |
| 418 const X509Certificate* served_certificate_chain, | 433 const X509Certificate* served_certificate_chain, |
| 419 const X509Certificate* validated_certificate_chain, | 434 const X509Certificate* validated_certificate_chain, |
| 420 const PublicKeyPinReportStatus report_status, | 435 const PublicKeyPinReportStatus report_status, |
| 421 std::string* failure_log); | 436 std::string* failure_log); |
| 422 | 437 |
| 423 // If a Delegate is present, notify it that the internal state has | 438 // If a Delegate is present, notify it that the internal state has |
| 424 // changed. | 439 // changed. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 445 void EnableSTSHost(const std::string& host, const STSState& state); | 460 void EnableSTSHost(const std::string& host, const STSState& state); |
| 446 void EnablePKPHost(const std::string& host, const PKPState& state); | 461 void EnablePKPHost(const std::string& host, const PKPState& state); |
| 447 | 462 |
| 448 // Returns true if a request to |host_port_pair| with the given | 463 // Returns true if a request to |host_port_pair| with the given |
| 449 // SubjectPublicKeyInfo |hashes| satisfies the pins in |pkp_state|, | 464 // SubjectPublicKeyInfo |hashes| satisfies the pins in |pkp_state|, |
| 450 // and false otherwise. If a violation is found and reporting is | 465 // and false otherwise. If a violation is found and reporting is |
| 451 // configured (i.e. there is a report URI in |pkp_state| and | 466 // configured (i.e. there is a report URI in |pkp_state| and |
| 452 // |report_status| says to), this method sends an HPKP violation | 467 // |report_status| says to), this method sends an HPKP violation |
| 453 // report containing |served_certificate_chain| and | 468 // report containing |served_certificate_chain| and |
| 454 // |validated_certificate_chain|. | 469 // |validated_certificate_chain|. |
| 455 bool CheckPinsAndMaybeSendReport( | 470 PKPStatus CheckPinsAndMaybeSendReport( |
| 456 const HostPortPair& host_port_pair, | 471 const HostPortPair& host_port_pair, |
| 457 bool is_issued_by_known_root, | 472 bool is_issued_by_known_root, |
| 458 const TransportSecurityState::PKPState& pkp_state, | 473 const TransportSecurityState::PKPState& pkp_state, |
| 459 const HashValueVector& hashes, | 474 const HashValueVector& hashes, |
| 460 const X509Certificate* served_certificate_chain, | 475 const X509Certificate* served_certificate_chain, |
| 461 const X509Certificate* validated_certificate_chain, | 476 const X509Certificate* validated_certificate_chain, |
| 462 const TransportSecurityState::PublicKeyPinReportStatus report_status, | 477 const TransportSecurityState::PublicKeyPinReportStatus report_status, |
| 463 std::string* failure_log); | 478 std::string* failure_log); |
| 464 | 479 |
| 465 // Returns true and updates |*expect_ct_result| iff there is a static | 480 // Returns true and updates |*expect_ct_result| iff there is a static |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 // rate-limiting. | 517 // rate-limiting. |
| 503 ExpiringCache<std::string, bool, base::TimeTicks, std::less<base::TimeTicks>> | 518 ExpiringCache<std::string, bool, base::TimeTicks, std::less<base::TimeTicks>> |
| 504 sent_reports_cache_; | 519 sent_reports_cache_; |
| 505 | 520 |
| 506 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); | 521 DISALLOW_COPY_AND_ASSIGN(TransportSecurityState); |
| 507 }; | 522 }; |
| 508 | 523 |
| 509 } // namespace net | 524 } // namespace net |
| 510 | 525 |
| 511 #endif // NET_HTTP_TRANSPORT_SECURITY_STATE_H_ | 526 #endif // NET_HTTP_TRANSPORT_SECURITY_STATE_H_ |
| OLD | NEW |