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