Skip to content

Commit

Permalink
fix: support for no Wireless Security (#4759)
Browse files Browse the repository at this point in the history
* fix: use proper NM settings for no Wireless Security

* fix: web2 NONE security parsing

* fix: Sonar const duplicate

* test: add regression test

* test: improve test
  • Loading branch information
mattdibi authored Jul 12, 2023
1 parent 7a8d9fa commit 05d6688
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@ public static Map<String, Map<String, Variant<?>>> buildSettings(NetworkProperti
if (deviceType == NMDeviceType.NM_DEVICE_TYPE_WIFI) {
Map<String, Variant<?>> wifiSettingsMap = NMSettingsConverter.build80211WirelessSettings(properties,
deviceId);
Map<String, Variant<?>> wifiSecuritySettingsMap = NMSettingsConverter
.build80211WirelessSecuritySettings(properties, deviceId);
newConnectionSettings.put("802-11-wireless", wifiSettingsMap);
newConnectionSettings.put("802-11-wireless-security", wifiSecuritySettingsMap);

String propMode = properties.get(String.class, "net.interface.%s.config.wifi.mode", deviceId);
String securityType = properties.get(String.class, "net.interface.%s.config.wifi.%s.securityType", deviceId,
propMode.toLowerCase());
if (!"NONE".equals(securityType)) {
Map<String, Variant<?>> wifiSecuritySettingsMap = NMSettingsConverter
.build80211WirelessSecuritySettings(properties, deviceId);
newConnectionSettings.put("802-11-wireless-security", wifiSecuritySettingsMap);
}
} else if (deviceType == NMDeviceType.NM_DEVICE_TYPE_MODEM) {
Map<String, Variant<?>> gsmSettingsMap = NMSettingsConverter.buildGsmSettings(properties, deviceId);
Map<String, Variant<?>> pppSettingsMap = NMSettingsConverter.buildPPPSettings(properties, deviceId);
Expand Down Expand Up @@ -172,18 +178,18 @@ public static Map<String, Variant<?>> build80211WirelessSecuritySettings(Network
Map<String, Variant<?>> settings = new HashMap<>();

String propMode = props.get(String.class, "net.interface.%s.config.wifi.mode", deviceId);
String securityType = props.get(String.class, "net.interface.%s.config.wifi.%s.securityType", deviceId,
propMode.toLowerCase());

String psk = props
.get(Password.class, "net.interface.%s.config.wifi.%s.passphrase", deviceId, propMode.toLowerCase())
.toString();
String keyMgmt = wifiKeyMgmtConvert(props.get(String.class, "net.interface.%s.config.wifi.%s.securityType",
deviceId, propMode.toLowerCase()));
settings.put("psk", new Variant<>(psk));
String keyMgmt = wifiKeyMgmtConvert(securityType);
settings.put("key-mgmt", new Variant<>(keyMgmt));

if ("wpa-psk".equals(keyMgmt)) {
List<String> proto = wifiProtoConvert(props.get(String.class,
"net.interface.%s.config.wifi.%s.securityType", deviceId, propMode.toLowerCase()));
List<String> proto = wifiProtoConvert(securityType);
settings.put("proto", new Variant<>(proto, "as"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public static String getNetInterfaceStatus(Optional<String> gwtNetIfStatus) {
*/
public static String getGwtWifiSecurity(Optional<String> wifiSecurity) {
if (wifiSecurity.isPresent()) {
if (wifiSecurity.get().equals(WifiSecurity.NONE.name())) {
return GwtWifiSecurity.netWifiSecurityNONE.name();
}

if (wifiSecurity.get().equals(WifiSecurity.SECURITY_WEP.name())) {
return GwtWifiSecurity.netWifiSecurityWEP.name();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,42 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanAndHidd
new Variant<>(Arrays.asList("ccmp"), "as").getValue());
}

@Test
public void buildSettingsShouldNotSet80211WirelessSecuritySettingsIfSecurityTypeIsSetToNone() {
givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false);
givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedLan");
givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12");
givenMapWith("net.interface.wlan0.config.ip4.prefix", (short) 25);
givenMapWith("net.interface.wlan0.config.ip4.dnsServers", "1.1.1.1");
givenMapWith("net.interface.wlan0.config.ip4.gateway", "192.168.0.1");
givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA");
givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", "ssidtest");
givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", "RADIO_MODE_80211a");
givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10");
givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", "NONE");
givenMapWith("net.interface.wlan0.config.wifi.infra.ignoreSSID", true);
givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", new Password("test"));
givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP");
givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP");
givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap);

whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0",
NMDeviceType.NM_DEVICE_TYPE_WIFI);

thenNoExceptionsHaveBeenThrown();
thenResultingBuildAllMapContains("ipv6", "method", "disabled");
thenResultingBuildAllMapContains("ipv4", "method", "manual");
thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25)));
thenResultingBuildAllMapContains("connection", "id", "kura-wlan0-connection");
thenResultingBuildAllMapContains("connection", "interface-name", "wlan0");
thenResultingBuildAllMapContains("connection", "type", "802-11-wireless");
thenResultingBuildAllMapContains("802-11-wireless", "mode", "infrastructure");
thenResultingBuildAllMapContainsBytes("802-11-wireless", "ssid", "ssidtest");
thenResultingBuildAllMapContains("802-11-wireless", "band", "a");
thenResultingBuildAllMapContains("802-11-wireless", "channel", new UInt32(Short.parseShort("10")));
thenResultingBuildAllMapNotContains("802-11-wireless-security");
}

@Test
public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiWanAndHiddenSsid() {
givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false);
Expand Down Expand Up @@ -1302,6 +1338,10 @@ public void thenResultingBuildAllMapContains(String key, String subKey, Object v
assertEquals(value, this.resultAllSettingsMap.get(key).get(subKey).getValue());
}

public void thenResultingBuildAllMapNotContains(String key) {
assertFalse(this.resultAllSettingsMap.containsKey(key));
}

public void thenResultingBuildAllMapContainsBytes(String key, String subKey, Object value) {
assertEquals(value,
new String((byte[]) this.resultAllSettingsMap.get(key).get(subKey).getValue(), StandardCharsets.UTF_8));
Expand Down

0 comments on commit 05d6688

Please sign in to comment.