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/url_request/url_request_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 void* iter = NULL; | 678 void* iter = NULL; |
679 HttpResponseHeaders* headers = GetResponseHeaders(); | 679 HttpResponseHeaders* headers = GetResponseHeaders(); |
680 while (headers->EnumerateHeader(&iter, name, &value)) { | 680 while (headers->EnumerateHeader(&iter, name, &value)) { |
681 if (!value.empty()) | 681 if (!value.empty()) |
682 cookies->push_back(value); | 682 cookies->push_back(value); |
683 } | 683 } |
684 } | 684 } |
685 | 685 |
686 // NOTE: |ProcessStrictTransportSecurityHeader| and | 686 // NOTE: |ProcessStrictTransportSecurityHeader| and |
687 // |ProcessPublicKeyPinsHeader| have very similar structures, by design. | 687 // |ProcessPublicKeyPinsHeader| have very similar structures, by design. |
688 // They manipulate different parts of |TransportSecurityState::DomainState|, | |
689 // and they must remain complementary. If, in future changes here, there is | |
690 // any conflict between their policies (such as in |domain_state.mode|), you | |
691 // should resolve the conflict in favor of the more strict policy. | |
692 void URLRequestHttpJob::ProcessStrictTransportSecurityHeader() { | 688 void URLRequestHttpJob::ProcessStrictTransportSecurityHeader() { |
693 DCHECK(response_info_); | 689 DCHECK(response_info_); |
694 | 690 TransportSecurityState* security_state = |
695 const URLRequestContext* ctx = request_->context(); | 691 request_->context()->transport_security_state(); |
696 const SSLInfo& ssl_info = response_info_->ssl_info; | 692 const SSLInfo& ssl_info = response_info_->ssl_info; |
697 | 693 |
698 // Only accept strict transport security headers on HTTPS connections that | 694 // Only accept HSTS headers on HTTPS connections that have no |
699 // have no certificate errors. | 695 // certificate errors. |
700 if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) || | 696 if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) || |
701 !ctx->transport_security_state()) { | 697 !security_state) |
702 return; | 698 return; |
703 } | |
704 | |
705 TransportSecurityState* security_state = ctx->transport_security_state(); | |
706 TransportSecurityState::DomainState domain_state; | |
707 const std::string& host = request_info_.url.host(); | |
708 | |
709 bool sni_available = | |
710 SSLConfigService::IsSNIAvailable(ctx->ssl_config_service()); | |
711 if (!security_state->GetDomainState(host, sni_available, &domain_state)) | |
712 // |GetDomainState| may have altered |domain_state| while searching. If | |
713 // not found, start with a fresh state. | |
714 domain_state.upgrade_mode = | |
715 TransportSecurityState::DomainState::MODE_FORCE_HTTPS; | |
716 | |
717 HttpResponseHeaders* headers = GetResponseHeaders(); | |
718 std::string value; | |
719 void* iter = NULL; | |
720 base::Time now = base::Time::Now(); | |
721 | 699 |
722 // http://tools.ietf.org/html/draft-ietf-websec-strict-transport-sec: | 700 // http://tools.ietf.org/html/draft-ietf-websec-strict-transport-sec: |
723 // | 701 // |
724 // If a UA receives more than one STS header field in a HTTP response | 702 // If a UA receives more than one STS header field in a HTTP response |
725 // message over secure transport, then the UA MUST process only the | 703 // message over secure transport, then the UA MUST process only the |
726 // first such header field. | 704 // first such header field. |
727 bool seen_sts = false; | 705 HttpResponseHeaders* headers = GetResponseHeaders(); |
728 while (headers->EnumerateHeader(&iter, "Strict-Transport-Security", &value)) { | 706 std::string value; |
729 if (seen_sts) | 707 if (headers->EnumerateHeader(NULL, "Strict-Transport-Security", &value)) |
730 return; | 708 security_state->AddHSTSHeader(request_info_.url.host(), value); |
731 seen_sts = true; | |
732 TransportSecurityState::DomainState domain_state; | |
733 if (domain_state.ParseSTSHeader(now, value)) | |
734 security_state->EnableHost(host, domain_state); | |
735 } | |
736 } | 709 } |
737 | 710 |
738 void URLRequestHttpJob::ProcessPublicKeyPinsHeader() { | 711 void URLRequestHttpJob::ProcessPublicKeyPinsHeader() { |
739 DCHECK(response_info_); | 712 DCHECK(response_info_); |
740 | 713 TransportSecurityState* security_state = |
741 const URLRequestContext* ctx = request_->context(); | 714 request_->context()->transport_security_state(); |
742 const SSLInfo& ssl_info = response_info_->ssl_info; | 715 const SSLInfo& ssl_info = response_info_->ssl_info; |
743 | 716 |
744 // Only accept public key pins headers on HTTPS connections that have no | 717 // Only accept HPKP headers on HTTPS connections that have no |
745 // certificate errors. | 718 // certificate errors. |
746 if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) || | 719 if (!ssl_info.is_valid() || IsCertStatusError(ssl_info.cert_status) || |
747 !ctx->transport_security_state()) { | 720 !security_state) |
748 return; | 721 return; |
749 } | |
750 | 722 |
751 TransportSecurityState* security_state = ctx->transport_security_state(); | 723 // http://tools.ietf.org/html/draft-ietf-websec-key-pinning: |
752 TransportSecurityState::DomainState domain_state; | 724 // |
753 const std::string& host = request_info_.url.host(); | 725 // If a UA receives more than one PKP header field in an HTTP |
754 | 726 // response message over secure transport, then the UA MUST process |
755 bool sni_available = | 727 // only the first such header field. |
756 SSLConfigService::IsSNIAvailable(ctx->ssl_config_service()); | |
757 if (!security_state->GetDomainState(host, sni_available, &domain_state)) | |
758 // |GetDomainState| may have altered |domain_state| while searching. If | |
759 // not found, start with a fresh state. | |
760 domain_state.upgrade_mode = | |
761 TransportSecurityState::DomainState::MODE_DEFAULT; | |
762 | |
763 HttpResponseHeaders* headers = GetResponseHeaders(); | 728 HttpResponseHeaders* headers = GetResponseHeaders(); |
764 void* iter = NULL; | |
765 std::string value; | 729 std::string value; |
766 base::Time now = base::Time::Now(); | 730 if (headers->EnumerateHeader(NULL, "Public-Key-Pins", &value)) |
767 | 731 security_state->AddHPKPHeader(request_info_.url.host(), value, ssl_info); |
768 while (headers->EnumerateHeader(&iter, "Public-Key-Pins", &value)) { | |
769 // Note that ParsePinsHeader updates |domain_state| (iff the header parses | |
770 // correctly), but does not completely overwrite it. It just updates the | |
771 // dynamic pinning metadata. | |
772 if (domain_state.ParsePinsHeader(now, value, ssl_info)) | |
773 security_state->EnableHost(host, domain_state); | |
774 } | |
775 } | 732 } |
776 | 733 |
777 void URLRequestHttpJob::OnStartCompleted(int result) { | 734 void URLRequestHttpJob::OnStartCompleted(int result) { |
778 RecordTimer(); | 735 RecordTimer(); |
779 | 736 |
780 // If the request was destroyed, then there is no more work to do. | 737 // If the request was destroyed, then there is no more work to do. |
781 if (!request_) | 738 if (!request_) |
782 return; | 739 return; |
783 | 740 |
784 // If the transaction was destroyed, then the job was cancelled, and | 741 // If the transaction was destroyed, then the job was cancelled, and |
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1613 | 1570 |
1614 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1571 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
1615 awaiting_callback_ = false; | 1572 awaiting_callback_ = false; |
1616 } | 1573 } |
1617 | 1574 |
1618 void URLRequestHttpJob::OnDetachRequest() { | 1575 void URLRequestHttpJob::OnDetachRequest() { |
1619 http_transaction_delegate_->OnDetachRequest(); | 1576 http_transaction_delegate_->OnDetachRequest(); |
1620 } | 1577 } |
1621 | 1578 |
1622 } // namespace net | 1579 } // namespace net |
OLD | NEW |