| 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/x509_certificate.h" | 21 #include "net/cert/x509_certificate.h" |
| 21 #include "net/ssl/openssl_client_key_store.h" | 22 #include "net/ssl/openssl_client_key_store.h" |
| 22 #include "net/ssl/ssl_cert_request_info.h" | 23 #include "net/ssl/ssl_cert_request_info.h" |
| 23 #include "net/ssl/ssl_client_cert_type.h" | 24 #include "net/ssl/ssl_client_cert_type.h" |
| 25 #include "ui/base/android/window_android.h" |
| 24 | 26 |
| 25 namespace chrome { | 27 namespace chrome { |
| 26 | 28 |
| 27 namespace { | 29 namespace { |
| 28 | 30 |
| 29 typedef net::OpenSSLClientKeyStore::ScopedEVP_PKEY ScopedEVP_PKEY; | 31 typedef net::OpenSSLClientKeyStore::ScopedEVP_PKEY ScopedEVP_PKEY; |
| 30 | 32 |
| 31 // Must be called on the I/O thread to record a client certificate | 33 // Must be called on the I/O thread to record a client certificate |
| 32 // and its private key in the OpenSSLClientKeyStore. | 34 // and its private key in the OpenSSLClientKeyStore. |
| 33 void RecordClientCertificateKey( | 35 void RecordClientCertificateKey( |
| 34 const scoped_refptr<net::X509Certificate>& client_cert, | 36 const scoped_refptr<net::X509Certificate>& client_cert, |
| 35 ScopedEVP_PKEY private_key) { | 37 ScopedEVP_PKEY private_key) { |
| 36 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 38 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 37 net::OpenSSLClientKeyStore::GetInstance()->RecordClientCertPrivateKey( | 39 net::OpenSSLClientKeyStore::GetInstance()->RecordClientCertPrivateKey( |
| 38 client_cert.get(), private_key.get()); | 40 client_cert.get(), private_key.get()); |
| 39 } | 41 } |
| 40 | 42 |
| 41 void StartClientCertificateRequest( | 43 void StartClientCertificateRequest( |
| 42 const net::SSLCertRequestInfo* cert_request_info, | 44 const net::SSLCertRequestInfo* cert_request_info, |
| 45 ui::WindowAndroid* window, |
| 43 const chrome::SelectCertificateCallback& callback) { | 46 const chrome::SelectCertificateCallback& callback) { |
| 44 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 47 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 45 | 48 |
| 46 // Ensure that callback(NULL) is posted as a task on the UI thread | 49 // Ensure that callback(NULL) is posted as a task on the UI thread |
| 47 // in case of an error. | 50 // in case of an error. |
| 48 base::Closure post_task_closure = base::Bind( | 51 base::Closure post_task_closure = base::Bind( |
| 49 base::IgnoreResult(&content::BrowserThread::PostTask), | 52 base::IgnoreResult(&content::BrowserThread::PostTask), |
| 50 content::BrowserThread::UI, | 53 content::BrowserThread::UI, |
| 51 FROM_HERE, | 54 FROM_HERE, |
| 52 base::Bind(callback, scoped_refptr<net::X509Certificate>())); | 55 base::Bind(callback, scoped_refptr<net::X509Certificate>())); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 100 |
| 98 // Create a copy of the callback on the heap so that its address | 101 // Create a copy of the callback on the heap so that its address |
| 99 // and ownership can be passed through and returned from Java via JNI. | 102 // and ownership can be passed through and returned from Java via JNI. |
| 100 scoped_ptr<chrome::SelectCertificateCallback> request( | 103 scoped_ptr<chrome::SelectCertificateCallback> request( |
| 101 new chrome::SelectCertificateCallback(callback)); | 104 new chrome::SelectCertificateCallback(callback)); |
| 102 | 105 |
| 103 jint request_id = reinterpret_cast<jint>(request.get()); | 106 jint request_id = reinterpret_cast<jint>(request.get()); |
| 104 | 107 |
| 105 if (!chrome::android:: | 108 if (!chrome::android:: |
| 106 Java_SSLClientCertificateRequest_selectClientCertificate( | 109 Java_SSLClientCertificateRequest_selectClientCertificate( |
| 107 env, request_id, key_types_ref.obj(), principals_ref.obj(), | 110 env, |
| 108 host_name_ref.obj(), cert_request_info->host_and_port.port())) { | 111 request_id, |
| 112 window->GetJavaObject().obj(), |
| 113 key_types_ref.obj(), |
| 114 principals_ref.obj(), |
| 115 host_name_ref.obj(), |
| 116 cert_request_info->host_and_port.port())) { |
| 109 return; | 117 return; |
| 110 } | 118 } |
| 111 | 119 |
| 112 ignore_result(guard.Release()); | 120 ignore_result(guard.Release()); |
| 113 | 121 |
| 114 // Ownership was transferred to Java. | 122 // Ownership was transferred to Java. |
| 115 chrome::SelectCertificateCallback* ALLOW_UNUSED dummy = | 123 chrome::SelectCertificateCallback* ALLOW_UNUSED dummy = |
| 116 request.release(); | 124 request.release(); |
| 117 } | 125 } |
| 118 | 126 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 return RegisterNativesImpl(env); | 207 return RegisterNativesImpl(env); |
| 200 } | 208 } |
| 201 | 209 |
| 202 } // namespace android | 210 } // namespace android |
| 203 | 211 |
| 204 void ShowSSLClientCertificateSelector( | 212 void ShowSSLClientCertificateSelector( |
| 205 content::WebContents* contents, | 213 content::WebContents* contents, |
| 206 const net::HttpNetworkSession* network_session, | 214 const net::HttpNetworkSession* network_session, |
| 207 net::SSLCertRequestInfo* cert_request_info, | 215 net::SSLCertRequestInfo* cert_request_info, |
| 208 const chrome::SelectCertificateCallback& callback) { | 216 const chrome::SelectCertificateCallback& callback) { |
| 217 ui::WindowAndroid* window = |
| 218 WindowAndroidHelper::FromWebContents(contents)->GetWindowAndroid(); |
| 219 DCHECK(window); |
| 209 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 220 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 210 StartClientCertificateRequest(cert_request_info, callback); | 221 StartClientCertificateRequest(cert_request_info, window, callback); |
| 211 } | 222 } |
| 212 | 223 |
| 213 } // namespace chrome | 224 } // namespace chrome |
| OLD | NEW |