Search in sources :

Example 1 with CryptoException

use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.

the class ExportKeyPairPublicKeyAction method getCertificateChain.

private X509Certificate[] getCertificateChain(String alias) throws CryptoException {
    try {
        KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
        KeyStore keyStore = history.getCurrentState().getKeyStore();
        X509Certificate[] certChain = X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias));
        return certChain;
    } catch (KeyStoreException ex) {
        String message = MessageFormat.format(res.getString("ExportKeyPairPublicKeyAction.NoAccessEntry.message"), alias);
        throw new CryptoException(message, ex);
    }
}
Also used : KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) KeyStoreException(java.security.KeyStoreException) CryptoException(org.kse.crypto.CryptoException) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate)

Example 2 with CryptoException

use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.

the class ExportTrustedCertificateAction method getCertificate.

private X509Certificate getCertificate(String alias) throws CryptoException {
    try {
        KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
        KeyStore keyStore = history.getCurrentState().getKeyStore();
        X509Certificate cert = X509CertUtil.convertCertificate(keyStore.getCertificate(alias));
        return cert;
    } catch (KeyStoreException ex) {
        String message = MessageFormat.format(res.getString("ExportTrustedCertificateAction.NoAccessEntry.message"), alias);
        throw new CryptoException(message, ex);
    }
}
Also used : KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) KeyStoreException(java.security.KeyStoreException) CryptoException(org.kse.crypto.CryptoException) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate)

Example 3 with CryptoException

use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.

the class ExportTrustedCertificatePublicKeyAction method getPublicKey.

private PublicKey getPublicKey(String alias) throws CryptoException {
    try {
        KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
        KeyStore keyStore = history.getCurrentState().getKeyStore();
        X509Certificate cert = X509CertUtil.convertCertificate(keyStore.getCertificate(alias));
        return cert.getPublicKey();
    } catch (KeyStoreException ex) {
        String message = MessageFormat.format(res.getString("ExportTrustedCertificatePublicKeyAction.NoAccessEntry.message"), alias);
        throw new CryptoException(message, ex);
    }
}
Also used : KeyStoreHistory(org.kse.utilities.history.KeyStoreHistory) KeyStoreException(java.security.KeyStoreException) CryptoException(org.kse.crypto.CryptoException) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate)

Example 4 with CryptoException

use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.

the class X509CertUtil method loadCertificatesPkiPath.

private static X509Certificate[] loadCertificatesPkiPath(InputStream is) throws CryptoException {
    try {
        CertificateFactory cf = CertificateFactory.getInstance(X509_CERT_TYPE, BOUNCY_CASTLE.jce());
        CertPath certPath = cf.generateCertPath(is, PKI_PATH_ENCODING);
        List<? extends Certificate> certs = certPath.getCertificates();
        ArrayList<X509Certificate> loadedCerts = new ArrayList<X509Certificate>();
        for (Iterator<? extends Certificate> itr = certs.iterator(); itr.hasNext(); ) {
            X509Certificate cert = (X509Certificate) itr.next();
            if (cert != null) {
                loadedCerts.add(cert);
            }
        }
        return loadedCerts.toArray(new X509Certificate[loadedCerts.size()]);
    } catch (CertificateException | NoSuchProviderException e) {
        throw new CryptoException(res.getString("NoLoadPkiPath.exception.message"), e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}
Also used : ArrayList(java.util.ArrayList) CertificateException(java.security.cert.CertificateException) CertPath(java.security.cert.CertPath) NoSuchProviderException(java.security.NoSuchProviderException) CryptoException(org.kse.crypto.CryptoException) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate)

Example 5 with CryptoException

use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.

the class X509CertUtil method getCertsEncodedPkcs7.

/**
 * PKCS #7 encode a number of certificates.
 *
 * @return The encoding
 * @param certs
 *            The certificates
 * @throws CryptoException
 *             If there was a problem encoding the certificates
 */
public static byte[] getCertsEncodedPkcs7(X509Certificate[] certs) throws CryptoException {
    try {
        ArrayList<Certificate> encodedCerts = new ArrayList<Certificate>();
        Collections.addAll(encodedCerts, certs);
        CertificateFactory cf = CertificateFactory.getInstance(X509_CERT_TYPE, BOUNCY_CASTLE.jce());
        CertPath cp = cf.generateCertPath(encodedCerts);
        return cp.getEncoded(PKCS7_ENCODING);
    } catch (CertificateException | NoSuchProviderException e) {
        throw new CryptoException(res.getString("NoPkcs7Encode.exception.message"), e);
    }
}
Also used : ArrayList(java.util.ArrayList) CertificateException(java.security.cert.CertificateException) CertPath(java.security.cert.CertPath) NoSuchProviderException(java.security.NoSuchProviderException) CryptoException(org.kse.crypto.CryptoException) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Aggregations

CryptoException (org.kse.crypto.CryptoException)80 GeneralSecurityException (java.security.GeneralSecurityException)22 IOException (java.io.IOException)21 X509Certificate (java.security.cert.X509Certificate)21 KeyStore (java.security.KeyStore)16 KeyStoreException (java.security.KeyStoreException)13 BigInteger (java.math.BigInteger)11 DError (org.kse.gui.error.DError)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 File (java.io.File)9 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)9 ByteBuffer (java.nio.ByteBuffer)8 CertificateException (java.security.cert.CertificateException)8 PrivateKey (java.security.PrivateKey)7 KeyFactory (java.security.KeyFactory)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 CertificateFactory (java.security.cert.CertificateFactory)6 DSAPrivateKey (java.security.interfaces.DSAPrivateKey)6 RSAPrivateCrtKey (java.security.interfaces.RSAPrivateCrtKey)6 Cipher (javax.crypto.Cipher)6