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.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.security.CertTool;
|
||||
import android.security.Keystore;
|
||||
import android.security.Credentials;
|
||||
import android.security.KeyStore;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
@@ -128,13 +128,13 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
private TextView mSecurityText;
|
||||
private Spinner mSecuritySpinner;
|
||||
private Spinner mWepTypeSpinner;
|
||||
private CertTool mCertTool;
|
||||
private KeyStore mKeyStore;
|
||||
|
||||
public AccessPointDialog(Context context, WifiLayer wifiLayer) {
|
||||
super(context);
|
||||
|
||||
mWifiLayer = wifiLayer;
|
||||
mCertTool = CertTool.getInstance();
|
||||
mKeyStore = KeyStore.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -342,18 +342,22 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
}
|
||||
|
||||
private String[] getAllCaCertificateKeys() {
|
||||
return appendEmptyInSelection(mCertTool.getAllCaCertificateKeys());
|
||||
return appendEmptyInSelection(mKeyStore.saw(Credentials.CA_CERTIFICATE));
|
||||
}
|
||||
|
||||
private String[] getAllUserCertificateKeys() {
|
||||
return appendEmptyInSelection(mCertTool.getAllUserCertificateKeys());
|
||||
return appendEmptyInSelection(mKeyStore.saw(Credentials.USER_CERTIFICATE));
|
||||
}
|
||||
|
||||
private String[] appendEmptyInSelection(String[] keys) {
|
||||
String[] selections = new String[keys.length + 1];
|
||||
System.arraycopy(keys, 0, selections, 0, keys.length);
|
||||
selections[keys.length] = NOT_APPLICABLE;
|
||||
return selections;
|
||||
if (keys == null) {
|
||||
return new String[] {NOT_APPLICABLE};
|
||||
} else {
|
||||
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) {
|
||||
@@ -635,31 +639,22 @@ public class AccessPointDialog extends AlertDialog implements DialogInterface.On
|
||||
Spinner spinner = mClientCertSpinner;
|
||||
int index = spinner.getSelectedItemPosition();
|
||||
if (index != (spinner.getCount() - 1)) {
|
||||
String key = (String)spinner.getSelectedItem();
|
||||
value = mCertTool.getUserCertificate(key);
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
mState.setEnterpriseField(AccessPointState.CLIENT_CERT,
|
||||
BLOB_HEADER + value);
|
||||
}
|
||||
value = mCertTool.getUserPrivateKey(key);
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
mState.setEnterpriseField(AccessPointState.PRIVATE_KEY,
|
||||
BLOB_HEADER + value);
|
||||
}
|
||||
String key = (String) spinner.getSelectedItem();
|
||||
mState.setEnterpriseField(AccessPointState.CLIENT_CERT,
|
||||
BLOB_HEADER + Credentials.USER_CERTIFICATE + key);
|
||||
mState.setEnterpriseField(AccessPointState.PRIVATE_KEY,
|
||||
BLOB_HEADER + Credentials.USER_PRIVATE_KEY + key);
|
||||
}
|
||||
spinner = mCaCertSpinner;
|
||||
index = spinner.getSelectedItemPosition();
|
||||
if (index != (spinner.getCount() - 1)) {
|
||||
String key = (String)spinner.getSelectedItem();
|
||||
value = mCertTool.getCaCertificate(key);
|
||||
if (!TextUtils.isEmpty(value)) {
|
||||
mState.setEnterpriseField(AccessPointState.CA_CERT,
|
||||
BLOB_HEADER + value);
|
||||
}
|
||||
String key = (String) spinner.getSelectedItem();
|
||||
mState.setEnterpriseField(AccessPointState.CA_CERT,
|
||||
BLOB_HEADER + Credentials.CA_CERTIFICATE + key);
|
||||
}
|
||||
mState.setSecurity(AccessPointState.EAP);
|
||||
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: {
|
||||
// Unlock the keystore if it is not unlocked yet.
|
||||
if (Keystore.getInstance().getState() != Keystore.UNLOCKED) {
|
||||
getContext().startActivity(new Intent(
|
||||
Keystore.ACTION_UNLOCK_CREDENTIAL_STORAGE));
|
||||
if (mKeyStore.test() != KeyStore.NO_ERROR) {
|
||||
Credentials.getInstance().unlock(getContext());
|
||||
return;
|
||||
}
|
||||
enableEnterpriseFields();
|
||||
|
Reference in New Issue
Block a user