| 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 14 matching lines...) Expand all Loading... |
| 41 | 43 |
| 42 CertDetails details; | 44 CertDetails details; |
| 43 details.first = cert_request_info_.get(); | 45 details.first = cert_request_info_.get(); |
| 44 details.second = certificate; | 46 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 scoped_refptr<net::SSLPrivateKey> private_key; |
| 54 |
| 55 if (certificate) |
| 56 private_key = net::FetchClientCertPrivateKey(certificate); |
| 57 |
| 58 delegate_->ContinueWithCertificate(certificate, private_key.get()); |
| 52 delegate_.reset(); | 59 delegate_.reset(); |
| 53 } | 60 } |
| 54 | 61 |
| 55 void SSLClientAuthObserver::CancelCertificateSelection() { | 62 void SSLClientAuthObserver::CancelCertificateSelection() { |
| 56 if (!delegate_) | 63 if (!delegate_) |
| 57 return; | 64 return; |
| 58 | 65 |
| 59 // Stop observing now that the delegate has been resolved. | 66 // Stop observing now that the delegate has been resolved. |
| 60 StopObserving(); | 67 StopObserving(); |
| 61 delegate_.reset(); | 68 delegate_.reset(); |
| 62 } | 69 } |
| 63 | 70 |
| 64 void SSLClientAuthObserver::Observe( | 71 void SSLClientAuthObserver::Observe( |
| 65 int type, | 72 int type, |
| 66 const content::NotificationSource& source, | 73 const content::NotificationSource& source, |
| 67 const content::NotificationDetails& details) { | 74 const content::NotificationDetails& details) { |
| 68 DVLOG(1) << "SSLClientAuthObserver::Observe " << this; | 75 DVLOG(1) << "SSLClientAuthObserver::Observe " << this; |
| 69 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 76 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 70 DCHECK(type == chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED); | 77 DCHECK(type == chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED); |
| 71 | 78 |
| 72 CertDetails* cert_details = content::Details<CertDetails>(details).ptr(); | 79 CertDetails* cert_details = content::Details<CertDetails>(details).ptr(); |
| 73 if (!cert_details->first->host_and_port.Equals( | 80 if (!cert_details->first->host_and_port.Equals( |
| 74 cert_request_info_->host_and_port)) | 81 cert_request_info_->host_and_port)) |
| 75 return; | 82 return; |
| 76 | 83 |
| 77 DVLOG(1) << this << " got matching notification and selecting cert " | 84 DVLOG(1) << this << " got matching notification and selecting cert " |
| 78 << cert_details->second; | 85 << cert_details->second; |
| 79 StopObserving(); | 86 StopObserving(); |
| 80 delegate_->ContinueWithCertificate(cert_details->second); | 87 |
| 88 scoped_refptr<net::SSLPrivateKey> private_key; |
| 89 |
| 90 if (cert_details->second) |
| 91 private_key = net::FetchClientCertPrivateKey(cert_details->second); |
| 92 |
| 93 delegate_->ContinueWithCertificate(cert_details->second, private_key.get()); |
| 81 delegate_.reset(); | 94 delegate_.reset(); |
| 82 OnCertSelectedByNotification(); | 95 OnCertSelectedByNotification(); |
| 83 } | 96 } |
| 84 | 97 |
| 85 void SSLClientAuthObserver::StartObserving() { | 98 void SSLClientAuthObserver::StartObserving() { |
| 86 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 99 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 87 notification_registrar_.Add( | 100 notification_registrar_.Add( |
| 88 this, chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED, | 101 this, chrome::NOTIFICATION_SSL_CLIENT_AUTH_CERT_SELECTED, |
| 89 content::Source<content::BrowserContext>(browser_context_)); | 102 content::Source<content::BrowserContext>(browser_context_)); |
| 90 } | 103 } |
| 91 | 104 |
| 92 void SSLClientAuthObserver::StopObserving() { | 105 void SSLClientAuthObserver::StopObserving() { |
| 93 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 106 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 94 notification_registrar_.RemoveAll(); | 107 notification_registrar_.RemoveAll(); |
| 95 } | 108 } |
| OLD | NEW |