Search in sources :

Example 1 with StoreException

use of org.bouncycastle.util.StoreException in project XobotOS by xamarin.

the class PKIXCRLUtil method findCRLs.

/**
     * Return a Collection of all CRLs found in the X509Store's that are
     * matching the crlSelect criteriums.
     *
     * @param crlSelect a {@link X509CRLStoreSelector} object that will be used
     *            to select the CRLs
     * @param crlStores a List containing only
     *            {@link org.bouncycastle.x509.X509Store  X509Store} objects.
     *            These are used to search for CRLs
     *
     * @return a Collection of all found {@link java.security.cert.X509CRL X509CRL} objects. May be
     *         empty but never <code>null</code>.
     */
private final Collection findCRLs(X509CRLStoreSelector crlSelect, List crlStores) throws AnnotatedException {
    Set crls = new HashSet();
    Iterator iter = crlStores.iterator();
    AnnotatedException lastException = null;
    boolean foundValidStore = false;
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof X509Store) {
            X509Store store = (X509Store) obj;
            try {
                crls.addAll(store.getMatches(crlSelect));
                foundValidStore = true;
            } catch (StoreException e) {
                lastException = new AnnotatedException("Exception searching in X.509 CRL store.", e);
            }
        } else {
            CertStore store = (CertStore) obj;
            try {
                crls.addAll(store.getCRLs(crlSelect));
                foundValidStore = true;
            } catch (CertStoreException e) {
                lastException = new AnnotatedException("Exception searching in X.509 CRL store.", e);
            }
        }
    }
    if (!foundValidStore && lastException != null) {
        throw lastException;
    }
    return crls;
}
Also used : X509Store(org.bouncycastle.x509.X509Store) Set(java.util.Set) HashSet(java.util.HashSet) CertStoreException(java.security.cert.CertStoreException) Iterator(java.util.Iterator) CertStore(java.security.cert.CertStore) HashSet(java.util.HashSet) StoreException(org.bouncycastle.util.StoreException) CertStoreException(java.security.cert.CertStoreException)

Example 2 with StoreException

use of org.bouncycastle.util.StoreException in project XobotOS by xamarin.

the class CertPathValidatorUtilities method findCertificates.

/**
     * Return a Collection of all certificates or attribute certificates found
     * in the X509Store's that are matching the certSelect criteriums.
     *
     * @param certSelect a {@link Selector} object that will be used to select
     *            the certificates
     * @param certStores a List containing only {@link X509Store} objects. These
     *            are used to search for certificates.
     *
     * @return a Collection of all found {@link X509Certificate} or
     *         {@link org.bouncycastle.x509.X509AttributeCertificate} objects.
     *         May be empty but never <code>null</code>.
     */
protected static Collection findCertificates(X509CertStoreSelector certSelect, List certStores) throws AnnotatedException {
    Set certs = new HashSet();
    Iterator iter = certStores.iterator();
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof X509Store) {
            X509Store certStore = (X509Store) obj;
            try {
                certs.addAll(certStore.getMatches(certSelect));
            } catch (StoreException e) {
                throw new AnnotatedException("Problem while picking certificates from X.509 store.", e);
            }
        } else {
            CertStore certStore = (CertStore) obj;
            try {
                certs.addAll(certStore.getCertificates(certSelect));
            } catch (CertStoreException e) {
                throw new AnnotatedException("Problem while picking certificates from certificate store.", e);
            }
        }
    }
    return certs;
}
Also used : X509Store(org.bouncycastle.x509.X509Store) Set(java.util.Set) HashSet(java.util.HashSet) CertStoreException(java.security.cert.CertStoreException) Iterator(java.util.Iterator) ASN1Object(org.bouncycastle.asn1.ASN1Object) DERObject(org.bouncycastle.asn1.DERObject) CertStore(java.security.cert.CertStore) HashSet(java.util.HashSet) CertStoreException(java.security.cert.CertStoreException) StoreException(org.bouncycastle.util.StoreException)

Example 3 with StoreException

use of org.bouncycastle.util.StoreException in project robovm by robovm.

the class PKIXCRLUtil method findCRLs.

/**
     * Return a Collection of all CRLs found in the X509Store's that are
     * matching the crlSelect criteriums.
     *
     * @param crlSelect a {@link X509CRLStoreSelector} object that will be used
     *            to select the CRLs
     * @param crlStores a List containing only
     *            {@link org.bouncycastle.x509.X509Store  X509Store} objects.
     *            These are used to search for CRLs
     *
     * @return a Collection of all found {@link java.security.cert.X509CRL X509CRL} objects. May be
     *         empty but never <code>null</code>.
     */
private final Collection findCRLs(X509CRLStoreSelector crlSelect, List crlStores) throws AnnotatedException {
    Set crls = new HashSet();
    Iterator iter = crlStores.iterator();
    AnnotatedException lastException = null;
    boolean foundValidStore = false;
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof X509Store) {
            X509Store store = (X509Store) obj;
            try {
                crls.addAll(store.getMatches(crlSelect));
                foundValidStore = true;
            } catch (StoreException e) {
                lastException = new AnnotatedException("Exception searching in X.509 CRL store.", e);
            }
        } else {
            CertStore store = (CertStore) obj;
            try {
                crls.addAll(store.getCRLs(crlSelect));
                foundValidStore = true;
            } catch (CertStoreException e) {
                lastException = new AnnotatedException("Exception searching in X.509 CRL store.", e);
            }
        }
    }
    if (!foundValidStore && lastException != null) {
        throw lastException;
    }
    return crls;
}
Also used : X509Store(org.bouncycastle.x509.X509Store) Set(java.util.Set) HashSet(java.util.HashSet) CertStoreException(java.security.cert.CertStoreException) Iterator(java.util.Iterator) CertStore(java.security.cert.CertStore) HashSet(java.util.HashSet) StoreException(org.bouncycastle.util.StoreException) CertStoreException(java.security.cert.CertStoreException)

Example 4 with StoreException

use of org.bouncycastle.util.StoreException in project robovm by robovm.

the class CertPathValidatorUtilities method findCertificates.

/**
     * Return a Collection of all certificates or attribute certificates found
     * in the X509Store's that are matching the certSelect criteriums.
     *
     * @param certSelect a {@link Selector} object that will be used to select
     *                   the certificates
     * @param certStores a List containing only {@link X509Store} objects. These
     *                   are used to search for certificates.
     * @return a Collection of all found {@link X509Certificate} or
     *         {@link org.bouncycastle.x509.X509AttributeCertificate} objects.
     *         May be empty but never <code>null</code>.
     */
protected static Collection findCertificates(X509CertStoreSelector certSelect, List certStores) throws AnnotatedException {
    Set certs = new HashSet();
    Iterator iter = certStores.iterator();
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof X509Store) {
            X509Store certStore = (X509Store) obj;
            try {
                certs.addAll(certStore.getMatches(certSelect));
            } catch (StoreException e) {
                throw new AnnotatedException("Problem while picking certificates from X.509 store.", e);
            }
        } else {
            CertStore certStore = (CertStore) obj;
            try {
                certs.addAll(certStore.getCertificates(certSelect));
            } catch (CertStoreException e) {
                throw new AnnotatedException("Problem while picking certificates from certificate store.", e);
            }
        }
    }
    return certs;
}
Also used : X509Store(org.bouncycastle.x509.X509Store) Set(java.util.Set) HashSet(java.util.HashSet) CertStoreException(java.security.cert.CertStoreException) Iterator(java.util.Iterator) CertStore(java.security.cert.CertStore) HashSet(java.util.HashSet) CertStoreException(java.security.cert.CertStoreException) StoreException(org.bouncycastle.util.StoreException)

Example 5 with StoreException

use of org.bouncycastle.util.StoreException in project robovm by robovm.

the class CertPathValidatorUtilities method addAdditionalStoresFromCRLDistributionPoint.

// BEGIN android-removed
// protected static Collection findCertificates(X509AttributeCertStoreSelector certSelect,
//                                              List certStores)
//     throws AnnotatedException
// {
//     Set certs = new HashSet();
//     Iterator iter = certStores.iterator();
//
//     while (iter.hasNext())
//     {
//         Object obj = iter.next();
//
//         if (obj instanceof X509Store)
//         {
//             X509Store certStore = (X509Store)obj;
//             try
//             {
//                 certs.addAll(certStore.getMatches(certSelect));
//             }
//             catch (StoreException e)
//             {
//                 throw new AnnotatedException(
//                         "Problem while picking certificates from X.509 store.", e);
//             }
//         }
//     }
//     return certs;
// }
// END android-removed
protected static void addAdditionalStoresFromCRLDistributionPoint(CRLDistPoint crldp, ExtendedPKIXParameters pkixParams) throws AnnotatedException {
    if (crldp != null) {
        DistributionPoint[] dps = null;
        try {
            dps = crldp.getDistributionPoints();
        } catch (Exception e) {
            throw new AnnotatedException("Distribution points could not be read.", e);
        }
        for (int i = 0; i < dps.length; i++) {
            DistributionPointName dpn = dps[i].getDistributionPoint();
            // look for URIs in fullName
            if (dpn != null) {
                if (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 location = DERIA5String.getInstance(genNames[j].getName()).getString();
                            CertPathValidatorUtilities.addAdditionalStoreFromLocation(location, pkixParams);
                        }
                    }
                }
            }
        }
    }
}
Also used : DistributionPointName(org.bouncycastle.asn1.x509.DistributionPointName) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint) GeneralName(org.bouncycastle.asn1.x509.GeneralName) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) DERIA5String(org.bouncycastle.asn1.DERIA5String) GeneralSecurityException(java.security.GeneralSecurityException) CertPathValidatorException(java.security.cert.CertPathValidatorException) ParseException(java.text.ParseException) ExtCertPathValidatorException(org.bouncycastle.jce.exception.ExtCertPathValidatorException) CertStoreException(java.security.cert.CertStoreException) CRLException(java.security.cert.CRLException) CertificateParsingException(java.security.cert.CertificateParsingException) StoreException(org.bouncycastle.util.StoreException) IOException(java.io.IOException) CRLDistPoint(org.bouncycastle.asn1.x509.CRLDistPoint) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint)

Aggregations

CertStoreException (java.security.cert.CertStoreException)6 StoreException (org.bouncycastle.util.StoreException)6 CertStore (java.security.cert.CertStore)4 HashSet (java.util.HashSet)4 Iterator (java.util.Iterator)4 Set (java.util.Set)4 X509Store (org.bouncycastle.x509.X509Store)4 IOException (java.io.IOException)2 GeneralSecurityException (java.security.GeneralSecurityException)2 CertPathValidatorException (java.security.cert.CertPathValidatorException)2 CertificateParsingException (java.security.cert.CertificateParsingException)2 ParseException (java.text.ParseException)2 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)2 DERIA5String (org.bouncycastle.asn1.DERIA5String)2 CRLDistPoint (org.bouncycastle.asn1.x509.CRLDistPoint)2 DistributionPoint (org.bouncycastle.asn1.x509.DistributionPoint)2 DistributionPointName (org.bouncycastle.asn1.x509.DistributionPointName)2 GeneralName (org.bouncycastle.asn1.x509.GeneralName)2 ExtCertPathValidatorException (org.bouncycastle.jce.exception.ExtCertPathValidatorException)2 CRLException (java.security.cert.CRLException)1