Fix weak cryptography issues 75/119475/2
authormalarvizhi <malarvizhi.44@wipro.com>
Thu, 18 Mar 2021 07:40:11 +0000 (00:40 -0700)
committerkrishna moorthy <krishna.moorthy6@wipro.com>
Thu, 18 Mar 2021 08:25:55 +0000 (08:25 +0000)
Issue-ID: OPTFRA-927
Signed-off-by: Malarvizhi Paramasivam <malarvizhi.44@wipro.com>
Change-Id: I9e48f7313a7f76bd431e17cebfc3c52bc7f91bda

cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/common/PropertiesManagement.java
cmso-optimizer/src/main/resources/META-INF/resources/swagger/swagger.json
cmso-optimizer/src/test/java/org/onap/optf/cmso/utilities/PropertiesAdmin.java
cmso-service/src/main/java/org/onap/optf/cmso/common/PropertiesManagement.java
cmso-service/src/main/resources/META-INF/resources/swagger/swagger.json
cmso-ticketmgt/src/main/java/org/onap/optf/cmso/common/PropertiesManagement.java
cmso-ticketmgt/src/main/resources/META-INF/resources/swagger/swagger.json
cmso-topology/src/main/java/org/onap/optf/cmso/common/PropertiesManagement.java
cmso-topology/src/main/resources/META-INF/resources/swagger/swagger.json

index 6bf0ee8..a638d99 100644 (file)
@@ -54,7 +54,6 @@ public class PropertiesManagement {
     private static final String transformation = algorithm + "/" + cipherMode + "/" + paddingScheme;
 
     private static final SecureRandom random = new SecureRandom();
-   
     
     @Autowired
     Environment env;
@@ -100,10 +99,9 @@ public class PropertiesManagement {
 
     private static final String encrypt(String key, String value) {
         try {
-
-           byte[] bytesIV = new byte[16];
-           random.nextBytes(bytesIV);
-            IvParameterSpec iv = new IvParameterSpec(bytesIV);
+           byte[] bytesIV = new byte[12];
+            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);
@@ -119,10 +117,10 @@ public class PropertiesManagement {
 
     private static final String decrypt(String key, String encrypted) {
         try {
-           byte[] bytesIV = new byte[16];
+           byte[] bytesIV = new byte[12];
             random.nextBytes(bytesIV);
-            IvParameterSpec iv = new IvParameterSpec(bytesIV);
-            SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
+           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);
             byte[] original = cipher.doFinal(Base64.getDecoder().decode(encrypted));
index f260bb1..1a25cf1 100644 (file)
@@ -1,7 +1,7 @@
 {
   "swagger" : "2.0",
   "info" : {
-    "version" : "2.3.1-SNAPSHOT",
+    "version" : "2.3.2-SNAPSHOT",
     "title" : "cmso-optimizer"
   },
   "basePath" : "/optimizer",
index f5adb6f..da7bfbe 100644 (file)
@@ -20,6 +20,9 @@
 package org.onap.optf.cmso.utilities;
 
 import org.onap.optf.cmso.optimizer.common.PropertiesManagement;
+import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertAll;
+import org.junit.jupiter.api.Test;
 
 /**
  * The Class PropertiesAdmin.
@@ -44,5 +47,12 @@ public class PropertiesAdmin {
         }
         System.out.println(args[0] + " : " + value);
     }
+    @Test
+    public void testEncryptionDecryption()
+    {
+    String encryptedInputData = PropertiesManagement.getEncryptedValue("Hello");
+    String decryptedData = PropertiesManagement.getDecryptedValue(encryptedInputData);
+    assertEquals(decryptedData,"Hello");
+    }
 
 }
index 3f7a808..1b6488f 100644 (file)
@@ -99,8 +99,8 @@ public class PropertiesManagement {
     }\r
 \r
     private static final String encrypt(String key, String value) {\r
-        try {\r
-           byte[] bytesIV = new byte[16];\r
+        try{\r
+           byte[] bytesIV = new byte[12];\r
             random.nextBytes(bytesIV);\r
             IvParameterSpec iv = new IvParameterSpec(bytesIV);\r
             SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");\r
@@ -118,8 +118,8 @@ public class PropertiesManagement {
 \r
     private static final String decrypt(String key, String encrypted) {\r
         try {\r
-            byte[] bytesIV = new byte[16];\r
-            random.nextBytes(bytesIV);\r
+             byte[] bytesIV = new byte[12];\r
+    random.nextBytes(bytesIV);\r
             IvParameterSpec iv = new IvParameterSpec(bytesIV);\r
             SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");\r
             Cipher cipher = Cipher.getInstance(transformation);\r
index eb563ad..16b69b8 100644 (file)
@@ -1,7 +1,7 @@
 {
   "swagger" : "2.0",
   "info" : {
-    "version" : "2.3.1-SNAPSHOT",
+    "version" : "2.3.2-SNAPSHOT",
     "title" : "cmso-service"
   },
   "basePath" : "/cmso",
           "format" : "int32",
           "description" : "Maximum number of VNF changes to schedule concurrently"
         },
-        "changeWindows" : {
-          "type" : "array",
-          "description" : "Lists of desired change windows to schedule the elements.",
-          "items" : {
-            "$ref" : "#/definitions/Change Window"
-          }
-        },
-        "policies" : {
-          "type" : "array",
-          "description" : "List of the policies to control optimization.",
-          "items" : {
-            "$ref" : "#/definitions/Supported Policy Information"
-          }
+        "policyId" : {
+          "type" : "string",
+          "description" : "Name of schedule optimization policy used by the change management cmso optimizer to determine available time slot"
         },
-        "elements" : {
+        "vnfDetails" : {
           "type" : "array",
           "description" : "Lists of the VNFs to be changed and the desired change windows",
           "items" : {
-            "$ref" : "#/definitions/Optimizer Element"
+            "$ref" : "#/definitions/VNF Details"
           }
         }
       },
       "properties" : {
         "startTime" : {
           "type" : "string",
-          "format" : "date-time",
-          "description" : "Earliest time for which changes may begin."
+          "description" : "Earliest time that a set of changes may begin."
         },
         "endTime" : {
           "type" : "string",
-          "format" : "date-time",
-          "description" : "Latest time by which all changes must be completed."
+          "description" : "Latest time by which all changes must be completed"
         }
       },
-      "description" : "Time window for which tickets are to returned"
+      "description" : "Time window within which the scheduler optimizer can schedule the changes for the  group of NVFs"
     },
     "CmDetailsMessage" : {
       "type" : "object",
index c36a587..e34a73d 100644 (file)
@@ -100,9 +100,9 @@ public class PropertiesManagement {
 
     private static final String encrypt(String key, String value) {
         try {
-           byte[] bytesIV = new byte[16];
-           random.nextBytes(bytesIV);
-           IvParameterSpec iv = new IvParameterSpec(bytesIV);
+           byte[] bytesIV = new byte[12];
+            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);
@@ -118,9 +118,8 @@ public class PropertiesManagement {
 
     private static final String decrypt(String key, String encrypted) {
         try {
-            
-            byte[] bytesIV = new byte[16];
-            random.nextBytes(bytesIV);
+            byte[] bytesIV = new byte[12];
+           random.nextBytes(bytesIV);  
             IvParameterSpec iv = new IvParameterSpec(bytesIV);
             SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
             Cipher cipher = Cipher.getInstance(transformation);
index 3cac0bb..0f077e0 100644 (file)
@@ -1,7 +1,7 @@
 {
   "swagger" : "2.0",
   "info" : {
-    "version" : "2.3.1-SNAPSHOT",
+    "version" : "2.3.2-SNAPSHOT",
     "title" : "cmso-ticketmgt"
   },
   "basePath" : "/ticketmgt",
index 8af1aea..518ce0c 100644 (file)
@@ -49,6 +49,7 @@ public class PropertiesManagement {
     private  static final String transformation = algorithm + "/" + cipherMode + "/" + paddingScheme;
     private  static final SecureRandom random = new SecureRandom();
 
+
     @Autowired
     Environment env;
 
@@ -93,7 +94,7 @@ public class PropertiesManagement {
 
     private static final String encrypt(String key, String value) {
         try {
-           byte[] bytesIV = new byte[16];
+            byte[] bytesIV = new byte[12];
             random.nextBytes(bytesIV);
             IvParameterSpec iv = new IvParameterSpec(bytesIV);
             SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
@@ -111,9 +112,9 @@ public class PropertiesManagement {
 
     private static final String decrypt(String key, String encrypted) {
         try {
-           byte[] bytesIV = new byte[16];
+            byte[] bytesIV = new byte[12];
             random.nextBytes(bytesIV);
-            IvParameterSpec iv = new IvParameterSpec(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);
index c6aeba7..a5abc3f 100644 (file)
@@ -1,7 +1,7 @@
 {
   "swagger" : "2.0",
   "info" : {
-    "version" : "2.3.1-SNAPSHOT",
+    "version" : "2.3.2-SNAPSHOT",
     "title" : "cmso-topology"
   },
   "basePath" : "/topology",