Example usage for org.bouncycastle.asn1.x509 DistributionPointName NAME_RELATIVE_TO_CRL_ISSUER

List of usage examples for org.bouncycastle.asn1.x509 DistributionPointName NAME_RELATIVE_TO_CRL_ISSUER

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.x509 DistributionPointName NAME_RELATIVE_TO_CRL_ISSUER.

Prototype

int NAME_RELATIVE_TO_CRL_ISSUER

To view the source code for org.bouncycastle.asn1.x509 DistributionPointName NAME_RELATIVE_TO_CRL_ISSUER.

Click Source Link

Usage

From source file:com.jlocksmith.util.ExtensionUtil.java

License:Open Source License

/**
 * Get Crl Distribution Points String Value
 * //from  ww w  . j a v a2s .co m
 * @param bytes
 * @return
 * @throws IOException
 */
private String getCrlDistributionPointsStringValue(byte[] bytes) throws IOException {
    CRLDistPoint dps = CRLDistPoint.getInstance(toDERObject(bytes));
    DistributionPoint[] points = dps.getDistributionPoints();

    StringBuffer sb = new StringBuffer();

    for (int i = 0, len = points.length; i < len; i++) {
        DistributionPoint point = points[i];
        DistributionPointName dpn;

        if ((dpn = point.getDistributionPoint()) != null) {
            ASN1TaggedObject tagObj = (ASN1TaggedObject) dpn.toASN1Object();

            switch (tagObj.getTagNo()) {
            case DistributionPointName.FULL_NAME:
                sb.append(localeUtil.getString("CrlDistributionPoint.0.0"));
                sb.append('\n');
                ASN1Sequence seq = (ASN1Sequence) tagObj.getObject();

                for (int j = 0, nLen = seq.size(); j < nLen; j++) {
                    sb.append('\t');
                    sb.append(getGeneralNameString((DERTaggedObject) seq.getObjectAt(j)));
                    sb.append('\n');
                }
                break;
            case DistributionPointName.NAME_RELATIVE_TO_CRL_ISSUER:
                sb.append(localeUtil.getString("CrlDistributionPoint.0.1"));

                sb.append('\t');
                sb.append(tagObj.getObject());
                sb.append('\n');
                break;
            default:
                break;
            }
        }

        ReasonFlags flags;

        if ((flags = point.getReasons()) != null) {
            sb.append(localeUtil.getString("CrlDistributionPoint.1"));
            sb.append('\t');
            sb.append(flags);
            sb.append('\n');
        }

        GeneralNames issuer;

        if ((issuer = point.getCRLIssuer()) != null) {
            sb.append(localeUtil.getString("CrlDistributionPoint.2"));
            sb.append('\n');
            ASN1Sequence seq = (ASN1Sequence) issuer.getDERObject();

            for (int j = 0, iLen = seq.size(); j < iLen; j++) {
                sb.append('\t');
                sb.append(getGeneralNameString((DERTaggedObject) seq.getObjectAt(j)));
                sb.append('\n');
            }
        }
    }

    return sb.toString();
}

From source file:mitm.common.security.crl.PKIXRevocationChecker.java

License:Open Source License

private boolean hasMatchingName(DistributionPointName dpn1, DistributionPointName dpn2, X500Principal issuer)
        throws IOException {
    if (dpn1 == null && dpn2 == null) {
        return true;
    }// www  .ja v a 2  s  .  co m

    if (dpn1 == null || dpn2 == null) {
        return false;
    }

    GeneralName[] generalNames1 = null;
    GeneralName[] generalNames2 = null;

    X500Name name1 = null;
    X500Name name2 = null;

    if (dpn1.getType() == DistributionPointName.NAME_RELATIVE_TO_CRL_ISSUER) {
        name1 = getFullName(issuer, dpn1);
    } else {
        generalNames1 = GeneralNames.getInstance(dpn1.getName()).getNames();
    }

    if (dpn2.getType() == DistributionPointName.NAME_RELATIVE_TO_CRL_ISSUER) {
        name2 = getFullName(issuer, dpn2);
    } else {
        generalNames2 = GeneralNames.getInstance(dpn2.getName()).getNames();
    }

    if (generalNames1 != null && generalNames2 != null) {
        return CollectionUtils.containsAny(Arrays.asList(generalNames1), Arrays.asList(generalNames2));
    }

    if (name1 != null && name2 != null) {
        return name1.equals(name2);
    }

    return name1 != null ? hasMatchingName(name1, generalNames2) : hasMatchingName(name2, generalNames1);
}

From source file:net.sf.portecle.crypto.X509Ext.java

License:Open Source License

/**
 * Get extension value for CRL Distribution Points as a string.
 * //from   w  ww .  j  av a 2 s. com
 * @param bValue The octet string value
 * @return Extension value as a string
 * @throws IOException If an I/O problem occurs
 */
private String getCrlDistributionPointsStringValue(byte[] bValue) throws IOException {
    CRLDistPoint dps = CRLDistPoint.getInstance(bValue);
    DistributionPoint[] points = dps.getDistributionPoints();

    StringBuilder sb = new StringBuilder();
    sb.append("<ul>");

    for (DistributionPoint point : points) {
        DistributionPointName dpn;
        if ((dpn = point.getDistributionPoint()) != null) {
            sb.append("<li>");
            switch (dpn.getType()) {
            case DistributionPointName.FULL_NAME:
                sb.append(RB.getString("CrlDistributionPoint.0.0"));
                sb.append(": ");
                sb.append(getGeneralNamesString((GeneralNames) dpn.getName(), LinkClass.CRL));
                break;
            case DistributionPointName.NAME_RELATIVE_TO_CRL_ISSUER:
                sb.append(RB.getString("CrlDistributionPoint.0.1"));
                sb.append(": ");
                // TODO: need better decode?
                sb.append(stringify(dpn.getName()));
                break;
            default:
                sb.append(RB.getString("UnknownCrlDistributionPointName"));
                sb.append(": ");
                sb.append(stringify(dpn.getName()));
                break;
            }
            sb.append("</li>");
        }

        ReasonFlags flags;
        if ((flags = point.getReasons()) != null) {
            sb.append("<li>");
            sb.append(RB.getString("CrlDistributionPoint.1"));
            sb.append(": ");
            // TODO: decode
            sb.append(stringify(flags));
            sb.append("</li>");
        }

        GeneralNames issuer;
        if ((issuer = point.getCRLIssuer()) != null) {
            sb.append("<li>");
            sb.append(RB.getString("CrlDistributionPoint.2"));
            sb.append(": ");
            sb.append(getGeneralNamesString(issuer, LinkClass.CRL));
            sb.append("</li>");
        }
    }

    sb.append("</ul>");
    return sb.toString();
}