blob: 4d5f694b774034de3ee9c3214e98071d62143b2a [file] [log] [blame]
Brian Carlstrom8862c1d2011-06-02 01:05:55 -07001/*
2 * Copyright (C) 201 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.browser;
18
19import android.content.Context;
20import android.os.AsyncTask;
Brian Carlstrom8862c1d2011-06-02 01:05:55 -070021import android.security.KeyChain;
Brian Carlstromaa09cd82011-06-09 16:04:40 -070022import android.security.KeyChainException;
Brian Carlstrom8862c1d2011-06-02 01:05:55 -070023import android.webkit.ClientCertRequestHandler;
24import java.security.PrivateKey;
25import java.security.cert.X509Certificate;
26
27final class KeyChainLookup extends AsyncTask<Void, Void, Void> {
28 private final Context mContext;
29 private final ClientCertRequestHandler mHandler;
30 private final String mAlias;
31 KeyChainLookup(Context context, ClientCertRequestHandler handler, String alias) {
Ben Murdoch914c5592011-08-01 13:58:47 +010032 mContext = context.getApplicationContext();
Brian Carlstrom8862c1d2011-06-02 01:05:55 -070033 mHandler = handler;
34 mAlias = alias;
35 }
36 @Override protected Void doInBackground(Void... params) {
37 PrivateKey privateKey;
38 X509Certificate[] certificateChain;
39 try {
40 privateKey = KeyChain.getPrivateKey(mContext, mAlias);
41 certificateChain = KeyChain.getCertificateChain(mContext, mAlias);
42 } catch (InterruptedException e) {
43 mHandler.ignore();
44 return null;
Brian Carlstromaa09cd82011-06-09 16:04:40 -070045 } catch (KeyChainException e) {
Brian Carlstrom8862c1d2011-06-02 01:05:55 -070046 mHandler.ignore();
47 return null;
48 }
49 mHandler.proceed(privateKey, certificateChain);
50 return null;
51 }
52}