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

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

Powered by Google App Engine
This is Rietveld 408576698