Example usage for org.bouncycastle.asn1.x509 GeneralName uniformResourceIdentifier

List of usage examples for org.bouncycastle.asn1.x509 GeneralName uniformResourceIdentifier

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.x509 GeneralName uniformResourceIdentifier.

Prototype

int uniformResourceIdentifier

To view the source code for org.bouncycastle.asn1.x509 GeneralName uniformResourceIdentifier.

Click Source Link

Usage

From source file:com.infinities.keystone4j.ssl.CRLVerifier.java

License:Apache License

/**
 * Extracts all CRL distribution point URLs from the
 * "CRL Distribution Point" extension in a X.509 certificate. If CRL
 * distribution point extension is unavailable, returns an empty list.
 *///from w ww .ja  v a 2s .c  o  m
public static List<String> getCrlDistributionPoints(X509Certificate cert)
        throws CertificateParsingException, IOException {
    byte[] crldpExt = cert.getExtensionValue(X509Extension.cRLDistributionPoints.getId());
    if (crldpExt == null) {
        return new ArrayList<String>();
    }
    ASN1InputStream oAsnInStream = null;
    ASN1InputStream oAsnInStream2 = null;
    try {
        oAsnInStream = new ASN1InputStream(new ByteArrayInputStream(crldpExt));
        DERObject derObjCrlDP = oAsnInStream.readObject();
        DEROctetString dosCrlDP = (DEROctetString) derObjCrlDP;
        byte[] crldpExtOctets = dosCrlDP.getOctets();
        oAsnInStream2 = new ASN1InputStream(new ByteArrayInputStream(crldpExtOctets));
        DERObject derObj2 = oAsnInStream2.readObject();
        CRLDistPoint distPoint = CRLDistPoint.getInstance(derObj2);
        List<String> crlUrls = new ArrayList<String>();
        for (DistributionPoint dp : distPoint.getDistributionPoints()) {
            DistributionPointName dpn = dp.getDistributionPoint();
            // Look for URIs in fullName
            if (dpn != null && dpn.getType() == DistributionPointName.FULL_NAME) {
                GeneralName[] genNames = GeneralNames.getInstance(dpn.getName()).getNames();
                // Look for an URI
                for (int j = 0; j < genNames.length; j++) {
                    if (genNames[j].getTagNo() == GeneralName.uniformResourceIdentifier) {
                        String url = DERIA5String.getInstance(genNames[j].getName()).getString();
                        crlUrls.add(url);
                    }
                }
            }
        }
        return crlUrls;
    } finally {
        if (oAsnInStream != null) {
            oAsnInStream.close();
        }

        if (oAsnInStream2 != null) {
            oAsnInStream2.close();
        }
    }
}

From source file:com.itextpdf.signatures.CertificateUtil.java

License:Open Source License

/**
 * Gets the URL of the Certificate Revocation List for a Certificate
 * @param certificate   the Certificate//from   w  w  w. j  a v a  2 s  . c  o  m
 * @return   the String where you can check if the certificate was revoked
 * @throws CertificateParsingException
 * @throws IOException
 */
public static String getCRLURL(X509Certificate certificate) throws CertificateParsingException {
    ASN1Primitive obj;
    try {
        obj = getExtensionValue(certificate, Extension.cRLDistributionPoints.getId());
    } catch (IOException e) {
        obj = (ASN1Primitive) null;
    }
    if (obj == null) {
        return null;
    }
    CRLDistPoint dist = CRLDistPoint.getInstance(obj);
    DistributionPoint[] dists = dist.getDistributionPoints();
    for (DistributionPoint p : dists) {
        DistributionPointName distributionPointName = p.getDistributionPoint();
        if (DistributionPointName.FULL_NAME != distributionPointName.getType()) {
            continue;
        }
        GeneralNames generalNames = (GeneralNames) distributionPointName.getName();
        GeneralName[] names = generalNames.getNames();
        for (GeneralName name : names) {
            if (name.getTagNo() != GeneralName.uniformResourceIdentifier) {
                continue;
            }
            DERIA5String derStr = DERIA5String.getInstance((ASN1TaggedObject) name.toASN1Primitive(), false);
            return derStr.getString();
        }
    }
    return null;
}

From source file:com.itextpdf.text.pdf.security.CertificateUtil.java

License:Open Source License

/**
 * Gets the URL of the Certificate Revocation List for a Certificate
 * @param certificate   the Certificate/*  w  ww  .  java 2 s.  co m*/
 * @return   the String where you can check if the certificate was revoked
 * @throws CertificateParsingException
 * @throws IOException 
 */
public static String getCRLURL(X509Certificate certificate) throws CertificateParsingException {
    ASN1Primitive obj;
    try {
        obj = getExtensionValue(certificate, Extension.cRLDistributionPoints.getId());
    } catch (IOException e) {
        obj = null;
    }
    if (obj == null) {
        return null;
    }
    CRLDistPoint dist = CRLDistPoint.getInstance(obj);
    DistributionPoint[] dists = dist.getDistributionPoints();
    for (DistributionPoint p : dists) {
        DistributionPointName distributionPointName = p.getDistributionPoint();
        if (DistributionPointName.FULL_NAME != distributionPointName.getType()) {
            continue;
        }
        GeneralNames generalNames = (GeneralNames) distributionPointName.getName();
        GeneralName[] names = generalNames.getNames();
        for (GeneralName name : names) {
            if (name.getTagNo() != GeneralName.uniformResourceIdentifier) {
                continue;
            }
            DERIA5String derStr = DERIA5String.getInstance((ASN1TaggedObject) name.toASN1Primitive(), false);
            return derStr.getString();
        }
    }
    return null;
}

From source file:com.otterca.common.crypto.X509CertificateBuilderImpl.java

License:Apache License

/**
 * @see com.otterca.common.crypto.X509CertificateBuilder#setOcspLocations(URI...)
 *///from   ww  w  .  j  av  a 2s  .co m
// @Override
public X509CertificateBuilder setOcspLocations(URI... locations) {
    ocspLocations.clear();
    for (URI location : locations) {
        ocspLocations.add(new GeneralName(GeneralName.uniformResourceIdentifier, location.toString()));
    }
    return this;
}

From source file:com.otterca.common.crypto.X509CertificateBuilderImpl.java

License:Apache License

/**
 * @see com.otterca.common.crypto.X509CertificateBuilder#setOcspLocation(com.otterca.common.crypto.GeneralName...)
 *///w  w  w  .ja  v a 2 s.c  o  m
@Override
public X509CertificateBuilder setOcspLocations(com.otterca.common.crypto.GeneralName<?>... names) {
    ocspLocations.clear();
    for (com.otterca.common.crypto.GeneralName<?> name : names) {
        switch (name.getType()) {
        case DIRECTORY:
            ocspLocations.add(new GeneralName(GeneralName.directoryName, name.get().toString()));
            break;
        case URI:
            ocspLocations.add(new GeneralName(GeneralName.uniformResourceIdentifier, name.get().toString()));
            break;
        default:
            throw new IllegalArgumentException("unexpected type for OCSP location: " + name.getType());
        }
    }
    return this;
}

From source file:com.otterca.common.crypto.X509CertificateBuilderImpl.java

License:Apache License

/**
 * @see com.otterca.common.crypto.X509CertificateBuilder#setCaIssuersLocations(URI...)
 *///from  w  ww .ja  v  a 2  s . c  o m
// @Override
public X509CertificateBuilder setCaIssuersLocations(URI... locations) {
    caIssuersLocations.clear();
    for (URI location : locations) {
        caIssuersLocations.add(new GeneralName(GeneralName.uniformResourceIdentifier, location.toString()));
    }
    return this;
}

From source file:com.otterca.common.crypto.X509CertificateBuilderImpl.java

License:Apache License

/**
 * @see com.otterca.common.crypto.X509CertificateBuilder#setCaIssuersLocations(com.otterca.common.crypto.GeneralName...)
 *//*  ww  w. j  a  v  a  2s  . com*/
@Override
public X509CertificateBuilder setCaIssuersLocations(com.otterca.common.crypto.GeneralName<?>... names) {
    caIssuersLocations.clear();
    for (com.otterca.common.crypto.GeneralName<?> name : names) {
        switch (name.getType()) {
        case DIRECTORY:
            caIssuersLocations.add(new GeneralName(GeneralName.directoryName, name.get().toString()));
            break;
        case URI:
            caIssuersLocations
                    .add(new GeneralName(GeneralName.uniformResourceIdentifier, name.get().toString()));
            break;
        default:
            throw new IllegalArgumentException("unexpected type for CA Issuer location: " + name.getType());
        }
    }
    return this;
}

From source file:com.otterca.common.crypto.X509CertificateBuilderImpl.java

License:Apache License

/**
 * @see com.otterca.common.crypto.X509CertificateBuilder#setCaRepositories(URI...)
 *///from w  ww  . j a  va2  s.c  o  m
// @Override
public X509CertificateBuilder setCaRepositories(URI... locations) {
    caRepositories.clear();
    for (URI location : locations) {
        caRepositories.add(new GeneralName(GeneralName.uniformResourceIdentifier, location.toString()));
    }
    return this;
}

From source file:com.otterca.common.crypto.X509CertificateBuilderImpl.java

License:Apache License

/**
 * @see com.otterca.common.crypto.X509CertificateBuilder#setCaRepositories(com.otterca.common.crypto.GeneralName...)
 *///  w w  w. j a va 2s  .c o  m
@Override
public X509CertificateBuilder setCaRepositories(com.otterca.common.crypto.GeneralName<?>... names) {
    caRepositories.clear();
    for (com.otterca.common.crypto.GeneralName<?> name : names) {
        switch (name.getType()) {
        case DIRECTORY:
            caRepositories.add(new GeneralName(GeneralName.directoryName, name.get().toString()));
            break;
        case URI:
            caRepositories.add(new GeneralName(GeneralName.uniformResourceIdentifier, name.get().toString()));
            break;
        default:
            throw new IllegalArgumentException("unexpected type for CA repository: " + name.getType());
        }
    }
    return this;
}

From source file:com.otterca.common.crypto.X509CertificateBuilderImpl.java

License:Apache License

/**
 * @see com.otterca.common.crypto.X509CertificateBuilder#setTimestampingLocations(URI...)
 *///  w  w w .j av a2 s .com
// @Override
public X509CertificateBuilder setTimestampingLocations(URI... locations) {
    timestamping.clear();
    for (URI location : locations) {
        timestamping.add(new GeneralName(GeneralName.uniformResourceIdentifier, location.toString()));
    }
    return this;
}