Search in sources :

Example 1 with StoreException

use of com.github.zhenwei.core.util.StoreException in project LinLong-Java by zhenwei1108.

the class PKIXCRLUtil method findCRLs.

/**
 * Add to a HashSet any and all CRLs found in the X509Store's that are matching the crlSelect
 * criteria.
 *
 * @param crls      the {@link HashSet} to add the CRLs to.
 * @param crlSelect a {@link PKIXCRLStoreSelector} object that will be used to select the CRLs
 * @param crlStores a List containing only {@link Store} objects. These are used to search for
 *                  CRLs
 */
private static void findCRLs(HashSet crls, PKIXCRLStoreSelector crlSelect, List crlStores) throws AnnotatedException {
    AnnotatedException lastException = null;
    boolean foundValidStore = false;
    Iterator iter = crlStores.iterator();
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof Store) {
            Store store = (Store) 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(PKIXCRLStoreSelector.getCRLs(crlSelect, store));
                foundValidStore = true;
            } catch (CertStoreException e) {
                lastException = new AnnotatedException("Exception searching in X.509 CRL store.", e);
            }
        }
    }
    if (!foundValidStore && lastException != null) {
        throw lastException;
    }
}
Also used : CertStoreException(java.security.cert.CertStoreException) Iterator(java.util.Iterator) Store(com.github.zhenwei.core.util.Store) CertStore(java.security.cert.CertStore) CertStore(java.security.cert.CertStore) StoreException(com.github.zhenwei.core.util.StoreException) CertStoreException(java.security.cert.CertStoreException)

Example 2 with StoreException

use of com.github.zhenwei.core.util.StoreException in project LinLong-Java by zhenwei1108.

the class CertPathValidatorUtilities method findCertificates.

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) HashSet(java.util.HashSet) CertStoreException(java.security.cert.CertStoreException) StoreException(com.github.zhenwei.core.util.StoreException) AnnotatedException(com.github.zhenwei.provider.jce.provider.AnnotatedException)

Example 3 with StoreException

use of com.github.zhenwei.core.util.StoreException in project LinLong-Java by zhenwei1108.

the class CertPathValidatorUtilities method findCertificates.

protected static Collection findCertificates(PKIXCertStoreSelector certSelect, List certStores) throws AnnotatedException {
    Set certs = new HashSet();
    Iterator iter = certStores.iterator();
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof Store) {
            Store certStore = (Store) 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(PKIXCertStoreSelector.getCertificates(certSelect, certStore));
            } catch (CertStoreException e) {
                throw new AnnotatedException("Problem while picking certificates from certificate store.", e);
            }
        }
    }
    return certs;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CertStoreException(java.security.cert.CertStoreException) Iterator(java.util.Iterator) Store(com.github.zhenwei.core.util.Store) CertStore(java.security.cert.CertStore) CertStore(java.security.cert.CertStore) HashSet(java.util.HashSet) CertStoreException(java.security.cert.CertStoreException) StoreException(com.github.zhenwei.core.util.StoreException) AnnotatedException(com.github.zhenwei.provider.jce.provider.AnnotatedException)

Example 4 with StoreException

use of com.github.zhenwei.core.util.StoreException in project LinLong-Java by zhenwei1108.

the class LDAPStoreHelper method search.

/**
 * Returns a <code>List</code> of encodings of the certificates, attribute certificates, CRL or
 * certificate pairs.
 *
 * @param attributeNames The attribute names to look for in the LDAP.
 * @param attributeValue The value the attribute name must have.
 * @param attrs          The attributes in the LDAP which hold the certificate, attribute
 *                       certificate, certificate pair or CRL in a found entry.
 * @return A <code>List</code> of byte arrays with the encodings.
 * @throws StoreException if an error occurs getting the results from the LDAP directory.
 */
private List search(String[] attributeNames, String attributeValue, String[] attrs) throws StoreException {
    String filter = null;
    if (attributeNames == null) {
        filter = null;
    } else {
        filter = "";
        if (attributeValue.equals("**")) {
            attributeValue = "*";
        }
        for (int i = 0; i < attributeNames.length; i++) {
            filter += "(" + attributeNames[i] + "=" + attributeValue + ")";
        }
        filter = "(|" + filter + ")";
    }
    String filter2 = "";
    for (int i = 0; i < attrs.length; i++) {
        filter2 += "(" + attrs[i] + "=*)";
    }
    filter2 = "(|" + filter2 + ")";
    String filter3 = "(&" + filter + "" + filter2 + ")";
    if (filter == null) {
        filter3 = filter2;
    }
    List list;
    list = getFromCache(filter3);
    if (list != null) {
        return list;
    }
    DirContext ctx = null;
    list = new ArrayList();
    try {
        ctx = connectLDAP();
        SearchControls constraints = new SearchControls();
        constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
        constraints.setCountLimit(0);
        constraints.setReturningAttributes(attrs);
        NamingEnumeration results = ctx.search(params.getBaseDN(), filter3, constraints);
        while (results.hasMoreElements()) {
            SearchResult sr = (SearchResult) results.next();
            NamingEnumeration enumeration = ((Attribute) (sr.getAttributes().getAll().next())).getAll();
            while (enumeration.hasMore()) {
                list.add(enumeration.next());
            }
        }
        addToCache(filter3, list);
    } catch (NamingException e) {
    // skip exception, unfortunately if an attribute type is not
    // supported an exception is thrown
    } finally {
        try {
            if (null != ctx) {
                ctx.close();
            }
        } catch (Exception e) {
        }
    }
    return list;
}
Also used : Attribute(javax.naming.directory.Attribute) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SearchControls(javax.naming.directory.SearchControls) NamingEnumeration(javax.naming.NamingEnumeration) SearchResult(javax.naming.directory.SearchResult) NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) CertificateParsingException(java.security.cert.CertificateParsingException) NamingException(javax.naming.NamingException) IOException(java.io.IOException) StoreException(com.github.zhenwei.core.util.StoreException)

Example 5 with StoreException

use of com.github.zhenwei.core.util.StoreException in project LinLong-Java by zhenwei1108.

the class PKIXAttrCertPathBuilderSpi method findCertificates.

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 Store) {
            Store certStore = (Store) obj;
            try {
                certs.addAll(certStore.getMatches(certSelect));
            } catch (StoreException e) {
                throw new AnnotatedException("Problem while picking certificates from X.509 store.", e);
            }
        }
    }
    return certs;
}
Also used : HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) Iterator(java.util.Iterator) Store(com.github.zhenwei.core.util.Store) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) StoreException(com.github.zhenwei.core.util.StoreException)

Aggregations

StoreException (com.github.zhenwei.core.util.StoreException)9 Iterator (java.util.Iterator)8 CertStoreException (java.security.cert.CertStoreException)6 Store (com.github.zhenwei.core.util.Store)5 CertStore (java.security.cert.CertStore)5 HashSet (java.util.HashSet)5 Set (java.util.Set)5 AnnotatedException (com.github.zhenwei.provider.jce.provider.AnnotatedException)4 IOException (java.io.IOException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 CertificateParsingException (java.security.cert.CertificateParsingException)2 X509Certificate (java.security.cert.X509Certificate)2 NamingException (javax.naming.NamingException)2 ASN1Encodable (com.github.zhenwei.core.asn1.ASN1Encodable)1 Encodable (com.github.zhenwei.core.util.Encodable)1 X509CertParser (com.github.zhenwei.provider.jce.provider.X509CertParser)1 Certificate (java.security.cert.Certificate)1 CertificateException (java.security.cert.CertificateException)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1