Search in sources :

Example 41 with WifiEnterpriseConfig

use of android.net.wifi.WifiEnterpriseConfig in project android_packages_apps_Settings by SudaMod.

the class WifiConfigController method getConfig.

/* package */
WifiConfiguration getConfig() {
    if (mMode == WifiConfigUiBase.MODE_VIEW) {
        return null;
    }
    WifiConfiguration config = new WifiConfiguration();
    if (mAccessPoint == null) {
        config.SSID = AccessPoint.convertToQuotedString(mSsidView.getText().toString());
        // If the user adds a network manually, assume that it is hidden.
        config.hiddenSSID = true;
    } else if (!mAccessPoint.isSaved()) {
        config.SSID = AccessPoint.convertToQuotedString(mAccessPoint.getSsidStr());
    } else {
        config.networkId = mAccessPoint.getConfig().networkId;
    }
    config.shared = mSharedCheckBox.isChecked();
    switch(mAccessPointSecurity) {
        case AccessPoint.SECURITY_NONE:
            config.allowedKeyManagement.set(KeyMgmt.NONE);
            break;
        case AccessPoint.SECURITY_WEP:
            config.allowedKeyManagement.set(KeyMgmt.NONE);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
            if (mPasswordView.length() != 0) {
                int length = mPasswordView.length();
                String password = mPasswordView.getText().toString();
                // WEP-40, WEP-104, and 256-bit WEP (WEP-232?)
                if ((length == 10 || length == 26 || length == 58) && password.matches("[0-9A-Fa-f]*")) {
                    config.wepKeys[0] = password;
                } else {
                    config.wepKeys[0] = '"' + password + '"';
                }
            }
            break;
        case AccessPoint.SECURITY_PSK:
            config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
            if (mPasswordView.length() != 0) {
                String password = mPasswordView.getText().toString();
                if (password.matches("[0-9A-Fa-f]{64}")) {
                    config.preSharedKey = password;
                } else {
                    config.preSharedKey = '"' + password + '"';
                }
            }
            break;
        case AccessPoint.SECURITY_EAP:
            config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
            config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
            config.enterpriseConfig = new WifiEnterpriseConfig();
            int eapMethod = mEapMethodSpinner.getSelectedItemPosition();
            int phase2Method = mPhase2Spinner.getSelectedItemPosition();
            config.enterpriseConfig.setEapMethod(eapMethod);
            switch(eapMethod) {
                case Eap.PEAP:
                    // by the API which has the full list of PEAP methods.
                    switch(phase2Method) {
                        case WIFI_PEAP_PHASE2_NONE:
                            config.enterpriseConfig.setPhase2Method(Phase2.NONE);
                            break;
                        case WIFI_PEAP_PHASE2_MSCHAPV2:
                            config.enterpriseConfig.setPhase2Method(Phase2.MSCHAPV2);
                            break;
                        case WIFI_PEAP_PHASE2_GTC:
                            config.enterpriseConfig.setPhase2Method(Phase2.GTC);
                            break;
                        case WIFI_PEAP_PHASE2_SIM:
                            config.enterpriseConfig.setPhase2Method(Phase2.SIM);
                            break;
                        case WIFI_PEAP_PHASE2_AKA:
                            config.enterpriseConfig.setPhase2Method(Phase2.AKA);
                            break;
                        case WIFI_PEAP_PHASE2_AKA_PRIME:
                            config.enterpriseConfig.setPhase2Method(Phase2.AKA_PRIME);
                            break;
                        default:
                            Log.e(TAG, "Unknown phase2 method" + phase2Method);
                            break;
                    }
                    break;
                default:
                    // The default index from mPhase2FullAdapter maps to the API
                    config.enterpriseConfig.setPhase2Method(phase2Method);
                    break;
            }
            String caCert = (String) mEapCaCertSpinner.getSelectedItem();
            config.enterpriseConfig.setCaCertificateAliases(null);
            config.enterpriseConfig.setCaPath(null);
            config.enterpriseConfig.setDomainSuffixMatch(mEapDomainView.getText().toString());
            if (caCert.equals(mUnspecifiedCertString) || caCert.equals(mDoNotValidateEapServerString)) {
            // ca_cert already set to null, so do nothing.
            } else if (caCert.equals(mUseSystemCertsString)) {
                config.enterpriseConfig.setCaPath(SYSTEM_CA_STORE_PATH);
            } else if (caCert.equals(mMultipleCertSetString)) {
                if (mAccessPoint != null) {
                    if (!mAccessPoint.isSaved()) {
                        Log.e(TAG, "Multiple certs can only be set " + "when editing saved network");
                    }
                    config.enterpriseConfig.setCaCertificateAliases(mAccessPoint.getConfig().enterpriseConfig.getCaCertificateAliases());
                }
            } else {
                config.enterpriseConfig.setCaCertificateAliases(new String[] { caCert });
            }
            // previously-set value on a saved configuration will be erased on an update.
            if (config.enterpriseConfig.getCaCertificateAliases() != null && config.enterpriseConfig.getCaPath() != null) {
                Log.e(TAG, "ca_cert (" + config.enterpriseConfig.getCaCertificateAliases() + ") and ca_path (" + config.enterpriseConfig.getCaPath() + ") should not both be non-null");
            }
            String clientCert = (String) mEapUserCertSpinner.getSelectedItem();
            if (clientCert.equals(mUnspecifiedCertString) || clientCert.equals(mDoNotProvideEapUserCertString)) {
                // Note: |clientCert| should not be able to take the value |unspecifiedCert|,
                // since we prevent such configurations from being saved.
                clientCert = "";
            }
            config.enterpriseConfig.setClientCertificateAlias(clientCert);
            if (eapMethod == Eap.SIM || eapMethod == Eap.AKA || eapMethod == Eap.AKA_PRIME) {
                config.enterpriseConfig.setIdentity("");
                config.enterpriseConfig.setAnonymousIdentity("");
            } else if (eapMethod == Eap.PWD) {
                config.enterpriseConfig.setIdentity(mEapIdentityView.getText().toString());
                config.enterpriseConfig.setAnonymousIdentity("");
            } else {
                config.enterpriseConfig.setIdentity(mEapIdentityView.getText().toString());
                config.enterpriseConfig.setAnonymousIdentity(mEapAnonymousView.getText().toString());
            }
            if (mPasswordView.isShown()) {
                // Update only if it has been changed.
                if (mPasswordView.length() > 0) {
                    config.enterpriseConfig.setPassword(mPasswordView.getText().toString());
                }
            } else {
                // clear password
                config.enterpriseConfig.setPassword(mPasswordView.getText().toString());
            }
            break;
        default:
            return null;
    }
    config.setIpConfiguration(new IpConfiguration(mIpAssignment, mProxySettings, mStaticIpConfiguration, mHttpProxy));
    return config;
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) StaticIpConfiguration(android.net.StaticIpConfiguration) IpConfiguration(android.net.IpConfiguration) WifiConfiguration(android.net.wifi.WifiConfiguration) AccessPoint(com.android.settingslib.wifi.AccessPoint)

Example 42 with WifiEnterpriseConfig

use of android.net.wifi.WifiEnterpriseConfig in project platform_packages_apps_Settings by BlissRoms.

the class WifiConfigController method showSecurityFields.

private void showSecurityFields() {
    if (mAccessPointSecurity == AccessPoint.SECURITY_NONE) {
        mView.findViewById(R.id.security_fields).setVisibility(View.GONE);
        return;
    }
    mView.findViewById(R.id.security_fields).setVisibility(View.VISIBLE);
    if (mPasswordView == null) {
        mPasswordView = (TextView) mView.findViewById(R.id.password);
        mPasswordView.addTextChangedListener(this);
        mPasswordView.setOnEditorActionListener(this);
        mPasswordView.setOnKeyListener(this);
        ((CheckBox) mView.findViewById(R.id.show_password)).setOnCheckedChangeListener(this);
        if (mAccessPoint != null && mAccessPoint.isSaved()) {
            mPasswordView.setHint(R.string.wifi_unchanged);
        }
    }
    if (mAccessPointSecurity != AccessPoint.SECURITY_EAP) {
        mView.findViewById(R.id.eap).setVisibility(View.GONE);
        return;
    }
    mView.findViewById(R.id.eap).setVisibility(View.VISIBLE);
    if (mEapMethodSpinner == null) {
        mEapMethodSpinner = (Spinner) mView.findViewById(R.id.method);
        mEapMethodSpinner.setOnItemSelectedListener(this);
        if (Utils.isWifiOnly(mContext) || !mContext.getResources().getBoolean(com.android.internal.R.bool.config_eap_sim_based_auth_supported)) {
            String[] eapMethods = mContext.getResources().getStringArray(R.array.eap_method_without_sim_auth);
            ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_item, eapMethods);
            spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mEapMethodSpinner.setAdapter(spinnerAdapter);
        }
        mPhase2Spinner = (Spinner) mView.findViewById(R.id.phase2);
        mPhase2Spinner.setOnItemSelectedListener(this);
        mEapCaCertSpinner = (Spinner) mView.findViewById(R.id.ca_cert);
        mEapCaCertSpinner.setOnItemSelectedListener(this);
        mEapDomainView = (TextView) mView.findViewById(R.id.domain);
        mEapDomainView.addTextChangedListener(this);
        mEapUserCertSpinner = (Spinner) mView.findViewById(R.id.user_cert);
        mEapUserCertSpinner.setOnItemSelectedListener(this);
        mEapIdentityView = (TextView) mView.findViewById(R.id.identity);
        mEapAnonymousView = (TextView) mView.findViewById(R.id.anonymous);
        if (mAccessPoint != null && mAccessPoint.isCarrierAp()) {
            mEapMethodSpinner.setSelection(mAccessPoint.getCarrierApEapType());
        }
        loadCertificates(mEapCaCertSpinner, Credentials.CA_CERTIFICATE, mDoNotValidateEapServerString, false, true);
        loadCertificates(mEapUserCertSpinner, Credentials.USER_PRIVATE_KEY, mDoNotProvideEapUserCertString, false, false);
        // Modifying an existing network
        if (mAccessPoint != null && mAccessPoint.isSaved()) {
            WifiEnterpriseConfig enterpriseConfig = mAccessPoint.getConfig().enterpriseConfig;
            int eapMethod = enterpriseConfig.getEapMethod();
            int phase2Method = enterpriseConfig.getPhase2Method();
            mEapMethodSpinner.setSelection(eapMethod);
            showEapFieldsByMethod(eapMethod);
            switch(eapMethod) {
                case Eap.PEAP:
                    switch(phase2Method) {
                        case Phase2.NONE:
                            mPhase2Spinner.setSelection(WIFI_PEAP_PHASE2_NONE);
                            break;
                        case Phase2.MSCHAPV2:
                            mPhase2Spinner.setSelection(WIFI_PEAP_PHASE2_MSCHAPV2);
                            break;
                        case Phase2.GTC:
                            mPhase2Spinner.setSelection(WIFI_PEAP_PHASE2_GTC);
                            break;
                        case Phase2.SIM:
                            mPhase2Spinner.setSelection(WIFI_PEAP_PHASE2_SIM);
                            break;
                        case Phase2.AKA:
                            mPhase2Spinner.setSelection(WIFI_PEAP_PHASE2_AKA);
                            break;
                        case Phase2.AKA_PRIME:
                            mPhase2Spinner.setSelection(WIFI_PEAP_PHASE2_AKA_PRIME);
                            break;
                        default:
                            Log.e(TAG, "Invalid phase 2 method " + phase2Method);
                            break;
                    }
                    break;
                default:
                    mPhase2Spinner.setSelection(phase2Method);
                    break;
            }
            if (!TextUtils.isEmpty(enterpriseConfig.getCaPath())) {
                setSelection(mEapCaCertSpinner, mUseSystemCertsString);
            } else {
                String[] caCerts = enterpriseConfig.getCaCertificateAliases();
                if (caCerts == null) {
                    setSelection(mEapCaCertSpinner, mDoNotValidateEapServerString);
                } else if (caCerts.length == 1) {
                    setSelection(mEapCaCertSpinner, caCerts[0]);
                } else {
                    // Reload the cert spinner with an extra "multiple certificates added" item.
                    loadCertificates(mEapCaCertSpinner, Credentials.CA_CERTIFICATE, mDoNotValidateEapServerString, true, true);
                    setSelection(mEapCaCertSpinner, mMultipleCertSetString);
                }
            }
            mEapDomainView.setText(enterpriseConfig.getDomainSuffixMatch());
            String userCert = enterpriseConfig.getClientCertificateAlias();
            if (TextUtils.isEmpty(userCert)) {
                setSelection(mEapUserCertSpinner, mDoNotProvideEapUserCertString);
            } else {
                setSelection(mEapUserCertSpinner, userCert);
            }
            mEapIdentityView.setText(enterpriseConfig.getIdentity());
            mEapAnonymousView.setText(enterpriseConfig.getAnonymousIdentity());
        } else {
            mPhase2Spinner = (Spinner) mView.findViewById(R.id.phase2);
            showEapFieldsByMethod(mEapMethodSpinner.getSelectedItemPosition());
        }
    } else {
        showEapFieldsByMethod(mEapMethodSpinner.getSelectedItemPosition());
    }
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) CheckBox(android.widget.CheckBox) ArrayAdapter(android.widget.ArrayAdapter) AccessPoint(com.android.settingslib.wifi.AccessPoint)

Example 43 with WifiEnterpriseConfig

use of android.net.wifi.WifiEnterpriseConfig in project platform_packages_apps_Settings by BlissRoms.

the class WifiConfigController method getConfig.

/* package */
WifiConfiguration getConfig() {
    if (mMode == WifiConfigUiBase.MODE_VIEW) {
        return null;
    }
    WifiConfiguration config = new WifiConfiguration();
    if (mAccessPoint == null) {
        config.SSID = AccessPoint.convertToQuotedString(mSsidView.getText().toString());
        // If the user adds a network manually, assume that it is hidden.
        config.hiddenSSID = true;
    } else if (!mAccessPoint.isSaved()) {
        config.SSID = AccessPoint.convertToQuotedString(mAccessPoint.getSsidStr());
    } else {
        config.networkId = mAccessPoint.getConfig().networkId;
        config.hiddenSSID = mAccessPoint.getConfig().hiddenSSID;
    }
    config.shared = mSharedCheckBox.isChecked();
    switch(mAccessPointSecurity) {
        case AccessPoint.SECURITY_NONE:
            config.allowedKeyManagement.set(KeyMgmt.NONE);
            break;
        case AccessPoint.SECURITY_WEP:
            config.allowedKeyManagement.set(KeyMgmt.NONE);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
            if (mPasswordView.length() != 0) {
                int length = mPasswordView.length();
                String password = mPasswordView.getText().toString();
                // WEP-40, WEP-104, and WEP128
                if ((length == 10 || length == 26 || length == 32) && password.matches("[0-9A-Fa-f]*")) {
                    config.wepKeys[0] = password;
                } else {
                    config.wepKeys[0] = '"' + password + '"';
                }
            }
            break;
        case AccessPoint.SECURITY_PSK:
            config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
            if (mPasswordView.length() != 0) {
                String password = mPasswordView.getText().toString();
                if (password.matches("[0-9A-Fa-f]{64}")) {
                    config.preSharedKey = password;
                } else {
                    config.preSharedKey = '"' + password + '"';
                }
            }
            break;
        case AccessPoint.SECURITY_EAP:
            config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
            config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
            config.enterpriseConfig = new WifiEnterpriseConfig();
            int eapMethod = mEapMethodSpinner.getSelectedItemPosition();
            int phase2Method = mPhase2Spinner.getSelectedItemPosition();
            config.enterpriseConfig.setEapMethod(eapMethod);
            switch(eapMethod) {
                case Eap.PEAP:
                    // by the API which has the full list of PEAP methods.
                    switch(phase2Method) {
                        case WIFI_PEAP_PHASE2_NONE:
                            config.enterpriseConfig.setPhase2Method(Phase2.NONE);
                            break;
                        case WIFI_PEAP_PHASE2_MSCHAPV2:
                            config.enterpriseConfig.setPhase2Method(Phase2.MSCHAPV2);
                            break;
                        case WIFI_PEAP_PHASE2_GTC:
                            config.enterpriseConfig.setPhase2Method(Phase2.GTC);
                            break;
                        case WIFI_PEAP_PHASE2_SIM:
                            config.enterpriseConfig.setPhase2Method(Phase2.SIM);
                            break;
                        case WIFI_PEAP_PHASE2_AKA:
                            config.enterpriseConfig.setPhase2Method(Phase2.AKA);
                            break;
                        case WIFI_PEAP_PHASE2_AKA_PRIME:
                            config.enterpriseConfig.setPhase2Method(Phase2.AKA_PRIME);
                            break;
                        default:
                            Log.e(TAG, "Unknown phase2 method" + phase2Method);
                            break;
                    }
                    break;
                default:
                    // The default index from mPhase2FullAdapter maps to the API
                    config.enterpriseConfig.setPhase2Method(phase2Method);
                    break;
            }
            String caCert = (String) mEapCaCertSpinner.getSelectedItem();
            config.enterpriseConfig.setCaCertificateAliases(null);
            config.enterpriseConfig.setCaPath(null);
            config.enterpriseConfig.setDomainSuffixMatch(mEapDomainView.getText().toString());
            if (caCert.equals(mUnspecifiedCertString) || caCert.equals(mDoNotValidateEapServerString)) {
            // ca_cert already set to null, so do nothing.
            } else if (caCert.equals(mUseSystemCertsString)) {
                config.enterpriseConfig.setCaPath(SYSTEM_CA_STORE_PATH);
            } else if (caCert.equals(mMultipleCertSetString)) {
                if (mAccessPoint != null) {
                    if (!mAccessPoint.isSaved()) {
                        Log.e(TAG, "Multiple certs can only be set " + "when editing saved network");
                    }
                    config.enterpriseConfig.setCaCertificateAliases(mAccessPoint.getConfig().enterpriseConfig.getCaCertificateAliases());
                }
            } else {
                config.enterpriseConfig.setCaCertificateAliases(new String[] { caCert });
            }
            // previously-set value on a saved configuration will be erased on an update.
            if (config.enterpriseConfig.getCaCertificateAliases() != null && config.enterpriseConfig.getCaPath() != null) {
                Log.e(TAG, "ca_cert (" + config.enterpriseConfig.getCaCertificateAliases() + ") and ca_path (" + config.enterpriseConfig.getCaPath() + ") should not both be non-null");
            }
            String clientCert = (String) mEapUserCertSpinner.getSelectedItem();
            if (clientCert.equals(mUnspecifiedCertString) || clientCert.equals(mDoNotProvideEapUserCertString)) {
                // Note: |clientCert| should not be able to take the value |unspecifiedCert|,
                // since we prevent such configurations from being saved.
                clientCert = "";
            }
            config.enterpriseConfig.setClientCertificateAlias(clientCert);
            if (eapMethod == Eap.SIM || eapMethod == Eap.AKA || eapMethod == Eap.AKA_PRIME) {
                config.enterpriseConfig.setIdentity("");
                config.enterpriseConfig.setAnonymousIdentity("");
            } else if (eapMethod == Eap.PWD) {
                config.enterpriseConfig.setIdentity(mEapIdentityView.getText().toString());
                config.enterpriseConfig.setAnonymousIdentity("");
            } else {
                config.enterpriseConfig.setIdentity(mEapIdentityView.getText().toString());
                config.enterpriseConfig.setAnonymousIdentity(mEapAnonymousView.getText().toString());
            }
            if (mPasswordView.isShown()) {
                // Update only if it has been changed.
                if (mPasswordView.length() > 0) {
                    config.enterpriseConfig.setPassword(mPasswordView.getText().toString());
                }
            } else {
                // clear password
                config.enterpriseConfig.setPassword(mPasswordView.getText().toString());
            }
            break;
        default:
            return null;
    }
    config.setIpConfiguration(new IpConfiguration(mIpAssignment, mProxySettings, mStaticIpConfiguration, mHttpProxy));
    return config;
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) StaticIpConfiguration(android.net.StaticIpConfiguration) IpConfiguration(android.net.IpConfiguration) WifiConfiguration(android.net.wifi.WifiConfiguration) AccessPoint(com.android.settingslib.wifi.AccessPoint)

Example 44 with WifiEnterpriseConfig

use of android.net.wifi.WifiEnterpriseConfig in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiConfigControllerTest method selectEapMethod_savedAccessPoint_shouldGetCorrectPosition.

@Test
public void selectEapMethod_savedAccessPoint_shouldGetCorrectPosition() {
    when(mAccessPoint.isSaved()).thenReturn(true);
    when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_EAP);
    final WifiConfiguration mockWifiConfig = mock(WifiConfiguration.class);
    final WifiEnterpriseConfig mockWifiEnterpriseConfig = mock(WifiEnterpriseConfig.class);
    when(mockWifiEnterpriseConfig.getEapMethod()).thenReturn(Eap.PEAP);
    mockWifiConfig.enterpriseConfig = mockWifiEnterpriseConfig;
    when(mAccessPoint.getConfig()).thenReturn(mockWifiConfig);
    mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint, WifiConfigUiBase.MODE_MODIFY);
    final Spinner eapMethodSpinner = mView.findViewById(R.id.method);
    final Spinner phase2Spinner = mView.findViewById(R.id.phase2);
    WifiConfiguration wifiConfiguration;
    // Test EAP method PEAP
    eapMethodSpinner.setSelection(Eap.PEAP);
    phase2Spinner.setSelection(WifiConfigController.WIFI_PEAP_PHASE2_MSCHAPV2);
    wifiConfiguration = mController.getConfig();
    assertThat(wifiConfiguration.enterpriseConfig.getEapMethod()).isEqualTo(Eap.PEAP);
    assertThat(wifiConfiguration.enterpriseConfig.getPhase2Method()).isEqualTo(Phase2.MSCHAPV2);
    // Test EAP method TTLS
    eapMethodSpinner.setSelection(Eap.TTLS);
    phase2Spinner.setSelection(WifiConfigController.WIFI_TTLS_PHASE2_MSCHAPV2);
    wifiConfiguration = mController.getConfig();
    assertThat(wifiConfiguration.enterpriseConfig.getEapMethod()).isEqualTo(Eap.TTLS);
    assertThat(wifiConfiguration.enterpriseConfig.getPhase2Method()).isEqualTo(Phase2.MSCHAPV2);
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) WifiConfiguration(android.net.wifi.WifiConfiguration) Spinner(android.widget.Spinner) Test(org.junit.Test)

Example 45 with WifiEnterpriseConfig

use of android.net.wifi.WifiEnterpriseConfig in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiConfigController method getConfig.

public WifiConfiguration getConfig() {
    if (mMode == WifiConfigUiBase.MODE_VIEW) {
        return null;
    }
    WifiConfiguration config = new WifiConfiguration();
    if (mAccessPoint == null) {
        config.SSID = AccessPoint.convertToQuotedString(mSsidView.getText().toString());
        // If the user adds a network manually, assume that it is hidden.
        config.hiddenSSID = mHiddenSettingsSpinner.getSelectedItemPosition() == HIDDEN_NETWORK;
    } else if (!mAccessPoint.isSaved()) {
        config.SSID = AccessPoint.convertToQuotedString(mAccessPoint.getSsidStr());
    } else {
        config.networkId = mAccessPoint.getConfig().networkId;
        config.hiddenSSID = mAccessPoint.getConfig().hiddenSSID;
    }
    config.shared = mSharedCheckBox.isChecked();
    switch(mAccessPointSecurity) {
        case AccessPoint.SECURITY_NONE:
            config.allowedKeyManagement.set(KeyMgmt.NONE);
            break;
        case AccessPoint.SECURITY_WEP:
            config.allowedKeyManagement.set(KeyMgmt.NONE);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
            if (mPasswordView.length() != 0) {
                int length = mPasswordView.length();
                String password = mPasswordView.getText().toString();
                // WEP-40, WEP-104, and 256-bit WEP (WEP-232?)
                if ((length == 10 || length == 26 || length == 58) && password.matches("[0-9A-Fa-f]*")) {
                    config.wepKeys[0] = password;
                } else {
                    config.wepKeys[0] = '"' + password + '"';
                }
            }
            break;
        case AccessPoint.SECURITY_PSK:
            config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
            if (mPasswordView.length() != 0) {
                String password = mPasswordView.getText().toString();
                if (password.matches("[0-9A-Fa-f]{64}")) {
                    config.preSharedKey = password;
                } else {
                    config.preSharedKey = '"' + password + '"';
                }
            }
            break;
        case AccessPoint.SECURITY_EAP:
        case AccessPoint.SECURITY_EAP_SUITE_B:
            config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
            config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
            if (mAccessPointSecurity == AccessPoint.SECURITY_EAP_SUITE_B) {
                config.allowedKeyManagement.set(KeyMgmt.SUITE_B_192);
                config.requirePMF = true;
                config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.GCMP_256);
                config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.GCMP_256);
                config.allowedGroupManagementCiphers.set(WifiConfiguration.GroupMgmtCipher.BIP_GMAC_256);
            // allowedSuiteBCiphers will be set according to certificate type
            }
            config.enterpriseConfig = new WifiEnterpriseConfig();
            int eapMethod = mEapMethodSpinner.getSelectedItemPosition();
            int phase2Method = mPhase2Spinner.getSelectedItemPosition();
            config.enterpriseConfig.setEapMethod(eapMethod);
            switch(eapMethod) {
                case Eap.PEAP:
                    // by the API which has the full list of PEAP methods.
                    switch(phase2Method) {
                        case WIFI_PEAP_PHASE2_MSCHAPV2:
                            config.enterpriseConfig.setPhase2Method(Phase2.MSCHAPV2);
                            break;
                        case WIFI_PEAP_PHASE2_GTC:
                            config.enterpriseConfig.setPhase2Method(Phase2.GTC);
                            break;
                        case WIFI_PEAP_PHASE2_SIM:
                            config.enterpriseConfig.setPhase2Method(Phase2.SIM);
                            break;
                        case WIFI_PEAP_PHASE2_AKA:
                            config.enterpriseConfig.setPhase2Method(Phase2.AKA);
                            break;
                        case WIFI_PEAP_PHASE2_AKA_PRIME:
                            config.enterpriseConfig.setPhase2Method(Phase2.AKA_PRIME);
                            break;
                        default:
                            Log.e(TAG, "Unknown phase2 method" + phase2Method);
                            break;
                    }
                    break;
                case Eap.TTLS:
                    // The default index from mPhase2TtlsAdapter maps to the API
                    switch(phase2Method) {
                        case WIFI_TTLS_PHASE2_PAP:
                            config.enterpriseConfig.setPhase2Method(Phase2.PAP);
                            break;
                        case WIFI_TTLS_PHASE2_MSCHAP:
                            config.enterpriseConfig.setPhase2Method(Phase2.MSCHAP);
                            break;
                        case WIFI_TTLS_PHASE2_MSCHAPV2:
                            config.enterpriseConfig.setPhase2Method(Phase2.MSCHAPV2);
                            break;
                        case WIFI_TTLS_PHASE2_GTC:
                            config.enterpriseConfig.setPhase2Method(Phase2.GTC);
                            break;
                        default:
                            Log.e(TAG, "Unknown phase2 method" + phase2Method);
                            break;
                    }
                    break;
                default:
                    break;
            }
            String caCert = (String) mEapCaCertSpinner.getSelectedItem();
            config.enterpriseConfig.setCaCertificateAliases(null);
            config.enterpriseConfig.setCaPath(null);
            config.enterpriseConfig.setDomainSuffixMatch(mEapDomainView.getText().toString());
            if (caCert.equals(mUnspecifiedCertString) || caCert.equals(mDoNotValidateEapServerString)) {
            // ca_cert already set to null, so do nothing.
            } else if (caCert.equals(mUseSystemCertsString)) {
                config.enterpriseConfig.setCaPath(SYSTEM_CA_STORE_PATH);
            } else if (caCert.equals(mMultipleCertSetString)) {
                if (mAccessPoint != null) {
                    if (!mAccessPoint.isSaved()) {
                        Log.e(TAG, "Multiple certs can only be set " + "when editing saved network");
                    }
                    config.enterpriseConfig.setCaCertificateAliases(mAccessPoint.getConfig().enterpriseConfig.getCaCertificateAliases());
                }
            } else {
                config.enterpriseConfig.setCaCertificateAliases(new String[] { caCert });
            }
            // previously-set value on a saved configuration will be erased on an update.
            if (config.enterpriseConfig.getCaCertificateAliases() != null && config.enterpriseConfig.getCaPath() != null) {
                Log.e(TAG, "ca_cert (" + config.enterpriseConfig.getCaCertificateAliases() + ") and ca_path (" + config.enterpriseConfig.getCaPath() + ") should not both be non-null");
            }
            String clientCert = (String) mEapUserCertSpinner.getSelectedItem();
            if (clientCert.equals(mUnspecifiedCertString) || clientCert.equals(mDoNotProvideEapUserCertString)) {
                // Note: |clientCert| should not be able to take the value |unspecifiedCert|,
                // since we prevent such configurations from being saved.
                clientCert = "";
            }
            config.enterpriseConfig.setClientCertificateAlias(clientCert);
            if (eapMethod == Eap.SIM || eapMethod == Eap.AKA || eapMethod == Eap.AKA_PRIME) {
                config.enterpriseConfig.setIdentity("");
                config.enterpriseConfig.setAnonymousIdentity("");
            } else if (eapMethod == Eap.PWD) {
                config.enterpriseConfig.setIdentity(mEapIdentityView.getText().toString());
                config.enterpriseConfig.setAnonymousIdentity("");
            } else {
                config.enterpriseConfig.setIdentity(mEapIdentityView.getText().toString());
                config.enterpriseConfig.setAnonymousIdentity(mEapAnonymousView.getText().toString());
            }
            if (mPasswordView.isShown()) {
                // Update only if it has been changed.
                if (mPasswordView.length() > 0) {
                    config.enterpriseConfig.setPassword(mPasswordView.getText().toString());
                }
            } else {
                // clear password
                config.enterpriseConfig.setPassword(mPasswordView.getText().toString());
            }
            break;
        case AccessPoint.SECURITY_SAE:
            config.allowedKeyManagement.set(KeyMgmt.SAE);
            config.requirePMF = true;
            if (mPasswordView.length() != 0) {
                String password = mPasswordView.getText().toString();
                config.preSharedKey = '"' + password + '"';
            }
            break;
        case AccessPoint.SECURITY_OWE:
            config.allowedKeyManagement.set(KeyMgmt.OWE);
            config.requirePMF = true;
            break;
        default:
            return null;
    }
    config.setIpConfiguration(new IpConfiguration(mIpAssignment, mProxySettings, mStaticIpConfiguration, mHttpProxy));
    if (mMeteredSettingsSpinner != null) {
        config.meteredOverride = mMeteredSettingsSpinner.getSelectedItemPosition();
    }
    if (mPrivacySettingsSpinner != null) {
        final int macValue = WifiPrivacyPreferenceController.translatePrefValueToMacRandomizedValue(mPrivacySettingsSpinner.getSelectedItemPosition());
        config.macRandomizationSetting = macValue;
    }
    return config;
}
Also used : WifiEnterpriseConfig(android.net.wifi.WifiEnterpriseConfig) StaticIpConfiguration(android.net.StaticIpConfiguration) IpConfiguration(android.net.IpConfiguration) WifiConfiguration(android.net.wifi.WifiConfiguration) AccessPoint(com.android.settingslib.wifi.AccessPoint)

Aggregations

WifiEnterpriseConfig (android.net.wifi.WifiEnterpriseConfig)46 WifiConfiguration (android.net.wifi.WifiConfiguration)39 IOException (java.io.IOException)20 Credential (com.android.hotspot2.pps.Credential)15 AccessPoint (com.android.settingslib.wifi.AccessPoint)15 WifiManager (android.net.wifi.WifiManager)10 EAP (com.android.anqp.eap.EAP)10 CheckBox (android.widget.CheckBox)8 IpConfiguration (android.net.IpConfiguration)7 StaticIpConfiguration (android.net.StaticIpConfiguration)7 ArrayAdapter (android.widget.ArrayAdapter)7 AuthParam (com.android.anqp.eap.AuthParam)5 EAPMethod (com.android.anqp.eap.EAPMethod)5 NonEAPInnerAuth (com.android.anqp.eap.NonEAPInnerAuth)5 MessageDigest (java.security.MessageDigest)5 X509Certificate (java.security.cert.X509Certificate)5 Spinner (android.widget.Spinner)1 Test (org.junit.Test)1