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 2034843003: Add Expect-Staple to preload list (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch with static.h 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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 expect_staple_include_subdomains;
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
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.expect_staple_include_subdomains = false;
519 if (tmp.expect_staple) {
520 if (!reader.Next(&tmp.expect_staple_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 ||
531 tmp.expect_staple_include_subdomains;
517 *out = tmp; 532 *out = tmp;
518 533
519 if (hostname_offset > 0) { 534 if (hostname_offset > 0) {
520 out->force_https &= tmp.sts_include_subdomains; 535 out->force_https &= tmp.sts_include_subdomains;
521 } else { 536 } else {
522 *out_found = true; 537 *out_found = true;
523 return true; 538 return true;
524 } 539 }
525 } 540 }
526 541
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 return found; 610 return found;
596 } 611 }
597 612
598 } // namespace 613 } // namespace
599 614
600 TransportSecurityState::TransportSecurityState() 615 TransportSecurityState::TransportSecurityState()
601 : delegate_(nullptr), 616 : delegate_(nullptr),
602 report_sender_(nullptr), 617 report_sender_(nullptr),
603 enable_static_pins_(true), 618 enable_static_pins_(true),
604 enable_static_expect_ct_(true), 619 enable_static_expect_ct_(true),
620 enable_static_expect_staple_(false),
estark 2016/06/03 22:53:04 I think you can initialize this to true and set it
605 expect_ct_reporter_(nullptr), 621 expect_ct_reporter_(nullptr),
606 sent_reports_cache_(kMaxHPKPReportCacheEntries) { 622 sent_reports_cache_(kMaxHPKPReportCacheEntries) {
607 // Static pinning is only enabled for official builds to make sure that 623 // Static pinning is only enabled for official builds to make sure that
608 // others don't end up with pins that cannot be easily updated. 624 // others don't end up with pins that cannot be easily updated.
609 #if !defined(OFFICIAL_BUILD) || defined(OS_ANDROID) || defined(OS_IOS) 625 #if !defined(OFFICIAL_BUILD) || defined(OS_ANDROID) || defined(OS_IOS)
610 enable_static_pins_ = false; 626 enable_static_pins_ = false;
611 enable_static_expect_ct_ = false; 627 enable_static_expect_ct_ = false;
612 #endif 628 #endif
613 DCHECK(CalledOnValidThread()); 629 DCHECK(CalledOnValidThread());
614 } 630 }
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 865
850 if (!enable_static_expect_ct_ || !result.expect_ct) 866 if (!enable_static_expect_ct_ || !result.expect_ct)
851 return false; 867 return false;
852 868
853 expect_ct_state->domain = host.substr(result.hostname_offset); 869 expect_ct_state->domain = host.substr(result.hostname_offset);
854 expect_ct_state->report_uri = 870 expect_ct_state->report_uri =
855 GURL(kExpectCTReportURIs[result.expect_ct_report_uri_id]); 871 GURL(kExpectCTReportURIs[result.expect_ct_report_uri_id]);
856 return true; 872 return true;
857 } 873 }
858 874
875 bool TransportSecurityState::GetStaticExpectStapleState(
876 const std::string& host,
877 ExpectStapleState* expect_staple_state) const {
878 DCHECK(CalledOnValidThread());
879
880 if (!IsBuildTimely())
881 return false;
882
883 PreloadResult result;
884 if (!DecodeHSTSPreload(host, &result))
885 return false;
886
887 if (!enable_static_expect_staple_ || !result.expect_staple)
888 return false;
889
890 expect_staple_state->domain = host.substr(result.hostname_offset);
891 expect_staple_state->include_subdomains =
892 result.expect_staple_include_subdomains;
893 expect_staple_state->report_uri =
894 GURL(kExpectStapleReportURIs[result.expect_staple_report_uri_id]);
895 return true;
896 }
897
859 bool TransportSecurityState::DeleteDynamicDataForHost(const std::string& host) { 898 bool TransportSecurityState::DeleteDynamicDataForHost(const std::string& host) {
860 DCHECK(CalledOnValidThread()); 899 DCHECK(CalledOnValidThread());
861 900
862 const std::string canonicalized_host = CanonicalizeHost(host); 901 const std::string canonicalized_host = CanonicalizeHost(host);
863 if (canonicalized_host.empty()) 902 if (canonicalized_host.empty())
864 return false; 903 return false;
865 904
866 const std::string hashed_host = HashHost(canonicalized_host); 905 const std::string hashed_host = HashHost(canonicalized_host);
867 bool deleted = false; 906 bool deleted = false;
868 STSStateMap::iterator sts_interator = enabled_sts_hosts_.find(hashed_host); 907 STSStateMap::iterator sts_interator = enabled_sts_hosts_.find(hashed_host);
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 1342
1304 TransportSecurityState::PKPState::PKPState(const PKPState& other) = default; 1343 TransportSecurityState::PKPState::PKPState(const PKPState& other) = default;
1305 1344
1306 TransportSecurityState::PKPState::~PKPState() { 1345 TransportSecurityState::PKPState::~PKPState() {
1307 } 1346 }
1308 1347
1309 TransportSecurityState::ExpectCTState::ExpectCTState() {} 1348 TransportSecurityState::ExpectCTState::ExpectCTState() {}
1310 1349
1311 TransportSecurityState::ExpectCTState::~ExpectCTState() {} 1350 TransportSecurityState::ExpectCTState::~ExpectCTState() {}
1312 1351
1352 TransportSecurityState::ExpectStapleState::ExpectStapleState()
1353 : include_subdomains(false) {}
1354
1355 TransportSecurityState::ExpectStapleState::~ExpectStapleState() {}
1356
1313 bool TransportSecurityState::PKPState::CheckPublicKeyPins( 1357 bool TransportSecurityState::PKPState::CheckPublicKeyPins(
1314 const HashValueVector& hashes, 1358 const HashValueVector& hashes,
1315 std::string* failure_log) const { 1359 std::string* failure_log) const {
1316 // Validate that hashes is not empty. By the time this code is called (in 1360 // 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. 1361 // production), that should never happen, but it's good to be defensive.
1318 // And, hashes *can* be empty in some test scenarios. 1362 // And, hashes *can* be empty in some test scenarios.
1319 if (hashes.empty()) { 1363 if (hashes.empty()) {
1320 failure_log->append( 1364 failure_log->append(
1321 "Rejecting empty public key chain for public-key-pinned domains: " + 1365 "Rejecting empty public key chain for public-key-pinned domains: " +
1322 domain); 1366 domain);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 TransportSecurityState::PKPStateIterator::PKPStateIterator( 1400 TransportSecurityState::PKPStateIterator::PKPStateIterator(
1357 const TransportSecurityState& state) 1401 const TransportSecurityState& state)
1358 : iterator_(state.enabled_pkp_hosts_.begin()), 1402 : iterator_(state.enabled_pkp_hosts_.begin()),
1359 end_(state.enabled_pkp_hosts_.end()) { 1403 end_(state.enabled_pkp_hosts_.end()) {
1360 } 1404 }
1361 1405
1362 TransportSecurityState::PKPStateIterator::~PKPStateIterator() { 1406 TransportSecurityState::PKPStateIterator::~PKPStateIterator() {
1363 } 1407 }
1364 1408
1365 } // namespace 1409 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698