| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| 11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 12 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/ref_counted.h" |
| 16 #include "chrome/browser/ssl/ssl_client_certificate_selector.h" | 17 #include "chrome/browser/ssl/ssl_client_certificate_selector.h" |
| 17 #include "chrome/browser/ui/android/view_android_helper.h" | 18 #include "chrome/browser/ui/android/view_android_helper.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/client_certificate_delegate.h" | 20 #include "content/public/browser/client_certificate_delegate.h" |
| 20 #include "crypto/scoped_openssl_types.h" | 21 #include "crypto/scoped_openssl_types.h" |
| 21 #include "jni/SSLClientCertificateRequest_jni.h" | 22 #include "jni/SSLClientCertificateRequest_jni.h" |
| 22 #include "net/android/keystore_openssl.h" | |
| 23 #include "net/base/host_port_pair.h" | 23 #include "net/base/host_port_pair.h" |
| 24 #include "net/cert/cert_database.h" | 24 #include "net/cert/cert_database.h" |
| 25 #include "net/cert/x509_certificate.h" | 25 #include "net/cert/x509_certificate.h" |
| 26 #include "net/ssl/openssl_client_key_store.h" | 26 #include "net/ssl/openssl_client_key_store.h" |
| 27 #include "net/ssl/ssl_cert_request_info.h" | 27 #include "net/ssl/ssl_cert_request_info.h" |
| 28 #include "net/ssl/ssl_client_cert_type.h" | 28 #include "net/ssl/ssl_client_cert_type.h" |
| 29 #include "net/ssl/ssl_platform_key_android.h" |
| 30 #include "net/ssl/ssl_private_key.h" |
| 29 #include "ui/android/view_android.h" | 31 #include "ui/android/view_android.h" |
| 30 #include "ui/android/window_android.h" | 32 #include "ui/android/window_android.h" |
| 31 | 33 |
| 32 using base::android::JavaParamRef; | 34 using base::android::JavaParamRef; |
| 33 using base::android::ScopedJavaLocalRef; | 35 using base::android::ScopedJavaLocalRef; |
| 34 | 36 |
| 35 namespace chrome { | 37 namespace chrome { |
| 36 | 38 |
| 37 namespace { | 39 namespace { |
| 38 | 40 |
| 39 // Must be called on the I/O thread to record a client certificate | 41 // Must be called on the I/O thread to record a client certificate |
| 40 // and its private key in the OpenSSLClientKeyStore. | 42 // and its private key in the OpenSSLClientKeyStore. |
| 41 void RecordClientCertificateKey( | 43 void RecordClientCertificateKey(net::X509Certificate* client_cert, |
| 42 const scoped_refptr<net::X509Certificate>& client_cert, | 44 scoped_refptr<net::SSLPrivateKey> private_key) { |
| 43 crypto::ScopedEVP_PKEY private_key) { | |
| 44 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 45 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 45 net::OpenSSLClientKeyStore::GetInstance()->RecordClientCertPrivateKey( | 46 net::OpenSSLClientKeyStore::GetInstance()->RecordClientCertPrivateKey( |
| 46 client_cert.get(), private_key.get()); | 47 client_cert, std::move(private_key)); |
| 47 } | 48 } |
| 48 | 49 |
| 49 void StartClientCertificateRequest( | 50 void StartClientCertificateRequest( |
| 50 const net::SSLCertRequestInfo* cert_request_info, | 51 const net::SSLCertRequestInfo* cert_request_info, |
| 51 ui::WindowAndroid* window, | 52 ui::WindowAndroid* window, |
| 52 std::unique_ptr<content::ClientCertificateDelegate> delegate) { | 53 std::unique_ptr<content::ClientCertificateDelegate> delegate) { |
| 53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 54 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 54 | 55 |
| 55 // Build the |key_types| JNI parameter, as a String[] | 56 // Build the |key_types| JNI parameter, as a String[] |
| 56 std::vector<std::string> key_types; | 57 std::vector<std::string> key_types; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 153 |
| 153 // Create the X509Certificate object from the encoded chain. | 154 // Create the X509Certificate object from the encoded chain. |
| 154 scoped_refptr<net::X509Certificate> client_cert( | 155 scoped_refptr<net::X509Certificate> client_cert( |
| 155 net::X509Certificate::CreateFromDERCertChain(encoded_chain)); | 156 net::X509Certificate::CreateFromDERCertChain(encoded_chain)); |
| 156 if (!client_cert.get()) { | 157 if (!client_cert.get()) { |
| 157 LOG(ERROR) << "Could not decode client certificate chain"; | 158 LOG(ERROR) << "Could not decode client certificate chain"; |
| 158 return; | 159 return; |
| 159 } | 160 } |
| 160 | 161 |
| 161 // Create an EVP_PKEY wrapper for the private key JNI reference. | 162 // Create an EVP_PKEY wrapper for the private key JNI reference. |
| 162 crypto::ScopedEVP_PKEY private_key( | 163 scoped_refptr<net::SSLPrivateKey> private_key = |
| 163 net::android::GetOpenSSLPrivateKeyWrapper(private_key_ref)); | 164 net::WrapJavaPrivateKey(private_key_ref); |
| 164 if (!private_key.get()) { | 165 if (!private_key.get()) { |
| 165 LOG(ERROR) << "Could not create OpenSSL wrapper for private key"; | 166 LOG(ERROR) << "Could not create OpenSSL wrapper for private key"; |
| 166 return; | 167 return; |
| 167 } | 168 } |
| 168 | 169 |
| 169 // RecordClientCertificateKey() must be called on the I/O thread, | 170 // RecordClientCertificateKey() must be called on the I/O thread, |
| 170 // before the callback is called with the selected certificate on | 171 // before the callback is called with the selected certificate on |
| 171 // the UI thread. | 172 // the UI thread. |
| 172 content::BrowserThread::PostTaskAndReply( | 173 content::BrowserThread::PostTaskAndReply( |
| 173 content::BrowserThread::IO, FROM_HERE, | 174 content::BrowserThread::IO, FROM_HERE, |
| 174 base::Bind(&RecordClientCertificateKey, client_cert, | 175 base::Bind(&RecordClientCertificateKey, base::RetainedRef(client_cert), |
| 175 base::Passed(&private_key)), | 176 base::Passed(&private_key)), |
| 176 base::Bind(&content::ClientCertificateDelegate::ContinueWithCertificate, | 177 base::Bind(&content::ClientCertificateDelegate::ContinueWithCertificate, |
| 177 base::Owned(delegate.release()), | 178 base::Owned(delegate.release()), |
| 178 base::RetainedRef(client_cert))); | 179 base::RetainedRef(client_cert))); |
| 179 } | 180 } |
| 180 | 181 |
| 181 static void NotifyClientCertificatesChanged() { | 182 static void NotifyClientCertificatesChanged() { |
| 182 net::CertDatabase::GetInstance()->OnAndroidKeyStoreChanged(); | 183 net::CertDatabase::GetInstance()->OnAndroidKeyStoreChanged(); |
| 183 } | 184 } |
| 184 | 185 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 206 net::SSLCertRequestInfo* cert_request_info, | 207 net::SSLCertRequestInfo* cert_request_info, |
| 207 std::unique_ptr<content::ClientCertificateDelegate> delegate) { | 208 std::unique_ptr<content::ClientCertificateDelegate> delegate) { |
| 208 ui::WindowAndroid* window = ViewAndroidHelper::FromWebContents(contents) | 209 ui::WindowAndroid* window = ViewAndroidHelper::FromWebContents(contents) |
| 209 ->GetViewAndroid()->GetWindowAndroid(); | 210 ->GetViewAndroid()->GetWindowAndroid(); |
| 210 DCHECK(window); | 211 DCHECK(window); |
| 211 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 212 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 212 StartClientCertificateRequest(cert_request_info, window, std::move(delegate)); | 213 StartClientCertificateRequest(cert_request_info, window, std::move(delegate)); |
| 213 } | 214 } |
| 214 | 215 |
| 215 } // namespace chrome | 216 } // namespace chrome |
| OLD | NEW |