Search in sources :

Example 11 with KeystoreProxy

use of com.adaptris.security.keystore.KeystoreProxy in project interlok by adaptris.

the class TestSingleX509Keystore method testKeystoreGetCertificate.

@Test
public void testKeystoreGetCertificate() {
    try {
        KeystoreProxy ksp = KeystoreFactory.getDefault().create(kloc);
        ksp.load();
        String alias = config.getProperty(Config.KEYSTORE_SINGLE_X509_ALIAS);
        if (ksp.containsAlias(alias)) {
            Certificate thisCert = ksp.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());
    }
}
Also used : KeystoreProxy(com.adaptris.security.keystore.KeystoreProxy) Certificate(java.security.cert.Certificate) Test(org.junit.Test)

Example 12 with KeystoreProxy

use of com.adaptris.security.keystore.KeystoreProxy in project interlok by adaptris.

the class TestSingleX509Keystore method testKeystoreGetPrivateKey.

@Test
public void testKeystoreGetPrivateKey() {
    try {
        KeystoreProxy ksp = KeystoreFactory.getDefault().create(kloc);
        ksp.load();
        String alias = config.getProperty(Config.KEYSTORE_SINGLE_X509_ALIAS);
        if (ksp.containsAlias(alias)) {
            PrivateKey pk = ksp.getPrivateKey(alias, "".toCharArray());
            assertNull(pk);
        }
        fail(alias + " exists in the specified keystore, and getPK didn't fail");
    } catch (Exception e) {
        // Expected bhaviour
        ;
    }
}
Also used : PrivateKey(java.security.PrivateKey) KeystoreProxy(com.adaptris.security.keystore.KeystoreProxy) Test(org.junit.Test)

Example 13 with KeystoreProxy

use of com.adaptris.security.keystore.KeystoreProxy in project interlok by adaptris.

the class TestSingleX509Keystore method testKeystoreGetCertificateChain.

@Test
public void testKeystoreGetCertificateChain() {
    try {
        KeystoreProxy ksp = KeystoreFactory.getDefault().create(kloc);
        ksp.load();
        String alias = config.getProperty(Config.KEYSTORE_SINGLE_X509_ALIAS);
        if (ksp.containsAlias(alias)) {
            Certificate[] thisCert = ksp.getCertificateChain(alias);
            assertEquals(1, thisCert.length);
        } else {
            fail(alias + " does not exist in the specified keystore");
        }
    } catch (Exception e) {
        logR.error(e.getMessage(), e);
        fail(e.getMessage());
    }
}
Also used : KeystoreProxy(com.adaptris.security.keystore.KeystoreProxy) Certificate(java.security.cert.Certificate) Test(org.junit.Test)

Example 14 with KeystoreProxy

use of com.adaptris.security.keystore.KeystoreProxy in project interlok by adaptris.

the class Config method importPrivateKey.

public void importPrivateKey(String ksUrl, String filename, boolean overwrite) throws AdaptrisSecurityException, IOException {
    String commonName = 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();
    }
    ksp.importPrivateKey(commonName, config.getProperty(KEYSTORE_COMMON_PRIVKEY_PW).toCharArray(), filename, config.getProperty(KEYSTORE_COMMON_PRIVKEY_PW).toCharArray());
    ksp.commit();
}
Also used : KeystoreLocation(com.adaptris.security.keystore.KeystoreLocation) KeystoreProxy(com.adaptris.security.keystore.KeystoreProxy)

Example 15 with KeystoreProxy

use of com.adaptris.security.keystore.KeystoreProxy in project interlok by adaptris.

the class SingleEntryKeystoreBase method testKeystoreGetKeyStore.

@Test
public void testKeystoreGetKeyStore() {
    try {
        KeystoreProxy ksp = KeystoreFactory.getDefault().create(kloc);
        ksp.load();
        assertNotNull("Keystore should not be null", ksp.getKeystore());
    } catch (Exception e) {
        logR.error(e.getMessage(), e);
        fail(e.getMessage());
    }
}
Also used : KeystoreProxy(com.adaptris.security.keystore.KeystoreProxy) KeystoreException(com.adaptris.security.exc.KeystoreException) Test(org.junit.Test)

Aggregations

KeystoreProxy (com.adaptris.security.keystore.KeystoreProxy)17 Test (org.junit.Test)11 KeystoreException (com.adaptris.security.exc.KeystoreException)7 Certificate (java.security.cert.Certificate)7 PrivateKey (java.security.PrivateKey)4 KeystoreLocation (com.adaptris.security.keystore.KeystoreLocation)3 CertificateBuilder (com.adaptris.security.certificate.CertificateBuilder)2 ConfiguredKeystore (com.adaptris.security.keystore.ConfiguredKeystore)2 Map (java.util.Map)2 AdaptrisSecurityException (com.adaptris.security.exc.AdaptrisSecurityException)1 CertException (com.adaptris.security.exc.CertException)1 DecryptException (com.adaptris.security.exc.DecryptException)1 EncryptException (com.adaptris.security.exc.EncryptException)1 VerifyException (com.adaptris.security.exc.VerifyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 Random (java.util.Random)1