am e7e587da
: Revert "Use the keystore service instead of the direct file acess."
Merge commit 'e7e587daf65ec39ca2b10e5c6a03f6bb0b4ccce0' * commit 'e7e587daf65ec39ca2b10e5c6a03f6bb0b4ccce0': Revert "Use the keystore service instead of the direct file acess."
This commit is contained in:
committed by
The Android Open Source Project
commit
24b17de66c
@@ -22,7 +22,6 @@ 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;
|
||||||
@@ -80,7 +79,6 @@ 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;
|
||||||
@@ -132,13 +130,11 @@ 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
|
||||||
@@ -329,34 +325,19 @@ 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(
|
||||||
getAllCertificateKeys(), mState.getEnterpriseField(
|
ks.getAllCertificateKeys(), mState.getEnterpriseField(
|
||||||
AccessPointState.CLIENT_CERT)));
|
AccessPointState.CLIENT_CERT)));
|
||||||
mCaCertSpinner.setSelection(getSelectionIndex(
|
mCaCertSpinner.setSelection(getSelectionIndex(
|
||||||
getAllCertificateKeys(), mState.getEnterpriseField(
|
ks.getAllCertificateKeys(), mState.getEnterpriseField(
|
||||||
AccessPointState.CA_CERT)));
|
AccessPointState.CA_CERT)));
|
||||||
mPrivateKeySpinner.setSelection(getSelectionIndex(
|
mPrivateKeySpinner.setSelection(getSelectionIndex(
|
||||||
getAllUserkeyKeys(), mState.getEnterpriseField(
|
ks.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);
|
||||||
@@ -384,24 +365,26 @@ 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, getAllCertificateKeys());
|
setSpinnerAdapter(mClientCertSpinner, ks.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, getAllCertificateKeys());
|
setSpinnerAdapter(mCaCertSpinner, ks.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, getAllUserkeyKeys());
|
setSpinnerAdapter(mPrivateKeySpinner, ks.getAllUserkeyKeys());
|
||||||
|
|
||||||
mEnterpriseTextFields = new EditText[] {
|
mEnterpriseTextFields = new EditText[] {
|
||||||
mIdentityEdit, mAnonymousIdentityEdit, mPrivateKeyPasswdEdit
|
mIdentityEdit, mAnonymousIdentityEdit, mPrivateKeyPasswdEdit
|
||||||
@@ -656,6 +639,7 @@ 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;
|
||||||
@@ -664,21 +648,16 @@ 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 (index == (spinner.getCount() - 1)) {
|
|
||||||
value = "";
|
|
||||||
} else {
|
|
||||||
if (i != AccessPointState.PRIVATE_KEY) {
|
if (i != AccessPointState.PRIVATE_KEY) {
|
||||||
value = mKeystore.getCertificate(
|
value = ks.getCertificate(ks.getAllCertificateKeys()
|
||||||
getAllCertificateKeys()[index]);
|
[spinner.getSelectedItemPosition()]);
|
||||||
} else {
|
} else {
|
||||||
value = mKeystore.getUserkey(
|
value = ks.getUserkey(ks.getAllUserkeyKeys()
|
||||||
getAllUserkeyKeys()[index]);
|
[spinner.getSelectedItemPosition()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (!TextUtils.isEmpty(value)) {
|
||||||
if (!TextUtils.isEmpty(value) ||
|
|
||||||
(i == AccessPointState.PRIVATE_KEY_PASSWD)) {
|
|
||||||
mState.setEnterpriseField(i, value);
|
mState.setEnterpriseField(i, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
81
src/com/android/settings/wifi/Keystore.java
Normal file
81
src/com/android/settings/wifi/Keystore.java
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user