diff --git a/kura/org.eclipse.kura.nm/META-INF/MANIFEST.MF b/kura/org.eclipse.kura.nm/META-INF/MANIFEST.MF
index 775bcf1ddb..260dfed1df 100644
--- a/kura/org.eclipse.kura.nm/META-INF/MANIFEST.MF
+++ b/kura/org.eclipse.kura.nm/META-INF/MANIFEST.MF
@@ -15,6 +15,7 @@ Import-Package: org.apache.commons.io;version="2.4.0",
org.eclipse.kura.core.net.modem;version="[1.0,2.0)",
org.eclipse.kura.core.net.util;version="[1.0,2.0)",
org.eclipse.kura.core.util;version="[1.0,2.0)",
+ org.eclipse.kura.core.keystore.util;version="[1.0,2.0)",
org.eclipse.kura.crypto;version="[1.1,2.0)",
org.eclipse.kura.executor;version="[1.0,2.0)",
org.eclipse.kura.internal.linux.net.dns;version="[1.0,2.0)",
@@ -35,6 +36,7 @@ Import-Package: org.apache.commons.io;version="2.4.0",
org.eclipse.kura.net.status.vlan;version="[1.0,2.0)",
org.eclipse.kura.net.wifi;version="[2.4,3.0]",
org.eclipse.kura.usb;version="[1.0,2.0)",
+ org.eclipse.kura.security.keystore;version="[1.0,2.0)",
org.osgi.framework;version="1.5.0",
org.osgi.service.component;version="1.2.0",
org.osgi.service.event;version="1.3.0",
diff --git a/kura/org.eclipse.kura.nm/OSGI-INF/networkConfigurationService.xml b/kura/org.eclipse.kura.nm/OSGI-INF/networkConfigurationService.xml
index 83de1761ea..afe926ff28 100644
--- a/kura/org.eclipse.kura.nm/OSGI-INF/networkConfigurationService.xml
+++ b/kura/org.eclipse.kura.nm/OSGI-INF/networkConfigurationService.xml
@@ -24,4 +24,5 @@
+
diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/configuration/NMConfigurationServiceImpl.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/configuration/NMConfigurationServiceImpl.java
index 167856e1af..97c305f648 100644
--- a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/configuration/NMConfigurationServiceImpl.java
+++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/configuration/NMConfigurationServiceImpl.java
@@ -13,6 +13,10 @@
package org.eclipse.kura.nm.configuration;
import java.net.UnknownHostException;
+import java.security.KeyStore.PrivateKeyEntry;
+import java.security.KeyStore.TrustedCertificateEntry;
+import java.security.PrivateKey;
+import java.security.cert.Certificate;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@@ -25,9 +29,10 @@
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
-
+import org.eclipse.kura.KuraErrorCode;
import org.eclipse.kura.KuraException;
import org.eclipse.kura.configuration.ComponentConfiguration;
+import org.eclipse.kura.configuration.ConfigurationService;
import org.eclipse.kura.configuration.Password;
import org.eclipse.kura.configuration.SelfConfiguringComponent;
import org.eclipse.kura.crypto.CryptoService;
@@ -45,6 +50,7 @@
import org.eclipse.kura.nm.configuration.monitor.DnsServerMonitor;
import org.eclipse.kura.nm.configuration.writer.DhcpServerConfigWriter;
import org.eclipse.kura.nm.configuration.writer.FirewallNatConfigWriter;
+import org.eclipse.kura.security.keystore.KeystoreService;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.exceptions.DBusExecutionException;
import org.osgi.service.component.ComponentContext;
@@ -61,12 +67,11 @@ public class NMConfigurationServiceImpl implements SelfConfiguringComponent {
private static final String MODIFIED_INTERFACE_NAMES = "modified.interface.names";
private static final String MODEM_PORT_REGEX = "^\\d+-\\d+";
private static final Pattern PPP_INTERFACE = Pattern.compile("ppp\\d+");
-
- private static final List SUPPORTED_NAT_INTERFACE_TYPES = Arrays.asList(
- NetInterfaceType.ETHERNET, NetInterfaceType.WIFI, NetInterfaceType.MODEM,
- NetInterfaceType.VLAN);
- private static final List SUPPORTED_DHCP_SERVER_INTERFACE_TYPES = Arrays.asList(
- NetInterfaceType.ETHERNET, NetInterfaceType.WIFI, NetInterfaceType.VLAN);
+
+ private static final List SUPPORTED_NAT_INTERFACE_TYPES = Arrays.asList(NetInterfaceType.ETHERNET,
+ NetInterfaceType.WIFI, NetInterfaceType.MODEM, NetInterfaceType.VLAN);
+ private static final List SUPPORTED_DHCP_SERVER_INTERFACE_TYPES = Arrays
+ .asList(NetInterfaceType.ETHERNET, NetInterfaceType.WIFI, NetInterfaceType.VLAN);
private NetworkService networkService;
private DnsServerService dnsServer;
@@ -74,6 +79,8 @@ public class NMConfigurationServiceImpl implements SelfConfiguringComponent {
private CommandExecutorService commandExecutorService;
private CryptoService cryptoService;
+ private Map keystoreServices = new HashMap<>();
+
private DhcpServerMonitor dhcpServerMonitor;
private DnsServerMonitor dnsServerMonitor;
@@ -127,6 +134,16 @@ public void unsetCryptoService(CryptoService cryptoService) {
}
}
+ public void setKeystoreService(KeystoreService keystoreService, Map properties) {
+ this.keystoreServices.put((String) properties.get(ConfigurationService.KURA_SERVICE_PID), keystoreService);
+ }
+
+ public void unsetKeystoreService(KeystoreService keystoreService, Map properties) {
+ if (this.keystoreServices.containsValue(keystoreService)) {
+ this.keystoreServices.remove(properties.get(ConfigurationService.KURA_SERVICE_PID));
+ }
+ }
+
public void setDnsServerService(DnsServerService dnsServer) {
this.dnsServer = dnsServer;
}
@@ -213,13 +230,16 @@ public synchronized void update(Map receivedProperties) {
}
if (NetInterfaceType.MODEM.equals(interfaceTypeProperty.get())) {
setModemPppNumber(modifiedProps, interfaceName);
- }
+ }
}
mergeNetworkConfigurationProperties(modifiedProps, this.networkProperties.getProperties());
+ this.networkProperties = new NetworkProperties(
+ discardModifiedNetworkInterfaces(new HashMap<>(modifiedProps)));
+
decryptAndConvertPasswordProperties(modifiedProps);
- this.networkProperties = new NetworkProperties(discardModifiedNetworkInterfaces(modifiedProps));
+ decryptAndConvertCertificatesProperties(modifiedProps, interfaces);
writeNetworkConfigurationSettings(modifiedProps);
writeFirewallNatRules(interfaces, modifiedProps);
@@ -252,7 +272,7 @@ protected void setModemPppNumber(Map modifiedProps, String inter
Integer pppNum = Integer.valueOf(this.networkService.getModemPppInterfaceName(interfaceName).substring(3));
modifiedProps.put(String.format(PREFIX + "%s.config.pppNum", interfaceName), pppNum);
}
-
+
protected void setInterfaceType(Map modifiedProps, String interfaceName, NetInterfaceType type) {
modifiedProps.put(String.format(PREFIX + "%s.type", interfaceName), type.toString());
}
@@ -295,6 +315,86 @@ private void decryptAndConvertPasswordProperties(Map modifiedPro
}
}
+ private void decryptAndConvertCertificatesProperties(Map modifiedProps, Set interfaces) {
+
+ interfaces.forEach(interfaceName -> {
+ String key = String.format("net.interface.%s.config.802-1x.keystore.pid", interfaceName);
+ if (modifiedProps.containsKey(key)) {
+
+ Object prop = modifiedProps.get(key);
+
+ if (prop instanceof String) {
+ String keystorePid = (String) prop;
+
+ findAndDecodeCertificatesForInterface(interfaceName, modifiedProps,
+ this.keystoreServices.get(keystorePid));
+ }
+ }
+ });
+ }
+
+ private void findAndDecodeCertificatesForInterface(String interfaceName, Map modifiedProps,
+ KeystoreService keystoreService) {
+
+ if (keystoreService == null) {
+ logger.error("Cannot find keystore service for interface {}", interfaceName);
+ return;
+ }
+
+ final String clientCertString = String.format("net.interface.%s.config.802-1x.client-cert-name", interfaceName);
+ final String caCertString = String.format("net.interface.%s.config.802-1x.ca-cert-name", interfaceName);
+ final String privateKeyString = String.format("net.interface.%s.config.802-1x.private-key-name", interfaceName);
+ final List keyCertStrings = Arrays.asList(clientCertString, caCertString, privateKeyString);
+
+ for (String key : keyCertStrings) {
+ if (!modifiedProps.containsKey(key)) {
+ continue;
+ }
+
+ Object value = modifiedProps.get(key);
+ try {
+ String valueString = value.toString();
+ if (isCertificate(key)) {
+ modifiedProps.put(key, getTrustedCertificateFromKeystore(valueString, keystoreService));
+ } else {
+ modifiedProps.put(key, getTrustedPrivateKeyFromKeystore(valueString, keystoreService));
+ }
+ } catch (KuraException e) {
+ logger.error("Unable to decode key/certificate {} from keystore.", key, e);
+ modifiedProps.put(key, value);
+ }
+ }
+ }
+
+ private boolean isCertificate(String key) {
+ return key.contains("802-1x.client-cert-name") || key.contains("802-1x.ca-cert-name");
+ }
+
+ private Certificate getTrustedCertificateFromKeystore(String certificateName, KeystoreService keystoreService)
+ throws KuraException {
+ if (keystoreService.getEntry(certificateName) instanceof TrustedCertificateEntry) {
+ TrustedCertificateEntry cert = (TrustedCertificateEntry) keystoreService.getEntry(certificateName);
+ return cert.getTrustedCertificate();
+ } else if (keystoreService.getEntry(certificateName) instanceof PrivateKeyEntry) {
+ PrivateKeyEntry cert = (PrivateKeyEntry) keystoreService.getEntry(certificateName);
+ return cert.getCertificate();
+ } else {
+ throw new KuraException(KuraErrorCode.CONFIGURATION_ERROR,
+ String.format("Certificate \"%s\" is not of the expected key type or not found.", certificateName));
+ }
+ }
+
+ private PrivateKey getTrustedPrivateKeyFromKeystore(String privateKeyName, KeystoreService keystoreService)
+ throws KuraException {
+ if (!(keystoreService.getEntry(privateKeyName) instanceof PrivateKeyEntry)) {
+ throw new KuraException(KuraErrorCode.CONFIGURATION_ERROR,
+ String.format("Private key \"%s\" is not of the expected key type or not found.", privateKeyName));
+ }
+
+ PrivateKeyEntry key = (PrivateKeyEntry) keystoreService.getEntry(privateKeyName);
+ return key.getPrivateKey();
+ }
+
@Override
@SuppressWarnings("restriction")
public synchronized ComponentConfiguration getConfiguration() throws KuraException {
diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/configuration/NMSettingsConverter.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/configuration/NMSettingsConverter.java
index 719eefd741..cb23356e34 100644
--- a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/configuration/NMSettingsConverter.java
+++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/configuration/NMSettingsConverter.java
@@ -16,6 +16,9 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
+import java.security.PrivateKey;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -64,6 +67,8 @@ public class NMSettingsConverter {
private static final String KURA_PROPS_KEY_WIFI_MODE = "net.interface.%s.config.wifi.mode";
private static final String KURA_PROPS_KEY_WIFI_SECURITY_TYPE = "net.interface.%s.config.wifi.%s.securityType";
+ static final UInt32 NM_SECRET_FLAGS_NOT_REQUIRED = new UInt32(4);
+
private NMSettingsConverter() {
throw new IllegalStateException("Utility class");
}
@@ -171,36 +176,51 @@ private static void create8021xTls(NetworkProperties props, String deviceId, Map
String identity = props.get(String.class, "net.interface.%s.config.802-1x.identity", deviceId);
settings.put("identity", new Variant<>(identity));
- String clientCert = props.get(String.class, "net.interface.%s.config.802-1x.client-cert", deviceId);
- settings.put("client-cert", new Variant<>(clientCert.getBytes(StandardCharsets.UTF_8)));
+ try {
+ Certificate clientCert = props.get(Certificate.class, "net.interface.%s.config.802-1x.client-cert-name",
+ deviceId);
+ settings.put("client-cert", new Variant<>(clientCert.getEncoded()));
+ } catch (CertificateEncodingException e) {
+ logger.error("Unable to find or decode Client Certificate");
+ }
+
+ PrivateKey privateKey = props.get(PrivateKey.class, "net.interface.%s.config.802-1x.private-key-name",
+ deviceId);
+
+ if (privateKey.getEncoded() != null) {
+ settings.put("private-key", new Variant<>(privateKey.getEncoded()));
+ } else {
+ logger.error("Unable to find or decode Private Key");
+ }
+
+ Optional privateKeyPassword = props.getOpt(Password.class,
+ "net.interface.%s.config.802-1x.private-key-password", deviceId);
- String privateKey = props.get(String.class, "net.interface.%s.config.802-1x.private-key", deviceId);
- settings.put("private-key", new Variant<>(privateKey.getBytes(StandardCharsets.UTF_8)));
+ privateKeyPassword.ifPresent(value -> settings.put("private-key-password", new Variant<>(value.toString())));
- String privateKeyPassword = props
- .get(Password.class, "net.interface.%s.config.802-1x.private-key-password", deviceId).toString();
- settings.put("private-key-password", new Variant<>(privateKeyPassword));
+ settings.put("private-key-password-flags", new Variant<>(NM_SECRET_FLAGS_NOT_REQUIRED));
}
private static void create8021xOptionalCaCertAndAnonIdentity(NetworkProperties props, String deviceId,
Map> settings) {
+
Optional anonymousIdentity = props.getOpt(String.class,
"net.interface.%s.config.802-1x.anonymous-identity", deviceId);
- if (anonymousIdentity.isPresent()) {
- settings.put("anonymous-identity", new Variant<>(anonymousIdentity.get()));
- }
- Optional caCert = props.getOpt(String.class, "net.interface.%s.config.802-1x.ca-cert", deviceId);
- if (caCert.isPresent()) {
- settings.put("ca-cert", new Variant<>(caCert.get().getBytes(StandardCharsets.UTF_8)));
+ anonymousIdentity.ifPresent(value -> settings.put("anonymous-identity", new Variant<>(value)));
+
+ try {
+ Certificate caCert = props.get(Certificate.class, "net.interface.%s.config.802-1x.ca-cert-name", deviceId);
+ settings.put("ca-cert", new Variant<>(caCert.getEncoded()));
+ } catch (Exception e) {
+ logger.error(String.format("Unable to find or decode CA Certificate for interface %s", deviceId));
}
Optional caCertPassword = props.getOpt(Password.class,
"net.interface.%s.config.802-1x.ca-cert-password", deviceId);
- if (caCertPassword.isPresent()) {
- settings.put("ca-cert-password", new Variant<>(caCertPassword.get().toString()));
- }
+
+ caCertPassword.ifPresent(value -> settings.put("ca-cert-password", new Variant<>(value.toString())));
}
private static void create8021xMschapV2(NetworkProperties props, String deviceId,
@@ -512,7 +532,7 @@ public static Map> buildPPPSettings(NetworkProperties props,
return settings;
}
-
+
public static Map> buildVlanSettings(NetworkProperties props, String deviceId) {
Map> settings = new HashMap<>();
settings.put("interface-name", new Variant<>(deviceId));
@@ -524,11 +544,9 @@ public static Map> buildVlanSettings(NetworkProperties props,
settings.put("flags", new Variant<>(new UInt32(vlanFlags.orElse(1))));
DBusListType listType = new DBusListType(String.class);
Optional> ingressMap = props.getOptStringList("net.interface.%s.config.vlan.ingress", deviceId);
- settings.put("ingress-priority-map", new Variant<>(ingressMap
- .orElse(new ArrayList()), listType));
+ settings.put("ingress-priority-map", new Variant<>(ingressMap.orElse(new ArrayList<>()), listType));
Optional> egressMap = props.getOptStringList("net.interface.%s.config.vlan.egress", deviceId);
- settings.put("egress-priority-map", new Variant<>(egressMap
- .orElse(new ArrayList()), listType));
+ settings.put("egress-priority-map", new Variant<>(egressMap.orElse(new ArrayList<>()), listType));
return settings;
}
@@ -552,7 +570,7 @@ public static Map> buildConnectionSettings(Optional> createConnectionSettings(String iface) {
Map> connectionMap = new HashMap<>();
diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/configuration/monitor/DhcpServerMonitor.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/configuration/monitor/DhcpServerMonitor.java
index 60c859655d..a60a9fb72d 100644
--- a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/configuration/monitor/DhcpServerMonitor.java
+++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/configuration/monitor/DhcpServerMonitor.java
@@ -76,7 +76,7 @@ private void monitor() {
stopDhcpServer(interfaceName);
}
} catch (KuraException e) {
- logger.warn("Failed to chech DHCP server status for the interface " + interfaceName, e);
+ logger.warn("Failed to check DHCP server status for the interface " + interfaceName, e);
}
});
}
diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/Tab8021xUi.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/Tab8021xUi.java
index 04889f6e0a..49021a5cd7 100644
--- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/Tab8021xUi.java
+++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/Tab8021xUi.java
@@ -327,16 +327,21 @@ public void setDirty(boolean dirty) {
public void getUpdatedNetInterface(GwtNetInterfaceConfig updatedNetIf) {
Gwt8021xConfig updated8021xConfig = new Gwt8021xConfig();
- if (this.username.isEnabled()) {
+ if (!this.username.getText().isEmpty() && this.username.getText() != null) {
updated8021xConfig.setIdentity(this.username.getText());
}
- if (this.password.isEnabled()) {
+ if (!this.password.getText().isEmpty() && this.password.getText() != null) {
updated8021xConfig.setPassword(this.password.getText());
}
- updated8021xConfig.setEap(Gwt8021xEap.valueOf(this.eap.getSelectedValue()));
- updated8021xConfig.setInnerAuthEnum(Gwt8021xInnerAuth.valueOf(this.innerAuth.getSelectedValue()));
+ if (!this.eap.getSelectedValue().isEmpty() && this.eap.getSelectedValue() != null) {
+ updated8021xConfig.setEap(Gwt8021xEap.valueOf(this.eap.getSelectedValue()));
+ }
+
+ if (!this.innerAuth.getSelectedValue().isEmpty() && this.innerAuth.getSelectedValue() != null) {
+ updated8021xConfig.setInnerAuthEnum(Gwt8021xInnerAuth.valueOf(this.innerAuth.getSelectedValue()));
+ }
updatedNetIf.setEnterpriseConfig(updated8021xConfig);
}
diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabIp4Ui.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabIp4Ui.java
index a862abf109..6f05ef3a84 100644
--- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabIp4Ui.java
+++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabIp4Ui.java
@@ -777,6 +777,7 @@ private void refreshForm() {
this.dns.setEnabled(false);
}
this.renew.setEnabled(false);
+
this.configure.setSelectedIndex(this.configure.getItemText(0).equals(IPV4_MODE_DHCP_MESSAGE) ? 0 : 1);
} else if (this.selectedNetIfConfig != null
&& this.selectedNetIfConfig.getHwTypeEnum() == GwtNetIfType.LOOPBACK) {
@@ -867,4 +868,4 @@ private void initModal() {
this.multipleWanWarnText.setText(MSGS.netStatusWarning());
this.wanModal.addHideHandler(evt -> this.setDirty(true));
}
-}
\ No newline at end of file
+}
diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/net2/configuration/NetworkConfigurationServiceProperties.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/net2/configuration/NetworkConfigurationServiceProperties.java
index 7ebb2da07d..543b609f0d 100644
--- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/net2/configuration/NetworkConfigurationServiceProperties.java
+++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/net2/configuration/NetworkConfigurationServiceProperties.java
@@ -195,8 +195,7 @@ public void setIp6AddressGenMode(String ifname, String addrGenMode) {
}
public Optional getIp6Privacy(String ifname) {
- return getNonEmptyStringProperty(
- this.properties.get(String.format(NET_INTERFACE_CONFIG_IP6_PRIVACY, ifname)));
+ return getNonEmptyStringProperty(this.properties.get(String.format(NET_INTERFACE_CONFIG_IP6_PRIVACY, ifname)));
}
public void setIp6Privacy(String ifname, String privacy) {
@@ -363,8 +362,8 @@ public void setWifiMasterDriver(String ifname, String driver) {
}
public Password getWifiMasterPassphrase(String ifname) {
- return getPasswordFromProperty(this.properties
- .get(String.format(NET_INTERFACE_CONFIG_WIFI_MASTER_PASSPHRASE, ifname)));
+ return getPasswordFromProperty(
+ this.properties.get(String.format(NET_INTERFACE_CONFIG_WIFI_MASTER_PASSPHRASE, ifname)));
}
public void setWifiMasterPassphrase(String ifname, String passphrase) {
@@ -373,8 +372,7 @@ public void setWifiMasterPassphrase(String ifname, String passphrase) {
}
public String getWifiMasterSsid(String ifname) {
- return (String) this.properties.getOrDefault(String.format(NET_INTERFACE_CONFIG_WIFI_MASTER_SSID, ifname),
- "");
+ return (String) this.properties.getOrDefault(String.format(NET_INTERFACE_CONFIG_WIFI_MASTER_SSID, ifname), "");
}
public void setWifiMasterSsid(String ifname, String ssid) {
@@ -391,8 +389,8 @@ public void setWifiMasterSecurityType(String ifname, String securityType) {
}
public Optional getWifiMasterMode(String ifname) {
- return Optional.ofNullable(
- (String) this.properties.get(String.format(NET_INTERFACE_CONFIG_WIFI_MASTER_MODE, ifname)));
+ return Optional
+ .ofNullable((String) this.properties.get(String.format(NET_INTERFACE_CONFIG_WIFI_MASTER_MODE, ifname)));
}
public void setWifiMasterMode(String ifname, String mode) {
@@ -400,9 +398,8 @@ public void setWifiMasterMode(String ifname, String mode) {
}
public List getWifiMasterChannel(String ifname) {
- return channelsAsIntegersList(
- (String) this.properties.getOrDefault(String.format(NET_INTERFACE_CONFIG_WIFI_MASTER_CHANNEL, ifname),
- ""));
+ return channelsAsIntegersList((String) this.properties
+ .getOrDefault(String.format(NET_INTERFACE_CONFIG_WIFI_MASTER_CHANNEL, ifname), ""));
}
public void setWifiMasterChannel(String ifname, List channels) {
@@ -479,9 +476,8 @@ public void setWifiInfraSsid(String ifname, String ssid) {
}
public List getWifiInfraChannel(String ifname) {
- return channelsAsIntegersList(
- (String) this.properties.getOrDefault(String.format(NET_INTERFACE_CONFIG_WIFI_INFRA_CHANNEL, ifname),
- ""));
+ return channelsAsIntegersList((String) this.properties
+ .getOrDefault(String.format(NET_INTERFACE_CONFIG_WIFI_INFRA_CHANNEL, ifname), ""));
}
public void setWifiInfraChannel(String ifname, List channels) {
@@ -499,8 +495,8 @@ public void setWifiInfraBgscan(String ifname, String bgScan) {
}
public Password getWifiInfraPassphrase(String ifname) {
- return getPasswordFromProperty(this.properties
- .get(String.format(NET_INTERFACE_CONFIG_WIFI_INFRA_PASSPHRASE, ifname)));
+ return getPasswordFromProperty(
+ this.properties.get(String.format(NET_INTERFACE_CONFIG_WIFI_INFRA_PASSPHRASE, ifname)));
}
public void setWifiInfraPassphrase(String ifname, String passphrase) {
@@ -810,7 +806,7 @@ public void setUsbDevicePath(String ifname, String path) {
}
/**
- * Wifi Enterprise / 802-1x Configuration
+ * Wifi Enterprise / 802-1x Configuration
*/
private static final String NET_INTERFACE_CONFIG_8021X_EAP = "net.interface.%s.config.802-1x.eap";
@@ -823,7 +819,8 @@ public void set8021xEap(String ifname, String eap) {
}
public String get8021xEap(String ifname) {
- return (String) this.properties.getOrDefault(String.format(NET_INTERFACE_CONFIG_8021X_EAP, ifname), "");
+ return (String) this.properties.getOrDefault(String.format(NET_INTERFACE_CONFIG_8021X_EAP, ifname),
+ "Kura8021xEapTtls");
}
public void set8021xInnerAuth(String ifname, String phase2) {
@@ -831,7 +828,8 @@ public void set8021xInnerAuth(String ifname, String phase2) {
}
public String get8021xInnerAuth(String ifname) {
- return (String) this.properties.getOrDefault(String.format(NET_INTERFACE_CONFIG_8021X_PHASE2, ifname), "");
+ return (String) this.properties.getOrDefault(String.format(NET_INTERFACE_CONFIG_8021X_PHASE2, ifname),
+ "Kura8021xEapNone");
}
public void set8021xIdentity(String ifname, String identity) {
@@ -839,7 +837,8 @@ public void set8021xIdentity(String ifname, String identity) {
}
public String get8021xIdentity(String ifname) {
- return (String) this.properties.getOrDefault(String.format(NET_INTERFACE_CONFIG_8021X_IDENTITY, ifname), "");
+ return (String) this.properties.getOrDefault(String.format(NET_INTERFACE_CONFIG_8021X_IDENTITY, ifname),
+ "changeme");
}
public void set8021xPassword(String ifname, String password) {
diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/net2/configuration/NetworkConfigurationServicePropertiesBuilder.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/net2/configuration/NetworkConfigurationServicePropertiesBuilder.java
index dbf543e78e..90b42c93d4 100644
--- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/net2/configuration/NetworkConfigurationServicePropertiesBuilder.java
+++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/net2/configuration/NetworkConfigurationServicePropertiesBuilder.java
@@ -247,11 +247,32 @@ private void setWifiMasterProperties() throws GwtKuraException {
}
private void set8021xConfig() {
- logger.error("setting 802-1x config");
- this.properties.set8021xEap(this.ifname, this.gwtConfig.get8021xConfig().getEap());
- this.properties.set8021xInnerAuth(this.ifname, this.gwtConfig.get8021xConfig().getInnerAuth());
- this.properties.set8021xIdentity(this.ifname, this.gwtConfig.get8021xConfig().getUsername());
- this.properties.set8021xPassword(this.ifname, this.gwtConfig.get8021xConfig().getPassword());
+ if (this.gwtConfig.get8021xConfig() == null || !(this.gwtConfig instanceof GwtWifiNetInterfaceConfig)) {
+ return;
+ }
+
+ logger.info("setting 802-1x config");
+
+ if (this.gwtConfig.get8021xConfig().getEap() != null && !this.gwtConfig.get8021xConfig().getEap().isEmpty()) {
+ this.properties.set8021xEap(this.ifname, this.gwtConfig.get8021xConfig().getEap());
+ }
+
+ if (this.gwtConfig.get8021xConfig().getInnerAuth() != null
+ && !this.gwtConfig.get8021xConfig().getInnerAuth().isEmpty()) {
+ this.properties.set8021xInnerAuth(this.ifname, this.gwtConfig.get8021xConfig().getInnerAuth());
+ }
+
+ if (this.gwtConfig.get8021xConfig().getUsername() != null
+ && !this.gwtConfig.get8021xConfig().getUsername().isEmpty()) {
+ this.properties.set8021xIdentity(this.ifname, this.gwtConfig.get8021xConfig().getUsername());
+ }
+
+ if (this.gwtConfig.get8021xConfig().getPassword() != null
+ && !this.gwtConfig.get8021xConfig().getPassword().isEmpty()) {
+ this.properties.set8021xPassword(this.ifname, this.gwtConfig.get8021xConfig().getPassword());
+ }
+
+ logger.info("DONE - setting 802-1x config");
}
private void setWifiInfraProperties() {
diff --git a/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/client/messages/Messages.properties b/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/client/messages/Messages.properties
index 7bcb20fce4..fa78dbda5d 100644
--- a/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/client/messages/Messages.properties
+++ b/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/client/messages/Messages.properties
@@ -620,7 +620,7 @@ netWifiChannelMissingError=The chosen network uses a channel that is not allowed
netWifiCountryCode=Country Code
netWifiCountryCodeLabel=Country Code
-netWifiWireless8021x=802-1x
+netWifiWireless8021x=802.1x
net8021xEap=Enterprise EAP (Extensible Authentication Protocol)
net8021xEapHelp=Extensible Authentication Protocol (EAP), determine what protocol will be used to authenticate the network.
net8021xInnerAuth=Inner Authentication (Phase2 Auth)
diff --git a/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/configuration/NMConfigurationServiceImplTest.java b/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/configuration/NMConfigurationServiceImplTest.java
index 51ef3cf28a..2a70e3a3b8 100644
--- a/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/configuration/NMConfigurationServiceImplTest.java
+++ b/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/configuration/NMConfigurationServiceImplTest.java
@@ -17,13 +17,19 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import java.security.PrivateKey;
+import java.security.KeyStore.PrivateKeyEntry;
+import java.security.KeyStore.TrustedCertificateEntry;
+import java.security.cert.Certificate;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -33,6 +39,7 @@
import org.eclipse.kura.KuraException;
import org.eclipse.kura.configuration.ComponentConfiguration;
+import org.eclipse.kura.configuration.ConfigurationService;
import org.eclipse.kura.configuration.metatype.AD;
import org.eclipse.kura.configuration.metatype.OCD;
import org.eclipse.kura.core.linux.executor.LinuxExitStatus;
@@ -48,6 +55,7 @@
import org.eclipse.kura.nm.NMDbusConnector;
import org.eclipse.kura.nm.NetworkProperties;
import org.eclipse.kura.nm.configuration.writer.DhcpServerConfigWriter;
+import org.eclipse.kura.security.keystore.KeystoreService;
import org.junit.Test;
import org.mockito.Mockito;
import org.osgi.framework.BundleContext;
@@ -67,6 +75,7 @@ public class NMConfigurationServiceImplTest {
private AtomicBoolean posted;
private Event event;
private final Set dhcpConfigWriterInterfaces = new HashSet<>();
+ private KeystoreService keystoreService = mock(KeystoreService.class);
@Test
public void shouldPostEventAfterActivationTest() throws InterruptedException, KuraException {
@@ -152,6 +161,18 @@ public void shouldStartConfigWriterIfEthernetInterfaceIsEnabledAndInDhcpServerMo
thenDhcpConfigWriterIsCreatedForInterfaces("eno1");
}
+ @Test
+ public void shouldStartConfigWriterIfEnterpriseWifi() throws KuraException {
+ givenNetworkConfigurationService();
+ givenEnterpriseWifiKeystore();
+ givenFullProperties();
+ givenWifiEnterprisePropertiesForInterfaceWlp2s0();
+
+ whenServiceIsActivated();
+
+ thenDhcpConfigWriterIsCreatedForInterfaces("wlp2s0");
+ }
+
@Test
public void shouldStartConfigWriterIfWifiInterfaceIsEnabledAndInDhcpServerMode() throws KuraException {
givenNetworkConfigurationService();
@@ -369,6 +390,92 @@ private void givenFullProperties() {
this.properties.put("net.interface.1-4.config.pdpType", "IP");
}
+ private void givenWifiEnterprisePropertiesForInterfaceWlp2s0() {
+ this.properties.put("net.interfaces", "enp5s0,lo,eno1,wlp1s0,wlp2s0,1-4");
+
+ this.properties.put("net.interface.wlp2s0.type", "WIFI");
+ this.properties.put("net.interface.wlp2s0.config.ip4.gateway", "");
+ this.properties.put("net.interface.wlp2s0.config.wifi.master.driver", "nl80211");
+ this.properties.put("net.interface.wlp2s0.config.wifi.infra.ssid", "testssid");
+ this.properties.put("net.interface.wlp2s0.config.wifi.infra.groupCiphers", "CCMP_TKIP");
+ this.properties.put("net.interface.wlp2s0.config.wifi.master.bgscan", "");
+ this.properties.put("net.interface.wlp2s0.config.dhcpServer4.rangeStart", "172.16.1.100");
+ this.properties.put("net.interface.wlp2s0.config.dhcpServer4.maxLeaseTime", 7200);
+ this.properties.put("net.interface.wlp2s0.config.wifi.master.pingAccessPoint", false);
+ this.properties.put("net.interface.wlp2s0.config.wifi.infra.channel", "1");
+ this.properties.put("net.interface.wlp2s0.config.wifi.master.passphrase", "qwerty=");
+ this.properties.put("net.interface.wlp2s0.config.wifi.master.groupCiphers", "CCMP_TKIP");
+ this.properties.put("net.interface.wlp2s0.config.wifi.infra.bgscan", "");
+ this.properties.put("net.interface.wlp2s0.config.wifi.infra.passphrase", "");
+ this.properties.put("net.interface.wlp2s0.config.dhcpServer4.defaultLeaseTime", 7200);
+ this.properties.put("net.interface.wlp2s0.config.wifi.master.ssid", "kura_gateway_0");
+ this.properties.put("net.interface.wlp2s0.config.wifi.master.securityType", "SECURITY_WPA2");
+ this.properties.put("net.interface.wlp2s0.config.dhcpServer4.rangeEnd", "172.16.1.110");
+ this.properties.put("net.interface.wlp2s0.config.wifi.infra.ignoreSSID", false);
+ this.properties.put("net.interface.wlp2s0.config.wifi.master.mode", "MASTER");
+ this.properties.put("net.interface.wlp2s0.config.dhcpServer4.prefix", 24);
+ this.properties.put("net.interface.wlp2s0.config.wifi.mode", "INFRA");
+ this.properties.put("net.interface.wlp2s0.config.wifi.infra.mode", "INFRA");
+ this.properties.put("net.interface.wlp2s0.config.wifi.infra.pingAccessPoint", false);
+ this.properties.put("net.interface.wlp2s0.config.nat.enabled", false);
+ this.properties.put("net.interface.wlp2s0.config.ip4.status", "netIPv4StatusEnabledWAN");
+ this.properties.put("net.interface.wlp2s0.config.ip6.status", "netIPv6StatusDisabled");
+ this.properties.put("net.interface.wlp2s0.config.wifi.master.channel", "1");
+ this.properties.put("net.interface.wlp2s0.config.wifi.master.radioMode", "RADIO_MODE_80211g");
+ this.properties.put("net.interface.wlp2s0.config.wifi.infra.driver", "nl80211");
+ this.properties.put("net.interface.wlp2s0.config.dhcpServer4.enabled", true);
+ this.properties.put("net.interface.wlp2s0.config.wifi.master.ignoreSSID", false);
+ this.properties.put("net.interface.wlp2s0.config.ip4.address", "172.16.1.1");
+ this.properties.put("net.interface.wlp2s0.config.ip6.dnsServers", "");
+ this.properties.put("net.interface.wlp2s0.config.wifi.master.pairwiseCiphers", "CCMP");
+ this.properties.put("net.interface.wlp2s0.config.dhcpClient6.enabled", false);
+ this.properties.put("net.interface.wlp2s0.config.dhcpServer4.passDns", false);
+ this.properties.put("net.interface.wlp2s0.config.wifi.infra.securityType", "SECURITY_WPA2_WPA3_ENTERPRISE");
+ this.properties.put("net.interface.wlp2s0.config.wifi.infra.radioMode", "RADIO_MODE_80211b");
+ this.properties.put("net.interface.wlp2s0.config.ip4.dnsServers", "");
+ this.properties.put("net.interface.wlp2s0.config.wifi.infra.pairwiseCiphers", "CCMP_TKIP");
+ this.properties.put("net.interface.wlp2s0.config.ip4.prefix", 24);
+ this.properties.put("net.interface.wlp2s0.config.802-1x.eap", "Kura8021xEapTls");
+ this.properties.put("net.interface.wlp2s0.config.802-1x.keystore.pid", "WifiKeystore");
+ this.properties.put("net.interface.wlp2s0.config.802-1x.ca-cert-name", "caCert");
+ this.properties.put("net.interface.wlp2s0.config.802-1x.client-cert-name", "privatekey");
+ this.properties.put("net.interface.wlp2s0.config.802-1x.private-key-name", "privatekey");
+ }
+
+ private void givenEnterpriseWifiKeystore() {
+
+ try {
+ TrustedCertificateEntry trustedCertificateEntry = mock(TrustedCertificateEntry.class);
+ Certificate certificate = mock(Certificate.class);
+
+ PrivateKeyEntry privateKeyEntry = mock(PrivateKeyEntry.class);
+ Certificate privateKeyCertificate = mock(Certificate.class);
+ PrivateKey privateKey = mock(PrivateKey.class);
+
+ when(trustedCertificateEntry.getTrustedCertificate()).thenReturn(certificate);
+ when(privateKeyEntry.getCertificate()).thenReturn(privateKeyCertificate);
+ when(privateKeyEntry.getPrivateKey()).thenReturn(privateKey);
+
+ when(certificate.getEncoded()).thenReturn("ca-certificate".getBytes());
+ when(privateKeyCertificate.getEncoded()).thenReturn("certificate-key".getBytes());
+ when(privateKey.getEncoded()).thenReturn("privatekey".getBytes());
+
+ this.keystoreService = mock(KeystoreService.class);
+
+ when(this.keystoreService.getEntry("caCert")).thenReturn(trustedCertificateEntry);
+ when(this.keystoreService.getEntry("privatekey")).thenReturn(privateKeyEntry);
+
+ Map propertiesMap = new HashMap<>();
+ propertiesMap.put(ConfigurationService.KURA_SERVICE_PID, "WifiKeystore");
+
+ this.networkConfigurationService.setKeystoreService(keystoreService, propertiesMap);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+
+ }
+
private void givenPropertiesWithPppInterfaceNames() {
this.properties.clear();
this.properties.put("net.interfaces", "enp5s0,lo,eno1,wlp1s0,ppp3");
@@ -792,6 +899,55 @@ private void thenComponentDefinitionHasCorrectProperties() {
assertEquals(40, adsConfigured);
}
+ private void thenComponentDefinitionHasCorrectEnterpriseProperties() {
+ int adsConfigured = 0;
+ for (AD ad : this.ads) {
+
+ if ("net.interfaces".equals(ad.getId())) {
+ assertEquals("net.interfaces", ad.getName());
+ assertEquals("STRING", ad.getType().name());
+ assertTrue(ad.isRequired());
+ adsConfigured++;
+ }
+
+ if ("net.interface.wlp2s0.config.802-1x.eap".equals(ad.getId())) {
+ assertEquals("net.interface.wlp2s0.config.802-1x.eap", ad.getName());
+ assertEquals("STRING", ad.getType().name());
+ assertFalse(ad.isRequired());
+ adsConfigured++;
+ }
+
+ if ("net.interface.wlp2s0.config.802-1x.keystore.pid".equals(ad.getId())) {
+ assertEquals("net.interface.wlp2s0.config.802-1x.keystore.pid", ad.getName());
+ assertEquals("STRING", ad.getType().name());
+ assertFalse(ad.isRequired());
+ adsConfigured++;
+ }
+
+ if ("net.interface.wlp2s0.config.802-1x.ca-cert-name".equals(ad.getId())) {
+ assertEquals("net.interface.wlp2s0.config.802-1x.ca-cert-name", ad.getName());
+ assertEquals("STRING", ad.getType().name());
+ assertFalse(ad.isRequired());
+ adsConfigured++;
+ }
+
+ if ("net.interface.wlp2s0.config.802-1x.client-cert-name".equals(ad.getId())) {
+ assertEquals("net.interface.wlp2s0.config.802-1x.client-cert-name", ad.getName());
+ assertEquals("STRING", ad.getType().name());
+ assertFalse(ad.isRequired());
+ adsConfigured++;
+ }
+
+ if ("net.interface.wlp2s0.config.802-1x.private-key-name".equals(ad.getId())) {
+ assertEquals("net.interface.wlp2s0.config.802-1x.private-key-name", ad.getName());
+ assertEquals("STRING", ad.getType().name());
+ assertFalse(ad.isRequired());
+ adsConfigured++;
+ }
+ }
+ assertEquals(5, adsConfigured);
+ }
+
private void thenPropertiesNumberIsCorrect() {
assertEquals(33, this.event.getPropertyNames().length);
}
diff --git a/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/configuration/NMSettingsConverterTest.java b/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/configuration/NMSettingsConverterTest.java
index 8f2b4aa050..28e4d4d8db 100644
--- a/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/configuration/NMSettingsConverterTest.java
+++ b/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/configuration/NMSettingsConverterTest.java
@@ -16,8 +16,14 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.nio.charset.StandardCharsets;
+import java.security.PrivateKey;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateEncodingException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -504,7 +510,8 @@ public void build8021xSettingsShouldWorkWithTtlsAndMschapV2AndOptionalParams() {
givenMapWith("net.interface.wlan0.config.802-1x.eap", "Kura8021xEapTtls");
givenMapWith("net.interface.wlan0.config.802-1x.innerAuth", "Kura8021xInnerAuthMschapv2");
givenMapWith("net.interface.wlan0.config.802-1x.anonymous-identity", "anonymous-identity-test-var");
- givenMapWith("net.interface.wlan0.config.802-1x.ca-cert", "binary ca cert");
+ givenMapWith("net.interface.wlan0.config.802-1x.ca-cert-name",
+ buildMockedCertificateWithCert("binary ca cert"));
givenMapWith("net.interface.wlan0.config.802-1x.ca-cert-password", new Password("secure-password"));
givenMapWith("net.interface.wlan0.config.802-1x.identity", "example-user-name");
givenMapWith("net.interface.wlan0.config.802-1x.password", new Password("secure-test-password-123!@#"));
@@ -549,7 +556,8 @@ public void build8021xSettingsShouldWorkWithPeapAndMschapV2() {
public void build8021xSettingsShouldWorkWithPeapAndMschapV2AndCertificates() {
givenMapWith("net.interface.wlan0.config.802-1x.eap", "Kura8021xEapPeap");
givenMapWith("net.interface.wlan0.config.802-1x.anonymous-identity", "anonymous-identity-test-var");
- givenMapWith("net.interface.wlan0.config.802-1x.ca-cert", "binary ca cert");
+ givenMapWith("net.interface.wlan0.config.802-1x.ca-cert-name",
+ buildMockedCertificateWithCert("binary ca cert"));
givenMapWith("net.interface.wlan0.config.802-1x.ca-cert-password", new Password("secure-password"));
givenMapWith("net.interface.wlan0.config.802-1x.innerAuth", "Kura8021xInnerAuthMschapv2");
givenMapWith("net.interface.wlan0.config.802-1x.identity", "example-user-name");
@@ -583,9 +591,12 @@ public void build8021xSettingsShouldWorkWithTls() {
givenMapWith("net.interface.wlan0.config.802-1x.eap", "Kura8021xEapTls");
givenMapWith("net.interface.wlan0.config.802-1x.innerAuth", "Kura8021xInnerAuthNone");
givenMapWith("net.interface.wlan0.config.802-1x.identity", "username@email.com");
- givenMapWith("net.interface.wlan0.config.802-1x.ca-cert", "binary ca cert");
- givenMapWith("net.interface.wlan0.config.802-1x.client-cert", "binary client cert");
- givenMapWith("net.interface.wlan0.config.802-1x.private-key", "binary private key");
+ givenMapWith("net.interface.wlan0.config.802-1x.ca-cert-name",
+ buildMockedCertificateWithCert("binary ca cert"));
+ givenMapWith("net.interface.wlan0.config.802-1x.client-cert-name",
+ buildMockedCertificateWithCert("binary client cert"));
+ givenMapWith("net.interface.wlan0.config.802-1x.private-key-name",
+ buildMockedPrivateKeyWithKey("binary private key"));
givenMapWith("net.interface.wlan0.config.802-1x.private-key-password", new Password("secure-password"));
givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap);
@@ -1099,7 +1110,7 @@ public void buildPPPSettingsShouldThrowWithUnsupportedAuthType() {
thenIllegalArgumentExceptionThrown();
}
-
+
@Test
public void buildVlanSettingsShouldWorkWithRequiredSettings() {
givenMapWith("net.interface.eth0.30.config.vlan.parent", "eth0");
@@ -1115,7 +1126,7 @@ public void buildVlanSettingsShouldWorkWithRequiredSettings() {
thenResultingMapContains("ingress-priority-map", new Variant<>(Arrays.asList(), "as").getValue());
thenResultingMapContains("egress-priority-map", new Variant<>(Arrays.asList(), "as").getValue());
}
-
+
@Test
public void buildVlanSettingsShouldWorkWithFullSettings() {
givenMapWith("net.interface.eth1.40.config.vlan.parent", "eth1");
@@ -1132,29 +1143,27 @@ public void buildVlanSettingsShouldWorkWithFullSettings() {
thenResultingMapContains("parent", "eth1");
thenResultingMapContains("id", new UInt32(40));
thenResultingMapContains("flags", new UInt32(3));
- thenResultingMapContains("ingress-priority-map", new Variant<>(
- Arrays.asList("0:1", "4:5"), "as").getValue());
- thenResultingMapContains("egress-priority-map", new Variant<>(
- Arrays.asList("2:3"), "as").getValue());
+ thenResultingMapContains("ingress-priority-map", new Variant<>(Arrays.asList("0:1", "4:5"), "as").getValue());
+ thenResultingMapContains("egress-priority-map", new Variant<>(Arrays.asList("2:3"), "as").getValue());
}
-
+
@Test
public void buildVlanSettingsShouldThrowWhenMissingParent() {
givenMapWith("net.interface.eth0.30.config.vlan.id", 30);
givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap);
whenBuildVlanSettingsIsRunWith(this.networkProperties, "eth0.30");
-
+
thenNoSuchElementExceptionThrown();
}
-
+
@Test
public void buildVlanSettingsShouldThrowWhenMissingVlanId() {
givenMapWith("net.interface.eth0.30.config.vlan.parent", "eth0");
givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap);
whenBuildVlanSettingsIsRunWith(this.networkProperties, "eth0.30");
-
+
thenNoSuchElementExceptionThrown();
}
@@ -1182,7 +1191,7 @@ public void buildConnectionSettingsShouldWorkWithUnsupported() {
thenIllegalArgumentExceptionThrown();
}
-
+
@Test
public void buildConnectionSettingsShouldWorkWithVlan() {
whenBuildConnectionSettings(Optional.empty(), "eth0.40", NMDeviceType.NM_DEVICE_TYPE_VLAN);
@@ -1288,7 +1297,8 @@ public void buildSettingsShouldWorkWith8021x() {
givenMapWith("net.interface.wlan0.config.802-1x.eap", "Kura8021xEapTtls");
givenMapWith("net.interface.wlan0.config.802-1x.innerAuth", "Kura8021xInnerAuthMschapv2");
givenMapWith("net.interface.wlan0.config.802-1x.anonymous-identity", "anonymous-identity-test-var");
- givenMapWith("net.interface.wlan0.config.802-1x.ca-cert", "binary ca cert");
+ givenMapWith("net.interface.wlan0.config.802-1x.ca-cert-name",
+ buildMockedCertificateWithCert("binary ca cert"));
givenMapWith("net.interface.wlan0.config.802-1x.ca-cert-password", new Password("secure-password"));
givenMapWith("net.interface.wlan0.config.802-1x.identity", "example-user-name");
givenMapWith("net.interface.wlan0.config.802-1x.password", new Password("secure-test-password-123!@#"));
@@ -1556,7 +1566,7 @@ public void buildSettingsShouldWorkWithExpectedInputsEthernetAndWanIp4() {
thenResultingBuildAllMapContains("connection", "interface-name", "eth0");
thenResultingBuildAllMapContains("connection", "type", "802-3-ethernet");
}
-
+
@Test
public void buildSettingsShouldWorkWithExpectedInputsVlanAndWanIp4() {
givenMapWith("net.interface.myVlan.config.dhcpClient4.enabled", false);
@@ -1589,10 +1599,10 @@ public void buildSettingsShouldWorkWithExpectedInputsVlanAndWanIp4() {
thenResultingBuildAllMapContains("vlan", "parent", "eth0");
thenResultingBuildAllMapContains("vlan", "id", new UInt32(55));
thenResultingBuildAllMapContains("vlan", "flags", new UInt32(2));
- thenResultingBuildAllMapContains("vlan", "ingress-priority-map", new Variant<>(
- Arrays.asList(), "as").getValue());
- thenResultingBuildAllMapContains("vlan", "egress-priority-map", new Variant<>(
- Arrays.asList("2:3"), "as").getValue());
+ thenResultingBuildAllMapContains("vlan", "ingress-priority-map",
+ new Variant<>(Arrays.asList(), "as").getValue());
+ thenResultingBuildAllMapContains("vlan", "egress-priority-map",
+ new Variant<>(Arrays.asList("2:3"), "as").getValue());
}
@Test
@@ -2845,6 +2855,11 @@ public void givenMockConnection() {
}
+ public void givenMockConnectionWithNullSettings() {
+ this.mockedConnection = Mockito.mock(Connection.class);
+ Mockito.when(this.mockedConnection.GetSettings()).thenReturn(null);
+ }
+
/*
* When
*/
@@ -2958,7 +2973,7 @@ private void whenBuildPPPSettingsIsRunWith(NetworkProperties props, String iface
this.hasAGenericExecptionBeenThrown = true;
}
}
-
+
private void whenBuildVlanSettingsIsRunWith(NetworkProperties props, String iface) {
try {
this.resultMap = NMSettingsConverter.buildVlanSettings(props, iface);
@@ -3043,4 +3058,22 @@ public Object buildAddressDataWith(String ipAddr, UInt32 prefix) {
return dataVariant.getValue();
}
+
+ public Certificate buildMockedCertificateWithCert(String certBytes) {
+ Certificate cert = mock(Certificate.class);
+ try {
+ when(cert.getEncoded()).thenReturn(certBytes.getBytes());
+ } catch (CertificateEncodingException e) {
+ fail();
+ }
+
+ return cert;
+ }
+
+ public PrivateKey buildMockedPrivateKeyWithKey(String keyBytes) {
+ PrivateKey key = mock(PrivateKey.class);
+ when(key.getEncoded()).thenReturn(keyBytes.getBytes());
+
+ return key;
+ }
}