OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/build_time.h" |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
12 #include "base/file_util.h" | 13 #include "base/file_util.h" |
13 #include "base/file_version_info.h" | 14 #include "base/file_version_info.h" |
14 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
15 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
16 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
17 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
18 #include "base/string_util.h" | 19 #include "base/string_util.h" |
19 #include "base/time.h" | 20 #include "base/time.h" |
20 #include "net/base/cert_status_flags.h" | 21 #include "net/base/cert_status_flags.h" |
21 #include "net/base/cookie_monster.h" | 22 #include "net/base/cookie_monster.h" |
22 #include "net/base/filter.h" | 23 #include "net/base/filter.h" |
23 #include "net/base/host_port_pair.h" | 24 #include "net/base/host_port_pair.h" |
24 #include "net/base/load_flags.h" | 25 #include "net/base/load_flags.h" |
25 #include "net/base/mime_util.h" | 26 #include "net/base/mime_util.h" |
26 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
27 #include "net/base/net_util.h" | 28 #include "net/base/net_util.h" |
28 #include "net/base/network_delegate.h" | 29 #include "net/base/network_delegate.h" |
29 #include "net/base/sdch_manager.h" | 30 #include "net/base/sdch_manager.h" |
30 #include "net/base/ssl_cert_request_info.h" | 31 #include "net/base/ssl_cert_request_info.h" |
31 #include "net/base/ssl_config_service.h" | 32 #include "net/base/ssl_config_service.h" |
| 33 #include "net/base/transport_security_state.h" |
32 #include "net/http/http_mac_signature.h" | 34 #include "net/http/http_mac_signature.h" |
33 #include "net/http/http_request_headers.h" | 35 #include "net/http/http_request_headers.h" |
34 #include "net/http/http_response_headers.h" | 36 #include "net/http/http_response_headers.h" |
35 #include "net/http/http_response_info.h" | 37 #include "net/http/http_response_info.h" |
36 #include "net/http/http_transaction.h" | 38 #include "net/http/http_transaction.h" |
37 #include "net/http/http_transaction_factory.h" | 39 #include "net/http/http_transaction_factory.h" |
38 #include "net/http/http_util.h" | 40 #include "net/http/http_util.h" |
39 #include "net/url_request/fraudulent_certificate_reporter.h" | 41 #include "net/url_request/fraudulent_certificate_reporter.h" |
40 #include "net/url_request/url_request.h" | 42 #include "net/url_request/url_request.h" |
41 #include "net/url_request/url_request_context.h" | 43 #include "net/url_request/url_request_context.h" |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 return; | 654 return; |
653 | 655 |
654 // If the transaction was destroyed, then the job was cancelled, and | 656 // If the transaction was destroyed, then the job was cancelled, and |
655 // we can just ignore this notification. | 657 // we can just ignore this notification. |
656 if (!transaction_.get()) | 658 if (!transaction_.get()) |
657 return; | 659 return; |
658 | 660 |
659 // Clear the IO_PENDING status | 661 // Clear the IO_PENDING status |
660 SetStatus(URLRequestStatus()); | 662 SetStatus(URLRequestStatus()); |
661 | 663 |
662 if (result == ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN && | 664 #if defined(OFFICIAL_BUILD) && !defined(OS_ANDROID) |
663 transaction_->GetResponseInfo() != NULL) { | 665 // Take care of any mandates for public key pinning. |
664 FraudulentCertificateReporter* reporter = | 666 // |
665 context_->fraudulent_certificate_reporter(); | 667 // Pinning is only enabled for official builds to make sure that others don't |
666 if (reporter != NULL) { | 668 // end up with pins that cannot be easily updated. |
667 const SSLInfo& ssl_info = transaction_->GetResponseInfo()->ssl_info; | 669 // |
| 670 // TODO(agl): we might have an issue here where a request for foo.example.com |
| 671 // merges into a SPDY connection to www.example.com, and gets a different |
| 672 // certificate. |
| 673 if (transaction_->GetResponseInfo() != NULL) { |
| 674 const SSLInfo& ssl_info = transaction_->GetResponseInfo()->ssl_info; |
| 675 if (ssl_info.is_valid() && |
| 676 (result == OK || (IsCertificateError(result) && |
| 677 IsCertStatusMinorError(ssl_info.cert_status))) && |
| 678 ssl_info.is_issued_by_known_root && |
| 679 context_->transport_security_state()) { |
| 680 TransportSecurityState::DomainState domain_state; |
668 bool sni_available = SSLConfigService::IsSNIAvailable( | 681 bool sni_available = SSLConfigService::IsSNIAvailable( |
669 context_->ssl_config_service()); | 682 context_->ssl_config_service()); |
670 const std::string& host = request_->url().host(); | 683 std::string host = request_->url().host(); |
671 | 684 |
672 reporter->SendReport(host, ssl_info, sni_available); | 685 if (context_->transport_security_state()->HasPinsForHost( |
| 686 &domain_state, host, sni_available)) { |
| 687 if (!domain_state.IsChainOfPublicKeysPermitted( |
| 688 ssl_info.public_key_hashes)) { |
| 689 const base::Time build_time = base::GetBuildTime(); |
| 690 // Pins are not enforced if the build is sufficiently old. Chrome |
| 691 // users should get updates every six weeks or so, but it's possible |
| 692 // that some users will stop getting updates for some reason. We |
| 693 // don't want those users building up as a pool of people with bad |
| 694 // pins. |
| 695 if ((base::Time::Now() - build_time).InDays() < 70 /* 10 weeks */) { |
| 696 result = ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN; |
| 697 UMA_HISTOGRAM_BOOLEAN("Net.PublicKeyPinSuccess", false); |
| 698 TransportSecurityState::ReportUMAOnPinFailure(host); |
| 699 FraudulentCertificateReporter* reporter = |
| 700 context_->fraudulent_certificate_reporter(); |
| 701 if (reporter != NULL) |
| 702 reporter->SendReport(host, ssl_info, sni_available); |
| 703 } |
| 704 } else { |
| 705 UMA_HISTOGRAM_BOOLEAN("Net.PublicKeyPinSuccess", true); |
| 706 } |
| 707 } |
673 } | 708 } |
674 } | 709 } |
| 710 #endif |
675 | 711 |
676 if (result == OK) { | 712 if (result == OK) { |
677 scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders(); | 713 scoped_refptr<HttpResponseHeaders> headers = GetResponseHeaders(); |
678 if (request_->context() && request_->context()->network_delegate()) { | 714 if (request_->context() && request_->context()->network_delegate()) { |
679 // Note that |this| may not be deleted until | 715 // Note that |this| may not be deleted until |
680 // |on_headers_received_callback_| or | 716 // |on_headers_received_callback_| or |
681 // |NetworkDelegate::URLRequestDestroyed()| has been called. | 717 // |NetworkDelegate::URLRequestDestroyed()| has been called. |
682 int error = request_->context()->network_delegate()-> | 718 int error = request_->context()->network_delegate()-> |
683 NotifyHeadersReceived(request_, on_headers_received_callback_, | 719 NotifyHeadersReceived(request_, on_headers_received_callback_, |
684 headers, &override_response_headers_); | 720 headers, &override_response_headers_); |
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1404 return override_response_headers_.get() ? | 1440 return override_response_headers_.get() ? |
1405 override_response_headers_ : | 1441 override_response_headers_ : |
1406 transaction_->GetResponseInfo()->headers; | 1442 transaction_->GetResponseInfo()->headers; |
1407 } | 1443 } |
1408 | 1444 |
1409 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1445 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
1410 awaiting_callback_ = false; | 1446 awaiting_callback_ = false; |
1411 } | 1447 } |
1412 | 1448 |
1413 } // namespace net | 1449 } // namespace net |
OLD | NEW |