Provide Browser implementation of WebViewClient.onReceivedClientCertRequest
Following the example of onReceivedSslError, implement onReceivedClientCertRequest
ERROR CASE CLIENT CERT CASE
<... From frameworks/base ...> <... From frameworks/base ...>
Tab.SubWindowClient.onReceivedSslError Tab.SubWindowClient.onReceivedClientCertRequest
Tab.mWebViewClient.onReceivedSslError Tab.mWebViewClient.onReceivedClientCertRequest
<... ssl_warnings dialog ...> <... KeyChain.choosePrivateKeyAlias/KeyChainLookup ...>
SslErrorHandler.proceed (with SslCertLookupTable) ClientCertRequestHandler.proceed (with SslClientCertLookupTable)
<... To frameworks/base ...> <... To frameworks/base ...>
Change-Id: I3ed3789c4efc97c87ab4773cdaed3e654a1fd1e3
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java
index 95c7850..e517d76 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -32,12 +32,15 @@
import android.os.Bundle;
import android.os.Message;
import android.os.SystemClock;
+import android.security.KeyChain;
+import android.security.KeyChainAliasResponse;
import android.speech.RecognizerResultsIntent;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewStub;
+import android.webkit.ClientCertRequestHandler;
import android.webkit.ConsoleMessage;
import android.webkit.DownloadListener;
import android.webkit.GeolocationPermissions;
@@ -791,6 +794,27 @@
}
/**
+ * Displays client certificate request to the user.
+ */
+ @Override
+ public void onReceivedClientCertRequest(final WebView view,
+ final ClientCertRequestHandler handler, final String host_and_port) {
+ if (!mInForeground) {
+ handler.ignore();
+ return;
+ }
+ KeyChain.choosePrivateKeyAlias(mActivity, new KeyChainAliasResponse() {
+ @Override public void alias(String alias) {
+ if (alias == null) {
+ handler.cancel();
+ return;
+ }
+ new KeyChainLookup(mActivity, handler, alias).execute();
+ }
+ });
+ }
+
+ /**
* Handles an HTTP authentication request.
*
* @param handler The authentication handler
@@ -1232,6 +1256,11 @@
mClient.onReceivedSslError(view, handler, error);
}
@Override
+ public void onReceivedClientCertRequest(WebView view,
+ ClientCertRequestHandler handler, String host_and_port) {
+ mClient.onReceivedClientCertRequest(view, handler, host_and_port);
+ }
+ @Override
public void onReceivedHttpAuthRequest(WebView view,
HttpAuthHandler handler, String host, String realm) {
mClient.onReceivedHttpAuthRequest(view, handler, host, realm);