Search in sources :

Example 96 with GeneralNames

use of com.android.org.bouncycastle.asn1.x509.GeneralNames in project keystore-explorer by kaikramer.

the class X509Ext method getIssuerAlternativeNameStringValue.

private String getIssuerAlternativeNameStringValue(byte[] value) throws IOException {
    // @formatter:off
    /*
		 * IssuerAltName ::= GeneralNames
		 *
		 * GeneralNames ::= ASN1Sequence SIZE (1..MAX) OF GeneralName
		 */
    // @formatter:on
    StringBuilder sb = new StringBuilder();
    GeneralNames issuerAltName = GeneralNames.getInstance(value);
    for (GeneralName generalName : issuerAltName.getNames()) {
        sb.append(GeneralNameUtil.toString(generalName));
        sb.append(NEWLINE);
    }
    return sb.toString();
}
Also used : GeneralNames(org.bouncycastle.asn1.x509.GeneralNames) GeneralName(org.bouncycastle.asn1.x509.GeneralName)

Example 97 with GeneralNames

use of com.android.org.bouncycastle.asn1.x509.GeneralNames in project keystore-explorer by kaikramer.

the class X509Ext method getDistributionPointString.

private String getDistributionPointString(DistributionPoint distributionPoint, String baseIndent) throws IOException {
    // @formatter:off
    /*
		 * DistributionPoint ::= ASN1Sequence {
		 * 		distributionPoint [0] DistributionPointName OPTIONAL,
		 * 		reasons [1] ReasonFlags OPTIONAL,
		 * 		cRLIssuer [2] GeneralNames OPTIONAL
		 * }
		 *
		 * GeneralNames ::= ASN1Sequence SIZE (1..MAX) OF GeneralName
		 */
    // @formatter:on
    StringBuilder sb = new StringBuilder();
    DistributionPointName distributionPointName = distributionPoint.getDistributionPoint();
    ReasonFlags reasons = distributionPoint.getReasons();
    GeneralNames crlIssuer = distributionPoint.getCRLIssuer();
    if (distributionPointName != null) {
        // Optional
        sb.append(getDistributionPointNameString(distributionPointName, baseIndent));
    }
    if (reasons != null) {
        // Optional
        sb.append(baseIndent);
        sb.append(res.getString("DistributionPointReasons"));
        sb.append(NEWLINE);
        String[] reasonFlags = getReasonFlagsStrings(reasons);
        for (String reasonFlag : reasonFlags) {
            sb.append(baseIndent);
            sb.append(INDENT);
            sb.append(reasonFlag);
            sb.append(NEWLINE);
        }
    }
    if (crlIssuer != null) {
        // Optional
        sb.append(baseIndent);
        sb.append(res.getString("DistributionPointCrlIssuer"));
        sb.append(NEWLINE);
        for (GeneralName generalName : crlIssuer.getNames()) {
            sb.append(baseIndent);
            sb.append(INDENT);
            sb.append(GeneralNameUtil.toString(generalName));
            sb.append(NEWLINE);
        }
    }
    return sb.toString();
}
Also used : GeneralNames(org.bouncycastle.asn1.x509.GeneralNames) ReasonFlags(org.bouncycastle.asn1.x509.ReasonFlags) DistributionPointName(org.bouncycastle.asn1.x509.DistributionPointName) DERBitString(org.bouncycastle.asn1.DERBitString) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) DERBMPString(org.bouncycastle.asn1.DERBMPString) DERGeneralString(org.bouncycastle.asn1.DERGeneralString) DirectoryString(org.bouncycastle.asn1.x500.DirectoryString) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) DERIA5String(org.bouncycastle.asn1.DERIA5String) GeneralName(org.bouncycastle.asn1.x509.GeneralName)

Example 98 with GeneralNames

use of com.android.org.bouncycastle.asn1.x509.GeneralNames in project keystore-explorer by kaikramer.

the class DAuthorityKeyIdentifier method prepopulateWithAuthorityCertDetails.

private void prepopulateWithAuthorityCertDetails(X500Name authorityCertName, BigInteger authorityCertSerialNumber) {
    if (authorityCertName != null) {
        try {
            GeneralName generalName = new GeneralName(GeneralName.directoryName, authorityCertName);
            GeneralNames generalNames = new GeneralNames(generalName);
            jgnAuthorityCertIssuer.setGeneralNames(generalNames);
        } catch (Exception ex) {
            DError dError = new DError(this, ex);
            dError.setLocationRelativeTo(this);
            dError.setVisible(true);
            return;
        }
    }
    if (authorityCertSerialNumber != null) {
        jtfAuthorityCertSerialNumber.setText("" + authorityCertSerialNumber.toString());
        jtfAuthorityCertSerialNumber.setCaretPosition(0);
    }
}
Also used : JGeneralNames(org.kse.gui.crypto.generalname.JGeneralNames) GeneralNames(org.bouncycastle.asn1.x509.GeneralNames) GeneralName(org.bouncycastle.asn1.x509.GeneralName) IOException(java.io.IOException) DError(org.kse.gui.error.DError)

Example 99 with GeneralNames

use of com.android.org.bouncycastle.asn1.x509.GeneralNames in project keystore-explorer by kaikramer.

the class DAuthorityKeyIdentifier method okPressed.

private void okPressed() {
    byte[] keyIdentifier = jkiKeyIdentifier.getKeyIdentifier();
    GeneralNames authorityCertIssuer = jgnAuthorityCertIssuer.getGeneralNames();
    BigInteger authorityCertSerialNumber = null;
    String authorityCertSerialNumberStr = jtfAuthorityCertSerialNumber.getText().trim();
    if (authorityCertSerialNumberStr.length() != 0) {
        try {
            authorityCertSerialNumber = new BigInteger(authorityCertSerialNumberStr);
            if (authorityCertSerialNumber.compareTo(BigInteger.ONE) < 0) {
                JOptionPane.showMessageDialog(this, res.getString("DAuthorityKeyIdentifier.AuthorityCertSerialNumberNonZero.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
                return;
            }
        } catch (NumberFormatException ex) {
            JOptionPane.showMessageDialog(this, res.getString("DAuthorityKeyIdentifier.AuthorityCertSerialNumberNotInteger.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
            return;
        }
    }
    // serial number are required
    if ((keyIdentifier == null) && ((authorityCertIssuer.getNames().length == 0) || (authorityCertSerialNumber == null))) {
        JOptionPane.showMessageDialog(this, res.getString("DAuthorityKeyIdentifier.ValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
        return;
    }
    AuthorityKeyIdentifier authorityKeyIdentifier;
    if ((keyIdentifier != null) && (authorityCertSerialNumber == null)) {
        // only key identifier
        authorityKeyIdentifier = new AuthorityKeyIdentifier(keyIdentifier);
    } else if (keyIdentifier == null) {
        // only issuer / serial
        authorityKeyIdentifier = new AuthorityKeyIdentifier(authorityCertIssuer, authorityCertSerialNumber);
    } else {
        // both
        authorityKeyIdentifier = new AuthorityKeyIdentifier(keyIdentifier, authorityCertIssuer, authorityCertSerialNumber);
    }
    try {
        value = authorityKeyIdentifier.getEncoded(ASN1Encoding.DER);
    } catch (IOException ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(this);
        dError.setVisible(true);
        return;
    }
    closeDialog();
}
Also used : JGeneralNames(org.kse.gui.crypto.generalname.JGeneralNames) GeneralNames(org.bouncycastle.asn1.x509.GeneralNames) BigInteger(java.math.BigInteger) AuthorityKeyIdentifier(org.bouncycastle.asn1.x509.AuthorityKeyIdentifier) IOException(java.io.IOException) DError(org.kse.gui.error.DError)

Example 100 with GeneralNames

use of com.android.org.bouncycastle.asn1.x509.GeneralNames in project keystore-explorer by kaikramer.

the class DIssuerAlternativeName method okPressed.

private void okPressed() {
    GeneralNames issuerAlternativeName = jgnAlternativeName.getGeneralNames();
    if (issuerAlternativeName.getNames().length == 0) {
        JOptionPane.showMessageDialog(this, res.getString("DIssuerAlternativeName.ValueReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
        return;
    }
    try {
        value = issuerAlternativeName.getEncoded(ASN1Encoding.DER);
    } catch (IOException ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(this);
        dError.setVisible(true);
        return;
    }
    closeDialog();
}
Also used : JGeneralNames(org.kse.gui.crypto.generalname.JGeneralNames) GeneralNames(org.bouncycastle.asn1.x509.GeneralNames) IOException(java.io.IOException) DError(org.kse.gui.error.DError)

Aggregations

GeneralNames (org.bouncycastle.asn1.x509.GeneralNames)87 GeneralName (org.bouncycastle.asn1.x509.GeneralName)75 IOException (java.io.IOException)36 X509Certificate (java.security.cert.X509Certificate)27 X500Name (org.bouncycastle.asn1.x500.X500Name)25 ArrayList (java.util.ArrayList)21 JcaX509CertificateConverter (org.bouncycastle.cert.jcajce.JcaX509CertificateConverter)21 ContentSigner (org.bouncycastle.operator.ContentSigner)20 JcaContentSignerBuilder (org.bouncycastle.operator.jcajce.JcaContentSignerBuilder)19 X509v3CertificateBuilder (org.bouncycastle.cert.X509v3CertificateBuilder)18 BigInteger (java.math.BigInteger)17 CRLDistPoint (org.bouncycastle.asn1.x509.CRLDistPoint)17 DistributionPoint (org.bouncycastle.asn1.x509.DistributionPoint)17 JcaX509v3CertificateBuilder (org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder)16 DERIA5String (org.bouncycastle.asn1.DERIA5String)15 BasicConstraints (org.bouncycastle.asn1.x509.BasicConstraints)15 X509CertificateHolder (org.bouncycastle.cert.X509CertificateHolder)15 X500Principal (javax.security.auth.x500.X500Principal)14 GeneralNames (sun.security.x509.GeneralNames)14 List (java.util.List)13