Search in sources :

Example 71 with CryptoException

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

the class DProperties method createKeysNodes.

private void createKeysNodes(DefaultMutableTreeNode parentNode) throws CryptoException {
    try {
        KeyStore keyStore = currentState.getKeyStore();
        TreeSet<String> aliases = getAliasesInAlphaOrder();
        DefaultMutableTreeNode keysNode = new DefaultMutableTreeNode(res.getString("DProperties.properties.Keys"));
        parentNode.add(keysNode);
        boolean keysPresent = false;
        for (String alias : aliases) {
            if (KeyStoreUtil.isKeyEntry(alias, keyStore)) {
                createKeyNodes(keysNode, alias);
                keysPresent = true;
            }
        }
        if (!keysPresent) {
            DefaultMutableTreeNode emptyKeyNode = new DefaultMutableTreeNode(res.getString("DProperties.properties.None"));
            keysNode.add(emptyKeyNode);
        }
    } catch (KeyStoreException ex) {
        throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyStoreException(java.security.KeyStoreException) CryptoException(org.kse.crypto.CryptoException) KeyStore(java.security.KeyStore)

Example 72 with CryptoException

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

the class DProperties method createPrivateKeyNodes.

private void createPrivateKeyNodes(DefaultMutableTreeNode parentNode, String alias) throws CryptoException {
    try {
        KeyStore keyStore = currentState.getKeyStore();
        Password password = getEntryPassword(alias);
        if (password == null) {
            DefaultMutableTreeNode privateKeyNode = new DefaultMutableTreeNode(res.getString("DProperties.properties.PrivateKey"));
            parentNode.add(privateKeyNode);
            DefaultMutableTreeNode lockedNode = new DefaultMutableTreeNode(res.getString("DProperties.properties.Locked"));
            privateKeyNode.add(lockedNode);
            return;
        }
        PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
        createPrivateKeyNodes(parentNode, privateKey);
    } catch (NoSuchAlgorithmException ex) {
        throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
    } catch (KeyStoreException ex) {
        throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
    } catch (UnrecoverableKeyException ex) {
        throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
    }
}
Also used : PrivateKey(java.security.PrivateKey) DSAPrivateKey(java.security.interfaces.DSAPrivateKey) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) UnrecoverableKeyException(java.security.UnrecoverableKeyException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) CryptoException(org.kse.crypto.CryptoException) KeyStore(java.security.KeyStore) Password(org.kse.crypto.Password)

Example 73 with CryptoException

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

the class DProperties method createKeyPairsNodes.

private void createKeyPairsNodes(DefaultMutableTreeNode parentNode) throws CryptoException {
    try {
        KeyStore keyStore = currentState.getKeyStore();
        TreeSet<String> aliases = getAliasesInAlphaOrder();
        DefaultMutableTreeNode keyPairsNode = new DefaultMutableTreeNode(res.getString("DProperties.properties.KeyPairs"));
        parentNode.add(keyPairsNode);
        boolean keyPairsPresent = false;
        for (String alias : aliases) {
            if (KeyStoreUtil.isKeyPairEntry(alias, keyStore)) {
                createKeyPairNodes(keyPairsNode, alias);
                keyPairsPresent = true;
            }
        }
        if (!keyPairsPresent) {
            DefaultMutableTreeNode emptyKeyPairNode = new DefaultMutableTreeNode(res.getString("DProperties.properties.None"));
            keyPairsNode.add(emptyKeyPairNode);
        }
    } catch (KeyStoreException ex) {
        throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyStoreException(java.security.KeyStoreException) CryptoException(org.kse.crypto.CryptoException) KeyStore(java.security.KeyStore)

Example 74 with CryptoException

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

the class DProperties method createLastModifiedNode.

private void createLastModifiedNode(DefaultMutableTreeNode parentNode, String alias) throws CryptoException {
    try {
        KeyStore keyStore = currentState.getKeyStore();
        if (KeyStoreType.resolveJce(keyStore.getType()) != KeyStoreType.PKCS12) {
            String lastModified = MessageFormat.format(res.getString("DProperties.properties.LastModified"), StringUtils.formatDate(keyStore.getCreationDate(alias)));
            parentNode.add(new DefaultMutableTreeNode(lastModified));
        }
    } catch (ProviderException e) {
    // some keystore types do not provide creation dates for their entries => simply create no node
    } catch (KeyStoreException e) {
        throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), e);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ProviderException(java.security.ProviderException) KeyStoreException(java.security.KeyStoreException) CryptoException(org.kse.crypto.CryptoException) KeyStore(java.security.KeyStore)

Example 75 with CryptoException

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

the class DProperties method createKeyNodes.

private void createKeyNodes(DefaultMutableTreeNode parentNode, String alias) throws CryptoException {
    try {
        KeyStore keyStore = currentState.getKeyStore();
        DefaultMutableTreeNode keyNode = new DefaultMutableTreeNode(alias);
        parentNode.add(keyNode);
        createLastModifiedNode(keyNode, alias);
        Password password = getEntryPassword(alias);
        if (password == null) {
            DefaultMutableTreeNode lockedNode = new DefaultMutableTreeNode(res.getString("DProperties.properties.Locked"));
            keyNode.add(lockedNode);
            return;
        }
        Key key = keyStore.getKey(alias, password.toCharArray());
        if (key instanceof PublicKey) {
            createPublicKeyNodes(keyNode, (PublicKey) key);
        } else if (key instanceof PrivateKey) {
            createPrivateKeyNodes(keyNode, (PrivateKey) key);
        } else if (key instanceof SecretKey) {
            createSecretKeyNodes(keyNode, (SecretKey) key);
        }
    } catch (NoSuchAlgorithmException ex) {
        throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
    } catch (KeyStoreException ex) {
        throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
    } catch (UnrecoverableKeyException ex) {
        throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
    }
}
Also used : SecretKey(javax.crypto.SecretKey) PrivateKey(java.security.PrivateKey) DSAPrivateKey(java.security.interfaces.DSAPrivateKey) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) UnrecoverableKeyException(java.security.UnrecoverableKeyException) RSAPublicKey(java.security.interfaces.RSAPublicKey) PublicKey(java.security.PublicKey) DSAPublicKey(java.security.interfaces.DSAPublicKey) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) CryptoException(org.kse.crypto.CryptoException) KeyStore(java.security.KeyStore) RSAPublicKey(java.security.interfaces.RSAPublicKey) Key(java.security.Key) PrivateKey(java.security.PrivateKey) RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey) SecretKey(javax.crypto.SecretKey) DSAPrivateKey(java.security.interfaces.DSAPrivateKey) PublicKey(java.security.PublicKey) DSAPublicKey(java.security.interfaces.DSAPublicKey) Password(org.kse.crypto.Password)

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