• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 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.server.wifi.hotspot2;
18 
19 import android.util.Log;
20 
21 import java.io.IOException;
22 import java.security.KeyStore;
23 import java.security.KeyStoreException;
24 import java.security.NoSuchAlgorithmException;
25 import java.security.cert.CertificateException;
26 import java.security.cert.X509Certificate;
27 import java.util.Set;
28 
29 /**
30  * WFA Keystore
31  */
32 public class WfaKeyStore {
33     private static final String TAG = "PasspointWfaKeyStore";
34     /* package */ static final String DEFAULT_WFA_CERT_DIR =
35             "/apex/com.android.wifi/etc/security/cacerts_wfa";
36 
37     private boolean mVerboseLoggingEnabled = false;
38     private KeyStore mKeyStore = null;
39 
40     /**
41      * Loads the keystore with root certificates
42      */
load()43     public void load() {
44         if (mKeyStore != null) {
45             return;
46         }
47         int index = 0;
48         try {
49             mKeyStore = KeyStore.getInstance(KeyStore.getDefaultType());
50             mKeyStore.load(null, null);
51             Set<X509Certificate> certs = WfaCertBuilder.loadCertsFromDisk(DEFAULT_WFA_CERT_DIR);
52             for (X509Certificate cert : certs) {
53                 mKeyStore.setCertificateEntry(String.format("%d", index), cert);
54                 index++;
55             }
56             if (index <= 0) {
57                 Log.wtf(TAG, "No certs loaded");
58             }
59         } catch (KeyStoreException | CertificateException | NoSuchAlgorithmException
60                 | IOException e) {
61             e.printStackTrace();
62         }
63     }
64 
65     /**
66      * Returns the underlying keystore object
67      * @return KeyStore Underlying keystore object created
68      */
get()69     public KeyStore get() {
70         return mKeyStore;
71     }
72 }
73