1 /* 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 17 package com.android.browser; 18 19 import android.content.Context; 20 import android.os.AsyncTask; 21 import android.security.KeyChain; 22 import android.security.KeyChainException; 23 import android.webkit.ClientCertRequestHandler; 24 import java.security.PrivateKey; 25 import java.security.cert.X509Certificate; 26 27 final class KeyChainLookup extends AsyncTask<Void, Void, Void> { 28 private final Context mContext; 29 private final ClientCertRequestHandler mHandler; 30 private final String mAlias; KeyChainLookup(Context context, ClientCertRequestHandler handler, String alias)31 KeyChainLookup(Context context, ClientCertRequestHandler handler, String alias) { 32 mContext = context.getApplicationContext(); 33 mHandler = handler; 34 mAlias = alias; 35 } doInBackground(Void... params)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; 45 } catch (KeyChainException e) { 46 mHandler.ignore(); 47 return null; 48 } 49 mHandler.proceed(privateKey, certificateChain); 50 return null; 51 } 52 } 53