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 "android_webview/native/aw_contents_client_bridge.h" | 5 #include "android_webview/native/aw_contents_client_bridge.h" |
6 | 6 |
7 #include <utility> | |
8 | |
7 #include "android_webview/common/devtools_instrumentation.h" | 9 #include "android_webview/common/devtools_instrumentation.h" |
8 #include "android_webview/native/aw_contents.h" | 10 #include "android_webview/native/aw_contents.h" |
9 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
10 #include "base/android/jni_array.h" | 12 #include "base/android/jni_array.h" |
11 #include "base/android/jni_string.h" | 13 #include "base/android/jni_string.h" |
12 #include "base/callback_helpers.h" | 14 #include "base/callback_helpers.h" |
13 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | |
14 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/client_certificate_delegate.h" | 18 #include "content/public/browser/client_certificate_delegate.h" |
16 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
17 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
18 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
19 #include "crypto/scoped_openssl_types.h" | 22 #include "crypto/scoped_openssl_types.h" |
20 #include "grit/components_strings.h" | 23 #include "grit/components_strings.h" |
21 #include "jni/AwContentsClientBridge_jni.h" | 24 #include "jni/AwContentsClientBridge_jni.h" |
22 #include "net/android/keystore_openssl.h" | |
23 #include "net/cert/x509_certificate.h" | 25 #include "net/cert/x509_certificate.h" |
24 #include "net/ssl/openssl_client_key_store.h" | 26 #include "net/ssl/openssl_client_key_store.h" |
25 #include "net/ssl/ssl_cert_request_info.h" | 27 #include "net/ssl/ssl_cert_request_info.h" |
26 #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" | |
27 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
28 #include "url/gurl.h" | 32 #include "url/gurl.h" |
29 | 33 |
30 using base::android::AttachCurrentThread; | 34 using base::android::AttachCurrentThread; |
31 using base::android::ConvertJavaStringToUTF16; | 35 using base::android::ConvertJavaStringToUTF16; |
32 using base::android::ConvertUTF8ToJavaString; | 36 using base::android::ConvertUTF8ToJavaString; |
33 using base::android::ConvertUTF16ToJavaString; | 37 using base::android::ConvertUTF16ToJavaString; |
34 using base::android::HasException; | 38 using base::android::HasException; |
35 using base::android::JavaRef; | 39 using base::android::JavaRef; |
36 using base::android::ScopedJavaLocalRef; | 40 using base::android::ScopedJavaLocalRef; |
37 using content::BrowserThread; | 41 using content::BrowserThread; |
38 | 42 |
39 namespace android_webview { | 43 namespace android_webview { |
40 | 44 |
41 namespace { | 45 namespace { |
42 | 46 |
43 // Must be called on the I/O thread to record a client certificate | 47 // Must be called on the I/O thread to record a client certificate |
44 // and its private key in the OpenSSLClientKeyStore. | 48 // and its private key in the OpenSSLClientKeyStore. |
45 void RecordClientCertificateKey( | 49 void RecordClientCertificateKey(net::X509Certificate* client_cert, |
46 const scoped_refptr<net::X509Certificate>& client_cert, | 50 scoped_refptr<net::SSLPrivateKey> private_key) { |
47 crypto::ScopedEVP_PKEY private_key) { | |
48 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 51 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
49 net::OpenSSLClientKeyStore::GetInstance()->RecordClientCertPrivateKey( | 52 net::OpenSSLClientKeyStore::GetInstance()->RecordClientCertPrivateKey( |
50 client_cert.get(), private_key.get()); | 53 client_cert, std::move(private_key)); |
51 } | 54 } |
52 | 55 |
53 } // namespace | 56 } // namespace |
54 | 57 |
55 AwContentsClientBridge::AwContentsClientBridge(JNIEnv* env, jobject obj) | 58 AwContentsClientBridge::AwContentsClientBridge(JNIEnv* env, jobject obj) |
56 : java_ref_(env, obj) { | 59 : java_ref_(env, obj) { |
57 DCHECK(obj); | 60 DCHECK(obj); |
58 Java_AwContentsClientBridge_setNativeContentsClientBridge( | 61 Java_AwContentsClientBridge_setNativeContentsClientBridge( |
59 env, obj, reinterpret_cast<intptr_t>(this)); | 62 env, obj, reinterpret_cast<intptr_t>(this)); |
60 } | 63 } |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 encoded_chain.push_back(encoded_chain_strings[i]); | 233 encoded_chain.push_back(encoded_chain_strings[i]); |
231 | 234 |
232 // Create the X509Certificate object from the encoded chain. | 235 // Create the X509Certificate object from the encoded chain. |
233 scoped_refptr<net::X509Certificate> client_cert( | 236 scoped_refptr<net::X509Certificate> client_cert( |
234 net::X509Certificate::CreateFromDERCertChain(encoded_chain)); | 237 net::X509Certificate::CreateFromDERCertChain(encoded_chain)); |
235 if (!client_cert.get()) { | 238 if (!client_cert.get()) { |
236 LOG(ERROR) << "Could not decode client certificate chain"; | 239 LOG(ERROR) << "Could not decode client certificate chain"; |
237 return; | 240 return; |
238 } | 241 } |
239 | 242 |
240 // Create an EVP_PKEY wrapper for the private key JNI reference. | 243 // Create an SSLPrivateKey wrapper for the private key JNI reference. |
241 crypto::ScopedEVP_PKEY private_key( | 244 scoped_refptr<net::SSLPrivateKey> private_key = |
242 net::android::GetOpenSSLPrivateKeyWrapper(private_key_ref.obj())); | 245 net::WrapJavaPrivateKey(private_key_ref.obj()); |
243 if (!private_key.get()) { | 246 if (!private_key) { |
244 LOG(ERROR) << "Could not create OpenSSL wrapper for private key"; | 247 LOG(ERROR) << "Could not create OpenSSL wrapper for private key"; |
245 return; | 248 return; |
246 } | 249 } |
247 | 250 |
248 // Release the guard and |pending_client_cert_request_delegates_| references | 251 // Release the guard and |pending_client_cert_request_delegates_| references |
249 // to |delegate|. | 252 // to |delegate|. |
250 pending_client_cert_request_delegates_.Remove(request_id); | 253 pending_client_cert_request_delegates_.Remove(request_id); |
251 ignore_result(guard.Release()); | 254 ignore_result(guard.Release()); |
252 | 255 |
253 // RecordClientCertificateKey() must be called on the I/O thread, | 256 // RecordClientCertificateKey() must be called on the I/O thread, |
254 // before the delegate is called with the selected certificate on | 257 // before the delegate is called with the selected certificate on |
255 // the UI thread. | 258 // the UI thread. |
256 content::BrowserThread::PostTaskAndReply( | 259 content::BrowserThread::PostTaskAndReply( |
257 content::BrowserThread::IO, FROM_HERE, | 260 content::BrowserThread::IO, FROM_HERE, |
258 base::Bind(&RecordClientCertificateKey, client_cert, | 261 base::Bind(&RecordClientCertificateKey, base::RetainedRef(client_cert), |
boliu
2016/09/01 20:22:30
is RetainedRef necessary here? (/me seeing it for
davidben
2016/09/01 20:28:01
It's possible I'm misunderstanding, but I think it
boliu
2016/09/01 20:35:53
I *think* RetainedRef just does the second part of
| |
259 base::Passed(&private_key)), | 262 base::Passed(&private_key)), |
260 base::Bind(&content::ClientCertificateDelegate::ContinueWithCertificate, | 263 base::Bind(&content::ClientCertificateDelegate::ContinueWithCertificate, |
261 base::Owned(delegate), base::RetainedRef(client_cert))); | 264 base::Owned(delegate), base::RetainedRef(client_cert))); |
262 } | 265 } |
263 | 266 |
264 void AwContentsClientBridge::RunJavaScriptDialog( | 267 void AwContentsClientBridge::RunJavaScriptDialog( |
265 content::JavaScriptMessageType message_type, | 268 content::JavaScriptMessageType message_type, |
266 const GURL& origin_url, | 269 const GURL& origin_url, |
267 const base::string16& message_text, | 270 const base::string16& message_text, |
268 const base::string16& default_prompt_text, | 271 const base::string16& default_prompt_text, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 pending_client_cert_request_delegates_.Remove(request_id); | 404 pending_client_cert_request_delegates_.Remove(request_id); |
402 | 405 |
403 delete delegate; | 406 delete delegate; |
404 } | 407 } |
405 | 408 |
406 bool RegisterAwContentsClientBridge(JNIEnv* env) { | 409 bool RegisterAwContentsClientBridge(JNIEnv* env) { |
407 return RegisterNativesImpl(env); | 410 return RegisterNativesImpl(env); |
408 } | 411 } |
409 | 412 |
410 } // namespace android_webview | 413 } // namespace android_webview |
OLD | NEW |