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

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

Issue 2898573002: Refactor client cert private key handling. (Closed)
Patch Set: missing include Created 3 years, 6 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 <tuple>
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_private_key.h"
17 18
18 using content::BrowserThread; 19 using content::BrowserThread;
19 20
20 typedef std::pair<net::SSLCertRequestInfo*, net::X509Certificate*> CertDetails; 21 typedef std::
22 tuple<net::SSLCertRequestInfo*, net::X509Certificate*, net::SSLPrivateKey*>
23 CertDetails;
davidben 2017/06/07 23:06:16 Style nit: using CertDetails = ...;
mattm 2017/06/08 21:47:55 Done.
21 24
22 SSLClientAuthObserver::SSLClientAuthObserver( 25 SSLClientAuthObserver::SSLClientAuthObserver(
23 const content::BrowserContext* browser_context, 26 const content::BrowserContext* browser_context,
24 const scoped_refptr<net::SSLCertRequestInfo>& cert_request_info, 27 const scoped_refptr<net::SSLCertRequestInfo>& cert_request_info,
25 std::unique_ptr<content::ClientCertificateDelegate> delegate) 28 std::unique_ptr<content::ClientCertificateDelegate> delegate)
26 : browser_context_(browser_context), 29 : browser_context_(browser_context),
27 cert_request_info_(cert_request_info), 30 cert_request_info_(cert_request_info),
28 delegate_(std::move(delegate)) {} 31 delegate_(std::move(delegate)) {}
29 32
30 SSLClientAuthObserver::~SSLClientAuthObserver() { 33 SSLClientAuthObserver::~SSLClientAuthObserver() {
31 } 34 }
32 35
33 void SSLClientAuthObserver::CertificateSelected( 36 void SSLClientAuthObserver::CertificateSelected(
34 net::X509Certificate* certificate) { 37 net::X509Certificate* certificate,
38 net::SSLPrivateKey* private_key) {
35 if (!delegate_) 39 if (!delegate_)
36 return; 40 return;
37 41
38 // Stop listening now that the delegate has been resolved. This is also to 42 // Stop listening now that the delegate has been resolved. This is also to
39 // avoid getting a self-notification. 43 // avoid getting a self-notification.
40 StopObserving(); 44 StopObserving();
41 45
42 CertDetails details; 46 CertDetails details(cert_request_info_.get(), certificate, private_key);
43 details.first = cert_request_info_.get();
44 details.second = certificate;
45 content::NotificationService* service = 47 content::NotificationService* service =
46 content::NotificationService::current(); 48 content::NotificationService::current();
47 service->Notify(chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED, 49 service->Notify(chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED,
48 content::Source<content::BrowserContext>(browser_context_), 50 content::Source<content::BrowserContext>(browser_context_),
49 content::Details<CertDetails>(&details)); 51 content::Details<CertDetails>(&details));
50 52
51 delegate_->ContinueWithCertificate(certificate); 53 delegate_->ContinueWithCertificate(certificate, private_key);
52 delegate_.reset(); 54 delegate_.reset();
53 } 55 }
54 56
55 void SSLClientAuthObserver::CancelCertificateSelection() { 57 void SSLClientAuthObserver::CancelCertificateSelection() {
56 if (!delegate_) 58 if (!delegate_)
57 return; 59 return;
58 60
59 // Stop observing now that the delegate has been resolved. 61 // Stop observing now that the delegate has been resolved.
60 StopObserving(); 62 StopObserving();
61 delegate_.reset(); 63 delegate_.reset();
62 } 64 }
63 65
64 void SSLClientAuthObserver::Observe( 66 void SSLClientAuthObserver::Observe(
65 int type, 67 int type,
66 const content::NotificationSource& source, 68 const content::NotificationSource& source,
67 const content::NotificationDetails& details) { 69 const content::NotificationDetails& details) {
68 DVLOG(1) << "SSLClientAuthObserver::Observe " << this; 70 DVLOG(1) << "SSLClientAuthObserver::Observe " << this;
69 DCHECK_CURRENTLY_ON(BrowserThread::UI); 71 DCHECK_CURRENTLY_ON(BrowserThread::UI);
70 DCHECK_EQ(chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED, type); 72 DCHECK_EQ(chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED, type);
71 73
72 CertDetails* cert_details = content::Details<CertDetails>(details).ptr(); 74 CertDetails* cert_details = content::Details<CertDetails>(details).ptr();
73 if (!cert_details->first->host_and_port.Equals( 75 if (!std::get<0>(*cert_details)
74 cert_request_info_->host_and_port)) 76 ->host_and_port.Equals(cert_request_info_->host_and_port))
75 return; 77 return;
76 78
77 DVLOG(1) << this << " got matching notification and selecting cert " 79 DVLOG(1) << this << " got matching notification and selecting cert "
78 << cert_details->second; 80 << std::get<1>(*cert_details);
79 StopObserving(); 81 StopObserving();
80 delegate_->ContinueWithCertificate(cert_details->second); 82 delegate_->ContinueWithCertificate(std::get<1>(*cert_details),
83 std::get<2>(*cert_details));
81 delegate_.reset(); 84 delegate_.reset();
82 OnCertSelectedByNotification(); 85 OnCertSelectedByNotification();
83 } 86 }
84 87
85 void SSLClientAuthObserver::StartObserving() { 88 void SSLClientAuthObserver::StartObserving() {
86 DCHECK_CURRENTLY_ON(BrowserThread::UI); 89 DCHECK_CURRENTLY_ON(BrowserThread::UI);
87 notification_registrar_.Add( 90 notification_registrar_.Add(
88 this, chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED, 91 this, chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED,
89 content::Source<content::BrowserContext>(browser_context_)); 92 content::Source<content::BrowserContext>(browser_context_));
90 } 93 }
91 94
92 void SSLClientAuthObserver::StopObserving() { 95 void SSLClientAuthObserver::StopObserving() {
93 DCHECK_CURRENTLY_ON(BrowserThread::UI); 96 DCHECK_CURRENTLY_ON(BrowserThread::UI);
94 notification_registrar_.RemoveAll(); 97 notification_registrar_.RemoveAll();
95 } 98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698