Search in sources :

Example 11 with DError

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

the class DGenerateKeyPairCert method generateCertificate.

private boolean generateCertificate() {
    Date validityStart = jdtValidityStart.getDateTime();
    Date validityEnd = jdtValidityEnd.getDateTime();
    String serialNumberStr = jtfSerialNumber.getText().trim();
    if (serialNumberStr.length() == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DGenerateKeyPairCert.ValReqSerialNumber.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
        return false;
    }
    BigInteger serialNumber;
    try {
        serialNumber = new BigInteger(serialNumberStr);
        if (serialNumber.compareTo(BigInteger.ONE) < 0) {
            JOptionPane.showMessageDialog(this, res.getString("DGenerateKeyPairCert.SerialNumberNonZero.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
            return false;
        }
    } catch (NumberFormatException ex) {
        JOptionPane.showMessageDialog(this, res.getString("DGenerateKeyPairCert.SerialNumberNotInteger.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
        return false;
    }
    X500Name x500Name = jdnName.getDistinguishedName();
    if (x500Name == null || x500Name.toString().isEmpty()) {
        JOptionPane.showMessageDialog(this, res.getString("DGenerateKeyPairCert.NameValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
        return false;
    }
    try {
        SignatureType signatureType = ((SignatureType) jcbSignatureAlgorithm.getSelectedItem());
        X509CertificateGenerator generator;
        if (jrbVersion1.isSelected()) {
            generator = new X509CertificateGenerator(VERSION1);
        } else {
            generator = new X509CertificateGenerator(VERSION3);
        }
        // self-signed or signed by other key pair?
        if (issuerPrivateKey == null) {
            certificate = generator.generateSelfSigned(x500Name, validityStart, validityEnd, keyPair.getPublic(), keyPair.getPrivate(), signatureType, serialNumber, extensions, provider);
        } else {
            certificate = generator.generate(x500Name, X500NameUtils.x500PrincipalToX500Name(issuerCert.getSubjectX500Principal()), validityStart, validityEnd, keyPair.getPublic(), issuerPrivateKey, signatureType, serialNumber, extensions, provider);
        }
    } catch (CryptoException ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(getParent());
        dError.setVisible(true);
        closeDialog();
    }
    return true;
}
Also used : BigInteger(java.math.BigInteger) X500Name(org.bouncycastle.asn1.x500.X500Name) SignatureType(org.kse.crypto.signing.SignatureType) CryptoException(org.kse.crypto.CryptoException) Date(java.util.Date) X509CertificateGenerator(org.kse.crypto.x509.X509CertificateGenerator) DError(org.kse.gui.error.DError)

Example 12 with DError

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

the class DBasicConstraints method okPressed.

private void okPressed() {
    boolean ca = jcbSubjectIsCa.isSelected();
    int pathLengthConstraint = -1;
    String pathLengthConstraintStr = jtfPathLengthConstraint.getText().trim();
    if (pathLengthConstraintStr.length() > 0) {
        try {
            pathLengthConstraint = Integer.parseInt(pathLengthConstraintStr);
        } catch (NumberFormatException ex) {
            JOptionPane.showMessageDialog(this, res.getString("DBasicConstraints.InvalidLengthValue.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
            return;
        }
        if (pathLengthConstraint < 0) {
            JOptionPane.showMessageDialog(this, res.getString("DBasicConstraints.InvalidLengthValue.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
            return;
        }
    }
    BasicConstraints basicConstraints;
    if (pathLengthConstraint != -1) {
        // pathLengthConstraint set automatically means ca=true
        basicConstraints = new BasicConstraints(pathLengthConstraint);
    } else {
        basicConstraints = new BasicConstraints(ca);
    }
    try {
        value = basicConstraints.getEncoded(ASN1Encoding.DER);
    } catch (IOException ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(this);
        dError.setVisible(true);
        return;
    }
    closeDialog();
}
Also used : IOException(java.io.IOException) BasicConstraints(org.bouncycastle.asn1.x509.BasicConstraints) DError(org.kse.gui.error.DError)

Example 13 with DError

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

the class DCertificatePolicies method okPressed.

private void okPressed() {
    List<PolicyInformation> policyInformation = jpiCertificatePolicies.getPolicyInformation();
    if (policyInformation.size() == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DCertificatePolicies.ValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
        return;
    }
    CertificatePolicies certificatePolicies = new CertificatePolicies(policyInformation.toArray(new PolicyInformation[policyInformation.size()]));
    try {
        value = certificatePolicies.getEncoded(ASN1Encoding.DER);
    } catch (IOException ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(this);
        dError.setVisible(true);
        return;
    }
    closeDialog();
}
Also used : PolicyInformation(org.bouncycastle.asn1.x509.PolicyInformation) JPolicyInformation(org.kse.gui.crypto.policyinformation.JPolicyInformation) CertificatePolicies(org.bouncycastle.asn1.x509.CertificatePolicies) IOException(java.io.IOException) DError(org.kse.gui.error.DError)

Example 14 with DError

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

the class DNetscapeBaseUrl method okPressed.

private void okPressed() {
    String netscapeBaseUrlStr = jtfNetscapeBaseUrl.getText().trim();
    if (netscapeBaseUrlStr.length() == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DNetscapeBaseUrl.ValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
        return;
    }
    DERIA5String netscapeBaseUrl = new DERIA5String(netscapeBaseUrlStr);
    try {
        value = netscapeBaseUrl.getEncoded(ASN1Encoding.DER);
    } catch (IOException ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(this);
        dError.setVisible(true);
        return;
    }
    closeDialog();
}
Also used : DERIA5String(org.bouncycastle.asn1.DERIA5String) DERIA5String(org.bouncycastle.asn1.DERIA5String) IOException(java.io.IOException) DError(org.kse.gui.error.DError)

Example 15 with DError

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

the class DNetscapeCaPolicyUrl method okPressed.

private void okPressed() {
    String netscapeCaPolicyUrlStr = jtfNetscapeCaPolicyUrl.getText().trim();
    if (netscapeCaPolicyUrlStr.length() == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DNetscapeCaPolicyUrl.ValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
        return;
    }
    DERIA5String netscapeCaPolicyUrl = new DERIA5String(netscapeCaPolicyUrlStr);
    try {
        value = netscapeCaPolicyUrl.getEncoded(ASN1Encoding.DER);
    } catch (IOException ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(this);
        dError.setVisible(true);
        return;
    }
    closeDialog();
}
Also used : DERIA5String(org.bouncycastle.asn1.DERIA5String) DERIA5String(org.bouncycastle.asn1.DERIA5String) IOException(java.io.IOException) 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