use of com.adaptris.security.keystore.KeystoreLocation in project interlok by adaptris.
the class JunitSecurityHelper method newKeystore.
private void newKeystore(String url, String commonName, char[] password) throws Exception {
KeystoreProxy ksp = null;
KeystoreLocation ksc = KeystoreFactory.getDefault().create(url, password);
CertificateBuilder builder = getBuilder(commonName);
Certificate selfCert = builder.createSelfSignedCertificate();
PrivateKey privkey = builder.getPrivateKey();
ksp = KeystoreFactory.getDefault().create(ksc);
try {
ksp.load();
} catch (Exception e) {
// Ignore the error...
}
String alias = config.getProperty(SECURITY_ALIAS);
Certificate[] certChain = new Certificate[1];
certChain[0] = selfCert;
ksp.setPrivateKey(alias, privkey, password, certChain);
ksp.commit();
}
use of com.adaptris.security.keystore.KeystoreLocation in project interlok by adaptris.
the class HttpsProduceConnection method initialiseClient.
/**
* @see HttpClientConnection#initialiseClient(java.lang.String)
*/
@Override
public HttpClientTransport initialiseClient(String url) throws HttpException {
HttpsClient client = new HttpsClient(url);
try {
if (keystore != null) {
KeystoreFactory ksf = KeystoreFactory.getDefault();
KeystoreLocation ksl = null;
if (keystorePassword != null) {
ksl = ksf.create(keystore, Password.decode(keystorePassword).toCharArray());
} else {
ksl = ksf.create(keystore);
}
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(alwaysTrust);
return client;
}
use of com.adaptris.security.keystore.KeystoreLocation in project interlok by adaptris.
the class Config method buildKeystore.
public KeystoreLocation buildKeystore(String ksUrl, String cn, boolean overwrite) throws Exception {
String commonName = StringUtils.defaultIfBlank(cn, config.getProperty(KEYSTORE_COMMON_PRIVKEY_ALIAS));
KeystoreLocation ksc = KeystoreFactory.getDefault().create(ksUrl, config.getProperty(Config.KEYSTORE_COMMON_KEYSTORE_PW).toCharArray());
KeystoreProxy ksp = KeystoreFactory.getDefault().create(ksc);
if (ksc.exists() && overwrite == false) {
ksp.load();
}
CertificateBuilder builder = getBuilder(commonName);
Certificate selfCert = builder.createSelfSignedCertificate();
PrivateKey privkey = builder.getPrivateKey();
char[] password = config.getProperty(KEYSTORE_COMMON_PRIVKEY_PW).toCharArray();
Certificate[] certChain = new Certificate[1];
certChain[0] = selfCert;
ksp.setPrivateKey(commonName, privkey, password, certChain);
ksp.commit();
return ksc;
}
use of com.adaptris.security.keystore.KeystoreLocation in project interlok by adaptris.
the class TestKeystoreLocation method testNonExistentLocalKeystore.
@Test
public void testNonExistentLocalKeystore() {
try {
KeystoreLocation k = KeystoreFactory.getDefault().create("file:///c:/fredblahblahblh?keystoreType=JKS", cfg.getProperty(Config.KEYSTORE_COMMON_KEYSTORE_PW).toCharArray());
assertTrue("Keystore Location", !k.exists());
} catch (Exception e) {
logR.error("testLocalKeystore failed", e);
fail(e.getMessage());
}
}
use of com.adaptris.security.keystore.KeystoreLocation in project interlok by adaptris.
the class TestKeystoreLocation method testLocalKeystore.
@Test
public void testLocalKeystore() {
try {
KeystoreLocation k = KeystoreFactory.getDefault().create(cfg.getProperty(Config.KEYSTORE_TEST_URL), cfg.getProperty(Config.KEYSTORE_COMMON_KEYSTORE_PW).toCharArray());
assertTrue("Keystore Location", k.exists());
InputStream in = k.openInput();
in.close();
} catch (Exception e) {
logR.error("testLocalKeystore failed", e);
fail(e.getMessage());
}
}
Aggregations