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

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

Issue 2144693004: Add the ability to send Expect-Staple reports. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ocsp-verify-result
Patch Set: More test cleanups. Created 4 years, 5 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 #include <vector> 10 #include <vector>
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 bool found; 630 bool found;
631 if (!DecodeHSTSPreloadRaw(hostname, &found, out)) { 631 if (!DecodeHSTSPreloadRaw(hostname, &found, out)) {
632 DCHECK(false) << "Internal error in DecodeHSTSPreloadRaw for hostname " 632 DCHECK(false) << "Internal error in DecodeHSTSPreloadRaw for hostname "
633 << hostname; 633 << hostname;
634 return false; 634 return false;
635 } 635 }
636 636
637 return found; 637 return found;
638 } 638 }
639 639
640 // Serializes an OCSPVerifyResult::ResponseStatus to a string enum, suitable for
641 // the |response-status| field in an Expect-Staple report.
642 std::string SerializeExpectStapleResponseStatus(
643 OCSPVerifyResult::ResponseStatus status) {
644 switch (status) {
645 case OCSPVerifyResult::MISSING:
646 return "MISSING";
647 case OCSPVerifyResult::PROVIDED:
648 return "PROVIDED";
649 case OCSPVerifyResult::ERROR_RESPONSE:
650 return "ERROR_RESPONSE";
651 case OCSPVerifyResult::BAD_PRODUCED_AT:
652 return "BAD_PRODUCED_AT";
653 case OCSPVerifyResult::NO_MATCHING_RESPONSE:
654 return "NO_MATCHING_RESPONSE";
655 case OCSPVerifyResult::INVALID_DATE:
656 return "INVALID_DATE";
657 case OCSPVerifyResult::PARSE_RESPONSE_ERROR:
658 return "PARSE_RESPONSE_ERROR";
659 case OCSPVerifyResult::PARSE_RESPONSE_DATA_ERROR:
660 return "PARSE_RESPONSE_DATA_ERROR";
661 }
662 }
663
664 // Serializes an OCSPRevocationStatus to a string enum, suitable for the
665 // |cert-status| field in an Expect-Staple report.
666 std::string SerializeExpectStapleRevocationStatus(
667 const OCSPRevocationStatus& status) {
668 switch (status) {
669 case OCSPRevocationStatus::GOOD:
670 return "GOOD";
671 case OCSPRevocationStatus::REVOKED:
672 return "REVOKED";
673 case OCSPRevocationStatus::UNKNOWN:
674 return "UNKNOWN";
675 }
676 }
677
678 bool SerializeExpectStapleReport(const HostPortPair& host_port_pair,
679 const SSLInfo& ssl_info,
680 const std::string& ocsp_response,
681 std::string* out_serialized_report) {
682 base::DictionaryValue report;
683 report.SetString("date-time", TimeToISO8601(base::Time::Now()));
684 report.SetString("hostname", host_port_pair.host());
685 report.SetInteger("port", host_port_pair.port());
686 report.SetString("response-status",
687 SerializeExpectStapleResponseStatus(
688 ssl_info.ocsp_result.response_status));
689
690 if (!ocsp_response.empty()) {
691 std::string encoded_ocsp_response;
692 base::Base64Encode(ocsp_response, &encoded_ocsp_response);
693 report.SetString("ocsp-response", encoded_ocsp_response);
694 }
695 if (ssl_info.ocsp_result.response_status == OCSPVerifyResult::PROVIDED) {
696 report.SetString("cert-status",
697 SerializeExpectStapleRevocationStatus(
698 ssl_info.ocsp_result.revocation_status));
699 }
700 if (ssl_info.is_issued_by_known_root) {
701 report.Set("served-certificate-chain",
702 GetPEMEncodedChainAsList(ssl_info.unverified_cert.get()));
703 report.Set("validated-certificate-chain",
704 GetPEMEncodedChainAsList(ssl_info.cert.get()));
705 }
706
707 if (!base::JSONWriter::Write(report, out_serialized_report))
708 return false;
709 return true;
710 }
711
640 } // namespace 712 } // namespace
641 713
642 TransportSecurityState::TransportSecurityState() 714 TransportSecurityState::TransportSecurityState()
643 : enable_static_pins_(true), 715 : enable_static_pins_(true),
644 enable_static_expect_ct_(true), 716 enable_static_expect_ct_(true),
645 enable_static_expect_staple_(false), 717 enable_static_expect_staple_(false),
646 enable_pkp_bypass_for_local_trust_anchors_(true), 718 enable_pkp_bypass_for_local_trust_anchors_(true),
647 sent_reports_cache_(kMaxHPKPReportCacheEntries) { 719 sent_reports_cache_(kMaxHPKPReportCacheEntries) {
648 // Static pinning is only enabled for official builds to make sure that 720 // Static pinning is only enabled for official builds to make sure that
649 // others don't end up with pins that cannot be easily updated. 721 // others don't end up with pins that cannot be easily updated.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 778
707 if (pin_validity == PKPStatus::VIOLATED) { 779 if (pin_validity == PKPStatus::VIOLATED) {
708 LOG(ERROR) << *pinning_failure_log; 780 LOG(ERROR) << *pinning_failure_log;
709 ReportUMAOnPinFailure(host_port_pair.host()); 781 ReportUMAOnPinFailure(host_port_pair.host());
710 } 782 }
711 UMA_HISTOGRAM_BOOLEAN("Net.PublicKeyPinSuccess", 783 UMA_HISTOGRAM_BOOLEAN("Net.PublicKeyPinSuccess",
712 pin_validity == PKPStatus::OK); 784 pin_validity == PKPStatus::OK);
713 return pin_validity; 785 return pin_validity;
714 } 786 }
715 787
788 void TransportSecurityState::CheckExpectStaple(
789 const HostPortPair& host_port_pair,
790 const SSLInfo& ssl_info,
791 const std::string& ocsp_response) {
792 DCHECK(CalledOnValidThread());
793 if (!enable_static_expect_staple_ || !report_sender_)
794 return;
795
796 // Determine if the host is on the Expect-Staple preload list. If the build is
797 // not timely (i.e. the preload list is not fresh), this will fail and return
798 // false.
799 ExpectStapleState expect_staple_state;
800 if (!GetStaticExpectStapleState(host_port_pair.host(), &expect_staple_state))
801 return;
802
803 // No report needed if a stapled OCSP response was provided.
804 if (ssl_info.ocsp_result.response_status == OCSPVerifyResult::PROVIDED &&
805 ssl_info.ocsp_result.revocation_status == OCSPRevocationStatus::GOOD) {
806 return;
807 }
808
809 std::string serialized_report;
810 if (!SerializeExpectStapleReport(host_port_pair, ssl_info, ocsp_response,
811 &serialized_report)) {
812 return;
813 }
814 report_sender_->Send(expect_staple_state.report_uri, serialized_report);
815 }
816
716 bool TransportSecurityState::HasPublicKeyPins(const std::string& host) { 817 bool TransportSecurityState::HasPublicKeyPins(const std::string& host) {
717 PKPState dynamic_state; 818 PKPState dynamic_state;
718 if (GetDynamicPKPState(host, &dynamic_state)) 819 if (GetDynamicPKPState(host, &dynamic_state))
719 return dynamic_state.HasPublicKeyPins(); 820 return dynamic_state.HasPublicKeyPins();
720 821
721 STSState unused; 822 STSState unused;
722 PKPState static_pkp_state; 823 PKPState static_pkp_state;
723 if (GetStaticDomainState(host, &unused, &static_pkp_state)) { 824 if (GetStaticDomainState(host, &unused, &static_pkp_state)) {
724 if (static_pkp_state.HasPublicKeyPins()) 825 if (static_pkp_state.HasPublicKeyPins())
725 return true; 826 return true;
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 TransportSecurityState::PKPStateIterator::PKPStateIterator( 1622 TransportSecurityState::PKPStateIterator::PKPStateIterator(
1522 const TransportSecurityState& state) 1623 const TransportSecurityState& state)
1523 : iterator_(state.enabled_pkp_hosts_.begin()), 1624 : iterator_(state.enabled_pkp_hosts_.begin()),
1524 end_(state.enabled_pkp_hosts_.end()) { 1625 end_(state.enabled_pkp_hosts_.end()) {
1525 } 1626 }
1526 1627
1527 TransportSecurityState::PKPStateIterator::~PKPStateIterator() { 1628 TransportSecurityState::PKPStateIterator::~PKPStateIterator() {
1528 } 1629 }
1529 1630
1530 } // namespace 1631 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698