OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/ui/android/ssl_client_certificate_request.h" | 5 #include "chrome/browser/ui/android/ssl_client_certificate_request.h" |
6 | 6 |
7 #include "base/android/jni_array.h" | 7 #include "base/android/jni_array.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "chrome/browser/ssl/ssl_client_certificate_selector.h" | 15 #include "chrome/browser/ssl/ssl_client_certificate_selector.h" |
| 16 #include "chrome/browser/ui/android/window_android_helper.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 #include "jni/SSLClientCertificateRequest_jni.h" | 18 #include "jni/SSLClientCertificateRequest_jni.h" |
18 #include "net/android/keystore_openssl.h" | 19 #include "net/android/keystore_openssl.h" |
19 #include "net/base/host_port_pair.h" | 20 #include "net/base/host_port_pair.h" |
20 #include "net/cert/cert_database.h" | 21 #include "net/cert/cert_database.h" |
21 #include "net/cert/x509_certificate.h" | 22 #include "net/cert/x509_certificate.h" |
22 #include "net/ssl/openssl_client_key_store.h" | 23 #include "net/ssl/openssl_client_key_store.h" |
23 #include "net/ssl/ssl_cert_request_info.h" | 24 #include "net/ssl/ssl_cert_request_info.h" |
24 #include "net/ssl/ssl_client_cert_type.h" | 25 #include "net/ssl/ssl_client_cert_type.h" |
| 26 #include "ui/base/android/window_android.h" |
25 | 27 |
26 | 28 |
27 namespace chrome { | 29 namespace chrome { |
28 | 30 |
29 namespace { | 31 namespace { |
30 | 32 |
31 typedef net::OpenSSLClientKeyStore::ScopedEVP_PKEY ScopedEVP_PKEY; | 33 typedef net::OpenSSLClientKeyStore::ScopedEVP_PKEY ScopedEVP_PKEY; |
32 | 34 |
33 // Must be called on the I/O thread to record a client certificate | 35 // Must be called on the I/O thread to record a client certificate |
34 // and its private key in the OpenSSLClientKeyStore. | 36 // and its private key in the OpenSSLClientKeyStore. |
35 void RecordClientCertificateKey( | 37 void RecordClientCertificateKey( |
36 const scoped_refptr<net::X509Certificate>& client_cert, | 38 const scoped_refptr<net::X509Certificate>& client_cert, |
37 ScopedEVP_PKEY private_key) { | 39 ScopedEVP_PKEY private_key) { |
38 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 40 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
39 net::OpenSSLClientKeyStore::GetInstance()->RecordClientCertPrivateKey( | 41 net::OpenSSLClientKeyStore::GetInstance()->RecordClientCertPrivateKey( |
40 client_cert.get(), private_key.get()); | 42 client_cert.get(), private_key.get()); |
41 } | 43 } |
42 | 44 |
43 void StartClientCertificateRequest( | 45 void StartClientCertificateRequest( |
44 const net::SSLCertRequestInfo* cert_request_info, | 46 const net::SSLCertRequestInfo* cert_request_info, |
| 47 ui::WindowAndroid* window, |
45 const chrome::SelectCertificateCallback& callback) { | 48 const chrome::SelectCertificateCallback& callback) { |
46 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 49 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
47 | 50 |
48 // Ensure that callback(NULL) is posted as a task on the UI thread | 51 // Ensure that callback(NULL) is posted as a task on the UI thread |
49 // in case of an error. | 52 // in case of an error. |
50 base::Closure post_task_closure = base::Bind( | 53 base::Closure post_task_closure = base::Bind( |
51 base::IgnoreResult(&content::BrowserThread::PostTask), | 54 base::IgnoreResult(&content::BrowserThread::PostTask), |
52 content::BrowserThread::UI, | 55 content::BrowserThread::UI, |
53 FROM_HERE, | 56 FROM_HERE, |
54 base::Bind(callback, scoped_refptr<net::X509Certificate>())); | 57 base::Bind(callback, scoped_refptr<net::X509Certificate>())); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 102 |
100 // Create a copy of the callback on the heap so that its address | 103 // Create a copy of the callback on the heap so that its address |
101 // and ownership can be passed through and returned from Java via JNI. | 104 // and ownership can be passed through and returned from Java via JNI. |
102 scoped_ptr<chrome::SelectCertificateCallback> request( | 105 scoped_ptr<chrome::SelectCertificateCallback> request( |
103 new chrome::SelectCertificateCallback(callback)); | 106 new chrome::SelectCertificateCallback(callback)); |
104 | 107 |
105 jint request_id = reinterpret_cast<jint>(request.get()); | 108 jint request_id = reinterpret_cast<jint>(request.get()); |
106 | 109 |
107 if (!chrome::android:: | 110 if (!chrome::android:: |
108 Java_SSLClientCertificateRequest_selectClientCertificate( | 111 Java_SSLClientCertificateRequest_selectClientCertificate( |
109 env, request_id, key_types_ref.obj(), principals_ref.obj(), | 112 env, |
110 host_name_ref.obj(), cert_request_info->host_and_port.port())) { | 113 request_id, |
| 114 window->GetJavaObject().obj(), |
| 115 key_types_ref.obj(), |
| 116 principals_ref.obj(), |
| 117 host_name_ref.obj(), |
| 118 cert_request_info->host_and_port.port())) { |
111 return; | 119 return; |
112 } | 120 } |
113 | 121 |
114 ignore_result(guard.Release()); | 122 ignore_result(guard.Release()); |
115 | 123 |
116 // Ownership was transferred to Java. | 124 // Ownership was transferred to Java. |
117 chrome::SelectCertificateCallback* ALLOW_UNUSED dummy = | 125 chrome::SelectCertificateCallback* ALLOW_UNUSED dummy = |
118 request.release(); | 126 request.release(); |
119 } | 127 } |
120 | 128 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 return RegisterNativesImpl(env); | 224 return RegisterNativesImpl(env); |
217 } | 225 } |
218 | 226 |
219 } // namespace android | 227 } // namespace android |
220 | 228 |
221 void ShowSSLClientCertificateSelector( | 229 void ShowSSLClientCertificateSelector( |
222 content::WebContents* contents, | 230 content::WebContents* contents, |
223 const net::HttpNetworkSession* network_session, | 231 const net::HttpNetworkSession* network_session, |
224 net::SSLCertRequestInfo* cert_request_info, | 232 net::SSLCertRequestInfo* cert_request_info, |
225 const chrome::SelectCertificateCallback& callback) { | 233 const chrome::SelectCertificateCallback& callback) { |
| 234 ui::WindowAndroid* window = |
| 235 WindowAndroidHelper::FromWebContents(contents)->GetWindowAndroid(); |
| 236 DCHECK(window); |
226 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 237 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
227 StartClientCertificateRequest(cert_request_info, callback); | 238 StartClientCertificateRequest(cert_request_info, window, callback); |
228 } | 239 } |
229 | 240 |
230 } // namespace chrome | 241 } // namespace chrome |
OLD | NEW |