| 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 "chrome/browser/ui/android/window_android_helper.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "crypto/scoped_openssl_types.h" |
| 18 #include "jni/SSLClientCertificateRequest_jni.h" | 19 #include "jni/SSLClientCertificateRequest_jni.h" |
| 19 #include "net/android/keystore_openssl.h" | 20 #include "net/android/keystore_openssl.h" |
| 20 #include "net/base/host_port_pair.h" | 21 #include "net/base/host_port_pair.h" |
| 21 #include "net/cert/cert_database.h" | 22 #include "net/cert/cert_database.h" |
| 22 #include "net/cert/x509_certificate.h" | 23 #include "net/cert/x509_certificate.h" |
| 23 #include "net/ssl/openssl_client_key_store.h" | 24 #include "net/ssl/openssl_client_key_store.h" |
| 24 #include "net/ssl/ssl_cert_request_info.h" | 25 #include "net/ssl/ssl_cert_request_info.h" |
| 25 #include "net/ssl/ssl_client_cert_type.h" | 26 #include "net/ssl/ssl_client_cert_type.h" |
| 26 #include "ui/base/android/window_android.h" | 27 #include "ui/base/android/window_android.h" |
| 27 | 28 |
| 28 | 29 |
| 29 namespace chrome { | 30 namespace chrome { |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 typedef net::OpenSSLClientKeyStore::ScopedEVP_PKEY ScopedEVP_PKEY; | |
| 34 | |
| 35 // Must be called on the I/O thread to record a client certificate | 34 // Must be called on the I/O thread to record a client certificate |
| 36 // and its private key in the OpenSSLClientKeyStore. | 35 // and its private key in the OpenSSLClientKeyStore. |
| 37 void RecordClientCertificateKey( | 36 void RecordClientCertificateKey( |
| 38 const scoped_refptr<net::X509Certificate>& client_cert, | 37 const scoped_refptr<net::X509Certificate>& client_cert, |
| 39 ScopedEVP_PKEY private_key) { | 38 crypto::ScopedEVP_PKEY private_key) { |
| 40 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 39 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 41 net::OpenSSLClientKeyStore::GetInstance()->RecordClientCertPrivateKey( | 40 net::OpenSSLClientKeyStore::GetInstance()->RecordClientCertPrivateKey( |
| 42 client_cert.get(), private_key.get()); | 41 client_cert.get(), private_key.get()); |
| 43 } | 42 } |
| 44 | 43 |
| 45 void StartClientCertificateRequest( | 44 void StartClientCertificateRequest( |
| 46 const net::SSLCertRequestInfo* cert_request_info, | 45 const net::SSLCertRequestInfo* cert_request_info, |
| 47 ui::WindowAndroid* window, | 46 ui::WindowAndroid* window, |
| 48 const chrome::SelectCertificateCallback& callback) { | 47 const chrome::SelectCertificateCallback& callback) { |
| 49 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 48 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 176 |
| 178 // Create the X509Certificate object from the encoded chain. | 177 // Create the X509Certificate object from the encoded chain. |
| 179 scoped_refptr<net::X509Certificate> client_cert( | 178 scoped_refptr<net::X509Certificate> client_cert( |
| 180 net::X509Certificate::CreateFromDERCertChain(encoded_chain)); | 179 net::X509Certificate::CreateFromDERCertChain(encoded_chain)); |
| 181 if (!client_cert.get()) { | 180 if (!client_cert.get()) { |
| 182 LOG(ERROR) << "Could not decode client certificate chain"; | 181 LOG(ERROR) << "Could not decode client certificate chain"; |
| 183 return; | 182 return; |
| 184 } | 183 } |
| 185 | 184 |
| 186 // Create an EVP_PKEY wrapper for the private key JNI reference. | 185 // Create an EVP_PKEY wrapper for the private key JNI reference. |
| 187 ScopedEVP_PKEY private_key( | 186 crypto::ScopedEVP_PKEY private_key( |
| 188 net::android::GetOpenSSLPrivateKeyWrapper(private_key_ref)); | 187 net::android::GetOpenSSLPrivateKeyWrapper(private_key_ref)); |
| 189 if (!private_key.get()) { | 188 if (!private_key.get()) { |
| 190 LOG(ERROR) << "Could not create OpenSSL wrapper for private key"; | 189 LOG(ERROR) << "Could not create OpenSSL wrapper for private key"; |
| 191 return; | 190 return; |
| 192 } | 191 } |
| 193 | 192 |
| 194 ignore_result(guard.Release()); | 193 ignore_result(guard.Release()); |
| 195 | 194 |
| 196 // RecordClientCertificateKey() must be called on the I/O thread, | 195 // RecordClientCertificateKey() must be called on the I/O thread, |
| 197 // before the callback is called with the selected certificate on | 196 // before the callback is called with the selected certificate on |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 net::SSLCertRequestInfo* cert_request_info, | 231 net::SSLCertRequestInfo* cert_request_info, |
| 233 const chrome::SelectCertificateCallback& callback) { | 232 const chrome::SelectCertificateCallback& callback) { |
| 234 ui::WindowAndroid* window = | 233 ui::WindowAndroid* window = |
| 235 WindowAndroidHelper::FromWebContents(contents)->GetWindowAndroid(); | 234 WindowAndroidHelper::FromWebContents(contents)->GetWindowAndroid(); |
| 236 DCHECK(window); | 235 DCHECK(window); |
| 237 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 236 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 238 StartClientCertificateRequest(cert_request_info, window, callback); | 237 StartClientCertificateRequest(cert_request_info, window, callback); |
| 239 } | 238 } |
| 240 | 239 |
| 241 } // namespace chrome | 240 } // namespace chrome |
| OLD | NEW |