summaryrefslogtreecommitdiffstats
path: root/cadi/core/src
diff options
context:
space:
mode:
authorInstrumental <jonathan.gathman@att.com>2018-10-06 20:32:59 -0500
committerInstrumental <jonathan.gathman@att.com>2018-10-06 21:37:15 -0500
commit49525303bc07064d60b3dde3056b2e9e8a379435 (patch)
tree2779f89f45e31b14799daaecaf856d56a448e6cd /cadi/core/src
parent196000bb838818d9e3cc3d5c08614c1898388135 (diff)
Refactor Client Config
Refactored the client to handle multiple keystores without compromising keys, etc. After testing, now valiates just fine Issue-ID: AAF-424, AAF-540 Change-Id: I3b99014dd4b73ae22c359d35658da3bb13745ef9 Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'cadi/core/src')
-rw-r--r--cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java40
-rw-r--r--cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_Symm.java4
2 files changed, 30 insertions, 14 deletions
diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java b/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java
index 28af03cd..9a66d313 100644
--- a/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java
+++ b/cadi/core/src/main/java/org/onap/aaf/cadi/Symm.java
@@ -32,6 +32,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.security.SecureRandom;
import java.util.ArrayList;
+import java.util.Date;
import java.util.Random;
import javax.crypto.CipherInputStream;
@@ -62,8 +63,7 @@ import org.onap.aaf.cadi.config.Config;
* supporting functions such as 2048 keyfile generation (see keygen). This keyfile should, of course,
* be set to "400" (Unix) and protected as any other mechanism requires.
*
- * However, this algorithm has not been tested against hackers. Until such a time, utilize more tested
- * packages to protect Data, especially sensitive data at rest (long term).
+ * AES Encryption is also employed to include standards.
*
* @author Jonathan
*
@@ -82,6 +82,7 @@ public class Symm {
private byte[] keyBytes = null;
//Note: AES Encryption is not Thread Safe. It is Synchronized
//private AES aes = null; // only initialized from File, and only if needed for Passwords
+ private String name;
/**
* This is the standard base64 Key Set.
@@ -89,11 +90,11 @@ public class Symm {
*/
public static final Symm base64 = new Symm(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray()
- ,76, Config.UTF_8,true);
+ ,76, Config.UTF_8,true, "Base64");
public static final Symm base64noSplit = new Symm(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray()
- ,Integer.MAX_VALUE, Config.UTF_8,true);
+ ,Integer.MAX_VALUE, Config.UTF_8,true, "Base64, no Split");
/**
* This is the standard base64 set suitable for URLs and Filenames
@@ -101,13 +102,13 @@ public class Symm {
*/
public static final Symm base64url = new Symm(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".toCharArray()
- ,76, Config.UTF_8,true);
+ ,76, Config.UTF_8,true, "Base64 for URL");
/**
* A Password set, using US-ASCII
* RFC 4648
*/
- public static final Symm encrypt = new Symm(base64url.codeset,1024, "US-ASCII", false);
+ public static final Symm encrypt = new Symm(base64url.codeset,1024, "US-ASCII", false, "Base64, 1024 size");
private static final byte[] EMPTY = new byte[0];
/**
@@ -127,11 +128,12 @@ public class Symm {
* @param codeset
* @param split
*/
- public Symm(char[] codeset, int split, String charset, boolean useEndEquals) {
+ public Symm(char[] codeset, int split, String charset, boolean useEndEquals, String name) {
this.codeset = codeset;
splitLinesAt = split;
encoding = charset;
endEquals = useEndEquals;
+ this.name = name;
char prev = 0, curr=0, first = 0;
int offset=Integer.SIZE; // something that's out of range for integer array
@@ -162,7 +164,7 @@ public class Symm {
}
public Symm copy(int lines) {
- return new Symm(codeset,lines,encoding,endEquals);
+ return new Symm(codeset,lines,encoding,endEquals, "Copied " + lines);
}
// Only used by keygen, which is intentionally randomized. Therefore, always use unordered
@@ -589,7 +591,9 @@ public class Symm {
public Symm obtain() throws IOException {
byte inkey[] = new byte[0x800];
new SecureRandom().nextBytes(inkey);
- return obtain(inkey);
+ Symm s = obtain(inkey);
+ s.name = "from Random";
+ return s;
}
/**
@@ -600,7 +604,9 @@ public class Symm {
* @throws IOException
*/
public static Symm obtain(String key) throws IOException {
- return obtain(new ByteArrayInputStream(key.getBytes()));
+ Symm s = obtain(new ByteArrayInputStream(key.getBytes()));
+ s.name = "from String";
+ return s;
}
/**
@@ -622,7 +628,9 @@ public class Symm {
if (bkey.length<0x88) { // 2048 bit key
throw new IOException("Invalid key");
}
- return baseCrypt().obtain(bkey);
+ Symm s = baseCrypt().obtain(bkey);
+ s.name = "from InputStream";
+ return s;
}
/**
@@ -635,7 +643,9 @@ public class Symm {
public static Symm obtain(File f) throws IOException {
FileInputStream fis = new FileInputStream(f);
try {
- return obtain(fis);
+ Symm s = obtain(fis);
+ s.name = "From " + f.getCanonicalPath() + " dated " + new Date(f.lastModified());
+ return s;
} finally {
fis.close();
}
@@ -855,6 +865,7 @@ public class Symm {
}
}
Symm newSymm = new Symm(seq,this);
+ newSymm.name = "from bytes";
// Set the KeyBytes
try {
newSymm.keyBytes = new byte[AES.AES_KEY_SIZE/8];
@@ -886,4 +897,9 @@ public class Symm {
}
return internalOnly;
}
+
+ @Override
+ public String toString() {
+ return name;
+ }
}
diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_Symm.java b/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_Symm.java
index 1c1d5a2c..5e6f69b8 100644
--- a/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_Symm.java
+++ b/cadi/core/src/test/java/org/onap/aaf/cadi/test/JU_Symm.java
@@ -46,7 +46,7 @@ public class JU_Symm {
public void setup() throws Exception {
defaultSymm = new Symm(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray()
- ,76, "Use default!" ,true);
+ ,76, "Use default!" ,true, "Junit 1");
outStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(outStream));
}
@@ -59,7 +59,7 @@ public class JU_Symm {
@Test
public void constructorTest() throws Exception {
Symm myCustomSymm = new Symm(
- "ACEGIKMOQSUWYacegikmoqsuwy02468+/".toCharArray(), 76, "Default", true);
+ "ACEGIKMOQSUWYacegikmoqsuwy02468+/".toCharArray(), 76, "Default", true, "Junit 2");
Field convert_field = Symm.class.getDeclaredField("convert");
convert_field.setAccessible(true);