Search in sources :

Example 16 with AccessDescription

use of sun.security.x509.AccessDescription in project j2objc by google.

the class ForwardBuilder method getCerts.

/**
 * Download Certificates from the given AIA and add them to the
 * specified Collection.
 */
// cs.getCertificates(caSelector) returns a collection of X509Certificate's
// because of the selector, so the cast is safe
@SuppressWarnings("unchecked")
private boolean getCerts(AuthorityInfoAccessExtension aiaExt, Collection<X509Certificate> certs) {
    if (Builder.USE_AIA == false) {
        return false;
    }
    List<AccessDescription> adList = aiaExt.getAccessDescriptions();
    if (adList == null || adList.isEmpty()) {
        return false;
    }
    boolean add = false;
    for (AccessDescription ad : adList) {
        CertStore cs = URICertStore.getInstance(ad);
        if (cs != null) {
            try {
                if (certs.addAll((Collection<X509Certificate>) cs.getCertificates(caSelector))) {
                    add = true;
                    if (!searchAllCertStores) {
                        return true;
                    }
                }
            } catch (CertStoreException cse) {
                if (debug != null) {
                    debug.println("exception getting certs from CertStore:");
                    cse.printStackTrace();
                }
            }
        }
    }
    return add;
}
Also used : AccessDescription(sun.security.x509.AccessDescription) CertStoreException(java.security.cert.CertStoreException) CertStore(java.security.cert.CertStore) X509Certificate(java.security.cert.X509Certificate)

Example 17 with AccessDescription

use of sun.security.x509.AccessDescription in project j2objc by google.

the class OCSP method getResponderURI.

static URI getResponderURI(X509CertImpl certImpl) {
    // Examine the certificate's AuthorityInfoAccess extension
    AuthorityInfoAccessExtension aia = certImpl.getAuthorityInfoAccessExtension();
    if (aia == null) {
        return null;
    }
    List<AccessDescription> descriptions = aia.getAccessDescriptions();
    for (AccessDescription description : descriptions) {
        if (description.getAccessMethod().equals((Object) AccessDescription.Ad_OCSP_Id)) {
            GeneralName generalName = description.getAccessLocation();
            if (generalName.getType() == GeneralNameInterface.NAME_URI) {
                URIName uri = (URIName) generalName.getName();
                return uri.getURI();
            }
        }
    }
    return null;
}
Also used : AuthorityInfoAccessExtension(sun.security.x509.AuthorityInfoAccessExtension) AccessDescription(sun.security.x509.AccessDescription) GeneralName(sun.security.x509.GeneralName) URIName(sun.security.x509.URIName)

Example 18 with AccessDescription

use of sun.security.x509.AccessDescription in project j2objc by google.

the class URICertStore method getInstance.

/**
 * Creates a CertStore from information included in the AccessDescription
 * object of a certificate's Authority Information Access Extension.
 */
static CertStore getInstance(AccessDescription ad) {
    if (!ad.getAccessMethod().equals((Object) AccessDescription.Ad_CAISSUERS_Id)) {
        return null;
    }
    GeneralNameInterface gn = ad.getAccessLocation().getName();
    if (!(gn instanceof URIName)) {
        return null;
    }
    URI uri = ((URIName) gn).getURI();
    try {
        return URICertStore.getInstance(new URICertStore.URICertStoreParameters(uri));
    } catch (Exception ex) {
        if (debug != null) {
            debug.println("exception creating CertStore: " + ex);
            ex.printStackTrace();
        }
        return null;
    }
}
Also used : GeneralNameInterface(sun.security.x509.GeneralNameInterface) URI(java.net.URI) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) CertStoreException(java.security.cert.CertStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CRLException(java.security.cert.CRLException) URIName(sun.security.x509.URIName)

Example 19 with AccessDescription

use of sun.security.x509.AccessDescription in project ddf by codice.

the class OcspChecker method getOcspUrlsFromCert.

/**
 * Attempts to grab additional OCSP server urls off of the given {@param cert}.
 *
 * @param - the {@link X509Certificate} to check.
 * @return {@link List} of additional OCSP server urls found on the given {@param cert}.
 */
private List<URI> getOcspUrlsFromCert(X509Certificate cert) {
    List<URI> ocspUrls = new ArrayList<>();
    try {
        byte[] authorityInfoAccess = cert.getExtensionValue(Extension.authorityInfoAccess.getId());
        if (authorityInfoAccess == null) {
            return ocspUrls;
        }
        AuthorityInformationAccess authorityInformationAccess = AuthorityInformationAccess.getInstance(X509ExtensionUtil.fromExtensionValue(authorityInfoAccess));
        if (authorityInformationAccess == null) {
            return ocspUrls;
        }
        for (AccessDescription description : authorityInformationAccess.getAccessDescriptions()) {
            GeneralName accessLocation = description.getAccessLocation();
            if (accessLocation.getTagNo() == GeneralName.uniformResourceIdentifier)
                try {
                    ocspUrls.add(new URI(((DERIA5String) accessLocation.getName()).getString()));
                } catch (URISyntaxException e) {
                    LOGGER.debug("Location is not a URI.", e);
                }
        }
    } catch (IOException e) {
        LOGGER.debug("Problem retrieving the OCSP server url(s) from the certificate." + CONTINUING_MSG, e);
    }
    return ocspUrls;
}
Also used : AuthorityInformationAccess(org.bouncycastle.asn1.x509.AuthorityInformationAccess) AccessDescription(org.bouncycastle.asn1.x509.AccessDescription) ArrayList(java.util.ArrayList) GeneralName(org.bouncycastle.asn1.x509.GeneralName) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI)

Example 20 with AccessDescription

use of sun.security.x509.AccessDescription in project jdk8u_jdk by JetBrains.

the class OCSP method getResponderURI.

static URI getResponderURI(X509CertImpl certImpl) {
    // Examine the certificate's AuthorityInfoAccess extension
    AuthorityInfoAccessExtension aia = certImpl.getAuthorityInfoAccessExtension();
    if (aia == null) {
        return null;
    }
    List<AccessDescription> descriptions = aia.getAccessDescriptions();
    for (AccessDescription description : descriptions) {
        if (description.getAccessMethod().equals(AccessDescription.Ad_OCSP_Id)) {
            GeneralName generalName = description.getAccessLocation();
            if (generalName.getType() == GeneralNameInterface.NAME_URI) {
                URIName uri = (URIName) generalName.getName();
                return uri.getURI();
            }
        }
    }
    return null;
}
Also used : AuthorityInfoAccessExtension(sun.security.x509.AuthorityInfoAccessExtension) AccessDescription(sun.security.x509.AccessDescription) GeneralName(sun.security.x509.GeneralName) URIName(sun.security.x509.URIName)

Aggregations

AccessDescription (org.bouncycastle.asn1.x509.AccessDescription)24 GeneralName (org.bouncycastle.asn1.x509.GeneralName)13 AuthorityInformationAccess (org.bouncycastle.asn1.x509.AuthorityInformationAccess)9 IOException (java.io.IOException)8 CertStoreException (java.security.cert.CertStoreException)7 ArrayList (java.util.ArrayList)6 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)6 AccessDescription (sun.security.x509.AccessDescription)6 URIName (sun.security.x509.URIName)6 DERIA5String (org.bouncycastle.asn1.DERIA5String)5 CRLDistPoint (org.bouncycastle.asn1.x509.CRLDistPoint)5 URI (java.net.URI)4 CertificateException (java.security.cert.CertificateException)4 X509Certificate (java.security.cert.X509Certificate)4 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)4 DirectoryString (org.bouncycastle.asn1.x500.DirectoryString)4 DistributionPoint (org.bouncycastle.asn1.x509.DistributionPoint)4 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 CRLException (java.security.cert.CRLException)3