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

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: Declarations close to use; add comment. 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
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) {
Ryan Sleevi 2013/07/02 23:41:10 BUG: I'm not sure this is correct. With DeleteAll
palmer 2013/07/08 22:48:16 Done.
206 dirtied = true; 206 dirtied = true;
207 enabled_hosts_.erase(i++); 207 enabled_hosts_.erase(i++);
208 } else { 208 } else {
209 i++; 209 i++;
210 } 210 }
211 } 211 }
212 212
213 if (dirtied) 213 if (dirtied)
214 DirtyNotify(); 214 DirtyNotify();
215 } 215 }
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 base::Time now = base::Time::Now(); 616 base::Time now = base::Time::Now();
617 base::TimeDelta max_age; 617 base::TimeDelta max_age;
618 TransportSecurityState::DomainState domain_state; 618 TransportSecurityState::DomainState domain_state;
619 GetDynamicDomainState(host, &domain_state); 619 GetDynamicDomainState(host, &domain_state);
620 if (ParseHSTSHeader(value, &max_age, &domain_state.sts_include_subdomains)) { 620 if (ParseHSTSHeader(value, &max_age, &domain_state.sts_include_subdomains)) {
621 // Handle max-age == 0 621 // Handle max-age == 0
622 if (max_age.InSeconds() == 0) 622 if (max_age.InSeconds() == 0)
623 domain_state.upgrade_mode = DomainState::MODE_DEFAULT; 623 domain_state.upgrade_mode = DomainState::MODE_DEFAULT;
624 else 624 else
625 domain_state.upgrade_mode = DomainState::MODE_FORCE_HTTPS; 625 domain_state.upgrade_mode = DomainState::MODE_FORCE_HTTPS;
626 domain_state.created = now; 626 domain_state.sts_observed = now;
627 domain_state.upgrade_expiry = now + max_age; 627 domain_state.upgrade_expiry = now + max_age;
628 EnableHost(host, domain_state); 628 EnableHost(host, domain_state);
629 return true; 629 return true;
630 } 630 }
631 return false; 631 return false;
632 } 632 }
633 633
634 bool TransportSecurityState::AddHPKPHeader(const std::string& host, 634 bool TransportSecurityState::AddHPKPHeader(const std::string& host,
635 const std::string& value, 635 const std::string& value,
636 const SSLInfo& ssl_info) { 636 const SSLInfo& ssl_info) {
637 DCHECK(CalledOnValidThread()); 637 DCHECK(CalledOnValidThread());
638 638
639 base::Time now = base::Time::Now(); 639 base::Time now = base::Time::Now();
640 base::TimeDelta max_age; 640 base::TimeDelta max_age;
641 TransportSecurityState::DomainState domain_state; 641 TransportSecurityState::DomainState domain_state;
642 GetDynamicDomainState(host, &domain_state); 642 GetDynamicDomainState(host, &domain_state);
643 if (ParseHPKPHeader(value, ssl_info.public_key_hashes, 643 if (ParseHPKPHeader(value, ssl_info.public_key_hashes,
644 &max_age, &domain_state.pkp_include_subdomains, 644 &max_age, &domain_state.pkp_include_subdomains,
645 &domain_state.dynamic_spki_hashes)) { 645 &domain_state.dynamic_spki_hashes)) {
646 // TODO(palmer): http://crbug.com/243865 handle max-age == 0. 646 // TODO(palmer): http://crbug.com/243865 handle max-age == 0.
647 domain_state.created = now; 647 domain_state.pkp_observed = now;
648 domain_state.dynamic_spki_hashes_expiry = now + max_age; 648 domain_state.dynamic_spki_hashes_expiry = now + max_age;
649 EnableHost(host, domain_state); 649 EnableHost(host, domain_state);
650 return true; 650 return true;
651 } 651 }
652 return false; 652 return false;
653 } 653 }
654 654
655 bool TransportSecurityState::AddHSTS(const std::string& host, 655 bool TransportSecurityState::AddHSTS(const std::string& host,
656 const base::Time& expiry, 656 const base::Time& expiry,
657 bool include_subdomains) { 657 bool include_subdomains) {
658 DCHECK(CalledOnValidThread()); 658 DCHECK(CalledOnValidThread());
659 659
660 // Copy-and-modify the existing DomainState for this host (if any). 660 // Copy-and-modify the existing DomainState for this host (if any).
661 TransportSecurityState::DomainState domain_state; 661 TransportSecurityState::DomainState domain_state;
662 const std::string canonicalized_host = CanonicalizeHost(host); 662 const std::string canonicalized_host = CanonicalizeHost(host);
663 const std::string hashed_host = HashHost(canonicalized_host); 663 const std::string hashed_host = HashHost(canonicalized_host);
664 DomainStateMap::const_iterator i = enabled_hosts_.find( 664 DomainStateMap::const_iterator i = enabled_hosts_.find(
665 hashed_host); 665 hashed_host);
666 if (i != enabled_hosts_.end()) 666 if (i != enabled_hosts_.end())
667 domain_state = i->second; 667 domain_state = i->second;
668 668
669 domain_state.created = base::Time::Now(); 669 domain_state.sts_observed = base::Time::Now();
670 domain_state.sts_include_subdomains = include_subdomains; 670 domain_state.sts_include_subdomains = include_subdomains;
671 domain_state.upgrade_expiry = expiry; 671 domain_state.upgrade_expiry = expiry;
672 domain_state.upgrade_mode = DomainState::MODE_FORCE_HTTPS; 672 domain_state.upgrade_mode = DomainState::MODE_FORCE_HTTPS;
673 EnableHost(host, domain_state); 673 EnableHost(host, domain_state);
674 return true; 674 return true;
675 } 675 }
676 676
677 bool TransportSecurityState::AddHPKP(const std::string& host, 677 bool TransportSecurityState::AddHPKP(const std::string& host,
678 const base::Time& expiry, 678 const base::Time& expiry,
679 bool include_subdomains, 679 bool include_subdomains,
680 const HashValueVector& hashes) { 680 const HashValueVector& hashes) {
681 DCHECK(CalledOnValidThread()); 681 DCHECK(CalledOnValidThread());
682 682
683 // Copy-and-modify the existing DomainState for this host (if any). 683 // Copy-and-modify the existing DomainState for this host (if any).
684 TransportSecurityState::DomainState domain_state; 684 TransportSecurityState::DomainState domain_state;
685 const std::string canonicalized_host = CanonicalizeHost(host); 685 const std::string canonicalized_host = CanonicalizeHost(host);
686 const std::string hashed_host = HashHost(canonicalized_host); 686 const std::string hashed_host = HashHost(canonicalized_host);
687 DomainStateMap::const_iterator i = enabled_hosts_.find( 687 DomainStateMap::const_iterator i = enabled_hosts_.find(
688 hashed_host); 688 hashed_host);
689 if (i != enabled_hosts_.end()) 689 if (i != enabled_hosts_.end())
690 domain_state = i->second; 690 domain_state = i->second;
691 691
692 domain_state.created = base::Time::Now(); 692 domain_state.pkp_observed = base::Time::Now();
693 domain_state.pkp_include_subdomains = include_subdomains; 693 domain_state.pkp_include_subdomains = include_subdomains;
694 domain_state.dynamic_spki_hashes_expiry = expiry; 694 domain_state.dynamic_spki_hashes_expiry = expiry;
695 domain_state.dynamic_spki_hashes = hashes; 695 domain_state.dynamic_spki_hashes = hashes;
696 EnableHost(host, domain_state); 696 EnableHost(host, domain_state);
697 return true; 697 return true;
698 } 698 }
699 699
700 // static 700 // static
701 bool TransportSecurityState::IsGooglePinnedProperty(const std::string& host, 701 bool TransportSecurityState::IsGooglePinnedProperty(const std::string& host,
702 bool sni_enabled) { 702 bool sni_enabled) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 827
828 828
829 void TransportSecurityState::AddOrUpdateEnabledHosts( 829 void TransportSecurityState::AddOrUpdateEnabledHosts(
830 const std::string& hashed_host, const DomainState& state) { 830 const std::string& hashed_host, const DomainState& state) {
831 DCHECK(CalledOnValidThread()); 831 DCHECK(CalledOnValidThread());
832 enabled_hosts_[hashed_host] = state; 832 enabled_hosts_[hashed_host] = state;
833 } 833 }
834 834
835 TransportSecurityState::DomainState::DomainState() 835 TransportSecurityState::DomainState::DomainState()
836 : upgrade_mode(MODE_DEFAULT), 836 : upgrade_mode(MODE_DEFAULT),
837 created(base::Time::Now()), 837 sts_observed(base::Time::Now()),
838 pkp_observed(base::Time::Now()),
838 sts_include_subdomains(false), 839 sts_include_subdomains(false),
839 pkp_include_subdomains(false) { 840 pkp_include_subdomains(false) {
840 } 841 }
841 842
842 TransportSecurityState::DomainState::~DomainState() { 843 TransportSecurityState::DomainState::~DomainState() {
843 } 844 }
844 845
845 bool TransportSecurityState::DomainState::CheckPublicKeyPins( 846 bool TransportSecurityState::DomainState::CheckPublicKeyPins(
846 const HashValueVector& hashes) const { 847 const HashValueVector& hashes) const {
847 // Validate that hashes is not empty. By the time this code is called (in 848 // 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; 886 return true;
886 } 887 }
887 888
888 bool TransportSecurityState::DomainState::HasPublicKeyPins() const { 889 bool TransportSecurityState::DomainState::HasPublicKeyPins() const {
889 return static_spki_hashes.size() > 0 || 890 return static_spki_hashes.size() > 0 ||
890 bad_static_spki_hashes.size() > 0 || 891 bad_static_spki_hashes.size() > 0 ||
891 dynamic_spki_hashes.size() > 0; 892 dynamic_spki_hashes.size() > 0;
892 } 893 }
893 894
894 } // namespace 895 } // namespace
OLDNEW
« net/http/transport_security_state.h ('K') | « net/http/transport_security_state.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698