| 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/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "chrome/browser/ssl/ssl_client_certificate_selector.h" | 15 #include "chrome/browser/ssl/ssl_client_certificate_selector.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "jni/SSLClientCertificateRequest_jni.h" | 17 #include "jni/SSLClientCertificateRequest_jni.h" |
| 17 #include "net/android/keystore_openssl.h" | 18 #include "net/android/keystore_openssl.h" |
| 18 #include "net/base/host_port_pair.h" | 19 #include "net/base/host_port_pair.h" |
| 19 #include "net/cert/x509_certificate.h" | 20 #include "net/cert/x509_certificate.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 | 109 |
| 109 jint request_id = reinterpret_cast<jint>(request.get()); | 110 jint request_id = reinterpret_cast<jint>(request.get()); |
| 110 | 111 |
| 111 if (!chrome::android:: | 112 if (!chrome::android:: |
| 112 Java_SSLClientCertificateRequest_selectClientCertificate( | 113 Java_SSLClientCertificateRequest_selectClientCertificate( |
| 113 env, request_id, key_types_ref.obj(), principals_ref.obj(), | 114 env, request_id, key_types_ref.obj(), principals_ref.obj(), |
| 114 host_name_ref.obj(), host_and_port.port())) { | 115 host_name_ref.obj(), host_and_port.port())) { |
| 115 return; | 116 return; |
| 116 } | 117 } |
| 117 | 118 |
| 118 guard.Release(); | 119 ignore_result(guard.Release()); |
| 119 | 120 |
| 120 // Ownership was transferred to Java. | 121 // Ownership was transferred to Java. |
| 121 chrome::SelectCertificateCallback* ALLOW_UNUSED dummy = | 122 chrome::SelectCertificateCallback* ALLOW_UNUSED dummy = |
| 122 request.release(); | 123 request.release(); |
| 123 } | 124 } |
| 124 | 125 |
| 125 } // namespace | 126 } // namespace |
| 126 | 127 |
| 127 namespace android { | 128 namespace android { |
| 128 | 129 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 } | 181 } |
| 181 | 182 |
| 182 // Create an EVP_PKEY wrapper for the private key JNI reference. | 183 // Create an EVP_PKEY wrapper for the private key JNI reference. |
| 183 ScopedEVP_PKEY private_key( | 184 ScopedEVP_PKEY private_key( |
| 184 net::android::GetOpenSSLPrivateKeyWrapper(private_key_ref)); | 185 net::android::GetOpenSSLPrivateKeyWrapper(private_key_ref)); |
| 185 if (!private_key.get()) { | 186 if (!private_key.get()) { |
| 186 LOG(ERROR) << "Could not create OpenSSL wrapper for private key"; | 187 LOG(ERROR) << "Could not create OpenSSL wrapper for private key"; |
| 187 return; | 188 return; |
| 188 } | 189 } |
| 189 | 190 |
| 190 guard.Release(); | 191 ignore_result(guard.Release()); |
| 191 | 192 |
| 192 // RecordClientCertificateKey() must be called on the I/O thread, | 193 // RecordClientCertificateKey() must be called on the I/O thread, |
| 193 // before the callback is called with the selected certificate on | 194 // before the callback is called with the selected certificate on |
| 194 // the UI thread. | 195 // the UI thread. |
| 195 content::BrowserThread::PostTaskAndReply( | 196 content::BrowserThread::PostTaskAndReply( |
| 196 content::BrowserThread::IO, | 197 content::BrowserThread::IO, |
| 197 FROM_HERE, | 198 FROM_HERE, |
| 198 base::Bind(&RecordClientCertificateKey, | 199 base::Bind(&RecordClientCertificateKey, |
| 199 client_cert, | 200 client_cert, |
| 200 base::Passed(&private_key)), | 201 base::Passed(&private_key)), |
| 201 base::Bind(*callback, client_cert)); | 202 base::Bind(*callback, client_cert)); |
| 202 } | 203 } |
| 203 | 204 |
| 204 bool RegisterSSLClientCertificateRequestAndroid(JNIEnv* env) { | 205 bool RegisterSSLClientCertificateRequestAndroid(JNIEnv* env) { |
| 205 return RegisterNativesImpl(env); | 206 return RegisterNativesImpl(env); |
| 206 } | 207 } |
| 207 | 208 |
| 208 } // namespace android | 209 } // namespace android |
| 209 | 210 |
| 210 void ShowSSLClientCertificateSelector( | 211 void ShowSSLClientCertificateSelector( |
| 211 content::WebContents* contents, | 212 content::WebContents* contents, |
| 212 const net::HttpNetworkSession* network_session, | 213 const net::HttpNetworkSession* network_session, |
| 213 net::SSLCertRequestInfo* cert_request_info, | 214 net::SSLCertRequestInfo* cert_request_info, |
| 214 const chrome::SelectCertificateCallback& callback) { | 215 const chrome::SelectCertificateCallback& callback) { |
| 215 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 216 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 216 StartClientCertificateRequest(cert_request_info, callback); | 217 StartClientCertificateRequest(cert_request_info, callback); |
| 217 } | 218 } |
| 218 | 219 |
| 219 } // namespace chrome | 220 } // namespace chrome |
| OLD | NEW |