Skip to content

Commit

Permalink
Modified WirelessTabUi to hide WPA3 entries if required
Browse files Browse the repository at this point in the history
Signed-off-by: pierantoniomerlino <[email protected]>
  • Loading branch information
pierantoniomerlino committed Dec 5, 2024
1 parent 926df89 commit f35da42
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.logging.Logger;

import org.eclipse.kura.system.SystemService;
import org.eclipse.kura.web.client.messages.Messages;
import org.eclipse.kura.web.client.ui.EntryClassUi;
import org.eclipse.kura.web.client.ui.NewPasswordInput;
Expand All @@ -27,6 +29,7 @@
import org.eclipse.kura.web.client.util.MessageUtils;
import org.eclipse.kura.web.shared.GwtSafeHtmlUtils;
import org.eclipse.kura.web.shared.model.GwtConsoleUserOptions;
import org.eclipse.kura.web.shared.model.GwtGroupedNVPair;
import org.eclipse.kura.web.shared.model.GwtNetIfStatus;
import org.eclipse.kura.web.shared.model.GwtNetInterfaceConfig;
import org.eclipse.kura.web.shared.model.GwtSession;
Expand All @@ -41,6 +44,8 @@
import org.eclipse.kura.web.shared.model.GwtWifiSecurity;
import org.eclipse.kura.web.shared.model.GwtWifiWirelessMode;
import org.eclipse.kura.web.shared.model.GwtXSRFToken;
import org.eclipse.kura.web.shared.service.GwtDeviceService;
import org.eclipse.kura.web.shared.service.GwtDeviceServiceAsync;
import org.eclipse.kura.web.shared.service.GwtNetworkService;
import org.eclipse.kura.web.shared.service.GwtNetworkServiceAsync;
import org.eclipse.kura.web.shared.service.GwtSecurityTokenService;
Expand Down Expand Up @@ -140,6 +145,7 @@ interface TabWirelessUiUiBinder extends UiBinder<Widget, TabWirelessUi> {

private final GwtSecurityTokenServiceAsync gwtXSRFService = GWT.create(GwtSecurityTokenService.class);
private final GwtNetworkServiceAsync gwtNetworkService = GWT.create(GwtNetworkService.class);
private final GwtDeviceServiceAsync gwtDeviceService = GWT.create(GwtDeviceService.class);

private static final String REGEX_PASS_WPA = "^[ -~]{8,63}$";
private static final String REGEX_PASS_WEP = "^(?:[\\x00-\\x7F]{5}|[\\x00-\\x7F]{13}|[a-fA-F0-9]{10}|[a-fA-F0-9]{26})$";
Expand All @@ -152,6 +158,7 @@ interface TabWirelessUiUiBinder extends UiBinder<Widget, TabWirelessUi> {
private final NetworkTabsUi netTabs;
private final ListDataProvider<GwtWifiHotspotEntry> ssidDataProvider = new ListDataProvider<>();
private final SingleSelectionModel<GwtWifiHotspotEntry> ssidSelectionModel = new SingleSelectionModel<>();
// private boolean isWPA3WifiSecuritySupported;

AnchorListItem wireless8021xTabAnchorItem;

Expand Down Expand Up @@ -372,6 +379,8 @@ public TabWirelessUi(GwtSession currentSession, TabIp4Ui tcp4, TabIp6Ui tcp6,
evalActiveConfig();
});

configureWifiSecurityListBox();

logger.info("Constructor done.");
}

Expand Down Expand Up @@ -914,23 +923,7 @@ private void initForm() {
});

// Wireless Security
this.labelSecurity.setText(MSGS.netWifiWirelessSecurity());
this.security.addMouseOverHandler(event -> {
if (TabWirelessUi.this.security.isEnabled()) {
TabWirelessUi.this.helpText.clear();
TabWirelessUi.this.helpText.add(new Span(MSGS.netWifiToolTipSecurity()));
}
});
this.security.addMouseOutHandler(event -> resetHelp());
for (GwtWifiSecurity mode : GwtWifiSecurity.values()) {
this.security.addItem(MessageUtils.get(mode.name()));
}
this.security.addChangeHandler(event -> {
setDirty(true);
setPasswordValidation();
refreshForm();
checkPassword();
});
initWifiSecurityListBox(false);

// Password
this.labelPassword.setText(MSGS.netWifiWirelessPassword());
Expand Down Expand Up @@ -1201,6 +1194,7 @@ private void remove8021xFromSecurityDropdown() {
for (int i = 0; i < this.security.getItemCount(); i++) {
if (this.security.getItemText(i).equals(WIFI_SECURITY_WPA2_WPA3_ENTERPRISE_MESSAGE)) {
this.security.removeItem(i);
return;
}
}
}
Expand Down Expand Up @@ -1866,4 +1860,74 @@ private void fillRadioMode(boolean acSupported) {
this.radio.addItem(WIFI_BAND_BOTH_MESSAGE, WIFI_RADIO_BGN);
}

private void configureWifiSecurityListBox() {

this.gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

@Override
public void onFailure(Throwable ex) {
FailureHandler.handle(ex);
}

@Override
public void onSuccess(GwtXSRFToken token) {
TabWirelessUi.this.gwtDeviceService.findSystemProperties(token,
new AsyncCallback<List<GwtGroupedNVPair>>() {

@Override
public void onFailure(Throwable caught) {
logger.info("Unable to read WPA3 WiFi Security support property.");
}

@Override
public void onSuccess(List<GwtGroupedNVPair> result) {
Optional<GwtGroupedNVPair> wpa3SupportPair = result.stream().filter(
pair -> pair.getName().equals(SystemService.KEY_WPA3_WIFI_SECURITY_ENABLE))
.findFirst();
if (wpa3SupportPair.isPresent()
&& Boolean.parseBoolean(wpa3SupportPair.get().getValue())) {
initWifiSecurityListBox(true);
}
}
});
}
});
}

private void initWifiSecurityListBox(boolean isWPA3WifiSecuritySupported) {
this.labelSecurity.setText(MSGS.netWifiWirelessSecurity());
this.security.addMouseOverHandler(event -> {
if (TabWirelessUi.this.security.isEnabled()) {
TabWirelessUi.this.helpText.clear();
TabWirelessUi.this.helpText.add(new Span(composeNetWifiToolTipSecurity(isWPA3WifiSecuritySupported)));
}
});
this.security.addMouseOutHandler(event -> resetHelp());
this.security.clear();
for (GwtWifiSecurity mode : GwtWifiSecurity.values()) {
if (mode.equals(GwtWifiSecurity.netWifiSecurityWPA3)
|| mode.equals(GwtWifiSecurity.netWifiSecurityWPA2_WPA3)) {
if (isWPA3WifiSecuritySupported) {
this.security.addItem(MessageUtils.get(mode.name()));
}
} else {
this.security.addItem(MessageUtils.get(mode.name()));
}
}
this.security.addChangeHandler(event -> {
setDirty(true);
setPasswordValidation();
refreshForm();
checkPassword();
});
}

private String composeNetWifiToolTipSecurity(boolean isWPA3WifiSecuritySupported) {
String toolTipMessage = MSGS.netWifiToolTipSecurity();
if (isWPA3WifiSecuritySupported) {
toolTipMessage += "<br><br>" + MSGS.netWifiToolTipSecurityWPA3();
}
return toolTipMessage;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ public ArrayList<GwtGroupedNVPair> findSystemProperties(GwtXSRFToken xsrfToken)
// kura properties
SystemService systemService = ServiceLocator.getInstance().getService(SystemService.class);
Properties kuraProps = systemService.getProperties();
SortedSet kuraKeys = new TreeSet(kuraProps.keySet());
SortedSet kuraKeys = new TreeSet(kuraProps.stringPropertyNames());
for (Object key : kuraKeys) {
pairs.add(new GwtGroupedNVPair("propsKura", key.toString(), kuraProps.get(key).toString()));
pairs.add(new GwtGroupedNVPair("propsKura", key.toString(), kuraProps.getProperty(key.toString())));
}
return new ArrayList<>(pairs);
}
Expand Down Expand Up @@ -233,17 +233,19 @@ public ArrayList<GwtGroupedNVPair> findBundles(GwtXSRFToken xsrfToken) throws Gw
public boolean checkIfContainerOrchestratorIsActive(GwtXSRFToken xsrfToken) throws GwtKuraException {
checkXSRFToken(xsrfToken);

ContainerOrchestrationService checkIfContainerOrchestratorIsActive = ServiceLocator.getInstance().getService(ContainerOrchestrationService.class);
ContainerOrchestrationService checkIfContainerOrchestratorIsActive = ServiceLocator.getInstance()
.getService(ContainerOrchestrationService.class);

return checkIfContainerOrchestratorIsActive != null;
}

@Override
public List<GwtGroupedNVPair> findImages(GwtXSRFToken xsrfToken) throws GwtKuraException {
checkXSRFToken(xsrfToken);
List<GwtGroupedNVPair> pairs = new ArrayList<>();
try {
ContainerOrchestrationService checkIfContainerOrchestratorIsActive = ServiceLocator.getInstance().getService(ContainerOrchestrationService.class);
ContainerOrchestrationService checkIfContainerOrchestratorIsActive = ServiceLocator.getInstance()
.getService(ContainerOrchestrationService.class);
List<ImageInstanceDescriptor> images = checkIfContainerOrchestratorIsActive.listImageInstanceDescriptors();
if (images != null) {
for (ImageInstanceDescriptor image : images) {
Expand All @@ -253,7 +255,7 @@ public List<GwtGroupedNVPair> findImages(GwtXSRFToken xsrfToken) throws GwtKuraE
pair.setStatus("bndInstalled");
pair.setVersion(image.getImageTag());
pair.set("arch", image.getImageArch());

pairs.add(pair);
}
}
Expand All @@ -264,12 +266,13 @@ public List<GwtGroupedNVPair> findImages(GwtXSRFToken xsrfToken) throws GwtKuraE

return new ArrayList<>(pairs);
}

@Override
public void deleteImage(GwtXSRFToken xsrfToken, String imageId) throws GwtKuraException {
checkXSRFToken(xsrfToken);

ContainerOrchestrationService containerOrchestrationService = ServiceLocator.getInstance().getService(ContainerOrchestrationService.class);
ContainerOrchestrationService containerOrchestrationService = ServiceLocator.getInstance()
.getService(ContainerOrchestrationService.class);

List<ImageInstanceDescriptor> images = containerOrchestrationService.listImageInstanceDescriptors();

Expand Down Expand Up @@ -299,8 +302,10 @@ public List<GwtGroupedNVPair> findContainers(GwtXSRFToken xsrfToken) throws GwtK
checkXSRFToken(xsrfToken);
List<GwtGroupedNVPair> pairs = new ArrayList<>();
try {
ContainerOrchestrationService checkIfContainerOrchestratorIsActive = ServiceLocator.getInstance().getService(ContainerOrchestrationService.class);
List<ContainerInstanceDescriptor> containers = checkIfContainerOrchestratorIsActive.listContainerDescriptors();
ContainerOrchestrationService checkIfContainerOrchestratorIsActive = ServiceLocator.getInstance()
.getService(ContainerOrchestrationService.class);
List<ContainerInstanceDescriptor> containers = checkIfContainerOrchestratorIsActive
.listContainerDescriptors();
if (containers != null) {
for (ContainerInstanceDescriptor container : containers) {
GwtGroupedNVPair pair = new GwtGroupedNVPair();
Expand All @@ -324,7 +329,8 @@ public List<GwtGroupedNVPair> findContainers(GwtXSRFToken xsrfToken) throws GwtK
public void startContainer(GwtXSRFToken xsrfToken, String containerName) throws GwtKuraException {
checkXSRFToken(xsrfToken);

ContainerOrchestrationService containerOrchestrationService = ServiceLocator.getInstance().getService(ContainerOrchestrationService.class);
ContainerOrchestrationService containerOrchestrationService = ServiceLocator.getInstance()
.getService(ContainerOrchestrationService.class);
List<ContainerInstanceDescriptor> containers = containerOrchestrationService.listContainerDescriptors();

logger.info("Starting container with name: {}", containerName);
Expand All @@ -351,7 +357,8 @@ public void startContainer(GwtXSRFToken xsrfToken, String containerName) throws
public void stopContainer(GwtXSRFToken xsrfToken, String containerName) throws GwtKuraException {
checkXSRFToken(xsrfToken);

ContainerOrchestrationService containerOrchestrationService = ServiceLocator.getInstance().getService(ContainerOrchestrationService.class);
ContainerOrchestrationService containerOrchestrationService = ServiceLocator.getInstance()
.getService(ContainerOrchestrationService.class);

List<ContainerInstanceDescriptor> containers = containerOrchestrationService.listContainerDescriptors();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public class GwtLogServiceImpl extends OsgiRemoteServiceServlet implements GwtLo
private static final LogEntriesCache cache = new LogEntriesCache();
private static final List<String> registeredLogProviders = new LinkedList<>();

private static SystemService systemService;

@Override
public List<String> initLogProviders(GwtXSRFToken xsrfToken) throws GwtKuraException {
checkXSRFToken(xsrfToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ netWifiToolTipWirelessModeAdhoc=Configure the wireless interface in adhoc mode.
netWifiToolTipNetworkName=In <i>Access Point</i> mode, enter the SSID that will identify this wireless network.<br><br>In <i>Station</i> mode, enter the SSID of the wireless network or click the button to select wireless network in range. The button may be disabled for some systems.
netWifiToolTipRadioMode=In <i>Access Point</i> mode, select the appropriate speed rating for this device.<br><br>* 802.11a - 54 MBps, 50 feet or 450 MBps, using 5Ghz channels (up to 32) <br>* 802.11b - 11 Mbps, 150 feet<br>* 802.11g - 54 MBps, 50 feet<br>* 802.11n - 300 MBps, 175 feet<br>* 802.11ac - 1000 MBps, 50 feet<br><br>Note that real-world speeds are more modest. Likewise, range varies depending on device configuration and placement.
netWifiToolTipBand=Select the frequency band to use for this wireless interface.<br><br><ul><li>2.4 GHz band provides the most coverage but transmits data at slower speeds.</li><li>5 GHz band provides less coverage but transmits data at faster speeds.</li></ul>Wireless range decreases with higher frequencies because higher frequencies cannot penetrate solid objects, such as walls and floors. However, higher frequencies allow data to be transmitted faster than lower frequencies.
netWifiToolTipSecurity=Select the appropriate security protocol for this wireless network.<br>WPA2 is the most secure encryption method available for wireless networks - we recommend using WPA2 with the CCMP cipher whenever possible. WPA2 with CCMP is the only option permitted for high throughput 802.11n transmissions.<br>If you need to accommodate legacy devices with an SSID, enable WPA encryption with the TKIP cipher.<br><br>The WPA3-SAE security protocol is experimental. Please check if the device, driver and firmware are compliant with the new standard.
netWifiToolTipSecurity=Select the appropriate security protocol for this wireless network.<br>WPA2 is the most secure encryption method available for wireless networks - we recommend using WPA2 with the CCMP cipher whenever possible. WPA2 with CCMP is the only option permitted for high throughput 802.11n transmissions.<br>If you need to accommodate legacy devices with an SSID, enable WPA encryption with the TKIP cipher.
netWifiToolTipSecurityWPA3=The WPA3-SAE security protocol is experimental. Please check if the device, driver and firmware are compliant with the new standard.
netWifiToolTipPassword=Enter password for wireless network.<br><br>* In <i>Access Point</i> mode, provide password verification in the field below.<br><br>* In <i>Station mode</i>, press the button below to verify password.
netWifiToolTipVerifyPassword=In <i>Access Point</i> mode, retype wireless password to verify it. If entries don''t match, the field will be marked invalid with the <i>Passwords do not match</i> error message.
netWifiToolTipChannels=Select the desired channel frequencies over which the device should communicate.
Expand Down
Loading

0 comments on commit f35da42

Please sign in to comment.