use of com.disney.uriparcel.URIParcel in project groovity by disney.
the class TestParcels method testKeystore.
@Test
public void testKeystore() throws Exception {
File myMapFile = File.createTempFile("testMapParcel", ".json");
try {
URI myUri = myMapFile.toURI();
String password = "myKeystorePassword";
Map<String, Object> config = new HashMap<>();
config.put(KeyStoreValueHandler.KEYSTORE_TYPE, "JCEKS");
config.put(KeyStoreValueHandler.KEYSTORE_PASSWORD, password);
SecretKeySpec secretKey = new SecretKeySpec("nobodyKnows".getBytes(), "DES");
KeyStore orig = KeyStore.getInstance("JCEKS");
orig.load(null);
orig.setKeyEntry("foobar", secretKey, password.toCharArray(), null);
URIParcel<KeyStore> putstore = new URIParcel<KeyStore>(KeyStore.class, myUri, config);
putstore.put(orig);
RuntimeException e = null;
try {
URIParcel<KeyStore> myParcel = new URIParcel<KeyStore>(KeyStore.class, myUri);
myParcel.call();
} catch (RuntimeException r) {
e = r;
}
Assert.assertNotNull("Expected error opening keystore with no config", e);
URIParcel<KeyStore> myParcel = new URIParcel<KeyStore>(KeyStore.class, myUri, config);
KeyStore result = myParcel.call();
Key rkey = result.getKey("foobar", password.toCharArray());
Assert.assertEquals(secretKey, rkey);
} finally {
myMapFile.delete();
}
}
use of com.disney.uriparcel.URIParcel in project groovity by disney.
the class TestJsonParcels method testJsonFile.
@Test
public void testJsonFile() throws Exception {
File myMapFile = File.createTempFile("testMapParcel", ".json");
FileWriter fw = new FileWriter(myMapFile);
try {
fw.write("{\"a\":1,\"b\":\"foo\"}");
} finally {
fw.close();
}
try {
URI myUri = myMapFile.toURI();
@SuppressWarnings("rawtypes") URIParcel<Map> myParcel = new URIParcel<>(Map.class, myUri);
Map<?, ?> result = myParcel.call();
Assert.assertEquals(1.0, result.get("a"));
} finally {
myMapFile.delete();
}
}
use of com.disney.uriparcel.URIParcel in project groovity by disney.
the class TestKeys method testKeyPair.
@Test
public void testKeyPair() throws Exception {
URI keyLoc = new URI("mem:myPrivateKey");
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
generator.initialize(2048);
KeyPair keyPair = generator.generateKeyPair();
URIParcel<KeyPair> myParcel = new URIParcel<KeyPair>(KeyPair.class, keyLoc);
myParcel.put(keyPair);
URIParcel<byte[]> rawParcel = new URIParcel<byte[]>(byte[].class, keyLoc);
Assert.assertTrue("Expected PKCS8 private key file", new String(rawParcel.call()).startsWith("-----BEGIN RSA PRIVATE KEY-----"));
myParcel = new URIParcel<KeyPair>(KeyPair.class, keyLoc);
KeyPair copy = myParcel.call();
Assert.assertEquals(keyPair.getPrivate(), copy.getPrivate());
}
use of com.disney.uriparcel.URIParcel in project groovity by disney.
the class TestKeys method testEncryptedKeyPair.
@Test
public void testEncryptedKeyPair() throws Exception {
URI keyLoc = new URI("mem:myEncryptedPrivateKey");
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
generator.initialize(2048);
KeyPair keyPair = generator.generateKeyPair();
Map<String, Object> config = new HashMap<>();
config.put("password", "hooloo");
URIParcel<KeyPair> myParcel = new URIParcel<KeyPair>(KeyPair.class, keyLoc, config);
myParcel.put(keyPair);
URIParcel<byte[]> rawParcel = new URIParcel<byte[]>(byte[].class, keyLoc);
Matcher encryptedPrivateMatcher = Pattern.compile("^-----BEGIN RSA PRIVATE KEY-----\\s+Proc-Type: 4,ENCRYPTED").matcher(new String(rawParcel.call()));
Assert.assertTrue("Expected PKCS8 encrypted private key file", encryptedPrivateMatcher.find());
Exception e = null;
try {
myParcel = new URIParcel<KeyPair>(KeyPair.class, keyLoc);
myParcel.call();
} catch (IllegalArgumentException e1) {
e = e1;
}
Assert.assertNotNull("Expected error", e);
myParcel = new URIParcel<KeyPair>(KeyPair.class, keyLoc, config);
KeyPair copy = myParcel.call();
Assert.assertEquals(keyPair.getPrivate(), copy.getPrivate());
}
Aggregations