Chromium Code Reviews| 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 <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 Loading... | |
| 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> private_key = |
| 55 FetchClientCertPrivateKey(certificate); | |
|
davidben
2015/10/13 20:32:15
net:: prefix. Ugh, I bet this is compiling because
svaldez
2015/10/14 15:06:18
Done.
| |
| 56 | |
| 57 delegate_->ContinueWithCertificate(certificate, private_key.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> private_key = | |
| 88 FetchClientCertPrivateKey(cert_details->second); | |
|
davidben
2015/10/13 20:32:15
(Ditto.)
svaldez
2015/10/14 15:06:18
Done.
| |
| 89 | |
| 90 delegate_->ContinueWithCertificate(cert_details->second, private_key.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 } |
| OLD | NEW |