Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: android_webview/native/aw_contents_client_bridge.cc

Issue 1304143010: Plumbing SSLPrivateKey Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "android_webview/common/devtools_instrumentation.h" 7 #include "android_webview/common/devtools_instrumentation.h"
8 #include "android_webview/native/aw_contents.h" 8 #include "android_webview/native/aw_contents.h"
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
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/callback_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/client_certificate_delegate.h" 15 #include "content/public/browser/client_certificate_delegate.h"
16 #include "content/public/browser/render_process_host.h" 16 #include "content/public/browser/render_process_host.h"
17 #include "content/public/browser/render_view_host.h" 17 #include "content/public/browser/render_view_host.h"
18 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
19 #include "crypto/scoped_openssl_types.h" 19 #include "crypto/scoped_openssl_types.h"
20 #include "jni/AwContentsClientBridge_jni.h" 20 #include "jni/AwContentsClientBridge_jni.h"
21 #include "net/android/keystore_openssl.h" 21 #include "net/android/keystore_openssl.h"
22 #include "net/cert/x509_certificate.h" 22 #include "net/cert/x509_certificate.h"
23 #include "net/ssl/openssl_client_key_store.h"
24 #include "net/ssl/ssl_cert_request_info.h" 23 #include "net/ssl/ssl_cert_request_info.h"
25 #include "net/ssl/ssl_client_cert_type.h" 24 #include "net/ssl/ssl_client_cert_type.h"
25 #include "net/ssl/ssl_platform_key.h"
26 #include "net/ssl/ssl_private_key.h"
26 #include "url/gurl.h" 27 #include "url/gurl.h"
27 28
28 using base::android::AttachCurrentThread; 29 using base::android::AttachCurrentThread;
29 using base::android::ConvertJavaStringToUTF16; 30 using base::android::ConvertJavaStringToUTF16;
30 using base::android::ConvertUTF8ToJavaString; 31 using base::android::ConvertUTF8ToJavaString;
31 using base::android::ConvertUTF16ToJavaString; 32 using base::android::ConvertUTF16ToJavaString;
32 using base::android::JavaRef; 33 using base::android::JavaRef;
33 using base::android::ScopedJavaLocalRef; 34 using base::android::ScopedJavaLocalRef;
34 using content::BrowserThread; 35 using content::BrowserThread;
35 36
36 namespace android_webview { 37 namespace android_webview {
37 38
38 namespace {
39
40 // Must be called on the I/O thread to record a client certificate
41 // and its private key in the OpenSSLClientKeyStore.
42 void RecordClientCertificateKey(
43 const scoped_refptr<net::X509Certificate>& client_cert,
44 crypto::ScopedEVP_PKEY private_key) {
45 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
46 net::OpenSSLClientKeyStore::GetInstance()->RecordClientCertPrivateKey(
47 client_cert.get(), private_key.get());
48 }
49
50 } // namespace
51
52 AwContentsClientBridge::AwContentsClientBridge(JNIEnv* env, jobject obj) 39 AwContentsClientBridge::AwContentsClientBridge(JNIEnv* env, jobject obj)
53 : java_ref_(env, obj) { 40 : java_ref_(env, obj) {
54 DCHECK(obj); 41 DCHECK(obj);
55 Java_AwContentsClientBridge_setNativeContentsClientBridge( 42 Java_AwContentsClientBridge_setNativeContentsClientBridge(
56 env, obj, reinterpret_cast<intptr_t>(this)); 43 env, obj, reinterpret_cast<intptr_t>(this));
57 } 44 }
58 45
59 AwContentsClientBridge::~AwContentsClientBridge() { 46 AwContentsClientBridge::~AwContentsClientBridge() {
60 JNIEnv* env = AttachCurrentThread(); 47 JNIEnv* env = AttachCurrentThread();
61 48
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 jobject private_key_ref) { 189 jobject private_key_ref) {
203 DCHECK_CURRENTLY_ON(BrowserThread::UI); 190 DCHECK_CURRENTLY_ON(BrowserThread::UI);
204 191
205 content::ClientCertificateDelegate* delegate = 192 content::ClientCertificateDelegate* delegate =
206 pending_client_cert_request_delegates_.Lookup(request_id); 193 pending_client_cert_request_delegates_.Lookup(request_id);
207 DCHECK(delegate); 194 DCHECK(delegate);
208 195
209 if (encoded_chain_ref == NULL || private_key_ref == NULL) { 196 if (encoded_chain_ref == NULL || private_key_ref == NULL) {
210 LOG(ERROR) << "No client certificate selected"; 197 LOG(ERROR) << "No client certificate selected";
211 pending_client_cert_request_delegates_.Remove(request_id); 198 pending_client_cert_request_delegates_.Remove(request_id);
212 delegate->ContinueWithCertificate(nullptr); 199 delegate->ContinueWithCertificate(nullptr, nullptr);
213 delete delegate; 200 delete delegate;
214 return; 201 return;
215 } 202 }
216 203
217 // Make sure callback is run on error. 204 // Make sure callback is run on error.
218 base::ScopedClosureRunner guard(base::Bind( 205 base::ScopedClosureRunner guard(base::Bind(
219 &AwContentsClientBridge::HandleErrorInClientCertificateResponse, 206 &AwContentsClientBridge::HandleErrorInClientCertificateResponse,
220 base::Unretained(this), 207 base::Unretained(this),
221 request_id)); 208 request_id));
222 209
(...skipping 17 matching lines...) Expand all
240 } 227 }
241 228
242 // Create an EVP_PKEY wrapper for the private key JNI reference. 229 // Create an EVP_PKEY wrapper for the private key JNI reference.
243 crypto::ScopedEVP_PKEY private_key( 230 crypto::ScopedEVP_PKEY private_key(
244 net::android::GetOpenSSLPrivateKeyWrapper(private_key_ref)); 231 net::android::GetOpenSSLPrivateKeyWrapper(private_key_ref));
245 if (!private_key.get()) { 232 if (!private_key.get()) {
246 LOG(ERROR) << "Could not create OpenSSL wrapper for private key"; 233 LOG(ERROR) << "Could not create OpenSSL wrapper for private key";
247 return; 234 return;
248 } 235 }
249 236
237 scoped_refptr<net::SSLPrivateKey> client_pkey =
238 net::WrapPrivateKey(private_key.Pass());
239
250 // Release the guard and |pending_client_cert_request_delegates_| references 240 // Release the guard and |pending_client_cert_request_delegates_| references
251 // to |delegate|. 241 // to |delegate|.
252 pending_client_cert_request_delegates_.Remove(request_id); 242 pending_client_cert_request_delegates_.Remove(request_id);
253 ignore_result(guard.Release()); 243 ignore_result(guard.Release());
254 244
255 // RecordClientCertificateKey() must be called on the I/O thread, 245 // RecordClientCertificateKey() must be called on the I/O thread,
256 // before the delegate is called with the selected certificate on 246 // before the delegate is called with the selected certificate on
257 // the UI thread. 247 // the UI thread.
258 content::BrowserThread::PostTaskAndReply( 248 content::BrowserThread::PostTask(
259 content::BrowserThread::IO, FROM_HERE, 249 content::BrowserThread::IO, FROM_HERE,
260 base::Bind(&RecordClientCertificateKey, client_cert,
261 base::Passed(&private_key)),
262 base::Bind(&content::ClientCertificateDelegate::ContinueWithCertificate, 250 base::Bind(&content::ClientCertificateDelegate::ContinueWithCertificate,
263 base::Owned(delegate), client_cert)); 251 base::Owned(delegate), client_cert, client_pkey));
264 } 252 }
265 253
266 void AwContentsClientBridge::RunJavaScriptDialog( 254 void AwContentsClientBridge::RunJavaScriptDialog(
267 content::JavaScriptMessageType message_type, 255 content::JavaScriptMessageType message_type,
268 const GURL& origin_url, 256 const GURL& origin_url,
269 const base::string16& message_text, 257 const base::string16& message_text,
270 const base::string16& default_prompt_text, 258 const base::string16& default_prompt_text,
271 const content::JavaScriptDialogManager::DialogClosedCallback& callback) { 259 const content::JavaScriptDialogManager::DialogClosedCallback& callback) {
272 DCHECK_CURRENTLY_ON(BrowserThread::UI); 260 DCHECK_CURRENTLY_ON(BrowserThread::UI);
273 JNIEnv* env = AttachCurrentThread(); 261 JNIEnv* env = AttachCurrentThread();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 pending_client_cert_request_delegates_.Remove(request_id); 367 pending_client_cert_request_delegates_.Remove(request_id);
380 368
381 delete delegate; 369 delete delegate;
382 } 370 }
383 371
384 bool RegisterAwContentsClientBridge(JNIEnv* env) { 372 bool RegisterAwContentsClientBridge(JNIEnv* env) {
385 return RegisterNativesImpl(env); 373 return RegisterNativesImpl(env);
386 } 374 }
387 375
388 } // namespace android_webview 376 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698