diff options
| author | 2016-09-02 11:05:17 -0700 | |
|---|---|---|
| committer | 2016-09-06 10:05:02 -0700 | |
| commit | c8cd577c862efb1578348517028673f06e70e48a (patch) | |
| tree | 151e403162f9c9ff647c0a882ec70332ebade069 | |
| parent | f7c508ae09ad9dce600af23572d3d618c9ff8475 (diff) | |
WifiEnterpriseConfig: Refactor set/get field values
WifiEnterpriseConfig has a few keys which are generated internally
have unquoted values. However, the public setFieldValue() always quotes
the value when set. So, this causes a problem when restoring
these field values from config store. Since this is an internal
disctinction that only WifiEnterpriseConfig understands, add a list to
check if a particular field value needs to be quoted or not. Also,
remove any direct "mFields.put" invocations with |setFieldValue|.
While there,
Refactor the existing |setFieldValue| & |getFieldValue| methods.
BUG: 31246524
TEST: Unit tests
TEST: Integrated with config store and verified that a previous TLS EAP
connection failure is no longer seen.
Change-Id: Ib85f3bce378720a6a6c2ae1439837a8e866a088d
| -rw-r--r-- | wifi/java/android/net/wifi/WifiEnterpriseConfig.java | 86 |
1 files changed, 50 insertions, 36 deletions
diff --git a/wifi/java/android/net/wifi/WifiEnterpriseConfig.java b/wifi/java/android/net/wifi/WifiEnterpriseConfig.java index 227230646250..c0e8bc200f63 100644 --- a/wifi/java/android/net/wifi/WifiEnterpriseConfig.java +++ b/wifi/java/android/net/wifi/WifiEnterpriseConfig.java @@ -33,7 +33,9 @@ import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -116,7 +118,6 @@ public class WifiEnterpriseConfig implements Parcelable { /** @hide */ public static final String CA_CERT_ALIAS_DELIMITER = " "; - // Fields to copy verbatim from wpa_supplicant. private static final String[] SUPPLICANT_CONFIG_KEYS = new String[] { IDENTITY_KEY, @@ -133,6 +134,11 @@ public class WifiEnterpriseConfig implements Parcelable { CA_PATH_KEY }; + /** + * Fields that have unquoted values in {@link #mFields}. + */ + private static final List<String> UNQUOTED_KEYS = Arrays.asList(ENGINE_KEY, OPP_KEY_CACHING); + private HashMap<String, String> mFields = new HashMap<String, String>(); private X509Certificate[] mCaCerts; private PrivateKey mClientPrivateKey; @@ -458,7 +464,7 @@ public class WifiEnterpriseConfig implements Parcelable { case Eap.AKA: case Eap.AKA_PRIME: mEapMethod = eapMethod; - mFields.put(OPP_KEY_CACHING, "1"); + setFieldValue(OPP_KEY_CACHING, "1"); break; default: throw new IllegalArgumentException("Unknown EAP method"); @@ -517,7 +523,7 @@ public class WifiEnterpriseConfig implements Parcelable { * @return the identity */ public String getIdentity() { - return getFieldValue(IDENTITY_KEY, ""); + return getFieldValue(IDENTITY_KEY); } /** @@ -526,7 +532,7 @@ public class WifiEnterpriseConfig implements Parcelable { * @param anonymousIdentity the anonymous identity */ public void setAnonymousIdentity(String anonymousIdentity) { - setFieldValue(ANON_IDENTITY_KEY, anonymousIdentity, ""); + setFieldValue(ANON_IDENTITY_KEY, anonymousIdentity); } /** @@ -534,7 +540,7 @@ public class WifiEnterpriseConfig implements Parcelable { * @return anonymous identity */ public String getAnonymousIdentity() { - return getFieldValue(ANON_IDENTITY_KEY, ""); + return getFieldValue(ANON_IDENTITY_KEY); } /** @@ -542,7 +548,7 @@ public class WifiEnterpriseConfig implements Parcelable { * @param password the password */ public void setPassword(String password) { - setFieldValue(PASSWORD_KEY, password, ""); + setFieldValue(PASSWORD_KEY, password); } /** @@ -552,7 +558,7 @@ public class WifiEnterpriseConfig implements Parcelable { * framework, returns "*". */ public String getPassword() { - return getFieldValue(PASSWORD_KEY, ""); + return getFieldValue(PASSWORD_KEY); } /** @@ -642,7 +648,7 @@ public class WifiEnterpriseConfig implements Parcelable { * @hide */ @Nullable public String[] getCaCertificateAliases() { - String value = getFieldValue(CA_CERT_KEY, ""); + String value = getFieldValue(CA_CERT_KEY); if (value.startsWith(CA_CERT_PREFIX)) { // Backwards compatibility: parse the original alias prefix. return new String[] {getFieldValue(CA_CERT_KEY, CA_CERT_PREFIX)}; @@ -769,7 +775,7 @@ public class WifiEnterpriseConfig implements Parcelable { * @hide */ public String getCaPath() { - return getFieldValue(CA_PATH_KEY, ""); + return getFieldValue(CA_PATH_KEY); } /** Set Client certificate alias. @@ -785,11 +791,11 @@ public class WifiEnterpriseConfig implements Parcelable { setFieldValue(PRIVATE_KEY_ID_KEY, alias, Credentials.USER_PRIVATE_KEY); // Also, set engine parameters if (TextUtils.isEmpty(alias)) { - mFields.put(ENGINE_KEY, ENGINE_DISABLE); - mFields.put(ENGINE_ID_KEY, EMPTY_VALUE); + setFieldValue(ENGINE_KEY, ENGINE_DISABLE); + setFieldValue(ENGINE_ID_KEY, ""); } else { - mFields.put(ENGINE_KEY, ENGINE_ENABLE); - mFields.put(ENGINE_ID_KEY, convertToQuotedString(ENGINE_ID_KEYSTORE)); + setFieldValue(ENGINE_KEY, ENGINE_ENABLE); + setFieldValue(ENGINE_ID_KEY, ENGINE_ID_KEYSTORE); } } @@ -862,7 +868,7 @@ public class WifiEnterpriseConfig implements Parcelable { * @deprecated in favor of altSubjectMatch */ public void setSubjectMatch(String subjectMatch) { - setFieldValue(SUBJECT_MATCH_KEY, subjectMatch, ""); + setFieldValue(SUBJECT_MATCH_KEY, subjectMatch); } /** @@ -871,7 +877,7 @@ public class WifiEnterpriseConfig implements Parcelable { * @deprecated in favor of altSubjectMatch */ public String getSubjectMatch() { - return getFieldValue(SUBJECT_MATCH_KEY, ""); + return getFieldValue(SUBJECT_MATCH_KEY); } /** @@ -881,7 +887,7 @@ public class WifiEnterpriseConfig implements Parcelable { * DNS:server.example.com;EMAIL:server@example.com */ public void setAltSubjectMatch(String altSubjectMatch) { - setFieldValue(ALTSUBJECT_MATCH_KEY, altSubjectMatch, ""); + setFieldValue(ALTSUBJECT_MATCH_KEY, altSubjectMatch); } /** @@ -889,7 +895,7 @@ public class WifiEnterpriseConfig implements Parcelable { * @return the alternate subject match string */ public String getAltSubjectMatch() { - return getFieldValue(ALTSUBJECT_MATCH_KEY, ""); + return getFieldValue(ALTSUBJECT_MATCH_KEY); } /** @@ -919,7 +925,7 @@ public class WifiEnterpriseConfig implements Parcelable { * @return The domain value. */ public String getDomainSuffixMatch() { - return getFieldValue(DOM_SUFFIX_MATCH_KEY, ""); + return getFieldValue(DOM_SUFFIX_MATCH_KEY); } /** @@ -928,7 +934,7 @@ public class WifiEnterpriseConfig implements Parcelable { * @param realm the realm */ public void setRealm(String realm) { - setFieldValue(REALM_KEY, realm, ""); + setFieldValue(REALM_KEY, realm); } /** @@ -936,7 +942,7 @@ public class WifiEnterpriseConfig implements Parcelable { * @return the realm */ public String getRealm() { - return getFieldValue(REALM_KEY, ""); + return getFieldValue(REALM_KEY); } /** @@ -944,7 +950,7 @@ public class WifiEnterpriseConfig implements Parcelable { * @param plmn the plmn value derived from mcc (mobile country code) & mnc (mobile network code) */ public void setPlmn(String plmn) { - setFieldValue(PLMN_KEY, plmn, ""); + setFieldValue(PLMN_KEY, plmn); } /** @@ -953,7 +959,7 @@ public class WifiEnterpriseConfig implements Parcelable { * @return the plmn */ public String getPlmn() { - return getFieldValue(PLMN_KEY, ""); + return getFieldValue(PLMN_KEY); } /** See {@link WifiConfiguration#getKeyIdForCredentials} @hide */ @@ -998,13 +1004,13 @@ public class WifiEnterpriseConfig implements Parcelable { } /** - * Returns the field value for the key. + * Returns the field value for the key with prefix removed. * @param key into the hash * @param prefix is the prefix that the value may have * @return value * @hide */ - public String getFieldValue(String key, String prefix) { + private String getFieldValue(String key, String prefix) { // TODO: Should raise an exception if |key| is EAP_KEY or PHASE2_KEY since // neither of these keys should be retrieved in this manner. String value = mFields.get(key); @@ -1020,38 +1026,46 @@ public class WifiEnterpriseConfig implements Parcelable { } /** + * Returns the field value for the key. + * @param key into the hash + * @return value + * @hide + */ + public String getFieldValue(String key) { + return getFieldValue(key, ""); + } + + /** * Set a value with an optional prefix at key * @param key into the hash * @param value to be set * @param prefix an optional value to be prefixed to actual value * @hide */ - public void setFieldValue(String key, String value, String prefix) { + private void setFieldValue(String key, String value, String prefix) { // TODO: Should raise an exception if |key| is EAP_KEY or PHASE2_KEY since // neither of these keys should be set in this manner. if (TextUtils.isEmpty(value)) { mFields.put(key, EMPTY_VALUE); } else { - mFields.put(key, convertToQuotedString(prefix + value)); + String valueToSet; + if (!UNQUOTED_KEYS.contains(key)) { + valueToSet = convertToQuotedString(prefix + value); + } else { + valueToSet = prefix + value; + } + mFields.put(key, valueToSet); } } - /** - * Set a value with an optional prefix at key + * Set a value at key * @param key into the hash * @param value to be set - * @param prefix an optional value to be prefixed to actual value * @hide */ public void setFieldValue(String key, String value) { - // TODO: Should raise an exception if |key| is EAP_KEY or PHASE2_KEY since - // neither of these keys should be set in this manner. - if (TextUtils.isEmpty(value)) { - mFields.put(key, EMPTY_VALUE); - } else { - mFields.put(key, convertToQuotedString(value)); - } + setFieldValue(key, value, ""); } @Override |