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

Side by Side Diff: chromecast/browser/cast_content_browser_client.cc

Issue 2898573002: Refactor client cert private key handling. (Closed)
Patch Set: rebase on https://codereview.chromium.org/2899083006/ Created 3 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chromecast/browser/cast_content_browser_client.h" 5 #include "chromecast/browser/cast_content_browser_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 // Otherwise, any fatal certificate errors will cause an abort. 398 // Otherwise, any fatal certificate errors will cause an abort.
399 if (!callback.is_null()) { 399 if (!callback.is_null()) {
400 callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL); 400 callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
401 } 401 }
402 return; 402 return;
403 } 403 }
404 404
405 void CastContentBrowserClient::SelectClientCertificate( 405 void CastContentBrowserClient::SelectClientCertificate(
406 content::WebContents* web_contents, 406 content::WebContents* web_contents,
407 net::SSLCertRequestInfo* cert_request_info, 407 net::SSLCertRequestInfo* cert_request_info,
408 net::CertificateList client_certs, 408 net::ClientCertIdentityList client_certs,
409 std::unique_ptr<content::ClientCertificateDelegate> delegate) { 409 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
410 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString()); 410 GURL requesting_url("https://" + cert_request_info->host_and_port.ToString());
411 411
412 if (!requesting_url.is_valid()) { 412 if (!requesting_url.is_valid()) {
413 LOG(ERROR) << "Invalid URL string: " 413 LOG(ERROR) << "Invalid URL string: "
414 << requesting_url.possibly_invalid_spec(); 414 << requesting_url.possibly_invalid_spec();
415 delegate->ContinueWithCertificate(nullptr); 415 delegate->ContinueWithCertificate(nullptr, nullptr);
416 return; 416 return;
417 } 417 }
418 418
419 // In our case there are no relevant certs in |client_certs|. The cert 419 // In our case there are no relevant certs in |client_certs|. The cert
420 // we need to return (if permitted) is the Cast device cert, which we can 420 // we need to return (if permitted) is the Cast device cert, which we can
421 // access directly through the ClientAuthSigner instance. However, we need to 421 // access directly through the ClientAuthSigner instance. However, we need to
422 // be on the IO thread to determine whether the app is whitelisted to return 422 // be on the IO thread to determine whether the app is whitelisted to return
423 // it, because CastNetworkDelegate is bound to the IO thread. 423 // it, because CastNetworkDelegate is bound to the IO thread.
424 // Subsequently, the callback must then itself be performed back here 424 // Subsequently, the callback must then itself be performed back here
425 // on the UI thread. 425 // on the UI thread.
426 // 426 //
427 // TODO(davidben): Stop using child ID to identify an app. 427 // TODO(davidben): Stop using child ID to identify an app.
428 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 428 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
429 content::BrowserThread::PostTaskAndReplyWithResult( 429 /*auto reply_callback = base::Bind(
430 &content::ClientCertificateDelegate::ContinueWithCertificate,
431 std::move(delegate));*/
432
433 content::BrowserThread::PostTask(
430 content::BrowserThread::IO, FROM_HERE, 434 content::BrowserThread::IO, FROM_HERE,
431 base::Bind(&CastContentBrowserClient::SelectClientCertificateOnIOThread, 435 base::BindOnce(
432 base::Unretained(this), requesting_url, 436 &CastContentBrowserClient::SelectClientCertificateOnIOThread,
433 web_contents->GetRenderProcessHost()->GetID()), 437 base::Unretained(this), requesting_url,
434 base::Bind(&content::ClientCertificateDelegate::ContinueWithCertificate, 438 web_contents->GetRenderProcessHost()->GetID(),
435 base::Owned(delegate.release()))); 439 base::SequencedTaskRunnerHandle::Get(),
440 // XXX maybe pass a callback already bound to ContinueWithCertificate?
441 std::move(delegate)));
436 } 442 }
437 443
438 net::X509Certificate* 444 void CastContentBrowserClient::SelectClientCertificateOnIOThread(
439 CastContentBrowserClient::SelectClientCertificateOnIOThread(
440 GURL requesting_url, 445 GURL requesting_url,
441 int render_process_id) { 446 int render_process_id,
447 scoped_refptr<base::SequencedTaskRunner> original_runner,
448 std::unique_ptr<content::ClientCertificateDelegate> delegate) {
442 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 449 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
443 CastNetworkDelegate* network_delegate = 450 CastNetworkDelegate* network_delegate =
444 url_request_context_factory_->app_network_delegate(); 451 url_request_context_factory_->app_network_delegate();
445 if (network_delegate->IsWhitelisted(requesting_url, 452 if (network_delegate->IsWhitelisted(requesting_url,
446 render_process_id, false)) { 453 render_process_id, false)) {
447 return CastNetworkDelegate::DeviceCert(); 454 original_runner->PostTask(
455 FROM_HERE,
456 base::Bind(&content::ClientCertificateDelegate::ContinueWithCertificate,
457 base::Owned(delegate.release()),
458 make_scoped_refptr(CastNetworkDelegate::DeviceCert()),
459 make_scoped_refptr(CastNetworkDelegate::DeviceKey())));
460 return;
448 } else { 461 } else {
449 LOG(ERROR) << "Invalid host for client certificate request: " 462 LOG(ERROR) << "Invalid host for client certificate request: "
450 << requesting_url.host() 463 << requesting_url.host()
451 << " with render_process_id: " 464 << " with render_process_id: "
452 << render_process_id; 465 << render_process_id;
453 return NULL;
454 } 466 }
467 original_runner->PostTask(
468 FROM_HERE,
469 base::Bind(&content::ClientCertificateDelegate::ContinueWithCertificate,
470 base::Owned(delegate.release()), nullptr, nullptr));
455 } 471 }
456 472
457 bool CastContentBrowserClient::CanCreateWindow( 473 bool CastContentBrowserClient::CanCreateWindow(
458 content::RenderFrameHost* opener, 474 content::RenderFrameHost* opener,
459 const GURL& opener_url, 475 const GURL& opener_url,
460 const GURL& opener_top_level_frame_url, 476 const GURL& opener_top_level_frame_url,
461 const GURL& source_origin, 477 const GURL& source_origin,
462 content::mojom::WindowContainerType container_type, 478 content::mojom::WindowContainerType container_type,
463 const GURL& target_url, 479 const GURL& target_url,
464 const content::Referrer& referrer, 480 const content::Referrer& referrer,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 process_type, dumps_path, false /* upload */); 588 process_type, dumps_path, false /* upload */);
573 // StartUploaderThread() even though upload is diferred. 589 // StartUploaderThread() even though upload is diferred.
574 // Breakpad-related memory is freed in the uploader thread. 590 // Breakpad-related memory is freed in the uploader thread.
575 crash_handler->StartUploaderThread(); 591 crash_handler->StartUploaderThread();
576 return crash_handler; 592 return crash_handler;
577 } 593 }
578 #endif // !defined(OS_ANDROID) 594 #endif // !defined(OS_ANDROID)
579 595
580 } // namespace shell 596 } // namespace shell
581 } // namespace chromecast 597 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/browser/cast_content_browser_client.h ('k') | chromecast/browser/cast_network_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698