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 | 10 |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 uint32_t domain_id; | 368 uint32_t domain_id; |
369 // hostname_offset contains the number of bytes from the start of the given | 369 // hostname_offset contains the number of bytes from the start of the given |
370 // hostname where the name of the matching entry starts. | 370 // hostname where the name of the matching entry starts. |
371 size_t hostname_offset; | 371 size_t hostname_offset; |
372 bool sts_include_subdomains; | 372 bool sts_include_subdomains; |
373 bool pkp_include_subdomains; | 373 bool pkp_include_subdomains; |
374 bool force_https; | 374 bool force_https; |
375 bool has_pins; | 375 bool has_pins; |
376 bool expect_ct; | 376 bool expect_ct; |
377 uint32_t expect_ct_report_uri_id; | 377 uint32_t expect_ct_report_uri_id; |
378 bool expect_staple; | |
379 bool es_include_subdomains; | |
estark
2016/06/02 22:41:51
nit: even though it's long my preference would be
dadrian
2016/06/02 23:17:24
Done.
| |
380 uint32_t expect_staple_report_uri_id; | |
378 }; | 381 }; |
379 | 382 |
380 // DecodeHSTSPreloadRaw resolves |hostname| in the preloaded data. It returns | 383 // DecodeHSTSPreloadRaw resolves |hostname| in the preloaded data. It returns |
381 // false on internal error and true otherwise. After a successful return, | 384 // false on internal error and true otherwise. After a successful return, |
382 // |*out_found| is true iff a relevant entry has been found. If so, |*out| | 385 // |*out_found| is true iff a relevant entry has been found. If so, |*out| |
383 // contains the details. | 386 // contains the details. |
384 // | 387 // |
385 // Don't call this function, call DecodeHSTSPreload, below. | 388 // Don't call this function, call DecodeHSTSPreload, below. |
386 // | 389 // |
387 // Although this code should be robust, it never processes attacker-controlled | 390 // Although this code should be robust, it never processes attacker-controlled |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 } | 506 } |
504 | 507 |
505 if (!reader.Next(&tmp.expect_ct)) | 508 if (!reader.Next(&tmp.expect_ct)) |
506 return false; | 509 return false; |
507 | 510 |
508 if (tmp.expect_ct) { | 511 if (tmp.expect_ct) { |
509 if (!reader.Read(4, &tmp.expect_ct_report_uri_id)) | 512 if (!reader.Read(4, &tmp.expect_ct_report_uri_id)) |
510 return false; | 513 return false; |
511 } | 514 } |
512 | 515 |
516 if (!reader.Next(&tmp.expect_staple)) | |
517 return false; | |
518 tmp.es_include_subdomains = false; | |
519 if (tmp.expect_staple) { | |
520 if (!reader.Next(&tmp.es_include_subdomains)) | |
521 return false; | |
522 if (!reader.Read(4, &tmp.expect_staple_report_uri_id)) | |
523 return false; | |
524 } | |
525 | |
513 tmp.hostname_offset = hostname_offset; | 526 tmp.hostname_offset = hostname_offset; |
514 | 527 |
515 if (hostname_offset == 0 || hostname[hostname_offset - 1] == '.') { | 528 if (hostname_offset == 0 || hostname[hostname_offset - 1] == '.') { |
516 *out_found = tmp.sts_include_subdomains || tmp.pkp_include_subdomains; | 529 *out_found = tmp.sts_include_subdomains || |
530 tmp.pkp_include_subdomains || tmp.es_include_subdomains; | |
517 *out = tmp; | 531 *out = tmp; |
518 | 532 |
519 if (hostname_offset > 0) { | 533 if (hostname_offset > 0) { |
520 out->force_https &= tmp.sts_include_subdomains; | 534 out->force_https &= tmp.sts_include_subdomains; |
521 } else { | 535 } else { |
522 *out_found = true; | 536 *out_found = true; |
523 return true; | 537 return true; |
524 } | 538 } |
525 } | 539 } |
526 | 540 |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
849 | 863 |
850 if (!enable_static_expect_ct_ || !result.expect_ct) | 864 if (!enable_static_expect_ct_ || !result.expect_ct) |
851 return false; | 865 return false; |
852 | 866 |
853 expect_ct_state->domain = host.substr(result.hostname_offset); | 867 expect_ct_state->domain = host.substr(result.hostname_offset); |
854 expect_ct_state->report_uri = | 868 expect_ct_state->report_uri = |
855 GURL(kExpectCTReportURIs[result.expect_ct_report_uri_id]); | 869 GURL(kExpectCTReportURIs[result.expect_ct_report_uri_id]); |
856 return true; | 870 return true; |
857 } | 871 } |
858 | 872 |
873 bool TransportSecurityState::GetStaticExpectStapleState( | |
874 const std::string& host, | |
875 ExpectStapleState* expect_staple_state) const { | |
876 DCHECK(CalledOnValidThread()); | |
877 | |
878 if (!IsBuildTimely()) | |
879 return false; | |
880 | |
881 PreloadResult result; | |
882 if (!DecodeHSTSPreload(host, &result)) | |
883 return false; | |
884 | |
885 if (!enable_static_expect_staple_ || !result.expect_staple) | |
886 return false; | |
887 | |
888 expect_staple_state->domain = host.substr(result.hostname_offset); | |
889 expect_staple_state->include_subdomains = result.es_include_subdomains; | |
890 expect_staple_state->report_uri = | |
891 GURL(kExpectStapleReportURIs[result.expect_staple_report_uri_id]); | |
892 return true; | |
893 } | |
894 | |
859 bool TransportSecurityState::DeleteDynamicDataForHost(const std::string& host) { | 895 bool TransportSecurityState::DeleteDynamicDataForHost(const std::string& host) { |
860 DCHECK(CalledOnValidThread()); | 896 DCHECK(CalledOnValidThread()); |
861 | 897 |
862 const std::string canonicalized_host = CanonicalizeHost(host); | 898 const std::string canonicalized_host = CanonicalizeHost(host); |
863 if (canonicalized_host.empty()) | 899 if (canonicalized_host.empty()) |
864 return false; | 900 return false; |
865 | 901 |
866 const std::string hashed_host = HashHost(canonicalized_host); | 902 const std::string hashed_host = HashHost(canonicalized_host); |
867 bool deleted = false; | 903 bool deleted = false; |
868 STSStateMap::iterator sts_interator = enabled_sts_hosts_.find(hashed_host); | 904 STSStateMap::iterator sts_interator = enabled_sts_hosts_.find(hashed_host); |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1303 | 1339 |
1304 TransportSecurityState::PKPState::PKPState(const PKPState& other) = default; | 1340 TransportSecurityState::PKPState::PKPState(const PKPState& other) = default; |
1305 | 1341 |
1306 TransportSecurityState::PKPState::~PKPState() { | 1342 TransportSecurityState::PKPState::~PKPState() { |
1307 } | 1343 } |
1308 | 1344 |
1309 TransportSecurityState::ExpectCTState::ExpectCTState() {} | 1345 TransportSecurityState::ExpectCTState::ExpectCTState() {} |
1310 | 1346 |
1311 TransportSecurityState::ExpectCTState::~ExpectCTState() {} | 1347 TransportSecurityState::ExpectCTState::~ExpectCTState() {} |
1312 | 1348 |
1349 TransportSecurityState::ExpectStapleState::ExpectStapleState() | |
1350 : include_subdomains(false) {} | |
1351 | |
1352 TransportSecurityState::ExpectStapleState::~ExpectStapleState() {} | |
1353 | |
1313 bool TransportSecurityState::PKPState::CheckPublicKeyPins( | 1354 bool TransportSecurityState::PKPState::CheckPublicKeyPins( |
1314 const HashValueVector& hashes, | 1355 const HashValueVector& hashes, |
1315 std::string* failure_log) const { | 1356 std::string* failure_log) const { |
1316 // Validate that hashes is not empty. By the time this code is called (in | 1357 // Validate that hashes is not empty. By the time this code is called (in |
1317 // production), that should never happen, but it's good to be defensive. | 1358 // production), that should never happen, but it's good to be defensive. |
1318 // And, hashes *can* be empty in some test scenarios. | 1359 // And, hashes *can* be empty in some test scenarios. |
1319 if (hashes.empty()) { | 1360 if (hashes.empty()) { |
1320 failure_log->append( | 1361 failure_log->append( |
1321 "Rejecting empty public key chain for public-key-pinned domains: " + | 1362 "Rejecting empty public key chain for public-key-pinned domains: " + |
1322 domain); | 1363 domain); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1356 TransportSecurityState::PKPStateIterator::PKPStateIterator( | 1397 TransportSecurityState::PKPStateIterator::PKPStateIterator( |
1357 const TransportSecurityState& state) | 1398 const TransportSecurityState& state) |
1358 : iterator_(state.enabled_pkp_hosts_.begin()), | 1399 : iterator_(state.enabled_pkp_hosts_.begin()), |
1359 end_(state.enabled_pkp_hosts_.end()) { | 1400 end_(state.enabled_pkp_hosts_.end()) { |
1360 } | 1401 } |
1361 | 1402 |
1362 TransportSecurityState::PKPStateIterator::~PKPStateIterator() { | 1403 TransportSecurityState::PKPStateIterator::~PKPStateIterator() { |
1363 } | 1404 } |
1364 | 1405 |
1365 } // namespace | 1406 } // namespace |
OLD | NEW |