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

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

Issue 859213006: Cancel client auth requests when not promptable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@client-auth-cancel-1
Patch Set: extension test Created 5 years, 10 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 "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/client_certificate_delegate.h"
14 #include "content/public/browser/render_process_host.h" 15 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/render_view_host.h" 16 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
17 #include "crypto/scoped_openssl_types.h" 18 #include "crypto/scoped_openssl_types.h"
18 #include "jni/AwContentsClientBridge_jni.h" 19 #include "jni/AwContentsClientBridge_jni.h"
19 #include "net/android/keystore_openssl.h" 20 #include "net/android/keystore_openssl.h"
20 #include "net/cert/x509_certificate.h" 21 #include "net/cert/x509_certificate.h"
21 #include "net/ssl/openssl_client_key_store.h" 22 #include "net/ssl/openssl_client_key_store.h"
22 #include "net/ssl/ssl_cert_request_info.h" 23 #include "net/ssl/ssl_cert_request_info.h"
23 #include "net/ssl/ssl_client_cert_type.h" 24 #include "net/ssl/ssl_client_cert_type.h"
(...skipping 21 matching lines...) Expand all
45 client_cert.get(), private_key.get()); 46 client_cert.get(), private_key.get());
46 } 47 }
47 48
48 } // namespace 49 } // namespace
49 50
50 AwContentsClientBridge::AwContentsClientBridge(JNIEnv* env, jobject obj) 51 AwContentsClientBridge::AwContentsClientBridge(JNIEnv* env, jobject obj)
51 : java_ref_(env, obj) { 52 : java_ref_(env, obj) {
52 DCHECK(obj); 53 DCHECK(obj);
53 Java_AwContentsClientBridge_setNativeContentsClientBridge( 54 Java_AwContentsClientBridge_setNativeContentsClientBridge(
54 env, obj, reinterpret_cast<intptr_t>(this)); 55 env, obj, reinterpret_cast<intptr_t>(this));
56
57 for (IDMap<content::ClientCertificateDelegate>::iterator iter(
58 &pending_client_cert_request_delegates_);
59 !iter.IsAtEnd(); iter.Advance()) {
60 delete iter.GetCurrentValue();
61 }
55 } 62 }
56 63
57 AwContentsClientBridge::~AwContentsClientBridge() { 64 AwContentsClientBridge::~AwContentsClientBridge() {
58 JNIEnv* env = AttachCurrentThread(); 65 JNIEnv* env = AttachCurrentThread();
59 66
60 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 67 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
61 if (obj.is_null()) 68 if (obj.is_null())
62 return; 69 return;
63 // Clear the weak reference from the java peer to the native object since 70 // Clear the weak reference from the java peer to the native object since
64 // it is possible that java object lifetime can exceed the AwContens. 71 // it is possible that java object lifetime can exceed the AwContens.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 LOG(WARNING) << "Ignoring unexpected ssl error proceed callback"; 114 LOG(WARNING) << "Ignoring unexpected ssl error proceed callback";
108 return; 115 return;
109 } 116 }
110 callback->Run(proceed); 117 callback->Run(proceed);
111 pending_cert_error_callbacks_.Remove(id); 118 pending_cert_error_callbacks_.Remove(id);
112 } 119 }
113 120
114 // This method is inspired by SelectClientCertificate() in 121 // This method is inspired by SelectClientCertificate() in
115 // chrome/browser/ui/android/ssl_client_certificate_request.cc 122 // chrome/browser/ui/android/ssl_client_certificate_request.cc
116 void AwContentsClientBridge::SelectClientCertificate( 123 void AwContentsClientBridge::SelectClientCertificate(
117 net::SSLCertRequestInfo* cert_request_info, 124 net::SSLCertRequestInfo* cert_request_info,
118 const SelectCertificateCallback& callback) { 125 scoped_ptr<content::ClientCertificateDelegate> delegate) {
119 DCHECK_CURRENTLY_ON(BrowserThread::UI); 126 DCHECK_CURRENTLY_ON(BrowserThread::UI);
120 127
121 // Add the callback to id map. 128 // Add the callback to id map.
122 int request_id = pending_client_cert_request_callbacks_.Add( 129 int request_id =
123 new SelectCertificateCallback(callback)); 130 pending_client_cert_request_delegates_.Add(delegate.release());
124 // Make sure callback is run on error. 131 // Make sure callback is run on error.
125 base::ScopedClosureRunner guard(base::Bind( 132 base::ScopedClosureRunner guard(base::Bind(
126 &AwContentsClientBridge::HandleErrorInClientCertificateResponse, 133 &AwContentsClientBridge::HandleErrorInClientCertificateResponse,
127 base::Unretained(this), 134 base::Unretained(this),
128 request_id)); 135 request_id));
129 136
130 JNIEnv* env = base::android::AttachCurrentThread(); 137 JNIEnv* env = base::android::AttachCurrentThread();
131 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 138 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
132 if (obj.is_null()) 139 if (obj.is_null())
133 return; 140 return;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 // This method is inspired by OnSystemRequestCompletion() in 196 // This method is inspired by OnSystemRequestCompletion() in
190 // chrome/browser/ui/android/ssl_client_certificate_request.cc 197 // chrome/browser/ui/android/ssl_client_certificate_request.cc
191 void AwContentsClientBridge::ProvideClientCertificateResponse( 198 void AwContentsClientBridge::ProvideClientCertificateResponse(
192 JNIEnv* env, 199 JNIEnv* env,
193 jobject obj, 200 jobject obj,
194 int request_id, 201 int request_id,
195 jobjectArray encoded_chain_ref, 202 jobjectArray encoded_chain_ref,
196 jobject private_key_ref) { 203 jobject private_key_ref) {
197 DCHECK_CURRENTLY_ON(BrowserThread::UI); 204 DCHECK_CURRENTLY_ON(BrowserThread::UI);
198 205
199 SelectCertificateCallback* callback = 206 content::ClientCertificateDelegate* delegate =
200 pending_client_cert_request_callbacks_.Lookup(request_id); 207 pending_client_cert_request_delegates_.Lookup(request_id);
201 DCHECK(callback); 208 DCHECK(delegate);
202 209
203 // Make sure callback is run on error. 210 // Make sure callback is run on error.
204 base::ScopedClosureRunner guard(base::Bind( 211 base::ScopedClosureRunner guard(base::Bind(
205 &AwContentsClientBridge::HandleErrorInClientCertificateResponse, 212 &AwContentsClientBridge::HandleErrorInClientCertificateResponse,
206 base::Unretained(this), 213 base::Unretained(this),
207 request_id)); 214 request_id));
208 if (encoded_chain_ref == NULL || private_key_ref == NULL) { 215 if (encoded_chain_ref == NULL || private_key_ref == NULL) {
209 LOG(ERROR) << "Client certificate request cancelled"; 216 LOG(ERROR) << "Client certificate request cancelled";
210 return; 217 return;
211 } 218 }
(...skipping 17 matching lines...) Expand all
229 } 236 }
230 237
231 // Create an EVP_PKEY wrapper for the private key JNI reference. 238 // Create an EVP_PKEY wrapper for the private key JNI reference.
232 crypto::ScopedEVP_PKEY private_key( 239 crypto::ScopedEVP_PKEY private_key(
233 net::android::GetOpenSSLPrivateKeyWrapper(private_key_ref)); 240 net::android::GetOpenSSLPrivateKeyWrapper(private_key_ref));
234 if (!private_key.get()) { 241 if (!private_key.get()) {
235 LOG(ERROR) << "Could not create OpenSSL wrapper for private key"; 242 LOG(ERROR) << "Could not create OpenSSL wrapper for private key";
236 return; 243 return;
237 } 244 }
238 245
246 // Release the guard and |pending_client_cert_request_delegates_| references
247 // to |delegate|.
248 pending_client_cert_request_delegates_.Remove(request_id);
249 ignore_result(guard.Release());
250
239 // RecordClientCertificateKey() must be called on the I/O thread, 251 // RecordClientCertificateKey() must be called on the I/O thread,
240 // before the callback is called with the selected certificate on 252 // before the delegate is called with the selected certificate on
241 // the UI thread. 253 // the UI thread.
242 content::BrowserThread::PostTaskAndReply( 254 content::BrowserThread::PostTaskAndReply(
243 content::BrowserThread::IO, 255 content::BrowserThread::IO, FROM_HERE,
244 FROM_HERE, 256 base::Bind(&RecordClientCertificateKey, client_cert,
245 base::Bind(&RecordClientCertificateKey,
246 client_cert,
247 base::Passed(&private_key)), 257 base::Passed(&private_key)),
248 base::Bind(*callback, client_cert)); 258 base::Bind(&content::ClientCertificateDelegate::ContinueWithCertificate,
249 pending_client_cert_request_callbacks_.Remove(request_id); 259 base::Owned(delegate), client_cert));
250
251 // Release the guard.
252 ignore_result(guard.Release());
253 } 260 }
254 261
255 void AwContentsClientBridge::RunJavaScriptDialog( 262 void AwContentsClientBridge::RunJavaScriptDialog(
256 content::JavaScriptMessageType message_type, 263 content::JavaScriptMessageType message_type,
257 const GURL& origin_url, 264 const GURL& origin_url,
258 const base::string16& message_text, 265 const base::string16& message_text,
259 const base::string16& default_prompt_text, 266 const base::string16& default_prompt_text,
260 const content::JavaScriptDialogManager::DialogClosedCallback& callback) { 267 const content::JavaScriptDialogManager::DialogClosedCallback& callback) {
261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
262 JNIEnv* env = AttachCurrentThread(); 269 JNIEnv* env = AttachCurrentThread();
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 LOG(WARNING) << "Unexpected JS dialog cancel. " << id; 377 LOG(WARNING) << "Unexpected JS dialog cancel. " << id;
371 return; 378 return;
372 } 379 }
373 callback->Run(false, base::string16()); 380 callback->Run(false, base::string16());
374 pending_js_dialog_callbacks_.Remove(id); 381 pending_js_dialog_callbacks_.Remove(id);
375 } 382 }
376 383
377 // Use to cleanup if there is an error in client certificate response. 384 // Use to cleanup if there is an error in client certificate response.
378 void AwContentsClientBridge::HandleErrorInClientCertificateResponse( 385 void AwContentsClientBridge::HandleErrorInClientCertificateResponse(
379 int request_id) { 386 int request_id) {
380 SelectCertificateCallback* callback = 387 content::ClientCertificateDelegate* delegate =
381 pending_client_cert_request_callbacks_.Lookup(request_id); 388 pending_client_cert_request_delegates_.Lookup(request_id);
382 callback->Run(nullptr); 389 pending_client_cert_request_delegates_.Remove(request_id);
383 pending_client_cert_request_callbacks_.Remove(request_id); 390
391 delegate->ContinueWithCertificate(nullptr);
392 delete delegate;
384 } 393 }
385 394
386 bool RegisterAwContentsClientBridge(JNIEnv* env) { 395 bool RegisterAwContentsClientBridge(JNIEnv* env) {
387 return RegisterNativesImpl(env); 396 return RegisterNativesImpl(env);
388 } 397 }
389 398
390 } // namespace android_webview 399 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698