WifiSettings: use Credentials instead of CertTool.
This commit is contained in:
@@ -23,8 +23,8 @@ import android.content.Context;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.security.CertTool;
|
import android.security.Credentials;
|
||||||
import android.security.Keystore;
|
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;
|
||||||
@@ -128,13 +128,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 CertTool mCertTool;
|
private KeyStore mKeyStore;
|
||||||
|
|
||||||
public AccessPointDialog(Context context, WifiLayer wifiLayer) {
|
public AccessPointDialog(Context context, WifiLayer wifiLayer) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
mWifiLayer = wifiLayer;
|
mWifiLayer = wifiLayer;
|
||||||
mCertTool = CertTool.getInstance();
|
mKeyStore = KeyStore.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -342,18 +342,22 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String[] getAllCaCertificateKeys() {
|
private String[] getAllCaCertificateKeys() {
|
||||||
return appendEmptyInSelection(mCertTool.getAllCaCertificateKeys());
|
return appendEmptyInSelection(mKeyStore.saw(Credentials.CA_CERTIFICATE));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] getAllUserCertificateKeys() {
|
private String[] getAllUserCertificateKeys() {
|
||||||
return appendEmptyInSelection(mCertTool.getAllUserCertificateKeys());
|
return appendEmptyInSelection(mKeyStore.saw(Credentials.USER_CERTIFICATE));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] appendEmptyInSelection(String[] keys) {
|
private String[] appendEmptyInSelection(String[] keys) {
|
||||||
String[] selections = new String[keys.length + 1];
|
if (keys == null) {
|
||||||
System.arraycopy(keys, 0, selections, 0, keys.length);
|
return new String[] {NOT_APPLICABLE};
|
||||||
selections[keys.length] = NOT_APPLICABLE;
|
} else {
|
||||||
return selections;
|
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) {
|
||||||
@@ -635,31 +639,22 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
|||||||
Spinner spinner = mClientCertSpinner;
|
Spinner spinner = mClientCertSpinner;
|
||||||
int index = spinner.getSelectedItemPosition();
|
int index = spinner.getSelectedItemPosition();
|
||||||
if (index != (spinner.getCount() - 1)) {
|
if (index != (spinner.getCount() - 1)) {
|
||||||
String key = (String)spinner.getSelectedItem();
|
String key = (String) spinner.getSelectedItem();
|
||||||
value = mCertTool.getUserCertificate(key);
|
mState.setEnterpriseField(AccessPointState.CLIENT_CERT,
|
||||||
if (!TextUtils.isEmpty(value)) {
|
BLOB_HEADER + Credentials.USER_CERTIFICATE + key);
|
||||||
mState.setEnterpriseField(AccessPointState.CLIENT_CERT,
|
mState.setEnterpriseField(AccessPointState.PRIVATE_KEY,
|
||||||
BLOB_HEADER + value);
|
BLOB_HEADER + Credentials.USER_PRIVATE_KEY + key);
|
||||||
}
|
|
||||||
value = mCertTool.getUserPrivateKey(key);
|
|
||||||
if (!TextUtils.isEmpty(value)) {
|
|
||||||
mState.setEnterpriseField(AccessPointState.PRIVATE_KEY,
|
|
||||||
BLOB_HEADER + value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
spinner = mCaCertSpinner;
|
spinner = mCaCertSpinner;
|
||||||
index = spinner.getSelectedItemPosition();
|
index = spinner.getSelectedItemPosition();
|
||||||
if (index != (spinner.getCount() - 1)) {
|
if (index != (spinner.getCount() - 1)) {
|
||||||
String key = (String)spinner.getSelectedItem();
|
String key = (String) spinner.getSelectedItem();
|
||||||
value = mCertTool.getCaCertificate(key);
|
mState.setEnterpriseField(AccessPointState.CA_CERT,
|
||||||
if (!TextUtils.isEmpty(value)) {
|
BLOB_HEADER + Credentials.CA_CERTIFICATE + key);
|
||||||
mState.setEnterpriseField(AccessPointState.CA_CERT,
|
|
||||||
BLOB_HEADER + value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mState.setSecurity(AccessPointState.EAP);
|
mState.setSecurity(AccessPointState.EAP);
|
||||||
mState.setEap(mEapSpinner.getSelectedItemPosition());
|
mState.setEap(mEapSpinner.getSelectedItemPosition());
|
||||||
mState.setPhase2((String)mPhase2Spinner.getSelectedItem());
|
mState.setPhase2((String) mPhase2Spinner.getSelectedItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -765,9 +760,8 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
|||||||
}
|
}
|
||||||
case SECURITY_EAP: {
|
case SECURITY_EAP: {
|
||||||
// Unlock the keystore if it is not unlocked yet.
|
// Unlock the keystore if it is not unlocked yet.
|
||||||
if (Keystore.getInstance().getState() != Keystore.UNLOCKED) {
|
if (mKeyStore.test() != KeyStore.NO_ERROR) {
|
||||||
getContext().startActivity(new Intent(
|
Credentials.getInstance().unlock(getContext());
|
||||||
Keystore.ACTION_UNLOCK_CREDENTIAL_STORAGE));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
enableEnterpriseFields();
|
enableEnterpriseFields();
|
||||||
|
@@ -29,7 +29,8 @@ import android.preference.PreferenceActivity;
|
|||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.security.Keystore;
|
import android.security.Credentials;
|
||||||
|
import android.security.KeyStore;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@@ -86,6 +87,7 @@ public class WifiSettings extends PreferenceActivity implements WifiLayer.Callba
|
|||||||
|
|
||||||
private WeakHashMap<AccessPointState, AccessPointPreference> mAps;
|
private WeakHashMap<AccessPointState, AccessPointPreference> mAps;
|
||||||
|
|
||||||
|
private KeyStore mKeyStore = KeyStore.getInstance();
|
||||||
private AccessPointState mResumeState = null;
|
private AccessPointState mResumeState = null;
|
||||||
private int mResumeMode;
|
private int mResumeMode;
|
||||||
|
|
||||||
@@ -156,14 +158,14 @@ public class WifiSettings extends PreferenceActivity implements WifiLayer.Callba
|
|||||||
mWifiEnabler.resume();
|
mWifiEnabler.resume();
|
||||||
// do what we should have after keystore is unlocked.
|
// do what we should have after keystore is unlocked.
|
||||||
if (mResumeState != null) {
|
if (mResumeState != null) {
|
||||||
if (Keystore.getInstance().getState() == Keystore.UNLOCKED) {
|
if (mKeyStore.test() == KeyStore.NO_ERROR) {
|
||||||
showAccessPointDialog(mResumeState, mResumeMode);
|
showAccessPointDialog(mResumeState, mResumeMode);
|
||||||
}
|
}
|
||||||
mResumeMode = -1;
|
mResumeMode = -1;
|
||||||
mResumeState = null;
|
mResumeState = null;
|
||||||
} else {
|
} else {
|
||||||
if (mResumeMode == AccessPointDialog.MODE_CONFIGURE) {
|
if (mResumeMode == AccessPointDialog.MODE_CONFIGURE) {
|
||||||
if (Keystore.getInstance().getState() == Keystore.UNLOCKED) {
|
if (mKeyStore.test() == KeyStore.NO_ERROR) {
|
||||||
((AccessPointDialog) mDialog).enableEnterpriseFields();
|
((AccessPointDialog) mDialog).enableEnterpriseFields();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -372,10 +374,8 @@ public class WifiSettings extends PreferenceActivity implements WifiLayer.Callba
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void showAccessPointDialog(AccessPointState state, int mode) {
|
public void showAccessPointDialog(AccessPointState state, int mode) {
|
||||||
if (state.isEnterprise() &&
|
if (state.isEnterprise() && mKeyStore.test() != KeyStore.NO_ERROR) {
|
||||||
Keystore.getInstance().getState() != Keystore.UNLOCKED) {
|
Credentials.getInstance().unlock(this);
|
||||||
startActivity(new Intent(
|
|
||||||
Keystore.ACTION_UNLOCK_CREDENTIAL_STORAGE));
|
|
||||||
mResumeState = state;
|
mResumeState = state;
|
||||||
mResumeMode = mode;
|
mResumeMode = mode;
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user