blob: 3a71e7e5bc33f1cbcb6b4906e18d34d2511ec28c [file] [log] [blame]
Brian Carlstroma1477592011-02-11 13:39:56 -08001/*
2 * Copyright (C) 2011 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 android.webkit;
18
19import java.security.PrivateKey;
20import java.security.cert.CertificateEncodingException;
21import java.security.cert.X509Certificate;
22import org.apache.harmony.xnet.provider.jsse.NativeCrypto;
23
24/**
25 * ClientCertRequestHandler: class responsible for handling client
26 * certificate requests. This class is passed as a parameter to
27 * BrowserCallback.displayClientCertRequestDialog and is meant to
28 * receive the user's response.
29 *
30 * @hide
31 */
32public final class ClientCertRequestHandler {
33
34 private final BrowserFrame mBrowserFrame;
35 private final int mHandle;
36 private final String mHostAndPort;
37 private final SslClientCertLookupTable mTable;
38 ClientCertRequestHandler(BrowserFrame browserFrame,
39 int handle,
40 String host_and_port,
41 SslClientCertLookupTable table) {
42 mBrowserFrame = browserFrame;
43 mHandle = handle;
44 mHostAndPort = host_and_port;
45 mTable = table;
46 }
47
48 /**
49 * Proceed with the specified private key and client certificate chain.
50 */
51 public void proceed(PrivateKey privateKey, X509Certificate[] chain) {
52 byte[] privateKeyBytes = privateKey.getEncoded();
53 byte[][] chainBytes;
54 try {
55 chainBytes = NativeCrypto.encodeCertificates(chain);
56 } catch (CertificateEncodingException e) {
57 mBrowserFrame.nativeSslClientCert(mHandle, null, null);
58 return;
59 }
60 mTable.Allow(mHostAndPort, privateKeyBytes, chainBytes);
61 mBrowserFrame.nativeSslClientCert(mHandle, privateKeyBytes, chainBytes);
62 }
63
64 /**
65 * Igore the request for now, the user may be prompted again.
66 */
67 public void ignore() {
68 mBrowserFrame.nativeSslClientCert(mHandle, null, null);
69 }
70
71 /**
72 * Cancel this request, remember the users negative choice.
73 */
74 public void cancel() {
75 mTable.Deny(mHostAndPort);
76 mBrowserFrame.nativeSslClientCert(mHandle, null, null);
77 }
78}