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

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

Issue 18554002: Distinguish STS observation times from PKP observation times. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to rsleevi's comments Created 7 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 | Annotate | Revision Log
« no previous file with comments | « net/http/transport_security_state.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #if defined(USE_OPENSSL) 7 #if defined(USE_OPENSSL)
8 #include <openssl/ecdsa.h> 8 #include <openssl/ecdsa.h>
9 #include <openssl/ssl.h> 9 #include <openssl/ssl.h>
10 #else // !defined(USE_OPENSSL) 10 #else // !defined(USE_OPENSSL)
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 enabled_hosts_.clear(); 195 enabled_hosts_.clear();
196 } 196 }
197 197
198 void TransportSecurityState::DeleteAllDynamicDataSince(const base::Time& time) { 198 void TransportSecurityState::DeleteAllDynamicDataSince(const base::Time& time) {
199 DCHECK(CalledOnValidThread()); 199 DCHECK(CalledOnValidThread());
200 200
201 bool dirtied = false; 201 bool dirtied = false;
202 202
203 DomainStateMap::iterator i = enabled_hosts_.begin(); 203 DomainStateMap::iterator i = enabled_hosts_.begin();
204 while (i != enabled_hosts_.end()) { 204 while (i != enabled_hosts_.end()) {
205 if (i->second.created >= time) { 205 if (i->second.sts_observed >= time && i->second.pkp_observed >= time) {
206 dirtied = true; 206 dirtied = true;
207 enabled_hosts_.erase(i++); 207 enabled_hosts_.erase(i++);
208 } else if (i->second.sts_observed >= time) {
209 dirtied = true;
210 i->second.upgrade_mode = DomainState::MODE_DEFAULT;
211 } else if (i->second.pkp_observed >= time) {
212 dirtied = true;
213 i->second.dynamic_spki_hashes.clear();
wtc 2013/07/23 21:31:07 Should we increment |i| in these two cases?
palmer 2013/12/12 01:32:12 Done.
208 } else { 214 } else {
209 i++; 215 i++;
210 } 216 }
Ryan Sleevi 2013/07/17 23:32:43 FWIW, this seems weird. Imagine the user visits s
palmer 2013/12/12 01:32:12 I don't see a way to avoid this, short of keeping
211 } 217 }
212 218
213 if (dirtied) 219 if (dirtied)
214 DirtyNotify(); 220 DirtyNotify();
215 } 221 }
216 222
217 TransportSecurityState::~TransportSecurityState() { 223 TransportSecurityState::~TransportSecurityState() {
218 DCHECK(CalledOnValidThread()); 224 DCHECK(CalledOnValidThread());
219 } 225 }
220 226
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 base::Time now = base::Time::Now(); 622 base::Time now = base::Time::Now();
617 base::TimeDelta max_age; 623 base::TimeDelta max_age;
618 TransportSecurityState::DomainState domain_state; 624 TransportSecurityState::DomainState domain_state;
619 GetDynamicDomainState(host, &domain_state); 625 GetDynamicDomainState(host, &domain_state);
620 if (ParseHSTSHeader(value, &max_age, &domain_state.sts_include_subdomains)) { 626 if (ParseHSTSHeader(value, &max_age, &domain_state.sts_include_subdomains)) {
621 // Handle max-age == 0 627 // Handle max-age == 0
622 if (max_age.InSeconds() == 0) 628 if (max_age.InSeconds() == 0)
623 domain_state.upgrade_mode = DomainState::MODE_DEFAULT; 629 domain_state.upgrade_mode = DomainState::MODE_DEFAULT;
624 else 630 else
625 domain_state.upgrade_mode = DomainState::MODE_FORCE_HTTPS; 631 domain_state.upgrade_mode = DomainState::MODE_FORCE_HTTPS;
626 domain_state.created = now; 632 domain_state.sts_observed = now;
627 domain_state.upgrade_expiry = now + max_age; 633 domain_state.upgrade_expiry = now + max_age;
628 EnableHost(host, domain_state); 634 EnableHost(host, domain_state);
629 return true; 635 return true;
630 } 636 }
631 return false; 637 return false;
632 } 638 }
633 639
634 bool TransportSecurityState::AddHPKPHeader(const std::string& host, 640 bool TransportSecurityState::AddHPKPHeader(const std::string& host,
635 const std::string& value, 641 const std::string& value,
636 const SSLInfo& ssl_info) { 642 const SSLInfo& ssl_info) {
637 DCHECK(CalledOnValidThread()); 643 DCHECK(CalledOnValidThread());
638 644
639 base::Time now = base::Time::Now(); 645 base::Time now = base::Time::Now();
640 base::TimeDelta max_age; 646 base::TimeDelta max_age;
641 TransportSecurityState::DomainState domain_state; 647 TransportSecurityState::DomainState domain_state;
642 GetDynamicDomainState(host, &domain_state); 648 GetDynamicDomainState(host, &domain_state);
643 if (ParseHPKPHeader(value, ssl_info.public_key_hashes, 649 if (ParseHPKPHeader(value, ssl_info.public_key_hashes,
644 &max_age, &domain_state.pkp_include_subdomains, 650 &max_age, &domain_state.pkp_include_subdomains,
645 &domain_state.dynamic_spki_hashes)) { 651 &domain_state.dynamic_spki_hashes)) {
646 // TODO(palmer): http://crbug.com/243865 handle max-age == 0. 652 // TODO(palmer): http://crbug.com/243865 handle max-age == 0.
647 domain_state.created = now; 653 domain_state.pkp_observed = now;
648 domain_state.dynamic_spki_hashes_expiry = now + max_age; 654 domain_state.dynamic_spki_hashes_expiry = now + max_age;
649 EnableHost(host, domain_state); 655 EnableHost(host, domain_state);
650 return true; 656 return true;
651 } 657 }
652 return false; 658 return false;
653 } 659 }
654 660
655 bool TransportSecurityState::AddHSTS(const std::string& host, 661 bool TransportSecurityState::AddHSTS(const std::string& host,
656 const base::Time& expiry, 662 const base::Time& expiry,
657 bool include_subdomains) { 663 bool include_subdomains) {
658 DCHECK(CalledOnValidThread()); 664 DCHECK(CalledOnValidThread());
659 665
660 // Copy-and-modify the existing DomainState for this host (if any). 666 // Copy-and-modify the existing DomainState for this host (if any).
661 TransportSecurityState::DomainState domain_state; 667 TransportSecurityState::DomainState domain_state;
662 const std::string canonicalized_host = CanonicalizeHost(host); 668 const std::string canonicalized_host = CanonicalizeHost(host);
663 const std::string hashed_host = HashHost(canonicalized_host); 669 const std::string hashed_host = HashHost(canonicalized_host);
664 DomainStateMap::const_iterator i = enabled_hosts_.find( 670 DomainStateMap::const_iterator i = enabled_hosts_.find(
665 hashed_host); 671 hashed_host);
666 if (i != enabled_hosts_.end()) 672 if (i != enabled_hosts_.end())
667 domain_state = i->second; 673 domain_state = i->second;
668 674
669 domain_state.created = base::Time::Now(); 675 domain_state.sts_observed = base::Time::Now();
670 domain_state.sts_include_subdomains = include_subdomains; 676 domain_state.sts_include_subdomains = include_subdomains;
671 domain_state.upgrade_expiry = expiry; 677 domain_state.upgrade_expiry = expiry;
672 domain_state.upgrade_mode = DomainState::MODE_FORCE_HTTPS; 678 domain_state.upgrade_mode = DomainState::MODE_FORCE_HTTPS;
673 EnableHost(host, domain_state); 679 EnableHost(host, domain_state);
674 return true; 680 return true;
675 } 681 }
676 682
677 bool TransportSecurityState::AddHPKP(const std::string& host, 683 bool TransportSecurityState::AddHPKP(const std::string& host,
678 const base::Time& expiry, 684 const base::Time& expiry,
679 bool include_subdomains, 685 bool include_subdomains,
680 const HashValueVector& hashes) { 686 const HashValueVector& hashes) {
681 DCHECK(CalledOnValidThread()); 687 DCHECK(CalledOnValidThread());
682 688
683 // Copy-and-modify the existing DomainState for this host (if any). 689 // Copy-and-modify the existing DomainState for this host (if any).
684 TransportSecurityState::DomainState domain_state; 690 TransportSecurityState::DomainState domain_state;
685 const std::string canonicalized_host = CanonicalizeHost(host); 691 const std::string canonicalized_host = CanonicalizeHost(host);
686 const std::string hashed_host = HashHost(canonicalized_host); 692 const std::string hashed_host = HashHost(canonicalized_host);
687 DomainStateMap::const_iterator i = enabled_hosts_.find( 693 DomainStateMap::const_iterator i = enabled_hosts_.find(
688 hashed_host); 694 hashed_host);
689 if (i != enabled_hosts_.end()) 695 if (i != enabled_hosts_.end())
690 domain_state = i->second; 696 domain_state = i->second;
691 697
692 domain_state.created = base::Time::Now(); 698 domain_state.pkp_observed = base::Time::Now();
693 domain_state.pkp_include_subdomains = include_subdomains; 699 domain_state.pkp_include_subdomains = include_subdomains;
694 domain_state.dynamic_spki_hashes_expiry = expiry; 700 domain_state.dynamic_spki_hashes_expiry = expiry;
695 domain_state.dynamic_spki_hashes = hashes; 701 domain_state.dynamic_spki_hashes = hashes;
696 EnableHost(host, domain_state); 702 EnableHost(host, domain_state);
697 return true; 703 return true;
698 } 704 }
699 705
700 // static 706 // static
701 bool TransportSecurityState::IsGooglePinnedProperty(const std::string& host, 707 bool TransportSecurityState::IsGooglePinnedProperty(const std::string& host,
702 bool sni_enabled) { 708 bool sni_enabled) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 833
828 834
829 void TransportSecurityState::AddOrUpdateEnabledHosts( 835 void TransportSecurityState::AddOrUpdateEnabledHosts(
830 const std::string& hashed_host, const DomainState& state) { 836 const std::string& hashed_host, const DomainState& state) {
831 DCHECK(CalledOnValidThread()); 837 DCHECK(CalledOnValidThread());
832 enabled_hosts_[hashed_host] = state; 838 enabled_hosts_[hashed_host] = state;
833 } 839 }
834 840
835 TransportSecurityState::DomainState::DomainState() 841 TransportSecurityState::DomainState::DomainState()
836 : upgrade_mode(MODE_DEFAULT), 842 : upgrade_mode(MODE_DEFAULT),
837 created(base::Time::Now()), 843 sts_observed(base::Time::Now()),
844 pkp_observed(base::Time::Now()),
wtc 2013/07/23 21:31:07 These two base::Time::Now() calls may potentially
palmer 2013/12/12 01:32:12 Done.
838 sts_include_subdomains(false), 845 sts_include_subdomains(false),
839 pkp_include_subdomains(false) { 846 pkp_include_subdomains(false) {
840 } 847 }
841 848
842 TransportSecurityState::DomainState::~DomainState() { 849 TransportSecurityState::DomainState::~DomainState() {
843 } 850 }
844 851
845 bool TransportSecurityState::DomainState::CheckPublicKeyPins( 852 bool TransportSecurityState::DomainState::CheckPublicKeyPins(
846 const HashValueVector& hashes) const { 853 const HashValueVector& hashes) const {
847 // Validate that hashes is not empty. By the time this code is called (in 854 // Validate that hashes is not empty. By the time this code is called (in
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 return true; 892 return true;
886 } 893 }
887 894
888 bool TransportSecurityState::DomainState::HasPublicKeyPins() const { 895 bool TransportSecurityState::DomainState::HasPublicKeyPins() const {
889 return static_spki_hashes.size() > 0 || 896 return static_spki_hashes.size() > 0 ||
890 bad_static_spki_hashes.size() > 0 || 897 bad_static_spki_hashes.size() > 0 ||
891 dynamic_spki_hashes.size() > 0; 898 dynamic_spki_hashes.size() > 0;
892 } 899 }
893 900
894 } // namespace 901 } // namespace
OLDNEW
« no previous file with comments | « net/http/transport_security_state.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698