• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package android.webkit;
18 
19 import java.security.PrivateKey;
20 import java.util.HashMap;
21 import java.util.HashSet;
22 import java.util.Map;
23 import java.util.Set;
24 
25 /**
26  * A simple class to store client certificates that user has chosen.
27  */
28 final class SslClientCertLookupTable {
29     private static SslClientCertLookupTable sTable;
30     private final Map<String, PrivateKey> privateKeys;
31     private final Map<String, byte[][]> certificateChains;
32     private final Set<String> denied;
33 
getInstance()34     public static synchronized SslClientCertLookupTable getInstance() {
35         if (sTable == null) {
36             sTable = new SslClientCertLookupTable();
37         }
38         return sTable;
39     }
40 
SslClientCertLookupTable()41     private SslClientCertLookupTable() {
42         privateKeys = new HashMap<String, PrivateKey>();
43         certificateChains = new HashMap<String, byte[][]>();
44         denied = new HashSet<String>();
45     }
46 
Allow(String host_and_port, PrivateKey privateKey, byte[][] chain)47     public void Allow(String host_and_port, PrivateKey privateKey, byte[][] chain) {
48         privateKeys.put(host_and_port, privateKey);
49         certificateChains.put(host_and_port, chain);
50         denied.remove(host_and_port);
51     }
52 
Deny(String host_and_port)53     public void Deny(String host_and_port) {
54         privateKeys.remove(host_and_port);
55         certificateChains.remove(host_and_port);
56         denied.add(host_and_port);
57     }
58 
IsAllowed(String host_and_port)59     public boolean IsAllowed(String host_and_port) {
60         return privateKeys.containsKey(host_and_port);
61     }
62 
IsDenied(String host_and_port)63     public boolean IsDenied(String host_and_port) {
64         return denied.contains(host_and_port);
65     }
66 
PrivateKey(String host_and_port)67     public PrivateKey PrivateKey(String host_and_port) {
68         return privateKeys.get(host_and_port);
69     }
70 
CertificateChain(String host_and_port)71     public byte[][] CertificateChain(String host_and_port) {
72         return certificateChains.get(host_and_port);
73     }
74 }
75