use of com.adaptris.security.keystore.KeystoreProxy 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.KeystoreProxy 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.KeystoreProxy in project interlok by adaptris.
the class SingleEntryKeystoreBase method testImportPrivateKey.
@Test
public void testImportPrivateKey() throws Exception {
KeystoreProxy ksp = KeystoreFactory.getDefault().create(kloc);
ksp.load();
try {
ksp.importPrivateKey("", "".toCharArray(), "", "".toCharArray());
fail("Import successful");
} catch (Exception e) {
assertEquals(KeystoreException.class, e.getClass());
}
try {
ksp.importPrivateKey("", "".toCharArray(), (InputStream) null, "".toCharArray());
fail("Import successful");
} catch (Exception e) {
assertEquals(KeystoreException.class, e.getClass());
}
try {
ksp.importPrivateKey("", "".toCharArray(), (File) null, "".toCharArray());
fail("Import successful");
} catch (Exception e) {
assertEquals(KeystoreException.class, e.getClass());
}
}
use of com.adaptris.security.keystore.KeystoreProxy in project interlok by adaptris.
the class SingleEntryKeystoreBase method testImportCertificateChain.
@Test
public void testImportCertificateChain() throws Exception {
KeystoreProxy ksp = KeystoreFactory.getDefault().create(kloc);
ksp.load();
try {
ksp.importCertificateChain("", "".toCharArray(), "");
fail("Import successful");
} catch (Exception e) {
assertEquals(KeystoreException.class, e.getClass());
}
try {
ksp.importCertificateChain("", "".toCharArray(), (InputStream) null);
fail("Import successful");
} catch (Exception e) {
assertEquals(KeystoreException.class, e.getClass());
}
try {
ksp.importCertificateChain("", "".toCharArray(), (File) null);
fail("Import successful");
} catch (Exception e) {
assertEquals(KeystoreException.class, e.getClass());
}
}
use of com.adaptris.security.keystore.KeystoreProxy in project interlok by adaptris.
the class TestKeyStoreInfoChange method testChangeKeyStorePassword.
@Test
public void testChangeKeyStorePassword() {
Certificate thisCert;
try {
ksm = KeystoreFactory.getDefault().create(ksi);
ksm.load();
String alias = config.getProperty(Config.KEYSTORE_COMMON_PRIVKEY_ALIAS);
// Now change the password
ksm.setKeystoreLocation(pwKsi);
ksm.commit();
// Now attempt to reload with the new keystore info.
KeystoreProxy tempKsm = KeystoreFactory.getDefault().create(pwKsi);
tempKsm.load();
// we should be able to reread the certificate information...
if (tempKsm.containsAlias(alias)) {
thisCert = tempKsm.getCertificate(alias);
assertNotNull(thisCert);
} else {
fail(alias + " does not exist in the specified keystore");
}
} catch (Exception e) {
logR.error(e.getMessage(), e);
fail(e.getMessage());
}
}
Aggregations