Skip to content

Commit

Permalink
refactor: created a hard copy of the modifiedMap so it is not passed …
Browse files Browse the repository at this point in the history
…to the configuration service and applied
  • Loading branch information
GregoryIvo authored and MMaiero committed Oct 10, 2023
1 parent 04b4ce4 commit 4465939
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,10 @@ public synchronized void update(Map<String, Object> receivedProperties) {

mergeNetworkConfigurationProperties(modifiedProps, this.networkProperties.getProperties());

this.networkProperties = new NetworkProperties(discardModifiedNetworkInterfaces(new HashMap<>(modifiedProps)));

decryptAndConvertPasswordProperties(modifiedProps);
decryptAndConvertCertificatesProperties(modifiedProps, interfaces);
this.networkProperties = new NetworkProperties(discardModifiedNetworkInterfaces(modifiedProps));

writeNetworkConfigurationSettings(modifiedProps);
writeFirewallNatRules(interfaces, modifiedProps);
Expand Down Expand Up @@ -353,9 +354,9 @@ private void findAndDecodeCertificatesForInterface(String interfaceName, Map<Str
try {
String valueString = value.toString();
if (isCertificate(key)) {
modifiedProps.put(key, decryptCertificate(valueString, keystoreService));
modifiedProps.put(key, getTrustedCertificateFromKeystore(valueString, keystoreService));
} else {
modifiedProps.put(key, decryptPrivateKey(valueString, keystoreService));
modifiedProps.put(key, getTrustedPrivateKeyFromKeystore(valueString, keystoreService));
}
} catch (KuraException e) {
logger.error("Unable to decode key/certificate {} from keystore.", key, e);
Expand All @@ -368,7 +369,7 @@ private boolean isCertificate(String key) {
return key.contains("cert");
}

private Certificate decryptCertificate(String certificateName, KeystoreService keystoreService)
private Certificate getTrustedCertificateFromKeystore(String certificateName, KeystoreService keystoreService)
throws KuraException {
if (keystoreService.getEntry(certificateName) instanceof TrustedCertificateEntry) {
TrustedCertificateEntry cert = (TrustedCertificateEntry) keystoreService.getEntry(certificateName);
Expand All @@ -382,7 +383,7 @@ private Certificate decryptCertificate(String certificateName, KeystoreService k
}
}

private PrivateKey decryptPrivateKey(String privateKeyName, KeystoreService keystoreService) throws KuraException {
private PrivateKey getTrustedPrivateKeyFromKeystore(String privateKeyName, KeystoreService keystoreService) throws KuraException {
PrivateKeyEntry key = (PrivateKeyEntry) keystoreService.getEntry(privateKeyName);

return key.getPrivateKey();
Expand Down

0 comments on commit 4465939

Please sign in to comment.