Search in sources :

Example 6 with DError

use of org.kse.gui.error.DError in project keystore-explorer by kaikramer.

the class DViewCertificate method asn1DumpPressed.

private void asn1DumpPressed() {
    X509Certificate cert = getSelectedCertificate();
    try {
        DViewAsn1Dump dViewAsn1Dump = new DViewAsn1Dump(this, cert);
        dViewAsn1Dump.setLocationRelativeTo(this);
        dViewAsn1Dump.setVisible(true);
    } catch (Asn1Exception ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(this);
        dError.setVisible(true);
    } catch (IOException ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(this);
        dError.setVisible(true);
    }
}
Also used : IOException(java.io.IOException) Asn1Exception(org.kse.utilities.asn1.Asn1Exception) X509Certificate(java.security.cert.X509Certificate) DError(org.kse.gui.error.DError)

Example 7 with DError

use of org.kse.gui.error.DError 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 8 with DError

use of org.kse.gui.error.DError 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)

Example 9 with DError

use of org.kse.gui.error.DError in project keystore-explorer by kaikramer.

the class DViewPrivateKey method pemEncodingPressed.

private void pemEncodingPressed() {
    try {
        DViewPem dViewCsrPem = new DViewPem(this, res.getString("DViewPrivateKey.Pem.Title"), privateKey);
        dViewCsrPem.setLocationRelativeTo(this);
        dViewCsrPem.setVisible(true);
    } catch (CryptoException ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(this);
        dError.setVisible(true);
    }
}
Also used : CryptoException(org.kse.crypto.CryptoException) DError(org.kse.gui.error.DError)

Example 10 with DError

use of org.kse.gui.error.DError in project keystore-explorer by kaikramer.

the class DViewPublicKey method asn1DumpPressed.

private void asn1DumpPressed() {
    try {
        DViewAsn1Dump dViewAsn1Dump = new DViewAsn1Dump(this, publicKey);
        dViewAsn1Dump.setLocationRelativeTo(this);
        dViewAsn1Dump.setVisible(true);
    } catch (Asn1Exception ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(this);
        dError.setVisible(true);
    } catch (IOException ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(this);
        dError.setVisible(true);
    }
}
Also used : IOException(java.io.IOException) Asn1Exception(org.kse.utilities.asn1.Asn1Exception) DError(org.kse.gui.error.DError)

Aggregations

DError (org.kse.gui.error.DError)52 IOException (java.io.IOException)38 CryptoException (org.kse.crypto.CryptoException)11 DERIA5String (org.bouncycastle.asn1.DERIA5String)9 JFrame (javax.swing.JFrame)8 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)8 Asn1Exception (org.kse.utilities.asn1.Asn1Exception)7 Container (java.awt.Container)6 JDialog (javax.swing.JDialog)6 X509Certificate (java.security.cert.X509Certificate)4 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)4 DERSequence (org.bouncycastle.asn1.DERSequence)4 GeneralNames (org.bouncycastle.asn1.x509.GeneralNames)4 PolicyInformation (org.bouncycastle.asn1.x509.PolicyInformation)4 PolicyQualifierInfo (org.bouncycastle.asn1.x509.PolicyQualifierInfo)4 JGeneralNames (org.kse.gui.crypto.generalname.JGeneralNames)4 Point (java.awt.Point)3 BigInteger (java.math.BigInteger)3 Date (java.util.Date)3 ArrayList (java.util.ArrayList)2