am 150d5d84
: Use the keystore service instead of the direct file access.
Merge commit '150d5d84e8913e93402950a84ff991b7549b71b4' * commit '150d5d84e8913e93402950a84ff991b7549b71b4': Use the keystore service instead of the direct file access.
This commit is contained in:
committed by
The Android Open Source Project
commit
1bac55d785
@@ -22,6 +22,7 @@ import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
import android.security.Keystore;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
@@ -79,6 +80,7 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
AccessPointState.WEP_PASSWORD_AUTO, AccessPointState.WEP_PASSWORD_ASCII,
|
||||
AccessPointState.WEP_PASSWORD_HEX
|
||||
};
|
||||
private static final String NOT_APPLICABLE = "N/A";
|
||||
|
||||
// Button positions, default to impossible values
|
||||
private int mConnectButtonPos = Integer.MAX_VALUE;
|
||||
@@ -130,11 +132,13 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
private TextView mSecurityText;
|
||||
private Spinner mSecuritySpinner;
|
||||
private Spinner mWepTypeSpinner;
|
||||
private Keystore mKeystore;
|
||||
|
||||
public AccessPointDialog(Context context, WifiLayer wifiLayer) {
|
||||
super(context);
|
||||
|
||||
mWifiLayer = wifiLayer;
|
||||
mKeystore = Keystore.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -325,19 +329,34 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
setEnterpriseFields(view);
|
||||
mEapSpinner.setSelection(getSelectionIndex(
|
||||
R.array.wifi_eap_entries, mState.getEap()));
|
||||
Keystore ks = Keystore.getInstance();
|
||||
mClientCertSpinner.setSelection(getSelectionIndex(
|
||||
ks.getAllCertificateKeys(), mState.getEnterpriseField(
|
||||
getAllCertificateKeys(), mState.getEnterpriseField(
|
||||
AccessPointState.CLIENT_CERT)));
|
||||
mCaCertSpinner.setSelection(getSelectionIndex(
|
||||
ks.getAllCertificateKeys(), mState.getEnterpriseField(
|
||||
getAllCertificateKeys(), mState.getEnterpriseField(
|
||||
AccessPointState.CA_CERT)));
|
||||
mPrivateKeySpinner.setSelection(getSelectionIndex(
|
||||
ks.getAllUserkeyKeys(), mState.getEnterpriseField(
|
||||
getAllUserkeyKeys(), mState.getEnterpriseField(
|
||||
AccessPointState.PRIVATE_KEY)));
|
||||
}
|
||||
}
|
||||
|
||||
private String[] getAllCertificateKeys() {
|
||||
return appendEmptyInSelection(mKeystore.getAllCertificateKeys());
|
||||
}
|
||||
|
||||
private String[] getAllUserkeyKeys() {
|
||||
return appendEmptyInSelection(mKeystore.getAllUserkeyKeys());
|
||||
}
|
||||
|
||||
private String[] appendEmptyInSelection(String[] keys) {
|
||||
if (keys.length == 0) return keys;
|
||||
String[] selections = new String[keys.length + 1];
|
||||
System.arraycopy(keys, 0, selections, 0, keys.length);
|
||||
selections[keys.length] = NOT_APPLICABLE;
|
||||
return selections;
|
||||
}
|
||||
|
||||
private void setEnterpriseFields(View view) {
|
||||
mIdentityText = (TextView) view.findViewById(R.id.identity_text);
|
||||
mIdentityEdit = (EditText) view.findViewById(R.id.identity_edit);
|
||||
@@ -365,26 +384,24 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
mPhase2Spinner.setPromptId(R.string.please_select_phase2);
|
||||
setSpinnerAdapter(mPhase2Spinner, R.array.wifi_phase2_entries);
|
||||
|
||||
Keystore ks = Keystore.getInstance();
|
||||
|
||||
mClientCertSpinner =
|
||||
(Spinner) view.findViewById(R.id.client_certificate_spinner);
|
||||
mClientCertSpinner.setOnItemSelectedListener(this);
|
||||
mClientCertSpinner.setPromptId(
|
||||
R.string.please_select_client_certificate);
|
||||
setSpinnerAdapter(mClientCertSpinner, ks.getAllCertificateKeys());
|
||||
setSpinnerAdapter(mClientCertSpinner, getAllCertificateKeys());
|
||||
|
||||
mCaCertSpinner =
|
||||
(Spinner) view.findViewById(R.id.ca_certificate_spinner);
|
||||
mCaCertSpinner.setOnItemSelectedListener(this);
|
||||
mCaCertSpinner.setPromptId(R.string.please_select_ca_certificate);
|
||||
setSpinnerAdapter(mCaCertSpinner, ks.getAllCertificateKeys());
|
||||
setSpinnerAdapter(mCaCertSpinner, getAllCertificateKeys());
|
||||
|
||||
mPrivateKeySpinner =
|
||||
(Spinner) view.findViewById(R.id.private_key_spinner);
|
||||
mPrivateKeySpinner.setOnItemSelectedListener(this);
|
||||
mPrivateKeySpinner.setPromptId(R.string.please_select_private_key);
|
||||
setSpinnerAdapter(mPrivateKeySpinner, ks.getAllUserkeyKeys());
|
||||
setSpinnerAdapter(mPrivateKeySpinner, getAllUserkeyKeys());
|
||||
|
||||
mEnterpriseTextFields = new EditText[] {
|
||||
mIdentityEdit, mAnonymousIdentityEdit, mPrivateKeyPasswdEdit
|
||||
@@ -639,7 +656,6 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
|
||||
private void updateEnterpriseFields(int securityType) {
|
||||
int i;
|
||||
Keystore ks = Keystore.getInstance();
|
||||
for (i = AccessPointState.IDENTITY ;
|
||||
i < AccessPointState.MAX_ENTRPRISE_FIELD ; i++) {
|
||||
String value;
|
||||
@@ -648,16 +664,21 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
} else {
|
||||
Spinner spinner = mEnterpriseSpinnerFields[i -
|
||||
AccessPointState.CLIENT_CERT];
|
||||
|
||||
if (i != AccessPointState.PRIVATE_KEY) {
|
||||
value = ks.getCertificate(ks.getAllCertificateKeys()
|
||||
[spinner.getSelectedItemPosition()]);
|
||||
int index = spinner.getSelectedItemPosition();
|
||||
if (index == (spinner.getCount() - 1)) {
|
||||
value = "";
|
||||
} else {
|
||||
value = ks.getUserkey(ks.getAllUserkeyKeys()
|
||||
[spinner.getSelectedItemPosition()]);
|
||||
if (i != AccessPointState.PRIVATE_KEY) {
|
||||
value = mKeystore.getCertificate(
|
||||
getAllCertificateKeys()[index]);
|
||||
} else {
|
||||
value = mKeystore.getUserkey(
|
||||
getAllUserkeyKeys()[index]);
|
||||
}
|
||||
}
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
}
|
||||
if (!TextUtils.isEmpty(value) ||
|
||||
(i == AccessPointState.PRIVATE_KEY_PASSWD)) {
|
||||
mState.setEnterpriseField(i, value);
|
||||
}
|
||||
}
|
||||
|
@@ -1,81 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user