summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/wifi/Keystore.java
blob: 68af8685590183ad1395b5e566670f906526f05f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.android.settings.wifi;

import android.util.Log;

import java.io.File;

/**
 */
public abstract class Keystore {
    public static final String TAG = "Keystore";

    private static final String PACKAGE_PREFIX =
        Keystore.class.getPackage().getName() + ".";

    public static final String ACTION_KEYSTORE_CERTIFICATES =
        PACKAGE_PREFIX + "CERTIFICATES";
    public static final String ACTION_KEYSTORE_USERKEYS =
        PACKAGE_PREFIX + "USERKEYS";

    /**
     */
    public static Keystore getInstance() {
        return new FileKeystore();
    }

    /**
     */
    public abstract String getUserkey(String key);

    /**
     */
    public abstract String getCertificate(String key);

    /**
     */
    public abstract String[] getAllCertificateKeys();

    /**
     */
    public abstract String[] getAllUserkeyKeys();

    private static class FileKeystore extends Keystore {
        private static final String PATH = "/data/misc/keystore/";
        private static final String USERKEY_PATH = PATH + "userkeys/";
        private static final String CERT_PATH = PATH + "certs/";

        @Override
        public String getUserkey(String key) {
            String path = USERKEY_PATH + key;
            return (new File(path).exists() ? path : null);
        }

        @Override
        public String getCertificate(String key) {
            String path = CERT_PATH + key;
            return (new File(path).exists() ? path : null);
        }

        @Override
        public String[] getAllCertificateKeys() {
            File dir = new File(CERT_PATH);
            if (dir.exists()) {
                return dir.list();
            } else {
                Log.v(TAG, "-------- cert directory does not exist!");
                return null;
            }
        }

        @Override
        public String[] getAllUserkeyKeys() {
            File dir = new File(USERKEY_PATH);
            if (dir.exists()) {
                return dir.list();
            } else {
                Log.v(TAG, "-------- userkey directory does not exist!");
                return null;
            }
        }
    }
}