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

Side by Side Diff: chrome/browser/ssl/ssl_client_auth_observer.cc

Issue 1304143010: Plumbing SSLPrivateKey Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 3 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 "chrome/browser/ssl/ssl_client_auth_observer.h" 5 #include "chrome/browser/ssl/ssl_client_auth_observer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/client_certificate_delegate.h" 13 #include "content/public/browser/client_certificate_delegate.h"
14 #include "content/public/browser/notification_service.h" 14 #include "content/public/browser/notification_service.h"
15 #include "net/cert/x509_certificate.h" 15 #include "net/cert/x509_certificate.h"
16 #include "net/ssl/ssl_cert_request_info.h" 16 #include "net/ssl/ssl_cert_request_info.h"
17 #include "net/ssl/ssl_platform_key.h"
18 #include "net/ssl/ssl_private_key.h"
17 19
18 using content::BrowserThread; 20 using content::BrowserThread;
19 21
20 typedef std::pair<net::SSLCertRequestInfo*, net::X509Certificate*> CertDetails; 22 typedef std::pair<net::SSLCertRequestInfo*, net::X509Certificate*> CertDetails;
21 23
22 SSLClientAuthObserver::SSLClientAuthObserver( 24 SSLClientAuthObserver::SSLClientAuthObserver(
23 const content::BrowserContext* browser_context, 25 const content::BrowserContext* browser_context,
24 const scoped_refptr<net::SSLCertRequestInfo>& cert_request_info, 26 const scoped_refptr<net::SSLCertRequestInfo>& cert_request_info,
25 scoped_ptr<content::ClientCertificateDelegate> delegate) 27 scoped_ptr<content::ClientCertificateDelegate> delegate)
26 : browser_context_(browser_context), 28 : browser_context_(browser_context),
(...skipping 15 matching lines...) Expand all
42 44
43 CertDetails details; 45 CertDetails details;
44 details.first = cert_request_info_.get(); 46 details.first = cert_request_info_.get();
45 details.second = certificate; 47 details.second = certificate;
46 content::NotificationService* service = 48 content::NotificationService* service =
47 content::NotificationService::current(); 49 content::NotificationService::current();
48 service->Notify(chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED, 50 service->Notify(chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED,
49 content::Source<content::BrowserContext>(browser_context_), 51 content::Source<content::BrowserContext>(browser_context_),
50 content::Details<CertDetails>(&details)); 52 content::Details<CertDetails>(&details));
51 53
52 delegate_->ContinueWithCertificate(certificate); 54 scoped_refptr<net::SSLPrivateKey> pkey =
55 FetchClientCertPrivateKey(certificate);
davidben 2015/09/25 20:10:11 [See comment at top of review. If I forget to type
svaldez 2015/09/28 16:54:52 Acknowledged.
56
57 delegate_->ContinueWithCertificate(certificate, pkey.get());
53 delegate_.reset(); 58 delegate_.reset();
54 } 59 }
55 60
56 void SSLClientAuthObserver::CancelCertificateSelection() { 61 void SSLClientAuthObserver::CancelCertificateSelection() {
57 if (!delegate_) 62 if (!delegate_)
58 return; 63 return;
59 64
60 // Stop observing now that the delegate has been resolved. 65 // Stop observing now that the delegate has been resolved.
61 StopObserving(); 66 StopObserving();
62 delegate_.reset(); 67 delegate_.reset();
63 } 68 }
64 69
65 void SSLClientAuthObserver::Observe( 70 void SSLClientAuthObserver::Observe(
66 int type, 71 int type,
67 const content::NotificationSource& source, 72 const content::NotificationSource& source,
68 const content::NotificationDetails& details) { 73 const content::NotificationDetails& details) {
69 DVLOG(1) << "SSLClientAuthObserver::Observe " << this; 74 DVLOG(1) << "SSLClientAuthObserver::Observe " << this;
70 DCHECK_CURRENTLY_ON(BrowserThread::UI); 75 DCHECK_CURRENTLY_ON(BrowserThread::UI);
71 DCHECK(type == chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED); 76 DCHECK(type == chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED);
72 77
73 CertDetails* cert_details = content::Details<CertDetails>(details).ptr(); 78 CertDetails* cert_details = content::Details<CertDetails>(details).ptr();
74 if (!cert_details->first->host_and_port.Equals( 79 if (!cert_details->first->host_and_port.Equals(
75 cert_request_info_->host_and_port)) 80 cert_request_info_->host_and_port))
76 return; 81 return;
77 82
78 DVLOG(1) << this << " got matching notification and selecting cert " 83 DVLOG(1) << this << " got matching notification and selecting cert "
79 << cert_details->second; 84 << cert_details->second;
80 StopObserving(); 85 StopObserving();
81 delegate_->ContinueWithCertificate(cert_details->second); 86
87 scoped_refptr<net::SSLPrivateKey> pkey =
88 FetchClientCertPrivateKey(cert_details->second);
89
90 delegate_->ContinueWithCertificate(cert_details->second, pkey.get());
82 delegate_.reset(); 91 delegate_.reset();
83 OnCertSelectedByNotification(); 92 OnCertSelectedByNotification();
84 } 93 }
85 94
86 void SSLClientAuthObserver::StartObserving() { 95 void SSLClientAuthObserver::StartObserving() {
87 DCHECK_CURRENTLY_ON(BrowserThread::UI); 96 DCHECK_CURRENTLY_ON(BrowserThread::UI);
88 notification_registrar_.Add( 97 notification_registrar_.Add(
89 this, chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED, 98 this, chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED,
90 content::Source<content::BrowserContext>(browser_context_)); 99 content::Source<content::BrowserContext>(browser_context_));
91 } 100 }
92 101
93 void SSLClientAuthObserver::StopObserving() { 102 void SSLClientAuthObserver::StopObserving() {
94 DCHECK_CURRENTLY_ON(BrowserThread::UI); 103 DCHECK_CURRENTLY_ON(BrowserThread::UI);
95 notification_registrar_.RemoveAll(); 104 notification_registrar_.RemoveAll();
96 } 105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698