eix enterprise config storage bugs

Reading empty and not updating was resulting in retaining old values
in a config. Also, fix matching phase2 entries.

Additionally, allow configuring subset of enterprise fields. Necessary
since password cannot be read back from supplicant.

Change-Id: I83a01690a0cf7cad1457a674f50f1e3a1a0441b5
This commit is contained in:
Irfan Sheriff
2013-01-17 08:58:14 -08:00
committed by Irfan Sheriff
parent 46e0931080
commit b07526fb1c
2 changed files with 42 additions and 28 deletions

View File

@@ -1121,17 +1121,19 @@ class WifiConfigStore {
break setVariables;
}
HashMap<String, String> enterpriseFields = config.enterpriseConfig.getFields();
for (String key : enterpriseFields.keySet()) {
String value = enterpriseFields.get(key);
if (!mWifiNative.setNetworkVariable(
netId,
key,
value)) {
loge(config.SSID + ": failed to set " + key +
": " + value);
break setVariables;
}
if (config.enterpriseConfig != null) {
HashMap<String, String> enterpriseFields = config.enterpriseConfig.getFields();
for (String key : enterpriseFields.keySet()) {
String value = enterpriseFields.get(key);
if (!mWifiNative.setNetworkVariable(
netId,
key,
value)) {
loge(config.SSID + ": failed to set " + key +
": " + value);
break setVariables;
}
}
}
updateFailed = false;
}
@@ -1430,11 +1432,16 @@ class WifiConfigStore {
}
}
HashMap<String, String> entepriseFields = config.enterpriseConfig.getFields();
for (String key : entepriseFields.keySet()) {
if (config.enterpriseConfig == null) {
config.enterpriseConfig = new WifiEnterpriseConfig();
}
HashMap<String, String> enterpriseFields = config.enterpriseConfig.getFields();
for (String key : WifiEnterpriseConfig.getSupplicantKeys()) {
value = mWifiNative.getNetworkVariable(netId, key);
if (!TextUtils.isEmpty(value)) {
entepriseFields.put(key, removeDoubleQuotes(value));
enterpriseFields.put(key, removeDoubleQuotes(value));
} else {
enterpriseFields.put(key, WifiEnterpriseConfig.EMPTY_VALUE);
}
}

View File

@@ -74,18 +74,14 @@ public class WifiEnterpriseConfig implements Parcelable {
/** This represents an empty value of an enterprise field.
* NULL is used at wpa_supplicant to indicate an empty value
*/
private static final String EMPTY_VALUE = "NULL";
static final String EMPTY_VALUE = "NULL";
public WifiEnterpriseConfig() {
// Set the required defaults
mFields.put(EAP_KEY, Eap.strings[Eap.PEAP]);
mFields.put(ENGINE_KEY, ENGINE_DISABLE);
// Do not set defaults so that the enterprise fields that are not changed
// by API are not changed underneath
// This is essential because an app may not have all fields like password
// available. It allows modification of subset of fields.
for (String key : new String[] {PHASE2_KEY, IDENTITY_KEY, ANON_IDENTITY_KEY,
PASSWORD_KEY, CLIENT_CERT_KEY, ENGINE_ID_KEY, PRIVATE_KEY_ID_KEY,
CA_CERT_KEY, SUBJECT_MATCH_KEY}) {
mFields.put(key, EMPTY_VALUE);
}
}
/** Copy constructor */
@@ -128,6 +124,8 @@ public class WifiEnterpriseConfig implements Parcelable {
};
public static final class Eap {
/* NONE represents an empty enterprise config */
public static final int NONE = -1;
public static final int PEAP = 0;
public static final int TLS = 1;
public static final int TTLS = 2;
@@ -152,6 +150,13 @@ public class WifiEnterpriseConfig implements Parcelable {
return mFields;
}
/** Internal use only @hide */
public static String[] getSupplicantKeys() {
return new String[] { EAP_KEY, PHASE2_KEY, IDENTITY_KEY, ANON_IDENTITY_KEY, PASSWORD_KEY,
CLIENT_CERT_KEY, CA_CERT_KEY, SUBJECT_MATCH_KEY, ENGINE_KEY, ENGINE_ID_KEY,
PRIVATE_KEY_ID_KEY };
}
/**
* Set the EAP authentication method.
* @param eapMethod is one {@link Eap#PEAP}, {@link Eap#TLS}, {@link Eap#TTLS} or
@@ -177,7 +182,7 @@ public class WifiEnterpriseConfig implements Parcelable {
*/
public int getEapMethod() {
String eapMethod = mFields.get(EAP_KEY);
return getStringIndex(Eap.strings, eapMethod, Eap.PEAP);
return getStringIndex(Eap.strings, eapMethod, Eap.NONE);
}
/**
@@ -211,7 +216,11 @@ public class WifiEnterpriseConfig implements Parcelable {
* @return a phase 2 method defined at {@link Phase2}
* */
public int getPhase2Method() {
String phase2Method = mFields.get(PHASE2_KEY);
String phase2Method = removeDoubleQuotes(mFields.get(PHASE2_KEY));
// Remove auth= prefix
if (phase2Method.startsWith(Phase2.PREFIX)) {
phase2Method = phase2Method.substring(Phase2.PREFIX.length());
}
return getStringIndex(Phase2.strings, phase2Method, Phase2.NONE);
}
@@ -387,9 +396,7 @@ public class WifiEnterpriseConfig implements Parcelable {
*/
private int getStringIndex(String arr[], String toBeFound, int defaultIndex) {
for (int i = 0; i < arr.length; i++) {
// toBeFound can be formatted with a prefix. For example, phase2
// string has "auth=" as the prefix.
if (toBeFound.contains(arr[i])) return i;
if (toBeFound.equals(arr[i])) return i;
}
return defaultIndex;
}