Search in sources :

Example 31 with CryptoException

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

the class DProperties method getAliasesInAlphaOrder.

private TreeSet<String> getAliasesInAlphaOrder() throws CryptoException {
    try {
        KeyStore keyStore = currentState.getKeyStore();
        TreeSet<String> aliases = new TreeSet<String>();
        Enumeration<String> enumAliases = keyStore.aliases();
        while (enumAliases.hasMoreElements()) {
            String alias = enumAliases.nextElement();
            if (KeyStoreUtil.isSupportedEntryType(alias, keyStore)) {
                aliases.add(alias);
            }
        }
        return aliases;
    } catch (KeyStoreException ex) {
        throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
    }
}
Also used : TreeSet(java.util.TreeSet) KeyStoreException(java.security.KeyStoreException) CryptoException(org.kse.crypto.CryptoException) KeyStore(java.security.KeyStore)

Example 32 with CryptoException

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

the class DProperties method createKeyPairNodes.

private void createKeyPairNodes(DefaultMutableTreeNode parentNode, String alias) throws CryptoException {
    try {
        KeyStore keyStore = currentState.getKeyStore();
        DefaultMutableTreeNode keyPairNode = new DefaultMutableTreeNode(alias);
        parentNode.add(keyPairNode);
        createLastModifiedNode(keyPairNode, alias);
        createPrivateKeyNodes(keyPairNode, alias);
        X509Certificate[] certificates = X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias));
        DefaultMutableTreeNode certificatesNode = new DefaultMutableTreeNode(res.getString("DProperties.properties.Certificates"));
        keyPairNode.add(certificatesNode);
        for (int i = 0; i < certificates.length; i++) {
            X509Certificate certificate = certificates[i];
            DefaultMutableTreeNode certificateNode = new DefaultMutableTreeNode(X509CertUtil.getShortName(certificate));
            certificatesNode.add(certificateNode);
            populateCertificateNode(certificateNode, certificate);
        }
    } 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) X509Certificate(java.security.cert.X509Certificate)

Example 33 with CryptoException

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

the class DProperties method populateCertificateNode.

private void populateCertificateNode(DefaultMutableTreeNode certificateNode, X509Certificate certificate) throws CryptoException {
    try {
        String version = MessageFormat.format(res.getString("DProperties.properties.Version"), "" + certificate.getVersion());
        certificateNode.add(new DefaultMutableTreeNode(version));
        String subject = MessageFormat.format(res.getString("DProperties.properties.Subject"), X500NameUtils.x500PrincipalToX500Name(certificate.getSubjectX500Principal()));
        certificateNode.add(new DefaultMutableTreeNode(subject));
        String issuer = MessageFormat.format(res.getString("DProperties.properties.Issuer"), X500NameUtils.x500PrincipalToX500Name(certificate.getIssuerX500Principal()));
        certificateNode.add(new DefaultMutableTreeNode(issuer));
        String serialNumber = MessageFormat.format(res.getString("DProperties.properties.SerialNumber"), new BigInteger(certificate.getSerialNumber().toByteArray()).toString(16).toUpperCase());
        certificateNode.add(new DefaultMutableTreeNode(serialNumber));
        Date validFromDate = certificate.getNotBefore();
        String validFrom = MessageFormat.format(res.getString("DProperties.properties.ValidFrom"), StringUtils.formatDate(validFromDate));
        certificateNode.add(new DefaultMutableTreeNode(validFrom));
        Date validUntilDate = certificate.getNotAfter();
        String validUntil = MessageFormat.format(res.getString("DProperties.properties.ValidUntil"), StringUtils.formatDate(validUntilDate));
        certificateNode.add(new DefaultMutableTreeNode(validUntil));
        createPublicKeyNodes(certificateNode, certificate);
        String signatureAlgorithm = MessageFormat.format(res.getString("DProperties.properties.SignatureAlgorithm"), X509CertUtil.getCertificateSignatureAlgorithm(certificate));
        certificateNode.add(new DefaultMutableTreeNode(signatureAlgorithm));
        byte[] cert = certificate.getEncoded();
        String md5 = MessageFormat.format(res.getString("DProperties.properties.Md5Fingerprint"), DigestUtil.getFriendlyMessageDigest(cert, DigestType.MD5));
        certificateNode.add(new DefaultMutableTreeNode(md5));
        String sha1 = MessageFormat.format(res.getString("DProperties.properties.Sha1Fingerprint"), DigestUtil.getFriendlyMessageDigest(cert, DigestType.SHA1));
        certificateNode.add(new DefaultMutableTreeNode(sha1));
    } catch (CertificateEncodingException ex) {
        throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) BigInteger(java.math.BigInteger) CertificateEncodingException(java.security.cert.CertificateEncodingException) CryptoException(org.kse.crypto.CryptoException) Date(java.util.Date)

Example 34 with CryptoException

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

the class DViewCertificate method populateDetails.

private void populateDetails() {
    X509Certificate cert = getSelectedCertificate();
    if (cert == null) {
        jdnSubject.setEnabled(false);
        jdnIssuer.setEnabled(false);
        jbViewPublicKeyDetails.setEnabled(false);
        jcfFingerprint.setEnabled(false);
        jbExtensions.setEnabled(false);
        jbPem.setEnabled(false);
        jbAsn1.setEnabled(false);
        jtfVersion.setText("");
        jdnSubject.setDistinguishedName(null);
        jdnIssuer.setDistinguishedName(null);
        jtfSerialNumber.setText("");
        jtfValidFrom.setText("");
        jtfValidUntil.setText("");
        jtfPublicKey.setText("");
        jtfSignatureAlgorithm.setText("");
        jcfFingerprint.setEncodedCertificate(null);
    } else {
        jdnSubject.setEnabled(true);
        jdnIssuer.setEnabled(true);
        jbViewPublicKeyDetails.setEnabled(true);
        jbExtensions.setEnabled(true);
        jbPem.setEnabled(true);
        jbAsn1.setEnabled(true);
        try {
            Date currentDate = new Date();
            Date startDate = cert.getNotBefore();
            Date endDate = cert.getNotAfter();
            boolean notYetValid = currentDate.before(startDate);
            boolean noLongerValid = currentDate.after(endDate);
            jtfVersion.setText(Integer.toString(cert.getVersion()));
            jtfVersion.setCaretPosition(0);
            jdnSubject.setDistinguishedName(X500NameUtils.x500PrincipalToX500Name(cert.getSubjectX500Principal()));
            jdnIssuer.setDistinguishedName(X500NameUtils.x500PrincipalToX500Name(cert.getIssuerX500Principal()));
            jtfSerialNumber.setText("0x" + new BigInteger(1, cert.getSerialNumber().toByteArray()).toString(16).toUpperCase());
            jtfSerialNumber.setCaretPosition(0);
            jtfValidFrom.setText(StringUtils.formatDate(startDate));
            if (notYetValid) {
                jtfValidFrom.setText(MessageFormat.format(res.getString("DViewCertificate.jtfValidFrom.notyetvalid.text"), jtfValidFrom.getText()));
                jtfValidFrom.setForeground(Color.red);
            } else {
                jtfValidFrom.setForeground(jtfVersion.getForeground());
            }
            jtfValidFrom.setCaretPosition(0);
            jtfValidUntil.setText(StringUtils.formatDate(endDate));
            if (noLongerValid) {
                jtfValidUntil.setText(MessageFormat.format(res.getString("DViewCertificate.jtfValidUntil.expired.text"), jtfValidUntil.getText()));
                jtfValidUntil.setForeground(Color.red);
            } else {
                jtfValidUntil.setForeground(jtfVersion.getForeground());
            }
            jtfValidUntil.setCaretPosition(0);
            KeyInfo keyInfo = KeyPairUtil.getKeyInfo(cert.getPublicKey());
            jtfPublicKey.setText(keyInfo.getAlgorithm());
            Integer keySize = keyInfo.getSize();
            if (keySize != null) {
                jtfPublicKey.setText(MessageFormat.format(res.getString("DViewCertificate.jtfPublicKey.text"), jtfPublicKey.getText(), "" + keySize));
            } else {
                jtfPublicKey.setText(MessageFormat.format(res.getString("DViewCertificate.jtfPublicKey.text"), jtfPublicKey.getText(), "?"));
            }
            jtfPublicKey.setCaretPosition(0);
            jtfSignatureAlgorithm.setText(X509CertUtil.getCertificateSignatureAlgorithm(cert));
            jtfSignatureAlgorithm.setCaretPosition(0);
            byte[] encodedCertificate;
            try {
                encodedCertificate = cert.getEncoded();
            } catch (CertificateEncodingException ex) {
                throw new CryptoException(res.getString("DViewCertificate.NoGetEncodedCert.exception.message"), ex);
            }
            jcfFingerprint.setEncodedCertificate(encodedCertificate);
            jcfFingerprint.setFingerprintAlg(ApplicationSettings.getInstance().getCertificateFingerprintType());
            Set<?> critExts = cert.getCriticalExtensionOIDs();
            Set<?> nonCritExts = cert.getNonCriticalExtensionOIDs();
            if (critExts != null && critExts.size() != 0 || nonCritExts != null && nonCritExts.size() != 0) {
                jbExtensions.setEnabled(true);
            } else {
                jbExtensions.setEnabled(false);
            }
        } catch (CryptoException ex) {
            DError dError = new DError(this, ex);
            dError.setLocationRelativeTo(this);
            dError.setVisible(true);
            dispose();
        }
    }
}
Also used : BigInteger(java.math.BigInteger) KeyInfo(org.kse.crypto.KeyInfo) BigInteger(java.math.BigInteger) CertificateEncodingException(java.security.cert.CertificateEncodingException) CryptoException(org.kse.crypto.CryptoException) X509Certificate(java.security.cert.X509Certificate) Date(java.util.Date) DError(org.kse.gui.error.DError)

Example 35 with CryptoException

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

the class DViewCsr method pubKeyDetailsPressed.

private void pubKeyDetailsPressed() {
    try {
        PublicKey publicKey = null;
        if (pkcs10Csr != null) {
            publicKey = getPkcs10PublicKey();
        } else {
            publicKey = spkacCsr.getPublicKey();
        }
        DViewPublicKey dViewPublicKey = new DViewPublicKey(this, res.getString("DViewCsr.PubKeyDetails.Title"), publicKey);
        dViewPublicKey.setLocationRelativeTo(this);
        dViewPublicKey.setVisible(true);
    } catch (CryptoException ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(this);
        dError.setVisible(true);
    }
}
Also used : PublicKey(java.security.PublicKey) CryptoException(org.kse.crypto.CryptoException) DError(org.kse.gui.error.DError)

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