Example usage for org.bouncycastle.asn1.x509 X509Extensions AuthorityInfoAccess

List of usage examples for org.bouncycastle.asn1.x509 X509Extensions AuthorityInfoAccess

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.x509 X509Extensions AuthorityInfoAccess.

Prototype

ASN1ObjectIdentifier AuthorityInfoAccess

To view the source code for org.bouncycastle.asn1.x509 X509Extensions AuthorityInfoAccess.

Click Source Link

Document

Authority Info Access

Usage

From source file:bluecrystal.bcdeps.helper.DerEncoder.java

License:Open Source License

public static List<String> extractOCSPUrl(X509Certificate nextCert) throws CRLException {
    List<String> OCSPUrl = new ArrayList<String>();
    // LOG.debug("MISSING!!");

    ASN1Primitive aiaExt = getExtensionValue(nextCert, X509Extensions.AuthorityInfoAccess.getId());
    if (aiaExt != null) {
        extractAuthorityInformationAccess(OCSPUrl, aiaExt);
    }//from w  w  w  .j  av  a2  s  .  co m
    return OCSPUrl;
}

From source file:com.itextpdf.text.pdf.PdfPKCS7.java

License:Open Source License

/**
 * Retrieves the OCSP URL from the given certificate.
 * @param certificate the certificate//from  ww  w. j  a v  a 2 s  .co m
 * @return the URL or null
 * @throws CertificateParsingException on error
 * @since   2.1.6
 */
public static String getOCSPURL(X509Certificate certificate) throws CertificateParsingException {
    try {
        DERObject obj = getExtensionValue(certificate, X509Extensions.AuthorityInfoAccess.getId());
        if (obj == null) {
            return null;
        }

        ASN1Sequence AccessDescriptions = (ASN1Sequence) obj;
        for (int i = 0; i < AccessDescriptions.size(); i++) {
            ASN1Sequence AccessDescription = (ASN1Sequence) AccessDescriptions.getObjectAt(i);
            if (AccessDescription.size() != 2) {
                continue;
            } else {
                if (AccessDescription.getObjectAt(0) instanceof DERObjectIdentifier
                        && ((DERObjectIdentifier) AccessDescription.getObjectAt(0)).getId()
                                .equals("1.3.6.1.5.5.7.48.1")) {
                    String AccessLocation = getStringFromGeneralName(
                            (DERObject) AccessDescription.getObjectAt(1));
                    if (AccessLocation == null) {
                        return "";
                    } else {
                        return AccessLocation;
                    }
                }
            }
        }
    } catch (Exception e) {
    }
    return null;
}

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

License:Apache License

/**
 * Set Authority Information Access (RFC5280 4.2.2)
 *//*from   w  ww  .ja va  2  s.  co m*/
protected void setAuthorityInfoAccess() {
    if (!ocspLocations.isEmpty() || !caIssuersLocations.isEmpty()) {
        ASN1Encodable[] values = new ASN1Encodable[ocspLocations.size() + caIssuersLocations.size()];

        // add OCSP locations
        for (int i = 0; i < ocspLocations.size(); i++) {
            values[i] = new AccessDescription(AccessDescription.id_ad_ocsp, ocspLocations.get(i));
        }

        // add CA Issuers locations
        int offset = ocspLocations.size();
        for (int i = 0; i < caIssuersLocations.size(); i++) {
            values[i + offset] = new AccessDescription(AccessDescription.id_ad_caIssuers,
                    caIssuersLocations.get(i));
        }
        DERSequence seq = new DERSequence(values);
        generator.addExtension(X509Extensions.AuthorityInfoAccess, false, seq);
    }
}

From source file:com.viettel.hqmc.DAO.FilesDAO.java

private static List<String> getAIALocations(X509Certificate cert) throws Exception {

    //Gets the DER-encoded OCTET string for the extension value for Authority information access Points
    byte[] aiaExtensionValue = cert.getExtensionValue(X509Extensions.AuthorityInfoAccess.getId());
    if (aiaExtensionValue == null) {
        throw new Exception("Certificate doesn't have authority " + "information access points");
    }//from  www.j  av a  2  s .c o  m
    //might have to pass an ByteArrayInputStream(aiaExtensionValue)
    ASN1InputStream asn1In = new ASN1InputStream(aiaExtensionValue);
    AuthorityInformationAccess authorityInformationAccess;

    try {
        DEROctetString aiaDEROctetString = (DEROctetString) (asn1In.readObject());
        ASN1InputStream asn1InOctets = new ASN1InputStream(aiaDEROctetString.getOctets());
        ASN1Sequence aiaASN1Sequence = (ASN1Sequence) asn1InOctets.readObject();
        authorityInformationAccess = AuthorityInformationAccess.getInstance(aiaASN1Sequence);
    } catch (IOException ex) {
        LogUtil.addLog(ex);//binhnt sonar a160901
        throw new Exception("Cannot read certificate to get OCSP URLs", ex);
    }

    List<String> ocspUrlList = new ArrayList<String>();
    AccessDescription[] accessDescriptions = authorityInformationAccess.getAccessDescriptions();
    for (AccessDescription accessDescription : accessDescriptions) {

        GeneralName gn = accessDescription.getAccessLocation();
        if (gn.getTagNo() == GeneralName.uniformResourceIdentifier) {
            DERIA5String str = DERIA5String.getInstance(gn.getName());
            String accessLocation = str.getString();
            ocspUrlList.add(accessLocation);
        }
    }
    if (ocspUrlList.isEmpty()) {
        throw new Exception("Cant get OCSP urls from certificate");
    }

    return ocspUrlList;
}

From source file:es.uji.security.crypto.pdf.PdfPKCS7TSA.java

License:Mozilla Public License

/**                                                                                                       
 * Retrieves the OCSP URL from the given certificate.                                                     
 * @param certificate the certificate                                                                     
 * @return the URL or null                                                                                
 * @throws CertificateParsingException on error                                                           
 * @since   2.1.6                                                                                         
 *//*from   w w w  . j  a  v a2  s  .  co  m*/
public static String getOCSPURL(X509Certificate certificate) throws CertificateParsingException {
    try {
        DERObject obj = getExtensionValue(certificate, X509Extensions.AuthorityInfoAccess.getId());
        if (obj == null) {
            return null;
        }

        ASN1Sequence AccessDescriptions = (ASN1Sequence) obj;
        for (int i = 0; i < AccessDescriptions.size(); i++) {
            ASN1Sequence AccessDescription = (ASN1Sequence) AccessDescriptions.getObjectAt(i);
            if (AccessDescription.size() != 2) {
                continue;
            } else {
                if ((AccessDescription.getObjectAt(0) instanceof DERObjectIdentifier)
                        && ((DERObjectIdentifier) AccessDescription.getObjectAt(0)).getId()
                                .equals("1.3.6.1.5.5.7.48.1")) {
                    String AccessLocation = getStringFromGeneralName(
                            (DERObject) AccessDescription.getObjectAt(1));
                    if (AccessLocation == null) {
                        return "";
                    } else {
                        return AccessLocation;
                    }
                }
            }
        }
    } catch (Exception e) {
    }
    return null;
}

From source file:eu.europa.ec.markt.dss.validation.certificate.AIACertificateSource.java

License:Open Source License

@SuppressWarnings("deprecation")
private String getAccessLocation(X509Certificate certificate, DERObjectIdentifier accessMethod) {
    try {// w w w  .j ava 2s.  co m

        byte[] authInfoAccessExtensionValue = certificate
                .getExtensionValue(X509Extensions.AuthorityInfoAccess.getId());

        /* If the extension is not there, then return null */
        if (null == authInfoAccessExtensionValue) {
            return null;
        }

        /* Parse the extension */
        AuthorityInformationAccess authorityInformationAccess;
        DEROctetString oct = (DEROctetString) (new ASN1InputStream(
                new ByteArrayInputStream(authInfoAccessExtensionValue)).readObject());
        authorityInformationAccess = new AuthorityInformationAccess(
                (ASN1Sequence) new ASN1InputStream(oct.getOctets()).readObject());

        AccessDescription[] accessDescriptions = authorityInformationAccess.getAccessDescriptions();
        for (AccessDescription accessDescription : accessDescriptions) {
            LOG.fine("access method: " + accessDescription.getAccessMethod());
            boolean correctAccessMethod = accessDescription.getAccessMethod().equals(accessMethod);
            if (!correctAccessMethod) {
                continue;
            }
            GeneralName gn = accessDescription.getAccessLocation();
            if (gn.getTagNo() != GeneralName.uniformResourceIdentifier) {
                LOG.fine("not a uniform resource identifier");
                continue;
            }
            DERIA5String str = (DERIA5String) ((DERTaggedObject) gn.getDERObject()).getObject();
            String accessLocation = str.getString();
            LOG.fine("access location: " + accessLocation);
            return accessLocation;
        }
        return null;

    } catch (IOException e) {
        throw new RuntimeException("IO error: " + e.getMessage(), e);
    }
}

From source file:eu.europa.ec.markt.dss.validation.ocsp.OnlineOCSPSource.java

License:Open Source License

@SuppressWarnings("deprecation")
private String getAccessLocation(X509Certificate certificate, DERObjectIdentifier accessMethod)
        throws IOException {
    byte[] authInfoAccessExtensionValue = certificate
            .getExtensionValue(X509Extensions.AuthorityInfoAccess.getId());
    if (null == authInfoAccessExtensionValue) {
        return null;
    }//from   w  w w .ja  v  a2  s  . c  o  m
    AuthorityInformationAccess authorityInformationAccess;

    DEROctetString oct = (DEROctetString) (new ASN1InputStream(
            new ByteArrayInputStream(authInfoAccessExtensionValue)).readObject());
    authorityInformationAccess = new AuthorityInformationAccess(
            (ASN1Sequence) new ASN1InputStream(oct.getOctets()).readObject());

    AccessDescription[] accessDescriptions = authorityInformationAccess.getAccessDescriptions();
    for (AccessDescription accessDescription : accessDescriptions) {
        LOG.fine("access method: " + accessDescription.getAccessMethod());
        boolean correctAccessMethod = accessDescription.getAccessMethod().equals(accessMethod);
        if (!correctAccessMethod) {
            continue;
        }
        GeneralName gn = accessDescription.getAccessLocation();
        if (gn.getTagNo() != GeneralName.uniformResourceIdentifier) {
            LOG.fine("not a uniform resource identifier");
            continue;
        }
        DERIA5String str = (DERIA5String) ((DERTaggedObject) gn.getDERObject()).getObject();
        String accessLocation = str.getString();
        LOG.fine("access location: " + accessLocation);
        return accessLocation;
    }
    return null;

}

From source file:org.apache.synapse.transport.certificatevalidation.ocsp.OCSPVerifier.java

License:Apache License

/**
 * Authority Information Access (AIA) is a non-critical extension in an X509 Certificate. This contains the
 * URL of the OCSP endpoint if one is available.
 * TODO: This might contain non OCSP urls as well. Handle this.
 *
 * @param cert is the certificate//from  w  w  w .j  a v  a  2  s  .com
 * @return a lit of URLs in AIA extension of the certificate which will hopefully contain an OCSP endpoint.
 * @throws CertificateVerificationException
 *
 */
private List<String> getAIALocations(X509Certificate cert) throws CertificateVerificationException {

    //Gets the DER-encoded OCTET string for the extension value for Authority information access Points
    byte[] aiaExtensionValue = cert.getExtensionValue(X509Extensions.AuthorityInfoAccess.getId());
    if (aiaExtensionValue == null)
        throw new CertificateVerificationException(
                "Certificate Doesnt have Authority Information Access points");
    //might have to pass an ByteArrayInputStream(aiaExtensionValue)
    ASN1InputStream asn1In = new ASN1InputStream(aiaExtensionValue);
    AuthorityInformationAccess authorityInformationAccess;

    try {
        DEROctetString aiaDEROctetString = (DEROctetString) (asn1In.readObject());
        ASN1InputStream asn1Inoctets = new ASN1InputStream(aiaDEROctetString.getOctets());
        ASN1Sequence aiaASN1Sequence = (ASN1Sequence) asn1Inoctets.readObject();
        authorityInformationAccess = new AuthorityInformationAccess(aiaASN1Sequence);
    } catch (IOException e) {
        throw new CertificateVerificationException("Cannot read certificate to get OSCP urls", e);
    }

    List<String> ocspUrlList = new ArrayList<String>();
    AccessDescription[] accessDescriptions = authorityInformationAccess.getAccessDescriptions();
    for (AccessDescription accessDescription : accessDescriptions) {

        GeneralName gn = accessDescription.getAccessLocation();
        if (gn.getTagNo() == GeneralName.uniformResourceIdentifier) {
            DERIA5String str = DERIA5String.getInstance(gn.getName());
            String accessLocation = str.getString();
            ocspUrlList.add(accessLocation);
        }
    }
    if (ocspUrlList.isEmpty())
        throw new CertificateVerificationException("Cant get OCSP urls from certificate");

    return ocspUrlList;
}

From source file:org.apache.synapse.transport.utils.sslcert.ocsp.OCSPVerifier.java

License:Apache License

/**
 * Authority Information Access (AIA) is a non-critical extension in an X509 Certificate. This contains the
 * URL of the OCSP endpoint if one is available.
 * TODO: This might contain non OCSP urls as well. Handle this.
 *
 * @param cert is the certificate/*from www.java  2  s  . c  o  m*/
 * @return a lit of URLs in AIA extension of the certificate which will hopefully contain an OCSP endpoint.
 * @throws CertificateVerificationException
 *
 */
private List<String> getAIALocations(X509Certificate cert) throws CertificateVerificationException {

    //Gets the DER-encoded OCTET string for the extension value for Authority information access Points
    byte[] aiaExtensionValue = cert.getExtensionValue(X509Extensions.AuthorityInfoAccess.getId());
    if (aiaExtensionValue == null) {
        throw new CertificateVerificationException(
                "Certificate doesn't have authority " + "information access points");
    }
    //might have to pass an ByteArrayInputStream(aiaExtensionValue)
    ASN1InputStream asn1In = new ASN1InputStream(aiaExtensionValue);
    AuthorityInformationAccess authorityInformationAccess;

    try {
        DEROctetString aiaDEROctetString = (DEROctetString) (asn1In.readObject());
        ASN1InputStream asn1InOctets = new ASN1InputStream(aiaDEROctetString.getOctets());
        ASN1Sequence aiaASN1Sequence = (ASN1Sequence) asn1InOctets.readObject();
        authorityInformationAccess = AuthorityInformationAccess.getInstance(aiaASN1Sequence);
    } catch (IOException e) {
        throw new CertificateVerificationException("Cannot read certificate to get OCSP URLs", e);
    }

    List<String> ocspUrlList = new ArrayList<String>();
    AccessDescription[] accessDescriptions = authorityInformationAccess.getAccessDescriptions();
    for (AccessDescription accessDescription : accessDescriptions) {

        GeneralName gn = accessDescription.getAccessLocation();
        if (gn.getTagNo() == GeneralName.uniformResourceIdentifier) {
            DERIA5String str = DERIA5String.getInstance(gn.getName());
            String accessLocation = str.getString();
            ocspUrlList.add(accessLocation);
        }
    }
    if (ocspUrlList.isEmpty()) {
        throw new CertificateVerificationException("Cant get OCSP urls from certificate");
    }

    return ocspUrlList;
}

From source file:org.ejbca.core.model.ca.certextensions.standard.AuthorityInformationAccess.java

License:Open Source License

@Override
public void init(final CertificateProfile certProf) {
    super.setOID(X509Extensions.AuthorityInfoAccess.getId());
    super.setCriticalFlag(false);
}