Search in sources :

Example 96 with GeneralName

use of org.mozilla.jss.netscape.security.x509.GeneralName in project keystore-explorer by kaikramer.

the class JGeneralName method editGeneralName.

private void editGeneralName() {
    Container container = getTopLevelAncestor();
    DGeneralNameChooser dGeneralNameChooser = null;
    if (container instanceof JDialog) {
        dGeneralNameChooser = new DGeneralNameChooser((JDialog) container, title, generalName);
    } else {
        dGeneralNameChooser = new DGeneralNameChooser((JFrame) container, title, generalName);
    }
    dGeneralNameChooser.setLocationRelativeTo(container);
    dGeneralNameChooser.setVisible(true);
    GeneralName newGeneralName = dGeneralNameChooser.getGeneralName();
    if (newGeneralName == null) {
        return;
    }
    setGeneralName(newGeneralName);
}
Also used : Container(java.awt.Container) JFrame(javax.swing.JFrame) GeneralName(org.bouncycastle.asn1.x509.GeneralName) JDialog(javax.swing.JDialog)

Example 97 with GeneralName

use of org.mozilla.jss.netscape.security.x509.GeneralName in project keystore-explorer by kaikramer.

the class DGeneralSubtreeChooser method okPressed.

private void okPressed() {
    GeneralName base = jgnBase.getGeneralName();
    if (base == null) {
        JOptionPane.showMessageDialog(this, res.getString("DGeneralSubtreeChooser.BaseValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
        return;
    }
    int minimum = -1;
    String minimumStr = jtfMinimum.getText().trim();
    if (minimumStr.length() == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DGeneralSubtreeChooser.MinimumValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
        return;
    }
    if (minimumStr.length() > 0) {
        try {
            minimum = Integer.parseInt(minimumStr);
        } catch (NumberFormatException ex) {
            JOptionPane.showMessageDialog(this, res.getString("DGeneralSubtreeChooser.InvalidMinimumValue.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
            return;
        }
        if (minimum < 0) {
            JOptionPane.showMessageDialog(this, res.getString("DGeneralSubtreeChooser.InvalidMinimumValue.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
            return;
        }
    }
    int maximum = -1;
    String maximumStr = jtfMaximum.getText().trim();
    if (maximumStr.length() > 0) {
        try {
            maximum = Integer.parseInt(maximumStr);
        } catch (NumberFormatException ex) {
            JOptionPane.showMessageDialog(this, res.getString("DGeneralSubtreeChooser.InvalidMaximumValue.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
            return;
        }
        if (maximum < 0) {
            JOptionPane.showMessageDialog(this, res.getString("DGeneralSubtreeChooser.InvalidMaximumValue.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
            return;
        }
    }
    BigInteger asn1Minimum = (minimum != -1) ? BigInteger.valueOf(minimum) : null;
    BigInteger asn1Maximum = (maximum != -1) ? BigInteger.valueOf(maximum) : null;
    generalSubtree = new GeneralSubtree(base, asn1Minimum, asn1Maximum);
    closeDialog();
}
Also used : BigInteger(java.math.BigInteger) JGeneralName(org.kse.gui.crypto.generalname.JGeneralName) GeneralName(org.bouncycastle.asn1.x509.GeneralName) GeneralSubtree(org.bouncycastle.asn1.x509.GeneralSubtree)

Example 98 with GeneralName

use of org.mozilla.jss.netscape.security.x509.GeneralName in project keystore-explorer by kaikramer.

the class DGeneralNameChooser method okPressed.

private void okPressed() {
    try {
        GeneralName newGeneralName = null;
        if (jrbDirectoryName.isSelected()) {
            X500Name directoryName = jdnDirectoryName.getDistinguishedName();
            if (directoryName == null) {
                JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.DirectoryNameValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
                return;
            }
            newGeneralName = new GeneralName(GeneralName.directoryName, directoryName);
        } else if (jrbDnsName.isSelected()) {
            String dnsName = jtfDnsName.getText().trim();
            if (dnsName.length() == 0) {
                JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.DnsNameValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
                return;
            }
            newGeneralName = new GeneralName(GeneralName.dNSName, new DERIA5String(dnsName));
        } else if (jrbIpAddress.isSelected()) {
            String ipAddress = jtfIpAddress.getText().trim();
            if (ipAddress.length() == 0) {
                JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.IpAddressValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
                return;
            }
            if (ipAddress.indexOf('/') == -1) {
                if (!IPAddress.isValid(ipAddress)) {
                    JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.NotAValidIP.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
                    return;
                }
            } else {
                if (!IPAddress.isValidWithNetMask(ipAddress)) {
                    JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.NotAValidIP.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
                    return;
                }
            }
            newGeneralName = new GeneralName(GeneralName.iPAddress, ipAddress);
        } else if (jrbRegisteredId.isSelected()) {
            ASN1ObjectIdentifier registeredId = joiRegisteredId.getObjectId();
            if (registeredId == null) {
                JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.RegisteredIdValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
                return;
            }
            newGeneralName = new GeneralName(GeneralName.registeredID, registeredId);
        } else if (jrbRfc822Name.isSelected()) {
            String rfc822Name = jtfRfc822Name.getText().trim();
            if (rfc822Name.length() == 0) {
                JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.Rfc822NameValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
                return;
            }
            newGeneralName = new GeneralName(GeneralName.rfc822Name, new DERIA5String(rfc822Name));
        } else if (jrbUniformResourceIdentifier.isSelected()) {
            String uniformResourceIdentifier = jtfUniformResourceIdentifier.getText().trim();
            if (uniformResourceIdentifier.length() == 0) {
                JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.UniformResourceIdentifierValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
                return;
            }
            newGeneralName = new GeneralName(GeneralName.uniformResourceIdentifier, new DERIA5String(uniformResourceIdentifier));
        } else if (jrbPrincipalName.isSelected()) {
            String upnString = jtfPrincipalName.getText().trim();
            if (upnString.length() == 0) {
                JOptionPane.showMessageDialog(this, res.getString("DGeneralNameChooser.PrincipalNameValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
                return;
            }
            ASN1EncodableVector asn1Vector = new ASN1EncodableVector();
            asn1Vector.add(new ASN1ObjectIdentifier(GeneralNameUtil.UPN_OID));
            asn1Vector.add(new DERTaggedObject(true, 0, new DERUTF8String(upnString)));
            newGeneralName = new GeneralName(GeneralName.otherName, new DERSequence(asn1Vector));
        }
        generalName = newGeneralName;
    } catch (Exception e) {
        DError.displayError(this, e);
        return;
    }
    closeDialog();
}
Also used : DERUTF8String(org.bouncycastle.asn1.DERUTF8String) DERIA5String(org.bouncycastle.asn1.DERIA5String) DERSequence(org.bouncycastle.asn1.DERSequence) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) GeneralName(org.bouncycastle.asn1.x509.GeneralName) X500Name(org.bouncycastle.asn1.x500.X500Name) DERIA5String(org.bouncycastle.asn1.DERIA5String) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 99 with GeneralName

use of org.mozilla.jss.netscape.security.x509.GeneralName in project keystore-explorer by kaikramer.

the class X509Ext method getProcurationStringValue.

private static String getProcurationStringValue(byte[] octets) throws IOException {
    // @formatter:off
    /*
			ProcurationSyntax ::= SEQUENCE
			{
				country [1] EXPLICIT PrintableString(SIZE(2)) OPTIONAL,
				typeOfSubstitution [2] EXPLICIT DirectoryString(SIZE(1..128)) OPTIONAL,
				signingFor [3] EXPLICIT SigningFor
			}

			SigningFor ::= CHOICE
			{
				thirdPerson GeneralName,
				certRef IssuerSerial
			}
		 */
    // @formatter:on
    StringBuilder sb = new StringBuilder();
    ProcurationSyntax procurationSyntax = ProcurationSyntax.getInstance(octets);
    String country = procurationSyntax.getCountry();
    DirectoryString typeOfSubstitution = procurationSyntax.getTypeOfSubstitution();
    GeneralName thirdPerson = procurationSyntax.getThirdPerson();
    IssuerSerial certRef = procurationSyntax.getCertRef();
    if (country != null) {
        sb.append(MessageFormat.format(res.getString("Procuration.Country"), country));
        sb.append(NEWLINE);
    }
    if (typeOfSubstitution != null) {
        sb.append(MessageFormat.format(res.getString("Procuration.TypeOfSubstitution"), typeOfSubstitution.toString()));
        sb.append(NEWLINE);
    }
    if (thirdPerson != null) {
        sb.append(MessageFormat.format(res.getString("Procuration.ThirdPerson"), GeneralNameUtil.toString(thirdPerson)));
        sb.append(NEWLINE);
    }
    if (certRef != null) {
        sb.append(res.getString("Procuration.CertRef"));
        sb.append(NEWLINE);
        sb.append(INDENT);
        sb.append(res.getString("Procuration.CertRef.Issuer"));
        for (GeneralName generalName : certRef.getIssuer().getNames()) {
            sb.append(INDENT);
            sb.append(INDENT);
            sb.append(GeneralNameUtil.toString(generalName));
            sb.append(NEWLINE);
        }
        sb.append(NEWLINE);
        sb.append(INDENT);
        sb.append(MessageFormat.format(res.getString("Procuration.CertRef.SN"), HexUtil.getHexString(certRef.getSerial().getValue())));
        sb.append(NEWLINE);
    }
    return sb.toString();
}
Also used : IssuerSerial(org.bouncycastle.asn1.x509.IssuerSerial) ProcurationSyntax(org.bouncycastle.asn1.isismtt.x509.ProcurationSyntax) DERBitString(org.bouncycastle.asn1.DERBitString) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) DERGeneralString(org.bouncycastle.asn1.DERGeneralString) ASN1IA5String(org.bouncycastle.asn1.ASN1IA5String) DirectoryString(org.bouncycastle.asn1.x500.DirectoryString) ASN1BitString(org.bouncycastle.asn1.ASN1BitString) DEROctetString(org.bouncycastle.asn1.DEROctetString) ASN1BMPString(org.bouncycastle.asn1.ASN1BMPString) DERIA5String(org.bouncycastle.asn1.DERIA5String) ASN1PrintableString(org.bouncycastle.asn1.ASN1PrintableString) DirectoryString(org.bouncycastle.asn1.x500.DirectoryString) GeneralName(org.bouncycastle.asn1.x509.GeneralName)

Example 100 with GeneralName

use of org.mozilla.jss.netscape.security.x509.GeneralName in project keystore-explorer by kaikramer.

the class X509Ext method getSubjectInformationAccessStringValue.

private static String getSubjectInformationAccessStringValue(byte[] value) throws IOException {
    // @formatter:off
    /*
		 * SubjectInfoAccessSyntax ::= ASN1Sequence SIZE (1..MAX) OF
		 * AccessDescription
		 *
		 * AccessDescription ::= ASN1Sequence { accessMethod OBJECT IDENTIFIER,
		 * accessLocation GeneralName }
		 */
    // @formatter:on
    StringBuilder sb = new StringBuilder();
    SubjectInfoAccess subjectInfoAccess = SubjectInfoAccess.getInstance(value);
    int accessDesc = 0;
    for (AccessDescription accessDescription : subjectInfoAccess.getAccessDescriptionList()) {
        accessDesc++;
        // Convert OID to access method
        ASN1ObjectIdentifier accessMethod = accessDescription.getAccessMethod();
        AccessMethodType accessMethodType = AccessMethodType.resolveOid(accessMethod.getId());
        String accessMethodStr = null;
        if (accessMethodType != null) {
            accessMethodStr = accessMethodType.friendly();
        } else {
            // Unrecognised Access Method OID
            accessMethodStr = ObjectIdUtil.toString(accessMethod);
        }
        GeneralName accessLocation = accessDescription.getAccessLocation();
        String accessLocationStr = GeneralNameUtil.toString(accessLocation);
        sb.append(MessageFormat.format(res.getString("SubjectInformationAccess"), accessDesc));
        sb.append(NEWLINE);
        sb.append(INDENT);
        sb.append(MessageFormat.format(res.getString("AccessMethod"), accessMethodStr));
        sb.append(NEWLINE);
        sb.append(INDENT);
        sb.append(res.getString("AccessLocation"));
        sb.append(NEWLINE);
        sb.append(INDENT);
        sb.append(INDENT);
        sb.append(accessLocationStr);
        sb.append(NEWLINE);
    }
    return sb.toString();
}
Also used : AccessDescription(org.bouncycastle.asn1.x509.AccessDescription) DERBitString(org.bouncycastle.asn1.DERBitString) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) DERGeneralString(org.bouncycastle.asn1.DERGeneralString) ASN1IA5String(org.bouncycastle.asn1.ASN1IA5String) DirectoryString(org.bouncycastle.asn1.x500.DirectoryString) ASN1BitString(org.bouncycastle.asn1.ASN1BitString) DEROctetString(org.bouncycastle.asn1.DEROctetString) ASN1BMPString(org.bouncycastle.asn1.ASN1BMPString) DERIA5String(org.bouncycastle.asn1.DERIA5String) ASN1PrintableString(org.bouncycastle.asn1.ASN1PrintableString) GeneralName(org.bouncycastle.asn1.x509.GeneralName) IssuingDistributionPoint(org.bouncycastle.asn1.x509.IssuingDistributionPoint) CRLDistPoint(org.bouncycastle.asn1.x509.CRLDistPoint) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Aggregations

GeneralName (org.bouncycastle.asn1.x509.GeneralName)238 GeneralNames (org.bouncycastle.asn1.x509.GeneralNames)113 IOException (java.io.IOException)110 ArrayList (java.util.ArrayList)76 DERIA5String (org.bouncycastle.asn1.DERIA5String)53 X500Name (org.bouncycastle.asn1.x500.X500Name)52 X509Certificate (java.security.cert.X509Certificate)51 CRLDistPoint (org.bouncycastle.asn1.x509.CRLDistPoint)48 DistributionPoint (org.bouncycastle.asn1.x509.DistributionPoint)47 List (java.util.List)40 BigInteger (java.math.BigInteger)37 JcaContentSignerBuilder (org.bouncycastle.operator.jcajce.JcaContentSignerBuilder)37 DEROctetString (org.bouncycastle.asn1.DEROctetString)36 ContentSigner (org.bouncycastle.operator.ContentSigner)35 JcaX509CertificateConverter (org.bouncycastle.cert.jcajce.JcaX509CertificateConverter)31 GeneralName (com.github.zhenwei.core.asn1.x509.GeneralName)30 Date (java.util.Date)30 X500Principal (javax.security.auth.x500.X500Principal)29 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)29 JcaX509v3CertificateBuilder (org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder)29