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

Side by Side Diff: content/browser/loader/resource_loader.cc

Issue 1244863003: Attach a SecurityStyle to each request in ResourceLoader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unit test fixes Created 5 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
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 "content/browser/loader/resource_loader.h" 5 #include "content/browser/loader/resource_loader.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/profiler/scoped_tracker.h" 10 #include "base/profiler/scoped_tracker.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "content/browser/appcache/appcache_interceptor.h" 14 #include "content/browser/appcache/appcache_interceptor.h"
15 #include "content/browser/child_process_security_policy_impl.h" 15 #include "content/browser/child_process_security_policy_impl.h"
16 #include "content/browser/loader/cross_site_resource_handler.h" 16 #include "content/browser/loader/cross_site_resource_handler.h"
17 #include "content/browser/loader/detachable_resource_handler.h" 17 #include "content/browser/loader/detachable_resource_handler.h"
18 #include "content/browser/loader/resource_loader_delegate.h" 18 #include "content/browser/loader/resource_loader_delegate.h"
19 #include "content/browser/loader/resource_request_info_impl.h" 19 #include "content/browser/loader/resource_request_info_impl.h"
20 #include "content/browser/service_worker/service_worker_request_handler.h" 20 #include "content/browser/service_worker/service_worker_request_handler.h"
21 #include "content/browser/ssl/ssl_client_auth_handler.h" 21 #include "content/browser/ssl/ssl_client_auth_handler.h"
22 #include "content/browser/ssl/ssl_manager.h" 22 #include "content/browser/ssl/ssl_manager.h"
23 #include "content/browser/ssl/ssl_policy.h"
23 #include "content/common/ssl_status_serialization.h" 24 #include "content/common/ssl_status_serialization.h"
24 #include "content/public/browser/cert_store.h" 25 #include "content/public/browser/cert_store.h"
25 #include "content/public/browser/resource_context.h" 26 #include "content/public/browser/resource_context.h"
26 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" 27 #include "content/public/browser/resource_dispatcher_host_login_delegate.h"
27 #include "content/public/browser/signed_certificate_timestamp_store.h" 28 #include "content/public/browser/signed_certificate_timestamp_store.h"
28 #include "content/public/common/content_client.h" 29 #include "content/public/common/content_client.h"
29 #include "content/public/common/content_switches.h" 30 #include "content/public/common/content_switches.h"
30 #include "content/public/common/process_type.h" 31 #include "content/public/common/process_type.h"
31 #include "content/public/common/resource_response.h" 32 #include "content/public/common/resource_response.h"
33 #include "content/public/common/security_style.h"
32 #include "net/base/io_buffer.h" 34 #include "net/base/io_buffer.h"
33 #include "net/base/load_flags.h" 35 #include "net/base/load_flags.h"
34 #include "net/http/http_response_headers.h" 36 #include "net/http/http_response_headers.h"
35 #include "net/ssl/client_cert_store.h" 37 #include "net/ssl/client_cert_store.h"
36 #include "net/url_request/redirect_info.h" 38 #include "net/url_request/redirect_info.h"
37 #include "net/url_request/url_request_status.h" 39 #include "net/url_request/url_request_status.h"
38 40
39 using base::TimeDelta; 41 using base::TimeDelta;
40 using base::TimeTicks; 42 using base::TimeTicks;
41 43
(...skipping 26 matching lines...) Expand all
68 handler->GetExtraResponseInfo(&response->head); 70 handler->GetExtraResponseInfo(&response->head);
69 } 71 }
70 AppCacheInterceptor::GetExtraResponseInfo( 72 AppCacheInterceptor::GetExtraResponseInfo(
71 request, 73 request,
72 &response->head.appcache_id, 74 &response->head.appcache_id,
73 &response->head.appcache_manifest_url); 75 &response->head.appcache_manifest_url);
74 if (info->is_load_timing_enabled()) 76 if (info->is_load_timing_enabled())
75 request->GetLoadTimingInfo(&response->head.load_timing); 77 request->GetLoadTimingInfo(&response->head.load_timing);
76 } 78 }
77 79
80 void StoreSignedCertificateTimestamps(
81 const net::SignedCertificateTimestampAndStatusList& sct_list,
82 int process_id,
83 SignedCertificateTimestampIDStatusList* sct_ids) {
84 SignedCertificateTimestampStore* sct_store(
85 SignedCertificateTimestampStore::GetInstance());
86
87 for (auto iter = sct_list.begin(); iter != sct_list.end(); ++iter) {
88 const int sct_id(sct_store->Store(iter->sct.get(), process_id));
89 sct_ids->push_back(
90 SignedCertificateTimestampIDAndStatus(sct_id, iter->status));
91 }
92 }
93
94 void GetSSLStatusForRequest(const GURL& url,
95 const net::SSLInfo& ssl_info,
96 int child_id,
97 SSLStatus* ssl_status) {
98 DCHECK(ssl_info.cert);
99
100 int cert_id =
101 CertStore::GetInstance()->StoreCert(ssl_info.cert.get(), child_id);
102
103 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
104 StoreSignedCertificateTimestamps(ssl_info.signed_certificate_timestamps,
105 child_id, &signed_certificate_timestamp_ids);
106
107 ssl_status->cert_id = cert_id;
108 ssl_status->cert_status = ssl_info.cert_status;
109 ssl_status->security_bits = ssl_info.security_bits;
110 ssl_status->connection_status = ssl_info.connection_status;
111 ssl_status->signed_certificate_timestamp_ids =
112 signed_certificate_timestamp_ids;
113 ssl_status->security_style =
114 SSLPolicy::GetSecurityStyleForResource(url, *ssl_status);
115 }
116
78 } // namespace 117 } // namespace
79 118
80 ResourceLoader::ResourceLoader(scoped_ptr<net::URLRequest> request, 119 ResourceLoader::ResourceLoader(scoped_ptr<net::URLRequest> request,
81 scoped_ptr<ResourceHandler> handler, 120 scoped_ptr<ResourceHandler> handler,
82 ResourceLoaderDelegate* delegate) 121 ResourceLoaderDelegate* delegate)
83 : deferred_stage_(DEFERRED_NONE), 122 : deferred_stage_(DEFERRED_NONE),
84 request_(request.Pass()), 123 request_(request.Pass()),
85 handler_(handler.Pass()), 124 handler_(handler.Pass()),
86 delegate_(delegate), 125 delegate_(delegate),
87 last_upload_position_(0), 126 last_upload_position_(0),
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 if (!was_pending) { 587 if (!was_pending) {
549 // If the request isn't in flight, then we won't get an asynchronous 588 // If the request isn't in flight, then we won't get an asynchronous
550 // notification from the request, so we have to signal ourselves to finish 589 // notification from the request, so we have to signal ourselves to finish
551 // this request. 590 // this request.
552 base::ThreadTaskRunnerHandle::Get()->PostTask( 591 base::ThreadTaskRunnerHandle::Get()->PostTask(
553 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted, 592 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted,
554 weak_ptr_factory_.GetWeakPtr())); 593 weak_ptr_factory_.GetWeakPtr()));
555 } 594 }
556 } 595 }
557 596
558 void ResourceLoader::StoreSignedCertificateTimestamps(
559 const net::SignedCertificateTimestampAndStatusList& sct_list,
560 int process_id,
561 SignedCertificateTimestampIDStatusList* sct_ids) {
562 SignedCertificateTimestampStore* sct_store(
563 SignedCertificateTimestampStore::GetInstance());
564
565 for (net::SignedCertificateTimestampAndStatusList::const_iterator iter =
566 sct_list.begin(); iter != sct_list.end(); ++iter) {
567 const int sct_id(sct_store->Store(iter->sct.get(), process_id));
568 sct_ids->push_back(
569 SignedCertificateTimestampIDAndStatus(sct_id, iter->status));
570 }
571 }
572
573 void ResourceLoader::CompleteResponseStarted() { 597 void ResourceLoader::CompleteResponseStarted() {
574 ResourceRequestInfoImpl* info = GetRequestInfo(); 598 ResourceRequestInfoImpl* info = GetRequestInfo();
575 scoped_refptr<ResourceResponse> response(new ResourceResponse()); 599 scoped_refptr<ResourceResponse> response(new ResourceResponse());
576 PopulateResourceResponse(info, request_.get(), response.get()); 600 PopulateResourceResponse(info, request_.get(), response.get());
577 601
578 if (request_->ssl_info().cert.get()) { 602 if (request_->ssl_info().cert.get()) {
579 int cert_id = CertStore::GetInstance()->StoreCert( 603 SSLStatus ssl_status;
580 request_->ssl_info().cert.get(), info->GetChildID()); 604 GetSSLStatusForRequest(request_->url(), request_->ssl_info(),
605 info->GetChildID(), &ssl_status);
581 606
582 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids; 607 response->head.security_info = SerializeSecurityInfo(ssl_status);
583 StoreSignedCertificateTimestamps(
584 request_->ssl_info().signed_certificate_timestamps,
585 info->GetChildID(),
586 &signed_certificate_timestamp_ids);
587
588 response->head.security_info = SerializeSecurityInfo(
589 cert_id,
590 request_->ssl_info().cert_status,
591 request_->ssl_info().security_bits,
592 request_->ssl_info().connection_status,
593 signed_certificate_timestamp_ids);
594 } else { 608 } else {
595 // We should not have any SSL state. 609 // We should not have any SSL state.
596 DCHECK(!request_->ssl_info().cert_status && 610 DCHECK(!request_->ssl_info().cert_status &&
597 request_->ssl_info().security_bits == -1 && 611 request_->ssl_info().security_bits == -1 &&
598 !request_->ssl_info().connection_status); 612 !request_->ssl_info().connection_status);
599 } 613 }
600 614
601 delegate_->DidReceiveResponse(this); 615 delegate_->DidReceiveResponse(this);
602 616
603 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. 617 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 } 713 }
700 714
701 void ResourceLoader::ResponseCompleted() { 715 void ResourceLoader::ResponseCompleted() {
702 DVLOG(1) << "ResponseCompleted: " << request_->url().spec(); 716 DVLOG(1) << "ResponseCompleted: " << request_->url().spec();
703 RecordHistograms(); 717 RecordHistograms();
704 ResourceRequestInfoImpl* info = GetRequestInfo(); 718 ResourceRequestInfoImpl* info = GetRequestInfo();
705 719
706 std::string security_info; 720 std::string security_info;
707 const net::SSLInfo& ssl_info = request_->ssl_info(); 721 const net::SSLInfo& ssl_info = request_->ssl_info();
708 if (ssl_info.cert.get() != NULL) { 722 if (ssl_info.cert.get() != NULL) {
709 int cert_id = CertStore::GetInstance()->StoreCert(ssl_info.cert.get(), 723 SSLStatus ssl_status;
710 info->GetChildID()); 724 GetSSLStatusForRequest(request_->url(), ssl_info, info->GetChildID(),
711 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids; 725 &ssl_status);
712 StoreSignedCertificateTimestamps(ssl_info.signed_certificate_timestamps,
713 info->GetChildID(),
714 &signed_certificate_timestamp_ids);
715 726
716 security_info = SerializeSecurityInfo( 727 security_info = SerializeSecurityInfo(ssl_status);
717 cert_id, ssl_info.cert_status, ssl_info.security_bits,
718 ssl_info.connection_status, signed_certificate_timestamp_ids);
719 } 728 }
720 729
721 bool defer = false; 730 bool defer = false;
722 { 731 {
723 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. 732 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed.
724 tracked_objects::ScopedTracker tracking_profile( 733 tracked_objects::ScopedTracker tracking_profile(
725 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseCompleted()")); 734 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseCompleted()"));
726 735
727 handler_->OnResponseCompleted(request_->status(), security_info, &defer); 736 handler_->OnResponseCompleted(request_->status(), security_info, &defer);
728 } 737 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 case net::URLRequestStatus::FAILED: 776 case net::URLRequestStatus::FAILED:
768 status = STATUS_UNDEFINED; 777 status = STATUS_UNDEFINED;
769 break; 778 break;
770 } 779 }
771 780
772 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); 781 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX);
773 } 782 }
774 } 783 }
775 784
776 } // namespace content 785 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698