use of com.adaptris.security.keystore.KeystoreLocation in project interlok by adaptris.
the class TestKeystoreLocation method testKeystoreEquality.
@Test
public void testKeystoreEquality() {
try {
KeystoreLocation ksi = KeystoreFactory.getDefault().create("JKS:///c:/fred.ks", "abcde".toCharArray());
KeystoreLocation ksi2 = KeystoreFactory.getDefault().create("file:///c:/fred.ks?keystoreType=JKS", "abcde".toCharArray());
assertEquals("Keystore Equality", ksi, ksi2);
} catch (Exception e) {
logR.error("testKeystoreFactory failed", e);
fail(e.getMessage());
}
}
use of com.adaptris.security.keystore.KeystoreLocation in project interlok by adaptris.
the class TestKeystoreLocation method testKeystoreFactory.
@Test
public void testKeystoreFactory() {
try {
KeystoreLocation ksi = KeystoreFactory.getDefault().create("jks:///c:/fred.ks", "abcde".toCharArray());
KeystoreLocation ksi2 = KeystoreFactory.getDefault().create("file:///c:/fred.ks?keystoreType=JKS&keystorePassword=abcde");
assertEquals("Keystore Equality", ksi, ksi2);
} catch (Exception e) {
logR.error("testKeystoreFactory failed", e);
fail(e.getMessage());
}
}
use of com.adaptris.security.keystore.KeystoreLocation in project interlok by adaptris.
the class TestKeystoreLocation method testRemoteKeystore.
@Test
public void testRemoteKeystore() throws Exception {
Assume.assumeTrue(Boolean.parseBoolean(cfg.getProperty(Config.REMOTE_TESTS_ENABLED, "false")));
String ks = cfg.getProperty(Config.KEYSTORE_TEST_URL);
ks = ks.replaceAll("\\\\", "/");
URI uri = new URI(ks);
File keystore = new File(uri.getPath());
String filename = keystore.getName();
File newFile = new File(cfg.getProperty(Config.KEYSTORE_REMOTE_REALPATH) + "/" + filename);
FileUtils.copyFile(keystore, newFile);
// Thread.sleep(10000);
logR.debug("newFile " + newFile.getCanonicalPath());
String keystoreType = uri.getQuery();
String url = cfg.getProperty(Config.KEYSTORE_REMOTE_ROOT) + filename + "?" + keystoreType;
KeystoreLocation k = KeystoreFactory.getDefault().create(url, cfg.getProperty(Config.KEYSTORE_COMMON_KEYSTORE_PW).toCharArray());
assertTrue("Remote Keystore exists", k.exists());
InputStream in = k.openInput();
in.close();
assertTrue(!k.isWriteable());
boolean openOutputSuccess = false;
try {
OutputStream o = k.openOutput();
openOutputSuccess = true;
o.close();
} catch (Exception e) {
// Expected as it's non-writeable
}
newFile.delete();
if (openOutputSuccess) {
fail("Successfully opened output to a remote keystore!");
}
}
use of com.adaptris.security.keystore.KeystoreLocation in project interlok by adaptris.
the class VersionedHttpsProduceConnection method initialiseClient.
/**
* @see HttpClientConnection#initialiseClient(java.lang.String)
*/
@Override
public HttpClientTransport initialiseClient(String url) throws HttpException {
HttpsClient client = new HttpsClient(new URLString(url), protocolVersion);
try {
if (getKeystore() != null) {
KeystoreFactory ksf = KeystoreFactory.getDefault();
KeystoreLocation ksl = null;
if (getKeystorePassword() != null) {
ksl = ksf.create(getKeystore(), Password.decode(getKeystorePassword()).toCharArray());
} else {
ksl = ksf.create(getKeystore());
}
char[] pkpw = PasswordOverride.discoverPrivateKeyPassword(ksl, getPrivateKeyPasswordProvider());
if (pkpw != null) {
client.registerPrivateKeyPassword(pkpw);
}
client.registerKeystore(ksf.create(ksl));
}
} catch (AdaptrisSecurityException e) {
throw new HttpException(e);
}
client.setAlwaysTrust(getAlwaysTrust());
return client;
}
use of com.adaptris.security.keystore.KeystoreLocation in project interlok by adaptris.
the class Https method getKeystoreProxy.
static KeystoreProxy getKeystoreProxy(KeystoreProxy ksp) throws Exception {
if (ksp != null) {
return ksp;
}
initialise();
String url = httpsProperties.getProperty(CONFIG_KEYSTORE_URL);
if (url == null) {
throw new IOException("Could not a keystore url to use in " + CONFIG_PROPERTY_FILE);
}
String pw = httpsProperties.getProperty(CONFIG_KEYSTORE_PW);
KeystoreLocation ksl = null;
if (pw != null) {
ksl = KeystoreFactory.getDefault().create(url, Password.decode(pw).toCharArray());
} else {
ksl = KeystoreFactory.getDefault().create(url);
}
return KeystoreFactory.getDefault().create(ksl);
}
Aggregations