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 #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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 DCHECK_EQ(HASH_VALUE_SHA256, rhs.tag); | 69 DCHECK_EQ(HASH_VALUE_SHA256, rhs.tag); |
70 return memcmp(lhs.data, rhs.data(), rhs.size()) < 0; | 70 return memcmp(lhs.data, rhs.data(), rhs.size()) < 0; |
71 } | 71 } |
72 | 72 |
73 bool operator()(const HashValue& lhs, const SHA256HashValue& rhs) const { | 73 bool operator()(const HashValue& lhs, const SHA256HashValue& rhs) const { |
74 DCHECK_EQ(HASH_VALUE_SHA256, lhs.tag); | 74 DCHECK_EQ(HASH_VALUE_SHA256, lhs.tag); |
75 return memcmp(lhs.data(), rhs.data, lhs.size()) < 0; | 75 return memcmp(lhs.data(), rhs.data, lhs.size()) < 0; |
76 } | 76 } |
77 }; | 77 }; |
78 | 78 |
79 void RecordUMAForHPKPReportFailure(const GURL& report_uri, int net_error) { | 79 void RecordUMAForHPKPReportFailure(const GURL& report_uri, |
| 80 int net_error, |
| 81 int http_response_code) { |
80 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.PublicKeyPinReportSendingFailure2", | 82 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.PublicKeyPinReportSendingFailure2", |
81 -net_error); | 83 -net_error); |
82 } | 84 } |
83 | 85 |
84 std::string TimeToISO8601(const base::Time& t) { | 86 std::string TimeToISO8601(const base::Time& t) { |
85 base::Time::Exploded exploded; | 87 base::Time::Exploded exploded; |
86 t.UTCExplode(&exploded); | 88 t.UTCExplode(&exploded); |
87 return base::StringPrintf( | 89 return base::StringPrintf( |
88 "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", exploded.year, exploded.month, | 90 "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", exploded.year, exploded.month, |
89 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second, | 91 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second, |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 return; | 834 return; |
833 } | 835 } |
834 | 836 |
835 std::string serialized_report; | 837 std::string serialized_report; |
836 if (!SerializeExpectStapleReport(host_port_pair, ssl_info, ocsp_response, | 838 if (!SerializeExpectStapleReport(host_port_pair, ssl_info, ocsp_response, |
837 &serialized_report)) { | 839 &serialized_report)) { |
838 return; | 840 return; |
839 } | 841 } |
840 report_sender_->Send(expect_staple_state.report_uri, | 842 report_sender_->Send(expect_staple_state.report_uri, |
841 "application/json; charset=utf-8", serialized_report, | 843 "application/json; charset=utf-8", serialized_report, |
842 base::Closure(), | 844 base::Callback<void()>(), |
843 base::Bind(RecordUMAForHPKPReportFailure)); | 845 base::Bind(RecordUMAForHPKPReportFailure)); |
844 } | 846 } |
845 | 847 |
846 bool TransportSecurityState::HasPublicKeyPins(const std::string& host) { | 848 bool TransportSecurityState::HasPublicKeyPins(const std::string& host) { |
847 PKPState dynamic_state; | 849 PKPState dynamic_state; |
848 if (GetDynamicPKPState(host, &dynamic_state)) | 850 if (GetDynamicPKPState(host, &dynamic_state)) |
849 return dynamic_state.HasPublicKeyPins(); | 851 return dynamic_state.HasPublicKeyPins(); |
850 | 852 |
851 STSState unused; | 853 STSState unused; |
852 PKPState static_pkp_state; | 854 PKPState static_pkp_state; |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1134 // also prevents accidental loops (a.com triggers a report to b.com | 1136 // also prevents accidental loops (a.com triggers a report to b.com |
1135 // which triggers a report to a.com). See section 2.1.4 of RFC 7469. | 1137 // which triggers a report to a.com). See section 2.1.4 of RFC 7469. |
1136 if (sent_reports_cache_.Get(report_cache_key, base::TimeTicks::Now())) | 1138 if (sent_reports_cache_.Get(report_cache_key, base::TimeTicks::Now())) |
1137 return PKPStatus::VIOLATED; | 1139 return PKPStatus::VIOLATED; |
1138 sent_reports_cache_.Put( | 1140 sent_reports_cache_.Put( |
1139 report_cache_key, true, base::TimeTicks::Now(), | 1141 report_cache_key, true, base::TimeTicks::Now(), |
1140 base::TimeTicks::Now() + | 1142 base::TimeTicks::Now() + |
1141 base::TimeDelta::FromMinutes(kTimeToRememberHPKPReportsMins)); | 1143 base::TimeDelta::FromMinutes(kTimeToRememberHPKPReportsMins)); |
1142 | 1144 |
1143 report_sender_->Send(pkp_state.report_uri, "application/json; charset=utf-8", | 1145 report_sender_->Send(pkp_state.report_uri, "application/json; charset=utf-8", |
1144 serialized_report, base::Closure(), | 1146 serialized_report, base::Callback<void()>(), |
1145 base::Bind(RecordUMAForHPKPReportFailure)); | 1147 base::Bind(RecordUMAForHPKPReportFailure)); |
1146 return PKPStatus::VIOLATED; | 1148 return PKPStatus::VIOLATED; |
1147 } | 1149 } |
1148 | 1150 |
1149 bool TransportSecurityState::GetStaticExpectCTState( | 1151 bool TransportSecurityState::GetStaticExpectCTState( |
1150 const std::string& host, | 1152 const std::string& host, |
1151 ExpectCTState* expect_ct_state) const { | 1153 ExpectCTState* expect_ct_state) const { |
1152 DCHECK(CalledOnValidThread()); | 1154 DCHECK(CalledOnValidThread()); |
1153 | 1155 |
1154 if (!IsBuildTimely()) | 1156 if (!IsBuildTimely()) |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1783 TransportSecurityState::PKPStateIterator::PKPStateIterator( | 1785 TransportSecurityState::PKPStateIterator::PKPStateIterator( |
1784 const TransportSecurityState& state) | 1786 const TransportSecurityState& state) |
1785 : iterator_(state.enabled_pkp_hosts_.begin()), | 1787 : iterator_(state.enabled_pkp_hosts_.begin()), |
1786 end_(state.enabled_pkp_hosts_.end()) { | 1788 end_(state.enabled_pkp_hosts_.end()) { |
1787 } | 1789 } |
1788 | 1790 |
1789 TransportSecurityState::PKPStateIterator::~PKPStateIterator() { | 1791 TransportSecurityState::PKPStateIterator::~PKPStateIterator() { |
1790 } | 1792 } |
1791 | 1793 |
1792 } // namespace | 1794 } // namespace |
OLD | NEW |