diff options
author | Selim Gurun <sgurun@google.com> | 2014-04-16 16:15:57 -0700 |
---|---|---|
committer | Selim Gurun <sgurun@google.com> | 2014-04-24 14:39:30 -0700 |
commit | 531ac8b4732d9bfaa0de89be888511e6db03c1cb (patch) | |
tree | f2d5d15292602bec07c4e76d26251ab12baaeda5 /src/com/android/browser | |
parent | 8a72b1f208493299f15223b3e63f53bb02933e4f (diff) | |
download | packages_apps_Browser-531ac8b4732d9bfaa0de89be888511e6db03c1cb.zip packages_apps_Browser-531ac8b4732d9bfaa0de89be888511e6db03c1cb.tar.gz packages_apps_Browser-531ac8b4732d9bfaa0de89be888511e6db03c1cb.tar.bz2 |
Add Client certificate support to AOSP browser
Bug: 14298085
The webview client cert API is not public at the time. This
change adds client certificate support to AOSP browser via this hidden
API mostly for testing purposes. We will be continuously updating Browser
as the API changes since browser is the main testing tool for it.
Change-Id: Idc993b4ebb5635a06435aaccdfa0e418a91ce48f
Diffstat (limited to 'src/com/android/browser')
-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); |