Search in sources :

Example 1 with X509Store

use of org.bouncycastle.x509.X509Store in project robovm by robovm.

the class CMSSignedHelper method createAttributeStore.

X509Store createAttributeStore(String type, Provider provider, Store certStore) throws NoSuchStoreException, CMSException {
    try {
        Collection certHldrs = certStore.getMatches(null);
        List certs = new ArrayList(certHldrs.size());
        for (Iterator it = certHldrs.iterator(); it.hasNext(); ) {
            certs.add(new X509V2AttributeCertificate(((X509AttributeCertificateHolder) it.next()).getEncoded()));
        }
        return X509Store.getInstance("AttributeCertificate/" + type, new X509CollectionStoreParameters(certs), provider);
    } catch (IllegalArgumentException e) {
        throw new CMSException("can't setup the X509Store", e);
    } catch (IOException e) {
        throw new CMSException("can't setup the X509Store", e);
    }
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) ArrayList(java.util.ArrayList) CertificateList(org.bouncycastle.asn1.x509.CertificateList) List(java.util.List) X509AttributeCertificateHolder(org.bouncycastle.cert.X509AttributeCertificateHolder) X509CollectionStoreParameters(org.bouncycastle.x509.X509CollectionStoreParameters) IOException(java.io.IOException) X509V2AttributeCertificate(org.bouncycastle.x509.X509V2AttributeCertificate)

Example 2 with X509Store

use of org.bouncycastle.x509.X509Store 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 3 with X509Store

use of org.bouncycastle.x509.X509Store 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 4 with X509Store

use of org.bouncycastle.x509.X509Store in project robovm by robovm.

the class CMSSignedGenerator method addAttributeCertificates.

// BEGIN android-removed
// /**
//  * Add a single instance of otherRevocationData to the CRL set to be included with the generated SignedData message.
//  *
//  * @param otherRevocationInfoFormat the OID specifying the format of the otherRevocationInfo data.
//  * @param otherRevocationInfo the otherRevocationInfo ASN.1 structure.
//  */
// public void addOtherRevocationInfo(
//     ASN1ObjectIdentifier   otherRevocationInfoFormat,
//     ASN1Encodable          otherRevocationInfo)
// {
//     crls.add(new DERTaggedObject(false, 1, new OtherRevocationInfoFormat(otherRevocationInfoFormat, otherRevocationInfo)));
// }
//
// /**
//  * Add a Store of otherRevocationData to the CRL set to be included with the generated SignedData message.
//  *
//  * @param otherRevocationInfoFormat the OID specifying the format of the otherRevocationInfo data.
//  * @param otherRevocationInfos a Store of otherRevocationInfo data to add.
//  */
// public void addOtherRevocationInfo(
//     ASN1ObjectIdentifier   otherRevocationInfoFormat,
//     Store                  otherRevocationInfos)
// {
//     crls.addAll(CMSUtils.getOthersFromStore(otherRevocationInfoFormat, otherRevocationInfos));
// }
// END android-removed
/**
     * Add the attribute certificates contained in the passed in store to the
     * generator.
     *
     * @param store a store of Version 2 attribute certificates
     * @throws CMSException if an error occurse processing the store.
     * @deprecated use basic Store method
     */
public void addAttributeCertificates(X509Store store) throws CMSException {
    try {
        for (Iterator it = store.getMatches(null).iterator(); it.hasNext(); ) {
            X509AttributeCertificate attrCert = (X509AttributeCertificate) it.next();
            certs.add(new DERTaggedObject(false, 2, AttributeCertificate.getInstance(ASN1Primitive.fromByteArray(attrCert.getEncoded()))));
        }
    } catch (IllegalArgumentException e) {
        throw new CMSException("error processing attribute certs", e);
    } catch (IOException e) {
        throw new CMSException("error processing attribute certs", e);
    }
}
Also used : DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) Iterator(java.util.Iterator) X509AttributeCertificate(org.bouncycastle.x509.X509AttributeCertificate) IOException(java.io.IOException)

Example 5 with X509Store

use of org.bouncycastle.x509.X509Store 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)

Aggregations

Iterator (java.util.Iterator)6 CertStore (java.security.cert.CertStore)4 CertStoreException (java.security.cert.CertStoreException)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 StoreException (org.bouncycastle.util.StoreException)4 X509Store (org.bouncycastle.x509.X509Store)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 ASN1Object (org.bouncycastle.asn1.ASN1Object)1 DERObject (org.bouncycastle.asn1.DERObject)1 DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)1 CertificateList (org.bouncycastle.asn1.x509.CertificateList)1 X509AttributeCertificateHolder (org.bouncycastle.cert.X509AttributeCertificateHolder)1 X509AttributeCertificate (org.bouncycastle.x509.X509AttributeCertificate)1 X509CollectionStoreParameters (org.bouncycastle.x509.X509CollectionStoreParameters)1 X509V2AttributeCertificate (org.bouncycastle.x509.X509V2AttributeCertificate)1