[Settings] Use WifiConfiguration#setSecurityParams

Use WifiConfiguration#setSecurityParams instead of manually
initializing security params.

Bug: 150889755
Test: Created new connections and manually connected to open, WPA2,
WPA3, EAP and SUITE-B networks.

Change-Id: I42f4c21a37428ee87be14f6ba09dc54fa327054a
This commit is contained in:
Hai Shalom
2020-03-05 14:43:25 -08:00
parent b79218f56d
commit 5bb13ebefe
4 changed files with 29 additions and 64 deletions

View File

@@ -28,8 +28,6 @@ import android.net.ProxyInfo;
import android.net.StaticIpConfiguration;
import android.net.Uri;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WifiEnterpriseConfig;
import android.net.wifi.WifiEnterpriseConfig.Eap;
import android.net.wifi.WifiEnterpriseConfig.Phase2;
@@ -638,13 +636,11 @@ public class WifiConfigController implements TextWatcher,
switch (mAccessPointSecurity) {
case AccessPoint.SECURITY_NONE:
config.allowedKeyManagement.set(KeyMgmt.NONE);
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OPEN);
break;
case AccessPoint.SECURITY_WEP:
config.allowedKeyManagement.set(KeyMgmt.NONE);
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_WEP);
if (mPasswordView.length() != 0) {
int length = mPasswordView.length();
String password = mPasswordView.getText().toString();
@@ -659,7 +655,7 @@ public class WifiConfigController implements TextWatcher,
break;
case AccessPoint.SECURITY_PSK:
config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_PSK);
if (mPasswordView.length() != 0) {
String password = mPasswordView.getText().toString();
if (password.matches("[0-9A-Fa-f]{64}")) {
@@ -672,16 +668,11 @@ public class WifiConfigController implements TextWatcher,
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.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP_SUITE_B);
} else {
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP);
}
config.enterpriseConfig = new WifiEnterpriseConfig();
int eapMethod = mEapMethodSpinner.getSelectedItemPosition();
@@ -815,8 +806,7 @@ public class WifiConfigController implements TextWatcher,
}
break;
case AccessPoint.SECURITY_SAE:
config.allowedKeyManagement.set(KeyMgmt.SAE);
config.requirePmf = true;
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_SAE);
if (mPasswordView.length() != 0) {
String password = mPasswordView.getText().toString();
config.preSharedKey = '"' + password + '"';
@@ -824,8 +814,7 @@ public class WifiConfigController implements TextWatcher,
break;
case AccessPoint.SECURITY_OWE:
config.allowedKeyManagement.set(KeyMgmt.OWE);
config.requirePmf = true;
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OWE);
break;
default:

View File

@@ -27,8 +27,6 @@ import android.net.ProxyInfo;
import android.net.StaticIpConfiguration;
import android.net.Uri;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WifiEnterpriseConfig;
import android.net.wifi.WifiEnterpriseConfig.Eap;
import android.net.wifi.WifiEnterpriseConfig.Phase2;
@@ -633,13 +631,11 @@ public class WifiConfigController2 implements TextWatcher,
switch (mWifiEntrySecurity) {
case WifiEntry.SECURITY_NONE:
config.allowedKeyManagement.set(KeyMgmt.NONE);
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OPEN);
break;
case WifiEntry.SECURITY_WEP:
config.allowedKeyManagement.set(KeyMgmt.NONE);
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_WEP);
if (mPasswordView.length() != 0) {
int length = mPasswordView.length();
String password = mPasswordView.getText().toString();
@@ -654,7 +650,7 @@ public class WifiConfigController2 implements TextWatcher,
break;
case WifiEntry.SECURITY_PSK:
config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_PSK);
if (mPasswordView.length() != 0) {
String password = mPasswordView.getText().toString();
if (password.matches("[0-9A-Fa-f]{64}")) {
@@ -667,16 +663,11 @@ public class WifiConfigController2 implements TextWatcher,
case WifiEntry.SECURITY_EAP:
case WifiEntry.SECURITY_EAP_SUITE_B:
config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
if (mWifiEntrySecurity == WifiEntry.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.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP_SUITE_B);
} else {
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP);
}
config.enterpriseConfig = new WifiEnterpriseConfig();
int eapMethod = mEapMethodSpinner.getSelectedItemPosition();
@@ -809,8 +800,7 @@ public class WifiConfigController2 implements TextWatcher,
}
break;
case WifiEntry.SECURITY_SAE:
config.allowedKeyManagement.set(KeyMgmt.SAE);
config.requirePmf = true;
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_SAE);
if (mPasswordView.length() != 0) {
String password = mPasswordView.getText().toString();
config.preSharedKey = '"' + password + '"';
@@ -818,8 +808,7 @@ public class WifiConfigController2 implements TextWatcher,
break;
case WifiEntry.SECURITY_OWE:
config.allowedKeyManagement.set(KeyMgmt.OWE);
config.requirePmf = true;
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OWE);
break;
default:

View File

@@ -157,13 +157,11 @@ public class WifiUtils {
switch (security) {
case AccessPoint.SECURITY_NONE:
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OPEN);
break;
case AccessPoint.SECURITY_WEP:
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_WEP);
if (!TextUtils.isEmpty(password)) {
int length = password.length();
// WEP-40, WEP-104, and 256-bit WEP (WEP-232?)
@@ -177,7 +175,7 @@ public class WifiUtils {
break;
case AccessPoint.SECURITY_PSK:
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_PSK);
if (!TextUtils.isEmpty(password)) {
if (password.matches("[0-9A-Fa-f]{64}")) {
config.preSharedKey = password;
@@ -189,16 +187,11 @@ public class WifiUtils {
case AccessPoint.SECURITY_EAP:
case AccessPoint.SECURITY_EAP_SUITE_B:
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);
if (security == AccessPoint.SECURITY_EAP_SUITE_B) {
config.allowedKeyManagement.set(WifiConfiguration.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.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP_SUITE_B);
} else {
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_EAP);
}
if (!TextUtils.isEmpty(password)) {
@@ -206,16 +199,14 @@ public class WifiUtils {
}
break;
case AccessPoint.SECURITY_SAE:
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.SAE);
config.requirePmf = true;
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_SAE);
if (!TextUtils.isEmpty(password)) {
config.preSharedKey = '"' + password + '"';
}
break;
case AccessPoint.SECURITY_OWE:
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.OWE);
config.requirePmf = true;
config.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OWE);
break;
default:

View File

@@ -24,7 +24,6 @@ import static com.android.settings.wifi.dpp.WifiQrCode.SECURITY_WPA_PSK;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration.AuthAlgorithm;
import android.net.wifi.WifiConfiguration.KeyMgmt;
import android.net.wifi.WifiManager;
import android.text.TextUtils;
@@ -252,17 +251,15 @@ public class WifiNetworkConfig {
final WifiConfiguration enhancedOpenNetworkWifiConfiguration =
getBasicWifiConfiguration();
enhancedOpenNetworkWifiConfiguration.allowedKeyManagement.set(KeyMgmt.OWE);
enhancedOpenNetworkWifiConfiguration.requirePmf = true;
enhancedOpenNetworkWifiConfiguration
.setSecurityParams(WifiConfiguration.SECURITY_TYPE_OWE);
wifiConfigurations.add(enhancedOpenNetworkWifiConfiguration);
return wifiConfigurations;
}
final WifiConfiguration wifiConfiguration = getBasicWifiConfiguration();
if (mSecurity.startsWith(SECURITY_WEP)) {
wifiConfiguration.allowedKeyManagement.set(KeyMgmt.NONE);
wifiConfiguration.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
wifiConfiguration.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
wifiConfiguration.setSecurityParams(WifiConfiguration.SECURITY_TYPE_WEP);
// WEP-40, WEP-104, and 256-bit WEP (WEP-232?)
final int length = mPreSharedKey.length();
@@ -273,7 +270,7 @@ public class WifiNetworkConfig {
wifiConfiguration.wepKeys[0] = addQuotationIfNeeded(mPreSharedKey);
}
} else if (mSecurity.startsWith(SECURITY_WPA_PSK)) {
wifiConfiguration.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
wifiConfiguration.setSecurityParams(WifiConfiguration.SECURITY_TYPE_PSK);
if (mPreSharedKey.matches("[0-9A-Fa-f]{64}")) {
wifiConfiguration.preSharedKey = mPreSharedKey;
@@ -281,8 +278,7 @@ public class WifiNetworkConfig {
wifiConfiguration.preSharedKey = addQuotationIfNeeded(mPreSharedKey);
}
} else if (mSecurity.startsWith(SECURITY_SAE)) {
wifiConfiguration.allowedKeyManagement.set(KeyMgmt.SAE);
wifiConfiguration.requirePmf = true;
wifiConfiguration.setSecurityParams(WifiConfiguration.SECURITY_TYPE_SAE);
if (mPreSharedKey.length() != 0) {
wifiConfiguration.preSharedKey = addQuotationIfNeeded(mPreSharedKey);
}