diff options
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/browser/KeyChainLookup.java | 52 | ||||
-rw-r--r-- | src/com/android/browser/Tab.java | 29 |
2 files changed, 81 insertions, 0 deletions
diff --git a/src/com/android/browser/KeyChainLookup.java b/src/com/android/browser/KeyChainLookup.java new file mode 100644 index 0000000..b89afc7 --- /dev/null +++ b/src/com/android/browser/KeyChainLookup.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 201 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.browser; + +import android.content.Context; +import android.os.AsyncTask; +import android.security.KeyChain; +import android.security.KeyChainException; +import android.webkit.ClientCertRequest; +import java.security.PrivateKey; +import java.security.cert.X509Certificate; + +final class KeyChainLookup extends AsyncTask<Void, Void, Void> { + private final Context mContext; + private final ClientCertRequest mHandler; + private final String mAlias; + KeyChainLookup(Context context, ClientCertRequest handler, String alias) { + mContext = context.getApplicationContext(); + mHandler = handler; + mAlias = alias; + } + @Override protected Void doInBackground(Void... params) { + PrivateKey privateKey; + X509Certificate[] certificateChain; + try { + privateKey = KeyChain.getPrivateKey(mContext, mAlias); + certificateChain = KeyChain.getCertificateChain(mContext, mAlias); + } catch (InterruptedException e) { + mHandler.ignore(); + return null; + } catch (KeyChainException e) { + mHandler.ignore(); + return null; + } + mHandler.proceed(privateKey, certificateChain); + return null; + } +} diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java index 5d564a1..ed20e67 100644 --- a/src/com/android/browser/Tab.java +++ b/src/com/android/browser/Tab.java @@ -47,6 +47,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewStub; import android.webkit.BrowserDownloadListener; +import android.webkit.ClientCertRequest; import android.webkit.ConsoleMessage; import android.webkit.GeolocationPermissions; import android.webkit.HttpAuthHandler; @@ -75,6 +76,7 @@ import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.nio.ByteBuffer; +import java.security.Principal; import java.util.LinkedList; import java.util.Map; import java.util.UUID; @@ -560,6 +562,29 @@ class Tab implements PictureListener { } } + /** + * Displays client certificate request to the user. + */ + @Override + public void onReceivedClientCertRequest(final WebView view, + final ClientCertRequest request) { + if (!mInForeground) { + request.ignore(); + return; + } + KeyChain.choosePrivateKeyAlias( + mWebViewController.getActivity(), new KeyChainAliasCallback() { + @Override public void alias(String alias) { + if (alias == null) { + request.cancel(); + return; + } + new KeyChainLookup(mContext, request, alias).execute(); + } + }, request.getKeyTypes(), request.getPrincipals(), request.getHost(), + request.getPort(), null); + } + /** * Handles an HTTP authentication request. * @@ -1015,6 +1040,10 @@ class Tab implements PictureListener { mClient.onReceivedSslError(view, handler, error); } @Override + public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) { + mClient.onReceivedClientCertRequest(view, request); + } + @Override public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { mClient.onReceivedHttpAuthRequest(view, handler, host, realm); |