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

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

Issue 1368863002: Set SSL info when an HTTP auth dialog is triggered by direct navigation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to creis' comments on the other CL. Created 5 years, 2 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/message_loop/message_loop.h"
9 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
10 #include "base/profiler/scoped_tracker.h" 11 #include "base/profiler/scoped_tracker.h"
11 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
12 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "content/browser/appcache/appcache_interceptor.h" 15 #include "content/browser/appcache/appcache_interceptor.h"
15 #include "content/browser/child_process_security_policy_impl.h" 16 #include "content/browser/child_process_security_policy_impl.h"
16 #include "content/browser/loader/cross_site_resource_handler.h" 17 #include "content/browser/loader/cross_site_resource_handler.h"
17 #include "content/browser/loader/detachable_resource_handler.h" 18 #include "content/browser/loader/detachable_resource_handler.h"
18 #include "content/browser/loader/resource_loader_delegate.h" 19 #include "content/browser/loader/resource_loader_delegate.h"
19 #include "content/browser/loader/resource_request_info_impl.h" 20 #include "content/browser/loader/resource_request_info_impl.h"
20 #include "content/browser/service_worker/service_worker_request_handler.h" 21 #include "content/browser/service_worker/service_worker_request_handler.h"
21 #include "content/browser/ssl/ssl_client_auth_handler.h" 22 #include "content/browser/ssl/ssl_client_auth_handler.h"
22 #include "content/browser/ssl/ssl_manager.h" 23 #include "content/browser/ssl/ssl_manager.h"
23 #include "content/browser/ssl/ssl_policy.h" 24 #include "content/browser/ssl/ssl_policy.h"
24 #include "content/common/ssl_status_serialization.h" 25 #include "content/common/ssl_status_serialization.h"
25 #include "content/public/browser/cert_store.h" 26 #include "content/public/browser/cert_store.h"
26 #include "content/public/browser/resource_context.h" 27 #include "content/public/browser/resource_context.h"
27 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" 28 #include "content/public/browser/resource_dispatcher_host_login_delegate.h"
28 #include "content/public/browser/signed_certificate_timestamp_store.h" 29 #include "content/public/browser/signed_certificate_timestamp_store.h"
29 #include "content/public/common/content_client.h" 30 #include "content/public/common/content_client.h"
30 #include "content/public/common/content_switches.h" 31 #include "content/public/common/content_switches.h"
31 #include "content/public/common/process_type.h" 32 #include "content/public/common/process_type.h"
32 #include "content/public/common/resource_response.h" 33 #include "content/public/common/resource_response.h"
33 #include "content/public/common/security_style.h" 34 #include "content/public/common/security_style.h"
35 #include "content/public/common/ssl_status.h"
34 #include "net/base/io_buffer.h" 36 #include "net/base/io_buffer.h"
35 #include "net/base/load_flags.h" 37 #include "net/base/load_flags.h"
36 #include "net/http/http_response_headers.h" 38 #include "net/http/http_response_headers.h"
37 #include "net/ssl/client_cert_store.h" 39 #include "net/ssl/client_cert_store.h"
38 #include "net/url_request/redirect_info.h" 40 #include "net/url_request/redirect_info.h"
39 #include "net/url_request/url_request_status.h" 41 #include "net/url_request/url_request_status.h"
40 42
41 using base::TimeDelta; 43 using base::TimeDelta;
42 using base::TimeTicks; 44 using base::TimeTicks;
43 45
44 namespace content { 46 namespace content {
45 namespace { 47 namespace {
46 48
49 // Stores the SignedCertificateTimestamps held in |sct_list| in the
50 // SignedCertificateTimestampStore singleton, associated with |process_id|.
51 // On return, |sct_ids| contains the assigned ID and verification status of
52 // each SignedCertificateTimestamp.
47 void StoreSignedCertificateTimestamps( 53 void StoreSignedCertificateTimestamps(
48 const net::SignedCertificateTimestampAndStatusList& sct_list, 54 const net::SignedCertificateTimestampAndStatusList& sct_list,
49 int process_id, 55 int process_id,
50 SignedCertificateTimestampIDStatusList* sct_ids) { 56 SignedCertificateTimestampIDStatusList* sct_ids) {
51 SignedCertificateTimestampStore* sct_store( 57 SignedCertificateTimestampStore* sct_store(
52 SignedCertificateTimestampStore::GetInstance()); 58 SignedCertificateTimestampStore::GetInstance());
53 59
54 for (auto iter = sct_list.begin(); iter != sct_list.end(); ++iter) { 60 for (const auto& sct : sct_list) {
55 const int sct_id(sct_store->Store(iter->sct.get(), process_id)); 61 const int sct_id(sct_store->Store(sct.sct.get(), process_id));
56 sct_ids->push_back( 62 sct_ids->push_back(
57 SignedCertificateTimestampIDAndStatus(sct_id, iter->status)); 63 SignedCertificateTimestampIDAndStatus(sct_id, sct.status));
58 } 64 }
59 } 65 }
60 66
61 void GetSSLStatusForRequest(const GURL& url, 67 void GetSSLStatusForRequest(const GURL& url,
62 const net::SSLInfo& ssl_info, 68 const net::SSLInfo& ssl_info,
63 int child_id, 69 int child_id,
64 SSLStatus* ssl_status) { 70 SSLStatus* ssl_status) {
65 DCHECK(ssl_info.cert); 71 DCHECK(ssl_info.cert);
66 72
67 int cert_id = 73 int cert_id =
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 response->head.security_info = SerializeSecurityInfo(ssl_status); 117 response->head.security_info = SerializeSecurityInfo(ssl_status);
112 } else { 118 } else {
113 // We should not have any SSL state. 119 // We should not have any SSL state.
114 DCHECK(!request->ssl_info().cert_status); 120 DCHECK(!request->ssl_info().cert_status);
115 DCHECK_EQ(request->ssl_info().security_bits, -1); 121 DCHECK_EQ(request->ssl_info().security_bits, -1);
116 DCHECK_EQ(request->ssl_info().key_exchange_info, 0); 122 DCHECK_EQ(request->ssl_info().key_exchange_info, 0);
117 DCHECK(!request->ssl_info().connection_status); 123 DCHECK(!request->ssl_info().connection_status);
118 } 124 }
119 } 125 }
120 126
127 std::string StoreAndSerializeSecurityInfo(const GURL& url,
128 const net::SSLInfo& ssl_info,
129 int process_id) {
130 DCHECK(ssl_info.cert.get());
131
132 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
133 StoreSignedCertificateTimestamps(ssl_info.signed_certificate_timestamps,
134 process_id,
135 &signed_certificate_timestamp_ids);
meacer 2015/09/29 00:17:02 Lines 132-135 aren't needed anymore now that this
palmer 2015/09/29 00:46:36 Done.
136
137 SSLStatus status;
138 GetSSLStatusForRequest(url, ssl_info, process_id, &status);
139 return SerializeSecurityInfo(status);
140 }
141
121 } // namespace 142 } // namespace
122 143
123 ResourceLoader::ResourceLoader(scoped_ptr<net::URLRequest> request, 144 ResourceLoader::ResourceLoader(scoped_ptr<net::URLRequest> request,
124 scoped_ptr<ResourceHandler> handler, 145 scoped_ptr<ResourceHandler> handler,
125 ResourceLoaderDelegate* delegate) 146 ResourceLoaderDelegate* delegate)
126 : deferred_stage_(DEFERRED_NONE), 147 : deferred_stage_(DEFERRED_NONE),
127 request_(request.Pass()), 148 request_(request.Pass()),
128 handler_(handler.Pass()), 149 handler_(handler.Pass()),
129 delegate_(delegate), 150 delegate_(delegate),
130 is_transferring_(false), 151 is_transferring_(false),
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 void ResourceLoader::OnAuthRequired(net::URLRequest* unused, 287 void ResourceLoader::OnAuthRequired(net::URLRequest* unused,
267 net::AuthChallengeInfo* auth_info) { 288 net::AuthChallengeInfo* auth_info) {
268 DCHECK_EQ(request_.get(), unused); 289 DCHECK_EQ(request_.get(), unused);
269 290
270 ResourceRequestInfoImpl* info = GetRequestInfo(); 291 ResourceRequestInfoImpl* info = GetRequestInfo();
271 if (info->do_not_prompt_for_login()) { 292 if (info->do_not_prompt_for_login()) {
272 request_->CancelAuth(); 293 request_->CancelAuth();
273 return; 294 return;
274 } 295 }
275 296
297 // Update the SSL state before showing the auth prompt.
298 const net::SSLInfo& ssl_info = request_->response_info().ssl_info;
299 if (ssl_info.cert.get()) {
300 bool is_main_frame = (request_->load_flags() & net::LOAD_MAIN_FRAME) != 0;
301 ResourceRequestInfoImpl* info = GetRequestInfo();
302 int render_process_id;
303 int render_frame_id;
304 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id))
305 CHECK(false);
306
307 SSLStatus status;
308 GetSSLStatusForRequest(request_->url(), ssl_info, render_process_id,
309 &status);
310
311 SSLManager::OnAuthDialog(render_process_id, render_frame_id, status,
312 is_main_frame);
313 } else {
314 // We should not have any SSL state.
315 DCHECK(!ssl_info.cert_status && ssl_info.security_bits == -1 &&
316 !ssl_info.connection_status);
317 }
318
276 // Create a login dialog on the UI thread to get authentication data, or pull 319 // Create a login dialog on the UI thread to get authentication data, or pull
277 // from cache and continue on the IO thread. 320 // from cache and continue on the IO thread.
278
279 DCHECK(!login_delegate_.get()) 321 DCHECK(!login_delegate_.get())
280 << "OnAuthRequired called with login_delegate pending"; 322 << "OnAuthRequired called with login_delegate pending";
281 login_delegate_ = delegate_->CreateLoginDelegate(this, auth_info); 323 login_delegate_ = delegate_->CreateLoginDelegate(this, auth_info);
282 if (!login_delegate_.get()) 324 if (!login_delegate_.get())
283 request_->CancelAuth(); 325 request_->CancelAuth();
284 } 326 }
285 327
286 void ResourceLoader::OnCertificateRequested( 328 void ResourceLoader::OnCertificateRequested(
287 net::URLRequest* unused, 329 net::URLRequest* unused,
288 net::SSLCertRequestInfo* cert_info) { 330 net::SSLCertRequestInfo* cert_info) {
(...skipping 13 matching lines...) Expand all
302 } 344 }
303 345
304 void ResourceLoader::OnSSLCertificateError(net::URLRequest* request, 346 void ResourceLoader::OnSSLCertificateError(net::URLRequest* request,
305 const net::SSLInfo& ssl_info, 347 const net::SSLInfo& ssl_info,
306 bool fatal) { 348 bool fatal) {
307 ResourceRequestInfoImpl* info = GetRequestInfo(); 349 ResourceRequestInfoImpl* info = GetRequestInfo();
308 350
309 int render_process_id; 351 int render_process_id;
310 int render_frame_id; 352 int render_frame_id;
311 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) 353 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id))
312 NOTREACHED(); 354 CHECK(false);
313 355
314 SSLManager::OnSSLCertificateError( 356 SSLManager::OnSSLCertificateError(
315 weak_ptr_factory_.GetWeakPtr(), 357 weak_ptr_factory_.GetWeakPtr(),
316 info->GetResourceType(), 358 info->GetResourceType(),
317 request_->url(), 359 request_->url(),
318 render_process_id, 360 render_process_id,
319 render_frame_id, 361 render_frame_id,
320 ssl_info, 362 ssl_info,
321 fatal); 363 fatal);
322 } 364 }
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 } else { 557 } else {
516 times_cancelled_after_request_start_++; 558 times_cancelled_after_request_start_++;
517 } 559 }
518 560
519 request_->CancelWithError(error); 561 request_->CancelWithError(error);
520 562
521 if (!was_pending) { 563 if (!was_pending) {
522 // If the request isn't in flight, then we won't get an asynchronous 564 // If the request isn't in flight, then we won't get an asynchronous
523 // notification from the request, so we have to signal ourselves to finish 565 // notification from the request, so we have to signal ourselves to finish
524 // this request. 566 // this request.
525 base::ThreadTaskRunnerHandle::Get()->PostTask( 567 base::MessageLoop::current()->PostTask(
526 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted, 568 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted,
527 weak_ptr_factory_.GetWeakPtr())); 569 weak_ptr_factory_.GetWeakPtr()));
528 } 570 }
529 } 571 }
530 572
531 void ResourceLoader::CompleteResponseStarted() { 573 void ResourceLoader::CompleteResponseStarted() {
532 ResourceRequestInfoImpl* info = GetRequestInfo(); 574 ResourceRequestInfoImpl* info = GetRequestInfo();
533 scoped_refptr<ResourceResponse> response(new ResourceResponse()); 575 scoped_refptr<ResourceResponse> response(new ResourceResponse());
534 PopulateResourceResponse(info, request_.get(), response.get()); 576 PopulateResourceResponse(info, request_.get(), response.get());
535 577
578 if (request_->ssl_info().cert.get()) {
579 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
580 tracked_objects::ScopedTracker tracking_profile3(
581 FROM_HERE_WITH_EXPLICIT_FUNCTION(
582 "423948 ResourceLoader::CompleteResponseStarted3"));
583
584 response->head.security_info = StoreAndSerializeSecurityInfo(
585 request_->url(), request_->ssl_info(), info->GetChildID());
586
587 } else {
588 // We should not have any SSL state.
589 DCHECK(!request_->ssl_info().cert_status &&
590 request_->ssl_info().security_bits == -1 &&
591 !request_->ssl_info().connection_status);
592 }
593
594 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed.
595 tracked_objects::ScopedTracker tracking_profile5(
596 FROM_HERE_WITH_EXPLICIT_FUNCTION(
597 "423948 ResourceLoader::CompleteResponseStarted5"));
598
536 delegate_->DidReceiveResponse(this); 599 delegate_->DidReceiveResponse(this);
537 600
538 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. 601 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed.
539 tracked_objects::ScopedTracker tracking_profile( 602 tracked_objects::ScopedTracker tracking_profile(
540 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseStarted()")); 603 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseStarted()"));
541 604
542 bool defer = false; 605 bool defer = false;
543 if (!handler_->OnResponseStarted(response.get(), &defer)) { 606 if (!handler_->OnResponseStarted(response.get(), &defer)) {
544 Cancel(); 607 Cancel();
545 } else if (defer) { 608 } else if (defer) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 // instance.) 696 // instance.)
634 } 697 }
635 698
636 void ResourceLoader::ResponseCompleted() { 699 void ResourceLoader::ResponseCompleted() {
637 DVLOG(1) << "ResponseCompleted: " << request_->url().spec(); 700 DVLOG(1) << "ResponseCompleted: " << request_->url().spec();
638 RecordHistograms(); 701 RecordHistograms();
639 ResourceRequestInfoImpl* info = GetRequestInfo(); 702 ResourceRequestInfoImpl* info = GetRequestInfo();
640 703
641 std::string security_info; 704 std::string security_info;
642 const net::SSLInfo& ssl_info = request_->ssl_info(); 705 const net::SSLInfo& ssl_info = request_->ssl_info();
643 if (ssl_info.cert.get() != NULL) { 706 if (ssl_info.cert.get() != NULL)
644 SSLStatus ssl_status; 707 security_info = StoreAndSerializeSecurityInfo(request_->url(), ssl_info,
meacer 2015/09/29 00:17:02 nit: Braces since this code spans two lines?
palmer 2015/09/29 00:46:35 Done.
645 GetSSLStatusForRequest(request_->url(), ssl_info, info->GetChildID(), 708 info->GetChildID());
646 &ssl_status);
647
648 security_info = SerializeSecurityInfo(ssl_status);
649 }
650 709
651 bool defer = false; 710 bool defer = false;
652 { 711 {
653 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. 712 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed.
654 tracked_objects::ScopedTracker tracking_profile( 713 tracked_objects::ScopedTracker tracking_profile(
655 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseCompleted()")); 714 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseCompleted()"));
656 715
657 handler_->OnResponseCompleted(request_->status(), security_info, &defer); 716 handler_->OnResponseCompleted(request_->status(), security_info, &defer);
658 } 717 }
659 if (defer) { 718 if (defer) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 case net::URLRequestStatus::FAILED: 756 case net::URLRequestStatus::FAILED:
698 status = STATUS_UNDEFINED; 757 status = STATUS_UNDEFINED;
699 break; 758 break;
700 } 759 }
701 760
702 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); 761 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX);
703 } 762 }
704 } 763 }
705 764
706 } // namespace content 765 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698