FileDocCategorySizeDatePackage
WifiEnterpriseConfig.javaAPI DocAndroid 5.1 API21856Thu Mar 12 22:22:44 GMT 2015android.net.wifi

WifiEnterpriseConfig

public class WifiEnterpriseConfig extends Object implements android.os.Parcelable
Enterprise configuration details for Wi-Fi. Stores details about the EAP method and any associated credentials.

Fields Summary
public static final String
EMPTY_VALUE
public static final String
EAP_KEY
public static final String
PHASE2_KEY
public static final String
IDENTITY_KEY
public static final String
ANON_IDENTITY_KEY
public static final String
PASSWORD_KEY
public static final String
SUBJECT_MATCH_KEY
public static final String
OPP_KEY_CACHING
public static final String
ENGINE_ID_KEYSTORE
String representing the keystore OpenSSL ENGINE's ID.
public static final String
KEYSTORE_URI
String representing the keystore URI used for wpa_supplicant.
public static final String
ENGINE_ENABLE
String to set the engine value to when it should be enabled.
public static final String
ENGINE_DISABLE
String to set the engine value to when it should be disabled.
public static final String
CA_CERT_PREFIX
public static final String
CLIENT_CERT_PREFIX
public static final String
CLIENT_CERT_KEY
public static final String
CA_CERT_KEY
public static final String
ENGINE_KEY
public static final String
ENGINE_ID_KEY
public static final String
PRIVATE_KEY_ID_KEY
private HashMap
mFields
private X509Certificate
mCaCert
private PrivateKey
mClientPrivateKey
private X509Certificate
mClientCertificate
public static final Creator
CREATOR
Constructors Summary
public WifiEnterpriseConfig()


      
        // 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.

    
public WifiEnterpriseConfig(WifiEnterpriseConfig source)
Copy constructor

        for (String key : source.mFields.keySet()) {
            mFields.put(key, source.mFields.get(key));
        }
    
Methods Summary
private java.lang.StringconvertToQuotedString(java.lang.String string)

        return "\"" + string + "\"";
    
public intdescribeContents()

        return 0;
    
public java.lang.StringgetAnonymousIdentity()
Get the anonymous identity

return
anonymous identity

        return getFieldValue(ANON_IDENTITY_KEY, "");
    
public java.security.cert.X509CertificategetCaCertificate()
Get CA certificate

return
X.509 CA certificate

        return mCaCert;
    
public java.lang.StringgetCaCertificateAlias()
Get CA certificate alias

return
alias to the CA certificate
hide

        return getFieldValue(CA_CERT_KEY, CA_CERT_PREFIX);
    
public java.security.cert.X509CertificategetClientCertificate()
Get client certificate

return
X.509 client certificate

        return mClientCertificate;
    
public java.lang.StringgetClientCertificateAlias()
Get client certificate alias

return
alias to the client certificate
hide

        return getFieldValue(CLIENT_CERT_KEY, CLIENT_CERT_PREFIX);
    
public java.security.PrivateKeygetClientPrivateKey()

hide

        return mClientPrivateKey;
    
public intgetEapMethod()
Get the eap method.

return
eap method configured

        String eapMethod  = mFields.get(EAP_KEY);
        return getStringIndex(Eap.strings, eapMethod, Eap.NONE);
    
public java.lang.StringgetFieldValue(java.lang.String key, java.lang.String prefix)
Returns the field value for the key.

param
key into the hash
param
prefix is the prefix that the value may have
return
value
hide

        String value = mFields.get(key);
        // Uninitialized or known to be empty after reading from supplicant
        if (TextUtils.isEmpty(value) || EMPTY_VALUE.equals(value)) return "";

        value = removeDoubleQuotes(value);
        if (value.startsWith(prefix)) {
            return value.substring(prefix.length());
        } else {
            return value;
        }
    
public java.util.HashMapgetFields()
Internal use only

hide

        return mFields;
    
public java.lang.StringgetIdentity()
Get the identity

return
the identity

        return getFieldValue(IDENTITY_KEY, "");
    
java.lang.StringgetKeyId(android.net.wifi.WifiEnterpriseConfig current)
See {@link WifiConfiguration#getKeyIdForCredentials} @hide

        String eap = mFields.get(EAP_KEY);
        String phase2 = mFields.get(PHASE2_KEY);

        // If either eap or phase2 are not initialized, use current config details
        if (TextUtils.isEmpty((eap))) {
            eap = current.mFields.get(EAP_KEY);
        }
        if (TextUtils.isEmpty(phase2)) {
            phase2 = current.mFields.get(PHASE2_KEY);
        }
        return eap + "_" + phase2;
    
public java.lang.StringgetPassword()
Get the password. Returns locally set password value. For networks fetched from framework, returns "*".

        return getFieldValue(PASSWORD_KEY, "");
    
public intgetPhase2Method()
Get the phase 2 authentication method.

return
a phase 2 method defined at {@link Phase2}

        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);
    
private intgetStringIndex(java.lang.String[] arr, java.lang.String toBeFound, int defaultIndex)
Returns the index at which the toBeFound string is found in the array.

param
arr array of strings
param
toBeFound string to be found
param
defaultIndex default index to be returned when string is not found
return
the index into array

        if (TextUtils.isEmpty(toBeFound)) return defaultIndex;
        for (int i = 0; i < arr.length; i++) {
            if (toBeFound.equals(arr[i])) return i;
        }
        return defaultIndex;
    
public java.lang.StringgetSubjectMatch()
Get subject match

return
the subject match string

        return getFieldValue(SUBJECT_MATCH_KEY, "");
    
private java.lang.StringremoveDoubleQuotes(java.lang.String string)

        if (TextUtils.isEmpty(string)) return "";
        int length = string.length();
        if ((length > 1) && (string.charAt(0) == '"")
                && (string.charAt(length - 1) == '"")) {
            return string.substring(1, length - 1);
        }
        return string;
    
public voidresetCaCertificate()

hide

        mCaCert = null;
    
public voidresetClientKeyEntry()

hide

        mClientPrivateKey = null;
        mClientCertificate = null;
    
public voidsetAnonymousIdentity(java.lang.String anonymousIdentity)
Set anonymous identity. This is used as the unencrypted identity with certain EAP types

param
anonymousIdentity the anonymous identity

        setFieldValue(ANON_IDENTITY_KEY, anonymousIdentity, "");
    
public voidsetCaCertificate(java.security.cert.X509Certificate cert)
Specify a X.509 certificate that identifies the server.

A default name is automatically assigned to the certificate and used with this configuration. The framework takes care of installing the certificate when the config is saved and removing the certificate when the config is removed.

param
cert X.509 CA certificate
throws
IllegalArgumentException if not a CA certificate

        if (cert != null) {
            if (cert.getBasicConstraints() >= 0) {
                mCaCert = cert;
            } else {
                throw new IllegalArgumentException("Not a CA certificate");
            }
        } else {
            mCaCert = null;
        }
    
public voidsetCaCertificateAlias(java.lang.String alias)
Set CA certificate alias.

See the {@link android.security.KeyChain} for details on installing or choosing a certificate

param
alias identifies the certificate
hide

        setFieldValue(CA_CERT_KEY, alias, CA_CERT_PREFIX);
    
public voidsetClientCertificateAlias(java.lang.String alias)
Set Client certificate alias.

See the {@link android.security.KeyChain} for details on installing or choosing a certificate

param
alias identifies the certificate
hide

        setFieldValue(CLIENT_CERT_KEY, alias, CLIENT_CERT_PREFIX);
        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);
        } else {
            mFields.put(ENGINE_KEY, ENGINE_ENABLE);
            mFields.put(ENGINE_ID_KEY, convertToQuotedString(ENGINE_ID_KEYSTORE));
        }
    
public voidsetClientKeyEntry(java.security.PrivateKey privateKey, java.security.cert.X509Certificate clientCertificate)
Specify a private key and client certificate for client authorization.

A default name is automatically assigned to the key entry and used with this configuration. The framework takes care of installing the key entry when the config is saved and removing the key entry when the config is removed.

param
privateKey
param
clientCertificate
throws
IllegalArgumentException for an invalid key or certificate.

        if (clientCertificate != null) {
            if (clientCertificate.getBasicConstraints() != -1) {
                throw new IllegalArgumentException("Cannot be a CA certificate");
            }
            if (privateKey == null) {
                throw new IllegalArgumentException("Client cert without a private key");
            }
            if (privateKey.getEncoded() == null) {
                throw new IllegalArgumentException("Private key cannot be encoded");
            }
        }

        mClientPrivateKey = privateKey;
        mClientCertificate = clientCertificate;
    
public voidsetEapMethod(int eapMethod)
Set the EAP authentication method.

param
eapMethod is one {@link Eap#PEAP}, {@link Eap#TLS}, {@link Eap#TTLS} or {@link Eap#PWD}
throws
IllegalArgumentException on an invalid eap method

        switch (eapMethod) {
            /** Valid methods */
            case Eap.TLS:
                setPhase2Method(Phase2.NONE);
                /* fall through */
            case Eap.PEAP:
            case Eap.PWD:
            case Eap.TTLS:
            case Eap.SIM:
            case Eap.AKA:
                mFields.put(EAP_KEY, Eap.strings[eapMethod]);
                mFields.put(OPP_KEY_CACHING, "1");
                break;
            default:
                throw new IllegalArgumentException("Unknown EAP method");
        }
    
public voidsetFieldValue(java.lang.String key, java.lang.String value, java.lang.String prefix)
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

        if (TextUtils.isEmpty(value)) {
            mFields.put(key, EMPTY_VALUE);
        } else {
            mFields.put(key, convertToQuotedString(prefix + value));
        }
    
public voidsetFieldValue(java.lang.String key, java.lang.String value)
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

        if (TextUtils.isEmpty(value)) {
           mFields.put(key, EMPTY_VALUE);
        } else {
            mFields.put(key, convertToQuotedString(value));
        }
    
public voidsetIdentity(java.lang.String identity)
Set the identity

param
identity

        setFieldValue(IDENTITY_KEY, identity, "");
    
public voidsetPassword(java.lang.String password)
Set the password.

param
password the password

        setFieldValue(PASSWORD_KEY, password, "");
    
public voidsetPhase2Method(int phase2Method)
Set Phase 2 authentication method. Sets the inner authentication method to be used in phase 2 after setting up a secure channel

param
phase2Method is the inner authentication method and can be one of {@link Phase2#NONE}, {@link Phase2#PAP}, {@link Phase2#MSCHAP}, {@link Phase2#MSCHAPV2}, {@link Phase2#GTC}
throws
IllegalArgumentException on an invalid phase2 method

        switch (phase2Method) {
            case Phase2.NONE:
                mFields.put(PHASE2_KEY, EMPTY_VALUE);
                break;
            /** Valid methods */
            case Phase2.PAP:
            case Phase2.MSCHAP:
            case Phase2.MSCHAPV2:
            case Phase2.GTC:
                mFields.put(PHASE2_KEY, convertToQuotedString(
                        Phase2.PREFIX + Phase2.strings[phase2Method]));
                break;
            default:
                throw new IllegalArgumentException("Unknown Phase 2 method");
        }
    
public voidsetSubjectMatch(java.lang.String subjectMatch)
Set subject match. This is the substring to be matched against the subject of the authentication server certificate.

param
subjectMatch substring to be matched

        setFieldValue(SUBJECT_MATCH_KEY, subjectMatch, "");
    
public java.lang.StringtoString()

        StringBuffer sb = new StringBuffer();
        for (String key : mFields.keySet()) {
            sb.append(key).append(" ").append(mFields.get(key)).append("\n");
        }
        return sb.toString();
    
private voidwriteCertificate(android.os.Parcel dest, java.security.cert.X509Certificate cert)

        if (cert != null) {
            try {
                byte[] certBytes = cert.getEncoded();
                dest.writeInt(certBytes.length);
                dest.writeByteArray(certBytes);
            } catch (CertificateEncodingException e) {
                dest.writeInt(0);
            }
        } else {
            dest.writeInt(0);
        }
    
public voidwriteToParcel(android.os.Parcel dest, int flags)

        dest.writeInt(mFields.size());
        for (Map.Entry<String, String> entry : mFields.entrySet()) {
            dest.writeString(entry.getKey());
            dest.writeString(entry.getValue());
        }

        writeCertificate(dest, mCaCert);

        if (mClientPrivateKey != null) {
            String algorithm = mClientPrivateKey.getAlgorithm();
            byte[] userKeyBytes = mClientPrivateKey.getEncoded();
            dest.writeInt(userKeyBytes.length);
            dest.writeByteArray(userKeyBytes);
            dest.writeString(algorithm);
        } else {
            dest.writeInt(0);
        }

        writeCertificate(dest, mClientCertificate);