Search in sources :

Example 41 with GeneralName

use of org.bouncycastle.asn1.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);
        dGeneralNameChooser.setLocationRelativeTo(container);
        dGeneralNameChooser.setVisible(true);
    } else if (container instanceof JFrame) {
        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 42 with GeneralName

use of org.bouncycastle.asn1.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 43 with GeneralName

use of org.bouncycastle.asn1.x509.GeneralName in project keystore-explorer by kaikramer.

the class GeneralNameUtil method toString.

/**
 * Get string representation for all General Names.
 *
 * @param generalName
 *            General name
 * @return String representation of general name
 * @throws IOException
 *             If general name is invalid
 */
public static String toString(GeneralName generalName) throws IOException {
    if (generalName == null) {
        return "";
    }
    switch(generalName.getTagNo()) {
        case GeneralName.ediPartyName:
            /* EDIPartyName ::= SEQUENCE {
			 *      nameAssigner            [0]     DirectoryString OPTIONAL,
			 *      partyName               [1]     DirectoryString }
			 */
            ASN1Sequence ediPartyName = (ASN1Sequence) generalName.getName();
            DirectoryString nameAssigner = DirectoryString.getInstance(ediPartyName.getObjectAt(0));
            DirectoryString partyName = DirectoryString.getInstance(ediPartyName.getObjectAt(1));
            String nameAssignerStr = null;
            if (nameAssigner != null) {
                // Optional
                nameAssignerStr = nameAssigner.getString();
            }
            String partyNameStr = partyName.getString();
            if (nameAssignerStr != null) {
                return MessageFormat.format(res.getString("GeneralNameUtil.EdiPartyGeneralName"), nameAssignerStr, partyNameStr);
            } else {
                return MessageFormat.format(res.getString("GeneralNameUtil.EdiPartyGeneralNameNoAssigner"), partyNameStr);
            }
        case GeneralName.otherName:
            return parseUPN(generalName);
        case GeneralName.x400Address:
            /*
			 * No support for this at the moment - just get a hex dump
			 * The Oracle CertificateFactory blows up if a certificate extension contains this anyway
			 */
            ASN1Encodable x400Address = generalName.getName();
            return MessageFormat.format(res.getString("GeneralNameUtil.X400AddressGeneralName"), HexUtil.getHexString(x400Address.toASN1Primitive().getEncoded(ASN1Encoding.DER)));
        default:
            return safeToString(generalName, true);
    }
}
Also used : ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) DirectoryString(org.bouncycastle.asn1.x500.DirectoryString) DERIA5String(org.bouncycastle.asn1.DERIA5String) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) DirectoryString(org.bouncycastle.asn1.x500.DirectoryString) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable)

Example 44 with GeneralName

use of org.bouncycastle.asn1.x509.GeneralName in project keystore-explorer by kaikramer.

the class GeneralNameUtil method parseUPN.

/**
 * Parse UPN/otherName
 *
 * @param generalName otherName object
 * @return UPN as string
 */
public static String parseUPN(GeneralName generalName) {
    // OtherName ::= SEQUENCE {
    // type-id OBJECT IDENTIFIER,
    // value [0] EXPLICIT ANY DEFINED BY type-id }
    ASN1Sequence otherName = (ASN1Sequence) generalName.getName();
    ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) otherName.getObjectAt(0);
    if (UPN_OID.equals(oid.getId())) {
        DERTaggedObject derTaggedObject = (DERTaggedObject) otherName.getObjectAt(1);
        DERUTF8String upn = DERUTF8String.getInstance(derTaggedObject.getObject());
        return MessageFormat.format(res.getString("GeneralNameUtil.OtherGeneralName"), "UPN", upn.getString());
    }
    // fallback to generic handling
    ASN1Encodable value = otherName.getObjectAt(1);
    try {
        return MessageFormat.format(res.getString("GeneralNameUtil.OtherGeneralName"), ObjectIdUtil.toString(oid), HexUtil.getHexString(value.toASN1Primitive().getEncoded(ASN1Encoding.DER)));
    } catch (IOException e) {
        return MessageFormat.format(res.getString("GeneralNameUtil.OtherGeneralName"), ObjectIdUtil.toString(oid), "");
    }
}
Also used : DERUTF8String(org.bouncycastle.asn1.DERUTF8String) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) IOException(java.io.IOException) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 45 with GeneralName

use of org.bouncycastle.asn1.x509.GeneralName in project Spark by igniterealtime.

the class SparkTrustManager method loadCRL.

public Collection<X509CRL> loadCRL(X509Certificate[] chain) throws IOException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, CertStoreException, CRLException, CertificateException {
    // for each certificate in chain
    for (X509Certificate cert : chain) {
        if (cert.getExtensionValue(Extension.cRLDistributionPoints.getId()) != null) {
            ASN1Primitive primitive = JcaX509ExtensionUtils.parseExtensionValue(cert.getExtensionValue(Extension.cRLDistributionPoints.getId()));
            // extract distribution point extension
            CRLDistPoint distPoint = CRLDistPoint.getInstance(primitive);
            DistributionPoint[] dp = distPoint.getDistributionPoints();
            // each distribution point extension can hold number of distribution points
            for (DistributionPoint d : dp) {
                DistributionPointName dpName = d.getDistributionPoint();
                // Look for URIs in fullName
                if (dpName != null && dpName.getType() == DistributionPointName.FULL_NAME) {
                    GeneralName[] genNames = GeneralNames.getInstance(dpName.getName()).getNames();
                    // Look for an URI
                    for (GeneralName genName : genNames) {
                        // extract url
                        URL url = new URL(genName.getName().toString());
                        try {
                            // download from Internet to the collection
                            crlCollection.add(downloadCRL(url));
                        } catch (CertificateException | CRLException e) {
                            throw new CRLException("Couldn't download CRL");
                        }
                    }
                }
            }
        } else {
            Log.warning("Certificate " + cert.getSubjectX500Principal().getName().toString() + " have no CRLs");
        }
        // parameters for cert store is collection type, using collection with crl create parameters
        CollectionCertStoreParameters params = new CollectionCertStoreParameters(crlCollection);
        // this parameters are next used for creation of certificate store with crls
        crlStore = CertStore.getInstance("Collection", params);
    }
    return crlCollection;
}
Also used : DistributionPointName(org.bouncycastle.asn1.x509.DistributionPointName) CertificateException(java.security.cert.CertificateException) X509Certificate(java.security.cert.X509Certificate) URL(java.net.URL) CollectionCertStoreParameters(java.security.cert.CollectionCertStoreParameters) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint) GeneralName(org.bouncycastle.asn1.x509.GeneralName) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive) CRLDistPoint(org.bouncycastle.asn1.x509.CRLDistPoint) CRLException(java.security.cert.CRLException)

Aggregations

GeneralName (org.bouncycastle.asn1.x509.GeneralName)144 GeneralNames (org.bouncycastle.asn1.x509.GeneralNames)68 IOException (java.io.IOException)59 DERIA5String (org.bouncycastle.asn1.DERIA5String)44 ArrayList (java.util.ArrayList)40 X500Name (org.bouncycastle.asn1.x500.X500Name)37 CRLDistPoint (org.bouncycastle.asn1.x509.CRLDistPoint)34 DistributionPoint (org.bouncycastle.asn1.x509.DistributionPoint)33 X509Certificate (java.security.cert.X509Certificate)32 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)31 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)31 DEROctetString (org.bouncycastle.asn1.DEROctetString)28 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)25 List (java.util.List)23 BigInteger (java.math.BigInteger)22 DERSequence (org.bouncycastle.asn1.DERSequence)22 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)21 DirectoryString (org.bouncycastle.asn1.x500.DirectoryString)20 JcaContentSignerBuilder (org.bouncycastle.operator.jcajce.JcaContentSignerBuilder)19 GeneralName (org.apache.harmony.security.x509.GeneralName)18