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