Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: net/http/transport_security_state.cc

Issue 2066603004: Return enum from TransportSecurityState::CheckPublicKeyPins (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Flatten DCHECK Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/transport_security_state.h ('k') | net/http/transport_security_state_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "net/http/transport_security_state.h" 5 #include "net/http/transport_security_state.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 STSState static_sts_state; 649 STSState static_sts_state;
650 PKPState unused; 650 PKPState unused;
651 if (GetStaticDomainState(host, &static_sts_state, &unused) && 651 if (GetStaticDomainState(host, &static_sts_state, &unused) &&
652 static_sts_state.ShouldUpgradeToSSL()) { 652 static_sts_state.ShouldUpgradeToSSL()) {
653 return true; 653 return true;
654 } 654 }
655 655
656 return false; 656 return false;
657 } 657 }
658 658
659 bool TransportSecurityState::CheckPublicKeyPins( 659 TransportSecurityState::PKPStatus TransportSecurityState::CheckPublicKeyPins(
660 const HostPortPair& host_port_pair, 660 const HostPortPair& host_port_pair,
661 bool is_issued_by_known_root, 661 bool is_issued_by_known_root,
662 const HashValueVector& public_key_hashes, 662 const HashValueVector& public_key_hashes,
663 const X509Certificate* served_certificate_chain, 663 const X509Certificate* served_certificate_chain,
664 const X509Certificate* validated_certificate_chain, 664 const X509Certificate* validated_certificate_chain,
665 const PublicKeyPinReportStatus report_status, 665 const PublicKeyPinReportStatus report_status,
666 std::string* pinning_failure_log) { 666 std::string* pinning_failure_log) {
667 // Perform pin validation only if the server actually has public key pins. 667 // Perform pin validation only if the server actually has public key pins.
668 if (!HasPublicKeyPins(host_port_pair.host())) { 668 if (!HasPublicKeyPins(host_port_pair.host())) {
669 return true; 669 return PKPStatus::OK;
670 } 670 }
671 671
672 bool pins_are_valid = CheckPublicKeyPinsImpl( 672 PKPStatus pin_validity = CheckPublicKeyPinsImpl(
673 host_port_pair, is_issued_by_known_root, public_key_hashes, 673 host_port_pair, is_issued_by_known_root, public_key_hashes,
674 served_certificate_chain, validated_certificate_chain, report_status, 674 served_certificate_chain, validated_certificate_chain, report_status,
675 pinning_failure_log); 675 pinning_failure_log);
676
676 // Don't track statistics when a local trust anchor would override the pinning 677 // Don't track statistics when a local trust anchor would override the pinning
677 // anyway. 678 // anyway.
678 if (!is_issued_by_known_root) 679 if (!is_issued_by_known_root)
679 return pins_are_valid; 680 return pin_validity;
680 681
681 if (!pins_are_valid) { 682 if (pin_validity == PKPStatus::VIOLATED) {
682 LOG(ERROR) << *pinning_failure_log; 683 LOG(ERROR) << *pinning_failure_log;
683 ReportUMAOnPinFailure(host_port_pair.host()); 684 ReportUMAOnPinFailure(host_port_pair.host());
684 } 685 }
685 686 UMA_HISTOGRAM_BOOLEAN("Net.PublicKeyPinSuccess",
686 UMA_HISTOGRAM_BOOLEAN("Net.PublicKeyPinSuccess", pins_are_valid); 687 pin_validity == PKPStatus::OK);
687 return pins_are_valid; 688 return pin_validity;
688 } 689 }
689 690
690 bool TransportSecurityState::HasPublicKeyPins(const std::string& host) { 691 bool TransportSecurityState::HasPublicKeyPins(const std::string& host) {
691 PKPState dynamic_state; 692 PKPState dynamic_state;
692 if (GetDynamicPKPState(host, &dynamic_state)) 693 if (GetDynamicPKPState(host, &dynamic_state))
693 return dynamic_state.HasPublicKeyPins(); 694 return dynamic_state.HasPublicKeyPins();
694 695
695 STSState unused; 696 STSState unused;
696 PKPState static_pkp_state; 697 PKPState static_pkp_state;
697 if (GetStaticDomainState(host, &unused, &static_pkp_state)) { 698 if (GetStaticDomainState(host, &unused, &static_pkp_state)) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 800
800 enabled_pkp_hosts_[HashHost(canonicalized_host)] = pkp_state; 801 enabled_pkp_hosts_[HashHost(canonicalized_host)] = pkp_state;
801 } else { 802 } else {
802 const std::string hashed_host = HashHost(canonicalized_host); 803 const std::string hashed_host = HashHost(canonicalized_host);
803 enabled_pkp_hosts_.erase(hashed_host); 804 enabled_pkp_hosts_.erase(hashed_host);
804 } 805 }
805 806
806 DirtyNotify(); 807 DirtyNotify();
807 } 808 }
808 809
809 bool TransportSecurityState::CheckPinsAndMaybeSendReport( 810 TransportSecurityState::PKPStatus
811 TransportSecurityState::CheckPinsAndMaybeSendReport(
810 const HostPortPair& host_port_pair, 812 const HostPortPair& host_port_pair,
811 bool is_issued_by_known_root, 813 bool is_issued_by_known_root,
812 const TransportSecurityState::PKPState& pkp_state, 814 const TransportSecurityState::PKPState& pkp_state,
813 const HashValueVector& hashes, 815 const HashValueVector& hashes,
814 const X509Certificate* served_certificate_chain, 816 const X509Certificate* served_certificate_chain,
815 const X509Certificate* validated_certificate_chain, 817 const X509Certificate* validated_certificate_chain,
816 const TransportSecurityState::PublicKeyPinReportStatus report_status, 818 const TransportSecurityState::PublicKeyPinReportStatus report_status,
817 std::string* failure_log) { 819 std::string* failure_log) {
818 if (pkp_state.CheckPublicKeyPins(hashes, failure_log)) 820 if (pkp_state.CheckPublicKeyPins(hashes, failure_log))
819 return true; 821 return PKPStatus::OK;
820 822
821 if (!report_sender_ || !is_issued_by_known_root || 823 // Don't report violations for certificates that chain to local roots.
824 if (!is_issued_by_known_root)
825 return PKPStatus::BYPASSED;
826
827 if (!report_sender_ ||
822 report_status != TransportSecurityState::ENABLE_PIN_REPORTS || 828 report_status != TransportSecurityState::ENABLE_PIN_REPORTS ||
823 pkp_state.report_uri.is_empty()) { 829 pkp_state.report_uri.is_empty()) {
824 return false; 830 return PKPStatus::VIOLATED;
825 } 831 }
826 832
827 DCHECK(pkp_state.report_uri.is_valid()); 833 DCHECK(pkp_state.report_uri.is_valid());
828 // Report URIs should not be used if they are the same host as the pin 834 // Report URIs should not be used if they are the same host as the pin
829 // and are HTTPS, to avoid going into a report-sending loop. 835 // and are HTTPS, to avoid going into a report-sending loop.
830 if (!IsReportUriValidForHost(pkp_state.report_uri, host_port_pair.host())) 836 if (!IsReportUriValidForHost(pkp_state.report_uri, host_port_pair.host()))
831 return false; 837 return PKPStatus::VIOLATED;
832 838
833 std::string serialized_report; 839 std::string serialized_report;
834 std::string report_cache_key; 840 std::string report_cache_key;
835 if (!GetHPKPReport(host_port_pair, pkp_state, served_certificate_chain, 841 if (!GetHPKPReport(host_port_pair, pkp_state, served_certificate_chain,
836 validated_certificate_chain, &serialized_report, 842 validated_certificate_chain, &serialized_report,
837 &report_cache_key)) { 843 &report_cache_key)) {
838 return false; 844 return PKPStatus::VIOLATED;
839 } 845 }
840 846
841 // Limit the rate at which duplicate reports are sent to the same 847 // Limit the rate at which duplicate reports are sent to the same
842 // report URI. The same report will not be sent within 848 // report URI. The same report will not be sent within
843 // |kTimeToRememberHPKPReportsMins|, which reduces load on servers and 849 // |kTimeToRememberHPKPReportsMins|, which reduces load on servers and
844 // also prevents accidental loops (a.com triggers a report to b.com 850 // also prevents accidental loops (a.com triggers a report to b.com
845 // which triggers a report to a.com). See section 2.1.4 of RFC 7469. 851 // which triggers a report to a.com). See section 2.1.4 of RFC 7469.
846 if (sent_reports_cache_.Get(report_cache_key, base::TimeTicks::Now())) 852 if (sent_reports_cache_.Get(report_cache_key, base::TimeTicks::Now()))
847 return false; 853 return PKPStatus::VIOLATED;
848 sent_reports_cache_.Put( 854 sent_reports_cache_.Put(
849 report_cache_key, true, base::TimeTicks::Now(), 855 report_cache_key, true, base::TimeTicks::Now(),
850 base::TimeTicks::Now() + 856 base::TimeTicks::Now() +
851 base::TimeDelta::FromMinutes(kTimeToRememberHPKPReportsMins)); 857 base::TimeDelta::FromMinutes(kTimeToRememberHPKPReportsMins));
852 858
853 report_sender_->Send(pkp_state.report_uri, serialized_report); 859 report_sender_->Send(pkp_state.report_uri, serialized_report);
854 return false; 860 return PKPStatus::VIOLATED;
855 } 861 }
856 862
857 bool TransportSecurityState::GetStaticExpectCTState( 863 bool TransportSecurityState::GetStaticExpectCTState(
858 const std::string& host, 864 const std::string& host,
859 ExpectCTState* expect_ct_state) const { 865 ExpectCTState* expect_ct_state) const {
860 DCHECK(CalledOnValidThread()); 866 DCHECK(CalledOnValidThread());
861 867
862 if (!IsBuildTimely()) 868 if (!IsBuildTimely())
863 return false; 869 return false;
864 870
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 "Net.PublicKeyPinFailureDomain", result.domain_id); 1117 "Net.PublicKeyPinFailureDomain", result.domain_id);
1112 } 1118 }
1113 1119
1114 // static 1120 // static
1115 bool TransportSecurityState::IsBuildTimely() { 1121 bool TransportSecurityState::IsBuildTimely() {
1116 const base::Time build_time = base::GetBuildTime(); 1122 const base::Time build_time = base::GetBuildTime();
1117 // We consider built-in information to be timely for 10 weeks. 1123 // We consider built-in information to be timely for 10 weeks.
1118 return (base::Time::Now() - build_time).InDays() < 70 /* 10 weeks */; 1124 return (base::Time::Now() - build_time).InDays() < 70 /* 10 weeks */;
1119 } 1125 }
1120 1126
1121 bool TransportSecurityState::CheckPublicKeyPinsImpl( 1127 TransportSecurityState::PKPStatus
1128 TransportSecurityState::CheckPublicKeyPinsImpl(
1122 const HostPortPair& host_port_pair, 1129 const HostPortPair& host_port_pair,
1123 bool is_issued_by_known_root, 1130 bool is_issued_by_known_root,
1124 const HashValueVector& hashes, 1131 const HashValueVector& hashes,
1125 const X509Certificate* served_certificate_chain, 1132 const X509Certificate* served_certificate_chain,
1126 const X509Certificate* validated_certificate_chain, 1133 const X509Certificate* validated_certificate_chain,
1127 const PublicKeyPinReportStatus report_status, 1134 const PublicKeyPinReportStatus report_status,
1128 std::string* failure_log) { 1135 std::string* failure_log) {
1129 PKPState pkp_state; 1136 PKPState pkp_state;
1130 STSState unused; 1137 STSState unused;
1131 1138
1132 if (!GetDynamicPKPState(host_port_pair.host(), &pkp_state) && 1139 bool found_state =
1133 !GetStaticDomainState(host_port_pair.host(), &unused, &pkp_state)) { 1140 GetDynamicPKPState(host_port_pair.host(), &pkp_state) ||
1134 // HasPublicKeyPins should have returned true in order for this method 1141 GetStaticDomainState(host_port_pair.host(), &unused, &pkp_state);
1135 // to have been called, so if we fall through to here, it's an error.
1136 return false;
1137 }
1138 1142
1143 // HasPublicKeyPins should have returned true in order for this method to have
1144 // been called, so if found_state is false, its an error.
estark 2016/06/21 18:31:28 sorry, one more tiny nit: pipes around |found_stat
1145 DCHECK(found_state);
1139 return CheckPinsAndMaybeSendReport( 1146 return CheckPinsAndMaybeSendReport(
1140 host_port_pair, is_issued_by_known_root, pkp_state, hashes, 1147 host_port_pair, is_issued_by_known_root, pkp_state, hashes,
1141 served_certificate_chain, validated_certificate_chain, report_status, 1148 served_certificate_chain, validated_certificate_chain, report_status,
1142 failure_log); 1149 failure_log);
1143 } 1150 }
1144 1151
1145 bool TransportSecurityState::GetStaticDomainState(const std::string& host, 1152 bool TransportSecurityState::GetStaticDomainState(const std::string& host,
1146 STSState* sts_state, 1153 STSState* sts_state,
1147 PKPState* pkp_state) const { 1154 PKPState* pkp_state) const {
1148 DCHECK(CalledOnValidThread()); 1155 DCHECK(CalledOnValidThread());
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 TransportSecurityState::PKPStateIterator::PKPStateIterator( 1408 TransportSecurityState::PKPStateIterator::PKPStateIterator(
1402 const TransportSecurityState& state) 1409 const TransportSecurityState& state)
1403 : iterator_(state.enabled_pkp_hosts_.begin()), 1410 : iterator_(state.enabled_pkp_hosts_.begin()),
1404 end_(state.enabled_pkp_hosts_.end()) { 1411 end_(state.enabled_pkp_hosts_.end()) {
1405 } 1412 }
1406 1413
1407 TransportSecurityState::PKPStateIterator::~PKPStateIterator() { 1414 TransportSecurityState::PKPStateIterator::~PKPStateIterator() {
1408 } 1415 }
1409 1416
1410 } // namespace 1417 } // namespace
OLDNEW
« no previous file with comments | « net/http/transport_security_state.h ('k') | net/http/transport_security_state_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698