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

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: Clean tests, add documentation. 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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 } 1280 }
1209 1281
1210 ExpectCTState state; 1282 ExpectCTState state;
1211 if (!GetStaticExpectCTState(host_port_pair.host(), &state)) 1283 if (!GetStaticExpectCTState(host_port_pair.host(), &state))
1212 return; 1284 return;
1213 1285
1214 expect_ct_reporter_->OnExpectCTFailed(host_port_pair, state.report_uri, 1286 expect_ct_reporter_->OnExpectCTFailed(host_port_pair, state.report_uri,
1215 ssl_info); 1287 ssl_info);
1216 } 1288 }
1217 1289
1290 void TransportSecurityState::ProcessExpectStaple(
1291 const HostPortPair& host_port_pair,
1292 const SSLInfo& ssl_info,
1293 const std::string& ocsp_response) {
1294 DCHECK(CalledOnValidThread());
1295 if (!enable_static_expect_staple_ || !report_sender_)
1296 return;
1297
1298 ExpectStapleState expect_staple_state;
1299 if (!GetStaticExpectStapleState(host_port_pair.host(), &expect_staple_state))
Ryan Sleevi 2016/07/19 19:11:04 In terms of matching conditions to documentation,
dadrian 2016/07/19 21:21:45 Done.
1300 return;
1301
1302 // No report needed if a stapled OCSP response was provided.
1303 if (ssl_info.ocsp_result.response_status == OCSPVerifyResult::PROVIDED &&
1304 ssl_info.ocsp_result.revocation_status == OCSPRevocationStatus::GOOD) {
1305 return;
1306 }
1307
1308 std::string serialized_report;
1309 if (!SerializeExpectStapleReport(host_port_pair, ssl_info, ocsp_response,
1310 &serialized_report)) {
1311 return;
1312 }
1313 report_sender_->Send(expect_staple_state.report_uri, serialized_report);
1314 }
1315
1218 // static 1316 // static
1219 void TransportSecurityState::ReportUMAOnPinFailure(const std::string& host) { 1317 void TransportSecurityState::ReportUMAOnPinFailure(const std::string& host) {
1220 PreloadResult result; 1318 PreloadResult result;
1221 if (!DecodeHSTSPreload(host, &result) || 1319 if (!DecodeHSTSPreload(host, &result) ||
1222 !result.has_pins) { 1320 !result.has_pins) {
1223 return; 1321 return;
1224 } 1322 }
1225 1323
1226 DCHECK(result.domain_id != DOMAIN_NOT_PINNED); 1324 DCHECK(result.domain_id != DOMAIN_NOT_PINNED);
1227 1325
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 TransportSecurityState::PKPStateIterator::PKPStateIterator( 1619 TransportSecurityState::PKPStateIterator::PKPStateIterator(
1522 const TransportSecurityState& state) 1620 const TransportSecurityState& state)
1523 : iterator_(state.enabled_pkp_hosts_.begin()), 1621 : iterator_(state.enabled_pkp_hosts_.begin()),
1524 end_(state.enabled_pkp_hosts_.end()) { 1622 end_(state.enabled_pkp_hosts_.end()) {
1525 } 1623 }
1526 1624
1527 TransportSecurityState::PKPStateIterator::~PKPStateIterator() { 1625 TransportSecurityState::PKPStateIterator::~PKPStateIterator() {
1528 } 1626 }
1529 1627
1530 } // namespace 1628 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698