Skip to content

Commit f881dde

Browse files
fix: added catch to exception to prevent failure when keystores don't exist [backport release-5.4.0] (#5031)
fix: added catch to exception to prevent failure when keystores don't exist (#5029) * fix: added catch to exception so when keystores do not exist status does not fail * fix: error throwing for private key * fix: changed logged message when private key does not exist (cherry picked from commit 5d58715) Co-authored-by: G_Ivo <[email protected]>
1 parent 564a513 commit f881dde

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/configuration/NMSettingsConverter.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,21 @@ private static void create8021xTls(NetworkProperties props, String deviceId, Map
190190
deviceId);
191191
settings.put("client-cert", new Variant<>(clientCert.getEncoded()));
192192
} catch (CertificateEncodingException e) {
193-
logger.error("Unable to find or decode Client Certificate");
193+
logger.error("Unable to decode Client Certificate");
194+
} catch (ClassCastException e) {
195+
logger.error("Unable to find Client Certificate");
194196
}
195197

196-
PrivateKey privateKey = props.get(PrivateKey.class, "net.interface.%s.config.802-1x.private-key-name",
197-
deviceId);
198-
199-
if (privateKey.getEncoded() != null) {
200-
settings.put("private-key", new Variant<>(privateKey.getEncoded()));
201-
} else {
202-
logger.error("Unable to find or decode Private Key");
198+
try {
199+
PrivateKey privateKey = props.get(PrivateKey.class, "net.interface.%s.config.802-1x.private-key-name",
200+
deviceId);
201+
if (privateKey.getEncoded() != null) {
202+
settings.put("private-key", new Variant<>(privateKey.getEncoded()));
203+
} else {
204+
logger.error("Unable to find or decode Private Key");
205+
}
206+
} catch (ClassCastException e) {
207+
logger.error("Unable to find Private Key");
203208
}
204209

205210
Optional<Password> privateKeyPassword = props.getOpt(Password.class,
@@ -306,7 +311,7 @@ public static Map<String, Variant<?>> buildIpv4Settings(NetworkProperties props,
306311
return settings;
307312
}
308313

309-
public static Map<String, Variant<?>> buildIpv6Settings(NetworkProperties props, String deviceId,
314+
public static Map<String, Variant<?>> buildIpv6Settings(NetworkProperties props, String deviceId,
310315
SemanticVersion nmVersion) {
311316

312317
// buildIpv6Settings doesn't support Unmanaged status. Therefore if ip6.status
@@ -404,9 +409,9 @@ public static Map<String, Variant<?>> buildIpv6Settings(NetworkProperties props,
404409
logger.warn("Unexpected ip status received: \"{}\". Ignoring", ip6Status);
405410
}
406411

407-
Optional<Integer> mtu = props.getOpt(Integer.class, "net.interface.%s.config.ip6.mtu", deviceId);
412+
Optional<Integer> mtu = props.getOpt(Integer.class, "net.interface.%s.config.ip6.mtu", deviceId);
408413
if (nmVersion.isGreaterEqualThan("1.40")) {
409-
//ipv6.mtu only supported in NetworkManager 1.40 and above
414+
// ipv6.mtu only supported in NetworkManager 1.40 and above
410415
mtu.ifPresent(value -> settings.put("mtu", new Variant<>(new UInt32(value))));
411416
} else {
412417
logger.warn("Ignoring parameter ipv6.mtu: NetworkManager 1.40 or above is required");
@@ -440,7 +445,7 @@ public static Map<String, Variant<?>> build80211WirelessSettings(NetworkProperti
440445

441446
Optional<Integer> mtu = props.getOpt(Integer.class, KURA_PROPS_IPV4_MTU, deviceId);
442447
mtu.ifPresent(value -> settings.put("mtu", new Variant<>(new UInt32(value))));
443-
448+
444449
return settings;
445450
}
446451

@@ -536,7 +541,7 @@ public static Map<String, Variant<?>> buildGsmSettings(NetworkProperties props,
536541

537542
Optional<Integer> mtu = props.getOpt(Integer.class, KURA_PROPS_IPV4_MTU, deviceId);
538543
mtu.ifPresent(value -> settings.put("mtu", new Variant<>(new UInt32(value))));
539-
544+
540545
return settings;
541546
}
542547

@@ -572,12 +577,12 @@ public static Map<String, Variant<?>> buildVlanSettings(NetworkProperties props,
572577
settings.put("egress-priority-map", new Variant<>(egressMap.orElse(new ArrayList<>()), listType));
573578
return settings;
574579
}
575-
580+
576581
public static Map<String, Variant<?>> buildEthernetSettings(NetworkProperties props, String deviceId) {
577582
Map<String, Variant<?>> settings = new HashMap<>();
578583
Optional<Integer> mtu = props.getOpt(Integer.class, KURA_PROPS_IPV4_MTU, deviceId);
579584
mtu.ifPresent(value -> settings.put("mtu", new Variant<>(new UInt32(value))));
580-
return settings;
585+
return settings;
581586
}
582587

583588
public static Map<String, Variant<?>> buildConnectionSettings(Optional<Connection> connection, String iface,

0 commit comments

Comments
 (0)