Search in sources :

Example 6 with KeystoreProxy

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

the class TestSingleX509Keystore method testContainsAlias.

@Test
public void testContainsAlias() {
    try {
        KeystoreProxy ksp = KeystoreFactory.getDefault().create(kloc);
        ksp.load();
        String alias = config.getProperty(Config.KEYSTORE_SINGLE_X509_ALIAS);
        if (!ksp.containsAlias(alias)) {
            fail(alias + " doesn't exist in the specified keystore!");
        }
    } catch (Exception e) {
        logR.error(e.getMessage(), e);
        fail(e.getMessage());
    }
}
Also used : KeystoreProxy(com.adaptris.security.keystore.KeystoreProxy) Test(org.junit.Test)

Example 7 with KeystoreProxy

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

the class StdSecurityService method getCertificate.

private Certificate getCertificate(String alias) throws AdaptrisSecurityException {
    Certificate c = null;
    for (Map.Entry<ConfiguredKeystore, KeystoreProxy> set : keystores.entrySet()) {
        ConfiguredKeystore ksi = set.getKey();
        KeystoreProxy ksm = set.getValue();
        if (ksm.containsAlias(alias)) {
            if (logR.isDebugEnabled()) {
                logR.debug("Certificate Alias " + alias + " found in " + ksi);
            }
            c = ksm.getCertificate(alias);
            break;
        }
    }
    if (c == null) {
        throw new KeystoreException("Alias " + alias + " not found in registered keystores");
    }
    return c;
}
Also used : KeystoreProxy(com.adaptris.security.keystore.KeystoreProxy) Map(java.util.Map) KeystoreException(com.adaptris.security.exc.KeystoreException) ConfiguredKeystore(com.adaptris.security.keystore.ConfiguredKeystore) Certificate(java.security.cert.Certificate)

Example 8 with KeystoreProxy

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

the class StdSecurityService method getPrivateKey.

private PrivateKey getPrivateKey(String alias, char[] password) throws AdaptrisSecurityException {
    PrivateKey pk = null;
    for (Map.Entry<ConfiguredKeystore, KeystoreProxy> set : keystores.entrySet()) {
        ConfiguredKeystore ksi = set.getKey();
        KeystoreProxy ksm = set.getValue();
        if (ksm.containsAlias(alias)) {
            pk = ksm.getPrivateKey(alias, password);
            if (logR.isDebugEnabled()) {
                logR.debug("Private key alias " + alias + " found in " + ksi);
            }
            break;
        }
    }
    if (pk == null) {
        throw new KeystoreException("Private Key Alias " + alias + " not found in registered keystores");
    }
    return pk;
}
Also used : PrivateKey(java.security.PrivateKey) KeystoreProxy(com.adaptris.security.keystore.KeystoreProxy) Map(java.util.Map) KeystoreException(com.adaptris.security.exc.KeystoreException) ConfiguredKeystore(com.adaptris.security.keystore.ConfiguredKeystore)

Example 9 with KeystoreProxy

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

the class StdSecurityService method registerKeystore.

/**
 * @see SecurityService#registerKeystore(ConfiguredKeystore)
 */
public void registerKeystore(ConfiguredKeystore keystore) throws AdaptrisSecurityException {
    try {
        KeystoreProxy ksh = keystore.asKeystoreProxy();
        keystores.put(keystore, ksh);
        logKeystores();
    } catch (Exception e) {
        throw new KeystoreException(e);
    }
}
Also used : KeystoreProxy(com.adaptris.security.keystore.KeystoreProxy) KeystoreException(com.adaptris.security.exc.KeystoreException) KeystoreException(com.adaptris.security.exc.KeystoreException) CertException(com.adaptris.security.exc.CertException) VerifyException(com.adaptris.security.exc.VerifyException) EncryptException(com.adaptris.security.exc.EncryptException) AdaptrisSecurityException(com.adaptris.security.exc.AdaptrisSecurityException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DecryptException(com.adaptris.security.exc.DecryptException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 10 with KeystoreProxy

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

the class TestKeyStoreInfoChange method testChangeKeyStoreInfo.

@Test
public void testChangeKeyStoreInfo() {
    Certificate thisCert;
    try {
        ksm = KeystoreFactory.getDefault().create(ksi);
        ksm.load();
        String alias = config.getProperty(Config.KEYSTORE_COMMON_PRIVKEY_ALIAS);
        ksm.setKeystoreLocation(newKsi);
        ksm.commit();
        KeystoreProxy tempKsm = KeystoreFactory.getDefault().create(newKsi);
        tempKsm.load();
        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());
    }
}
Also used : KeystoreProxy(com.adaptris.security.keystore.KeystoreProxy) Certificate(java.security.cert.Certificate) 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