diff options
Diffstat (limited to 'src/com/android/settings/wifi/Keystore.java')
| -rw-r--r-- | src/com/android/settings/wifi/Keystore.java | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/com/android/settings/wifi/Keystore.java b/src/com/android/settings/wifi/Keystore.java new file mode 100644 index 000000000..68af86855 --- /dev/null +++ b/src/com/android/settings/wifi/Keystore.java @@ -0,0 +1,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; + } + } + } +} |
