Search in sources :

Example 1 with KeystoreException

use of com.adaptris.security.exc.KeystoreException in project interlok by adaptris.

the class X509KeystoreProxy method getCertificateChain.

/**
 * Return the certificate specified by the given alias.
 *
 * @param alias the alias of the Certificate
 * @return requested certificate chain, or null if the alias does not
 *         exist/not a certificate
 * @throws AdaptrisSecurityException for any error
 */
public Certificate[] getCertificateChain(String alias) throws AdaptrisSecurityException {
    Certificate cert = null;
    if (getAliasName().equalsIgnoreCase(alias)) {
        cert = certHandler.getCertificate();
    } else {
        throw new KeystoreException(alias + " not found");
    }
    Certificate[] certChain = new Certificate[1];
    certChain[0] = cert;
    return certChain;
}
Also used : KeystoreException(com.adaptris.security.exc.KeystoreException) Certificate(java.security.cert.Certificate)

Example 2 with KeystoreException

use of com.adaptris.security.exc.KeystoreException in project interlok by adaptris.

the class CompositeKeystore method load.

/**
 * @see KeystoreProxy#load()
 */
public void load() throws AdaptrisSecurityException {
    aliasCache = new Hashtable<String, AliasListEntry>();
    try {
        for (KeystoreLocation k : keystores) {
            KeystoreProxy kp = keystoreFactory.create(k);
            kp.load();
            KeyStore ks = kp.getKeystore();
            AliasListEntry kk = new AliasListEntry(kp, k);
            if (ks != null) {
                for (Enumeration<String> e = kp.getKeystore().aliases(); e.hasMoreElements(); ) {
                    String key = (String) e.nextElement();
                    if (!addToAliases(key, kk)) {
                        logR.warn("{} already exists in keystore group, ignoring {} in {}", key, key, k);
                    }
                }
            } else {
                String key = k.getAdditionalParams().getProperty(Constants.KEYSTORE_ALIAS);
                if (!addToAliases(key, kk)) {
                    logR.warn("{} already exists in keystore group, ignoring {} in {}", key, key, k);
                }
            }
        }
    } catch (GeneralSecurityException e) {
        aliasCache = null;
        throw new KeystoreException(e);
    } catch (IOException e) {
        aliasCache = null;
        throw new KeystoreException(e);
    }
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) KeyStore(java.security.KeyStore) KeystoreException(com.adaptris.security.exc.KeystoreException)

Example 3 with KeystoreException

use of com.adaptris.security.exc.KeystoreException 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 4 with KeystoreException

use of com.adaptris.security.exc.KeystoreException 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 5 with KeystoreException

use of com.adaptris.security.exc.KeystoreException 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)

Aggregations

KeystoreException (com.adaptris.security.exc.KeystoreException)6 KeystoreProxy (com.adaptris.security.keystore.KeystoreProxy)3 AdaptrisSecurityException (com.adaptris.security.exc.AdaptrisSecurityException)2 ConfiguredKeystore (com.adaptris.security.keystore.ConfiguredKeystore)2 IOException (java.io.IOException)2 GeneralSecurityException (java.security.GeneralSecurityException)2 PrivateKey (java.security.PrivateKey)2 Certificate (java.security.cert.Certificate)2 Map (java.util.Map)2 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 KeyStore (java.security.KeyStore)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1