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

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

Issue 2052363002: Enable public key pinning of local trust anchors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 } 611 }
612 612
613 } // namespace 613 } // namespace
614 614
615 TransportSecurityState::TransportSecurityState() 615 TransportSecurityState::TransportSecurityState()
616 : delegate_(nullptr), 616 : delegate_(nullptr),
617 report_sender_(nullptr), 617 report_sender_(nullptr),
618 enable_static_pins_(true), 618 enable_static_pins_(true),
619 enable_static_expect_ct_(true), 619 enable_static_expect_ct_(true),
620 enable_static_expect_staple_(false), 620 enable_static_expect_staple_(false),
621 enable_local_trust_anchor_pinning_(false),
621 expect_ct_reporter_(nullptr), 622 expect_ct_reporter_(nullptr),
622 sent_reports_cache_(kMaxHPKPReportCacheEntries) { 623 sent_reports_cache_(kMaxHPKPReportCacheEntries) {
623 // Static pinning is only enabled for official builds to make sure that 624 // Static pinning is only enabled for official builds to make sure that
624 // others don't end up with pins that cannot be easily updated. 625 // others don't end up with pins that cannot be easily updated.
625 #if !defined(OFFICIAL_BUILD) || defined(OS_ANDROID) || defined(OS_IOS) 626 #if !defined(OFFICIAL_BUILD) || defined(OS_ANDROID) || defined(OS_IOS)
626 enable_static_pins_ = false; 627 enable_static_pins_ = false;
627 enable_static_expect_ct_ = false; 628 enable_static_expect_ct_ = false;
628 #endif 629 #endif
629 DCHECK(CalledOnValidThread()); 630 DCHECK(CalledOnValidThread());
630 } 631 }
(...skipping 26 matching lines...) Expand all
657 } 658 }
658 659
659 bool TransportSecurityState::CheckPublicKeyPins( 660 bool TransportSecurityState::CheckPublicKeyPins(
660 const HostPortPair& host_port_pair, 661 const HostPortPair& host_port_pair,
661 bool is_issued_by_known_root, 662 bool is_issued_by_known_root,
662 const HashValueVector& public_key_hashes, 663 const HashValueVector& public_key_hashes,
663 const X509Certificate* served_certificate_chain, 664 const X509Certificate* served_certificate_chain,
664 const X509Certificate* validated_certificate_chain, 665 const X509Certificate* validated_certificate_chain,
665 const PublicKeyPinReportStatus report_status, 666 const PublicKeyPinReportStatus report_status,
666 std::string* pinning_failure_log) { 667 std::string* pinning_failure_log) {
667 // Perform pin validation if, and only if, all these conditions obtain: 668 // Perform pin validation if, and only if:
668 // 669 //
669 // * the server's certificate chain chains up to a known root (i.e. not a 670 // 1. the server actually has public key pins; and one of the following
670 // user-installed trust anchor); and 671 // conditions is met:
671 // * the server actually has public key pins. 672 // 2.1. the server's certificate chain chains up to a known root (i.e. not a
672 if (!is_issued_by_known_root || !HasPublicKeyPins(host_port_pair.host())) { 673 // user-installed trust anchor).
674 // 2.2 the server's certificate chain chains up to user-installed trust
675 // anchor and local trust pinning is enabled.
676 //
677 if ((!is_issued_by_known_root && !enable_local_trust_anchor_pinning_) ||
678 !HasPublicKeyPins(host_port_pair.host())) {
673 return true; 679 return true;
674 } 680 }
675 681
676 bool pins_are_valid = CheckPublicKeyPinsImpl( 682 bool pins_are_valid = CheckPublicKeyPinsImpl(
677 host_port_pair, public_key_hashes, served_certificate_chain, 683 host_port_pair, public_key_hashes, served_certificate_chain,
678 validated_certificate_chain, report_status, pinning_failure_log); 684 validated_certificate_chain, report_status, pinning_failure_log);
679 if (!pins_are_valid) { 685 if (!pins_are_valid) {
680 LOG(ERROR) << *pinning_failure_log; 686 LOG(ERROR) << *pinning_failure_log;
681 ReportUMAOnPinFailure(host_port_pair.host()); 687 ReportUMAOnPinFailure(host_port_pair.host());
682 } 688 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 PKPState pkp_state; 753 PKPState pkp_state;
748 pkp_state.last_observed = last_observed; 754 pkp_state.last_observed = last_observed;
749 pkp_state.expiry = expiry; 755 pkp_state.expiry = expiry;
750 pkp_state.include_subdomains = include_subdomains; 756 pkp_state.include_subdomains = include_subdomains;
751 pkp_state.spki_hashes = hashes; 757 pkp_state.spki_hashes = hashes;
752 pkp_state.report_uri = report_uri; 758 pkp_state.report_uri = report_uri;
753 759
754 EnablePKPHost(host, pkp_state); 760 EnablePKPHost(host, pkp_state);
755 } 761 }
756 762
763 void TransportSecurityState::EnableLocalTrustAnchorPinning(bool value) {
764 enable_local_trust_anchor_pinning_ = value;
765 }
766
757 void TransportSecurityState::EnableSTSHost(const std::string& host, 767 void TransportSecurityState::EnableSTSHost(const std::string& host,
758 const STSState& state) { 768 const STSState& state) {
759 DCHECK(CalledOnValidThread()); 769 DCHECK(CalledOnValidThread());
760 770
761 const std::string canonicalized_host = CanonicalizeHost(host); 771 const std::string canonicalized_host = CanonicalizeHost(host);
762 if (canonicalized_host.empty()) 772 if (canonicalized_host.empty())
763 return; 773 return;
764 774
765 // Only store new state when HSTS is explicitly enabled. If it is 775 // Only store new state when HSTS is explicitly enabled. If it is
766 // disabled, remove the state from the enabled hosts. 776 // disabled, remove the state from the enabled hosts.
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 1061
1052 PKPState pkp_state; 1062 PKPState pkp_state;
1053 pkp_state.last_observed = now; 1063 pkp_state.last_observed = now;
1054 pkp_state.expiry = now; 1064 pkp_state.expiry = now;
1055 pkp_state.include_subdomains = include_subdomains; 1065 pkp_state.include_subdomains = include_subdomains;
1056 pkp_state.spki_hashes = spki_hashes; 1066 pkp_state.spki_hashes = spki_hashes;
1057 pkp_state.report_uri = report_uri; 1067 pkp_state.report_uri = report_uri;
1058 pkp_state.domain = DNSDomainToString(CanonicalizeHost(host_port_pair.host())); 1068 pkp_state.domain = DNSDomainToString(CanonicalizeHost(host_port_pair.host()));
1059 1069
1060 // Only perform pin validation if the cert chains up to a known root. 1070 // Only perform pin validation if the cert chains up to a known root.
1061 if (!ssl_info.is_issued_by_known_root) 1071 if (!ssl_info.is_issued_by_known_root && !enable_local_trust_anchor_pinning_)
1062 return true; 1072 return true;
1063 1073
1064 CheckPinsAndMaybeSendReport( 1074 CheckPinsAndMaybeSendReport(
1065 host_port_pair, pkp_state, ssl_info.public_key_hashes, 1075 host_port_pair, pkp_state, ssl_info.public_key_hashes,
1066 ssl_info.unverified_cert.get(), ssl_info.cert.get(), ENABLE_PIN_REPORTS, 1076 ssl_info.unverified_cert.get(), ssl_info.cert.get(), ENABLE_PIN_REPORTS,
1067 &unused_failure_log); 1077 &unused_failure_log);
1068 return true; 1078 return true;
1069 } 1079 }
1070 1080
1071 void TransportSecurityState::ProcessExpectCTHeader( 1081 void TransportSecurityState::ProcessExpectCTHeader(
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 TransportSecurityState::PKPStateIterator::PKPStateIterator( 1410 TransportSecurityState::PKPStateIterator::PKPStateIterator(
1401 const TransportSecurityState& state) 1411 const TransportSecurityState& state)
1402 : iterator_(state.enabled_pkp_hosts_.begin()), 1412 : iterator_(state.enabled_pkp_hosts_.begin()),
1403 end_(state.enabled_pkp_hosts_.end()) { 1413 end_(state.enabled_pkp_hosts_.end()) {
1404 } 1414 }
1405 1415
1406 TransportSecurityState::PKPStateIterator::~PKPStateIterator() { 1416 TransportSecurityState::PKPStateIterator::~PKPStateIterator() {
1407 } 1417 }
1408 1418
1409 } // namespace 1419 } // namespace
OLDNEW
« net/http/transport_security_state.h ('K') | « net/http/transport_security_state.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698