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.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.security.Keystore;
|
||||||
import android.net.wifi.WifiInfo;
|
import android.net.wifi.WifiInfo;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -79,7 +80,8 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
|||||||
AccessPointState.WEP_PASSWORD_AUTO, AccessPointState.WEP_PASSWORD_ASCII,
|
AccessPointState.WEP_PASSWORD_AUTO, AccessPointState.WEP_PASSWORD_ASCII,
|
||||||
AccessPointState.WEP_PASSWORD_HEX
|
AccessPointState.WEP_PASSWORD_HEX
|
||||||
};
|
};
|
||||||
|
private static final String NOT_APPLICABLE = "N/A";
|
||||||
|
|
||||||
// Button positions, default to impossible values
|
// Button positions, default to impossible values
|
||||||
private int mConnectButtonPos = Integer.MAX_VALUE;
|
private int mConnectButtonPos = Integer.MAX_VALUE;
|
||||||
private int mForgetButtonPos = Integer.MAX_VALUE;
|
private int mForgetButtonPos = Integer.MAX_VALUE;
|
||||||
@@ -130,11 +132,13 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
|||||||
private TextView mSecurityText;
|
private TextView mSecurityText;
|
||||||
private Spinner mSecuritySpinner;
|
private Spinner mSecuritySpinner;
|
||||||
private Spinner mWepTypeSpinner;
|
private Spinner mWepTypeSpinner;
|
||||||
|
private Keystore mKeystore;
|
||||||
|
|
||||||
public AccessPointDialog(Context context, WifiLayer wifiLayer) {
|
public AccessPointDialog(Context context, WifiLayer wifiLayer) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
mWifiLayer = wifiLayer;
|
mWifiLayer = wifiLayer;
|
||||||
|
mKeystore = Keystore.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -325,19 +329,34 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
|||||||
setEnterpriseFields(view);
|
setEnterpriseFields(view);
|
||||||
mEapSpinner.setSelection(getSelectionIndex(
|
mEapSpinner.setSelection(getSelectionIndex(
|
||||||
R.array.wifi_eap_entries, mState.getEap()));
|
R.array.wifi_eap_entries, mState.getEap()));
|
||||||
Keystore ks = Keystore.getInstance();
|
|
||||||
mClientCertSpinner.setSelection(getSelectionIndex(
|
mClientCertSpinner.setSelection(getSelectionIndex(
|
||||||
ks.getAllCertificateKeys(), mState.getEnterpriseField(
|
getAllCertificateKeys(), mState.getEnterpriseField(
|
||||||
AccessPointState.CLIENT_CERT)));
|
AccessPointState.CLIENT_CERT)));
|
||||||
mCaCertSpinner.setSelection(getSelectionIndex(
|
mCaCertSpinner.setSelection(getSelectionIndex(
|
||||||
ks.getAllCertificateKeys(), mState.getEnterpriseField(
|
getAllCertificateKeys(), mState.getEnterpriseField(
|
||||||
AccessPointState.CA_CERT)));
|
AccessPointState.CA_CERT)));
|
||||||
mPrivateKeySpinner.setSelection(getSelectionIndex(
|
mPrivateKeySpinner.setSelection(getSelectionIndex(
|
||||||
ks.getAllUserkeyKeys(), mState.getEnterpriseField(
|
getAllUserkeyKeys(), mState.getEnterpriseField(
|
||||||
AccessPointState.PRIVATE_KEY)));
|
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) {
|
private void setEnterpriseFields(View view) {
|
||||||
mIdentityText = (TextView) view.findViewById(R.id.identity_text);
|
mIdentityText = (TextView) view.findViewById(R.id.identity_text);
|
||||||
mIdentityEdit = (EditText) view.findViewById(R.id.identity_edit);
|
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);
|
mPhase2Spinner.setPromptId(R.string.please_select_phase2);
|
||||||
setSpinnerAdapter(mPhase2Spinner, R.array.wifi_phase2_entries);
|
setSpinnerAdapter(mPhase2Spinner, R.array.wifi_phase2_entries);
|
||||||
|
|
||||||
Keystore ks = Keystore.getInstance();
|
|
||||||
|
|
||||||
mClientCertSpinner =
|
mClientCertSpinner =
|
||||||
(Spinner) view.findViewById(R.id.client_certificate_spinner);
|
(Spinner) view.findViewById(R.id.client_certificate_spinner);
|
||||||
mClientCertSpinner.setOnItemSelectedListener(this);
|
mClientCertSpinner.setOnItemSelectedListener(this);
|
||||||
mClientCertSpinner.setPromptId(
|
mClientCertSpinner.setPromptId(
|
||||||
R.string.please_select_client_certificate);
|
R.string.please_select_client_certificate);
|
||||||
setSpinnerAdapter(mClientCertSpinner, ks.getAllCertificateKeys());
|
setSpinnerAdapter(mClientCertSpinner, getAllCertificateKeys());
|
||||||
|
|
||||||
mCaCertSpinner =
|
mCaCertSpinner =
|
||||||
(Spinner) view.findViewById(R.id.ca_certificate_spinner);
|
(Spinner) view.findViewById(R.id.ca_certificate_spinner);
|
||||||
mCaCertSpinner.setOnItemSelectedListener(this);
|
mCaCertSpinner.setOnItemSelectedListener(this);
|
||||||
mCaCertSpinner.setPromptId(R.string.please_select_ca_certificate);
|
mCaCertSpinner.setPromptId(R.string.please_select_ca_certificate);
|
||||||
setSpinnerAdapter(mCaCertSpinner, ks.getAllCertificateKeys());
|
setSpinnerAdapter(mCaCertSpinner, getAllCertificateKeys());
|
||||||
|
|
||||||
mPrivateKeySpinner =
|
mPrivateKeySpinner =
|
||||||
(Spinner) view.findViewById(R.id.private_key_spinner);
|
(Spinner) view.findViewById(R.id.private_key_spinner);
|
||||||
mPrivateKeySpinner.setOnItemSelectedListener(this);
|
mPrivateKeySpinner.setOnItemSelectedListener(this);
|
||||||
mPrivateKeySpinner.setPromptId(R.string.please_select_private_key);
|
mPrivateKeySpinner.setPromptId(R.string.please_select_private_key);
|
||||||
setSpinnerAdapter(mPrivateKeySpinner, ks.getAllUserkeyKeys());
|
setSpinnerAdapter(mPrivateKeySpinner, getAllUserkeyKeys());
|
||||||
|
|
||||||
mEnterpriseTextFields = new EditText[] {
|
mEnterpriseTextFields = new EditText[] {
|
||||||
mIdentityEdit, mAnonymousIdentityEdit, mPrivateKeyPasswdEdit
|
mIdentityEdit, mAnonymousIdentityEdit, mPrivateKeyPasswdEdit
|
||||||
@@ -639,7 +656,6 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
|||||||
|
|
||||||
private void updateEnterpriseFields(int securityType) {
|
private void updateEnterpriseFields(int securityType) {
|
||||||
int i;
|
int i;
|
||||||
Keystore ks = Keystore.getInstance();
|
|
||||||
for (i = AccessPointState.IDENTITY ;
|
for (i = AccessPointState.IDENTITY ;
|
||||||
i < AccessPointState.MAX_ENTRPRISE_FIELD ; i++) {
|
i < AccessPointState.MAX_ENTRPRISE_FIELD ; i++) {
|
||||||
String value;
|
String value;
|
||||||
@@ -648,16 +664,21 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
|||||||
} else {
|
} else {
|
||||||
Spinner spinner = mEnterpriseSpinnerFields[i -
|
Spinner spinner = mEnterpriseSpinnerFields[i -
|
||||||
AccessPointState.CLIENT_CERT];
|
AccessPointState.CLIENT_CERT];
|
||||||
|
int index = spinner.getSelectedItemPosition();
|
||||||
if (i != AccessPointState.PRIVATE_KEY) {
|
if (index == (spinner.getCount() - 1)) {
|
||||||
value = ks.getCertificate(ks.getAllCertificateKeys()
|
value = "";
|
||||||
[spinner.getSelectedItemPosition()]);
|
|
||||||
} else {
|
} else {
|
||||||
value = ks.getUserkey(ks.getAllUserkeyKeys()
|
if (i != AccessPointState.PRIVATE_KEY) {
|
||||||
[spinner.getSelectedItemPosition()]);
|
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);
|
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