summaryrefslogtreecommitdiffstats
path: root/common/src/main/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main/java/org/onap')
-rw-r--r--common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java6
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java8
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/uri/parsers/UriParserSpringImpl.java6
-rw-r--r--common/src/main/java/org/onap/so/constants/Defaults.java4
-rw-r--r--common/src/main/java/org/onap/so/serviceinstancebeans/RequestParameters.java3
-rw-r--r--common/src/main/java/org/onap/so/utils/CryptoUtils.java66
6 files changed, 42 insertions, 51 deletions
diff --git a/common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java b/common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java
index 45621f09a6..77ea9bcdfe 100644
--- a/common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java
+++ b/common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java
@@ -26,9 +26,11 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
-import org.apache.log4j.Logger;
+
import org.onap.so.client.aai.AAICommonObjectMapperProvider;
import org.onap.so.jsonpath.JsonPathUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
@@ -39,7 +41,7 @@ public class AAIResultWrapper implements Serializable {
private static final long serialVersionUID = 5895841925807816737L;
private final String jsonBody;
private final ObjectMapper mapper;
- private final transient Logger logger = Logger.getLogger(AAIResultWrapper.class);
+ private final transient Logger logger = LoggerFactory.getLogger(AAIResultWrapper.class);
public AAIResultWrapper(String json) {
this.jsonBody = json;
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java
index 874b06e192..2876f77d82 100644
--- a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java
+++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/SimpleUri.java
@@ -158,12 +158,8 @@ public class SimpleUri implements GraphInventoryResourceUri, Serializable {
protected URI build(Object... values) {
//This is a workaround because resteasy does not encode URIs correctly
final String[] encoded = new String[values.length];
- for (int i = 0; i < values.length; i++) {
- try {
- encoded[i] = UriUtils.encode(values[i].toString(), StandardCharsets.UTF_8.toString());
- } catch (UnsupportedEncodingException e) {
- encoded[i] = values[i].toString();
- }
+ for (int i = 0; i < values.length; i++) {
+ encoded[i] = UriUtils.encode(values[i].toString(), StandardCharsets.UTF_8.toString());
}
return internalURI.buildFromEncoded(encoded);
}
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/parsers/UriParserSpringImpl.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/parsers/UriParserSpringImpl.java
index aeaa923d1b..b4cf8eb949 100644
--- a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/parsers/UriParserSpringImpl.java
+++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/parsers/UriParserSpringImpl.java
@@ -56,11 +56,7 @@ public class UriParserSpringImpl implements UriParser {
final Map<String, String> result = new LinkedHashMap<>();
for (Entry<String, String> entry : map.entrySet()) {
- try {
- result.put(entry.getKey(), UriUtils.decode(entry.getValue(), "UTF-8"));
- } catch (UnsupportedEncodingException e) {
- result.put(entry.getKey(), "");
- }
+ result.put(entry.getKey(), UriUtils.decode(entry.getValue(), "UTF-8"));
}
return result;
diff --git a/common/src/main/java/org/onap/so/constants/Defaults.java b/common/src/main/java/org/onap/so/constants/Defaults.java
index 13a378eadb..0dc084a899 100644
--- a/common/src/main/java/org/onap/so/constants/Defaults.java
+++ b/common/src/main/java/org/onap/so/constants/Defaults.java
@@ -31,7 +31,7 @@ public enum Defaults {
private final String propName;
private final String defaultValue;
-
+
private Defaults(String propName, String defaultValue) {
this.defaultValue = defaultValue;
this.propName = propName;
@@ -51,4 +51,4 @@ public enum Defaults {
protected Optional<ApplicationContext> getAppContext() {
return Optional.ofNullable(SpringContextHelper.getAppContext());
}
-}
+} \ No newline at end of file
diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/RequestParameters.java b/common/src/main/java/org/onap/so/serviceinstancebeans/RequestParameters.java
index 87cb481dec..4dfa1d4130 100644
--- a/common/src/main/java/org/onap/so/serviceinstancebeans/RequestParameters.java
+++ b/common/src/main/java/org/onap/so/serviceinstancebeans/RequestParameters.java
@@ -20,13 +20,12 @@
package org.onap.so.serviceinstancebeans;
+import java.beans.Transient;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import javax.persistence.Transient;
-
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
diff --git a/common/src/main/java/org/onap/so/utils/CryptoUtils.java b/common/src/main/java/org/onap/so/utils/CryptoUtils.java
index 11d464a85c..c35ced531d 100644
--- a/common/src/main/java/org/onap/so/utils/CryptoUtils.java
+++ b/common/src/main/java/org/onap/so/utils/CryptoUtils.java
@@ -21,15 +21,15 @@
package org.onap.so.utils;
-
-import java.security.GeneralSecurityException;
-import java.security.NoSuchAlgorithmException;
+import org.onap.so.logger.MessageEnum;
+import org.onap.so.logger.MsoLogger;
import javax.crypto.Cipher;
+import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
-
-import org.onap.so.logger.MessageEnum;
-import org.onap.so.logger.MsoLogger;
+import java.security.GeneralSecurityException;
+import java.security.SecureRandom;
+import java.util.Arrays;
/**
@@ -40,8 +40,12 @@ public final class CryptoUtils {
private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA, CryptoUtils.class);
- public static final String AES = "AES";
+ private static final String AES = "AES";
private static final String CLOUD_KEY = "aa3871669d893c7fb8abbcda31b88b4f";
+ private static final int GCM_TAG_LENGTH = 16;
+ private static final int GCM_IV_LENGTH = 12;
+ private static final String AES_GCM_NO_PADDING = "AES/GCM/NoPadding";
+
/**
* encrypt a value and generate a keyfile
* if the keyfile is not found then a new one is created
@@ -50,10 +54,16 @@ public final class CryptoUtils {
*/
public static String encrypt (String value, String keyString) throws GeneralSecurityException {
SecretKeySpec sks = getSecretKeySpec (keyString);
- Cipher cipher = Cipher.getInstance (CryptoUtils.AES);
- cipher.init (Cipher.ENCRYPT_MODE, sks, cipher.getParameters ());
- byte[] encrypted = cipher.doFinal (value.getBytes ());
- return byteArrayToHexString (encrypted);
+ Cipher cipher = Cipher.getInstance(AES_GCM_NO_PADDING);
+ byte[] initVector = new byte[GCM_IV_LENGTH];
+ (new SecureRandom()).nextBytes(initVector);
+ GCMParameterSpec spec = new GCMParameterSpec(GCM_TAG_LENGTH * java.lang.Byte.SIZE, initVector);
+ cipher.init(Cipher.ENCRYPT_MODE, sks, spec);
+ byte[] encoded = value.getBytes(java.nio.charset.StandardCharsets.UTF_8);
+ byte[] cipherText = new byte[initVector.length + cipher.getOutputSize(encoded.length)];
+ System.arraycopy(initVector, 0, cipherText, 0, initVector.length);
+ cipher.doFinal(encoded, 0, encoded.length, cipherText, initVector.length);
+ return byteArrayToHexString(cipherText);
}
/**
@@ -63,29 +73,18 @@ public final class CryptoUtils {
*/
public static String decrypt (String message, String keyString) throws GeneralSecurityException {
SecretKeySpec sks = getSecretKeySpec (keyString);
- Cipher cipher = Cipher.getInstance (CryptoUtils.AES);
- cipher.init (Cipher.DECRYPT_MODE, sks);
- byte[] decrypted = cipher.doFinal (hexStringToByteArray (message));
- return new String (decrypted);
+ byte[] cipherText = hexStringToByteArray(message);
+ Cipher cipher = Cipher.getInstance(AES_GCM_NO_PADDING);
+ byte[] initVector = Arrays.copyOfRange(cipherText, 0, GCM_IV_LENGTH);
+ GCMParameterSpec spec = new GCMParameterSpec(GCM_TAG_LENGTH * java.lang.Byte.SIZE, initVector);
+ cipher.init(Cipher.DECRYPT_MODE, sks, spec);
+ byte[] plaintext = cipher.doFinal(cipherText, GCM_IV_LENGTH, cipherText.length - GCM_IV_LENGTH);
+ return new String(plaintext);
}
-
- /**
- * decrypt a value or return defaultValue
- *
- */
- public static String decryptProperty (String prop, String defaultValue, String encryptionKey) {
- try {
- return CryptoUtils.decrypt(prop, encryptionKey);
- }
- catch (GeneralSecurityException e) {
- LOGGER.debug("Security exception", e);
- }
- return defaultValue;
- }
public static String encryptCloudConfigPassword(String message) {
try {
- return CryptoUtils.encrypt(message, CryptoUtils.CLOUD_KEY);
+ return CryptoUtils.encrypt(message, CLOUD_KEY);
} catch (GeneralSecurityException e) {
LOGGER.error (MessageEnum.RA_GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in encryptPassword", e);
return null;
@@ -93,16 +92,15 @@ public final class CryptoUtils {
}
public static String decryptCloudConfigPassword(String message) {
try {
- return CryptoUtils.decrypt(message, CryptoUtils.CLOUD_KEY);
+ return CryptoUtils.decrypt(message, CLOUD_KEY);
} catch (GeneralSecurityException e) {
LOGGER.error (MessageEnum.RA_GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in encryptPassword", e);
return null;
}
}
- private static SecretKeySpec getSecretKeySpec (String keyString) throws NoSuchAlgorithmException {
+ private static SecretKeySpec getSecretKeySpec (String keyString) {
byte[] key = hexStringToByteArray (keyString);
- SecretKeySpec sks = new SecretKeySpec (key, CryptoUtils.AES);
- return sks;
+ return new SecretKeySpec (key, AES);
}
public static String byteArrayToHexString (byte[] b) {