diff options
Diffstat (limited to 'cmso-optimizer')
3 files changed, 19 insertions, 13 deletions
diff --git a/cmso-optimizer/pom.xml b/cmso-optimizer/pom.xml index 32a5546..1cca4ad 100644 --- a/cmso-optimizer/pom.xml +++ b/cmso-optimizer/pom.xml @@ -19,7 +19,7 @@ <parent> <groupId>org.onap.optf.cmso</groupId> <artifactId>cmso</artifactId> - <version>2.3.1-SNAPSHOT</version> + <version>2.3.2-SNAPSHOT</version> </parent> <groupId>org.onap.optf.cmso.optimizer</groupId> diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/common/PropertiesManagement.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/common/PropertiesManagement.java index 12da757..6bf0ee8 100644 --- a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/common/PropertiesManagement.java +++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/common/PropertiesManagement.java @@ -35,7 +35,7 @@ import javax.crypto.spec.SecretKeySpec; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; - +import java.security.SecureRandom; /** * The Class PropertiesManagement. */ @@ -47,14 +47,15 @@ public class PropertiesManagement { private static final String algorithm = "AES"; - private static final String cipherMode = "CBC"; + private static final String cipherMode = "GCM"; - private static final String paddingScheme = "PKCS5Padding"; + private static final String paddingScheme = "NoPadding"; private static final String transformation = algorithm + "/" + cipherMode + "/" + paddingScheme; - private static final String initVector = "ONAPCMSOVECTORIV"; // 16 bytes IV - + private static final SecureRandom random = new SecureRandom(); + + @Autowired Environment env; @@ -80,7 +81,7 @@ public class PropertiesManagement { public static String getDecryptedValue(String value) { if (value.startsWith("enc:")) { String secret = getSecret(); - value = decrypt(secret, initVector, value.substring(4)); + value = decrypt(secret, value.substring(4)); } return value; } @@ -93,13 +94,16 @@ public class PropertiesManagement { */ public static String getEncryptedValue(String value) { String secret = getSecret(); - value = encrypt(secret, initVector, value); + value = encrypt(secret, value); return value; } - private static final String encrypt(String key, String initVector, String value) { + private static final String encrypt(String key, String value) { try { - IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8")); + + byte[] bytesIV = new byte[16]; + random.nextBytes(bytesIV); + IvParameterSpec iv = new IvParameterSpec(bytesIV); SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); Cipher cipher = Cipher.getInstance(transformation); cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); @@ -113,9 +117,11 @@ public class PropertiesManagement { return null; } - private static final String decrypt(String key, String initVector, String encrypted) { + private static final String decrypt(String key, String encrypted) { try { - IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8")); + byte[] bytesIV = new byte[16]; + random.nextBytes(bytesIV); + IvParameterSpec iv = new IvParameterSpec(bytesIV); SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES"); Cipher cipher = Cipher.getInstance(transformation); cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv); diff --git a/cmso-optimizer/src/main/resources/META-INF/resources/swagger/swagger.json b/cmso-optimizer/src/main/resources/META-INF/resources/swagger/swagger.json index cdac14e..f260bb1 100644 --- a/cmso-optimizer/src/main/resources/META-INF/resources/swagger/swagger.json +++ b/cmso-optimizer/src/main/resources/META-INF/resources/swagger/swagger.json @@ -1,7 +1,7 @@ { "swagger" : "2.0", "info" : { - "version" : "2.3.0-SNAPSHOT", + "version" : "2.3.1-SNAPSHOT", "title" : "cmso-optimizer" }, "basePath" : "/optimizer", |