Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix double encryption of values
  • Loading branch information
BryanMLima committed Sep 19, 2023
commit 4e2868310749f42f9f46b3dc8de068438e344778
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public ConfigurationResponse setResponseValue(ConfigurationResponse response, Co
if (cfg.isEncrypted()) {
response.setValue(DBEncryptionUtil.encrypt(getValue()));
} else {
response.setValue(cfg.getValue());
response.setValue(getValue());
}
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import javax.naming.ConfigurationException;


import com.cloud.utils.crypt.DBEncryptionUtil;
import com.cloud.hypervisor.HypervisorGuru;
import org.apache.cloudstack.acl.SecurityChecker;
import org.apache.cloudstack.affinity.AffinityGroup;
Expand Down Expand Up @@ -884,6 +883,7 @@ private void updateCustomDisplayNameOnHypervisorsList(String previousValue, Stri
public Configuration updateConfiguration(final UpdateCfgCmd cmd) throws InvalidParameterValueException {
final Long userId = CallContext.current().getCallingUserId();
final String name = cmd.getCfgName();
String value = cmd.getValue();
final Long zoneId = cmd.getZoneId();
final Long clusterId = cmd.getClusterId();
final Long storagepoolId = cmd.getStoragepoolId();
Expand All @@ -893,6 +893,8 @@ public Configuration updateConfiguration(final UpdateCfgCmd cmd) throws InvalidP
// check if config value exists
final ConfigurationVO config = _configDao.findByName(name);
String category = null;
String eventValue = encryptEventValueIfConfigIsEncrypted(config, value);
CallContext.current().setEventDetails(String.format(" Name: %s New Value: %s", name, eventValue));

final Account caller = CallContext.current().getCallingAccount();
if (_accountMgr.isDomainAdmin(caller.getId())) {
Expand All @@ -916,15 +918,6 @@ public Configuration updateConfiguration(final UpdateCfgCmd cmd) throws InvalidP
category = config.getCategory();
}

String value = cmd.getValue();
boolean isConfigEncrypted = config != null && config.isEncrypted();
if (isConfigEncrypted) {
value = DBEncryptionUtil.encrypt(value);
}

String eventValue = isConfigEncrypted ? "*****" : Objects.requireNonNullElse(value, "");
CallContext.current().setEventDetails(String.format(" Name: %s New Value: %s", name, eventValue));

validateIpAddressRelatedConfigValues(name, value);

if (value == null) {
Expand Down Expand Up @@ -987,6 +980,13 @@ public Configuration updateConfiguration(final UpdateCfgCmd cmd) throws InvalidP
}
}

private String encryptEventValueIfConfigIsEncrypted(ConfigurationVO config, String value) {
if (config != null && config.isEncrypted()) {
return "*****";
}
return Objects.requireNonNullElse(value, "");
}

private ParamCountPair getParamCount(Map<String, Long> scopeMap) {
Long id = null;
int paramCount = 0;
Expand Down