Search in sources :

Example 1 with X509CertPairStoreSelector

use of com.github.zhenwei.provider.x509.X509CertPairStoreSelector in project LinLong-Java by zhenwei1108.

the class LDAPStoreHelper method getCrossCertificatePairs.

/**
 * Returns cross certificate pairs.
 *
 * @param selector The selector to use to find the cross certificates.
 * @return A possible empty collection with {@link X509CertificatePair}s
 * @throws StoreException
 */
public Collection getCrossCertificatePairs(X509CertPairStoreSelector selector) throws StoreException {
    String[] attrs = splitString(params.getCrossCertificateAttribute());
    String[] attrNames = splitString(params.getLdapCrossCertificateAttributeName());
    String[] subjectAttributeNames = splitString(params.getCrossCertificateSubjectAttributeName());
    List list = crossCertificatePairSubjectSearch(selector, attrs, attrNames, subjectAttributeNames);
    Set resultSet = createCrossCertificatePairs(list, selector);
    if (resultSet.size() == 0) {
        X509CertStoreSelector emptyCertselector = new X509CertStoreSelector();
        X509CertPairStoreSelector emptySelector = new X509CertPairStoreSelector();
        emptySelector.setForwardSelector(emptyCertselector);
        emptySelector.setReverseSelector(emptyCertselector);
        list = crossCertificatePairSubjectSearch(emptySelector, attrs, attrNames, subjectAttributeNames);
        resultSet.addAll(createCrossCertificatePairs(list, selector));
    }
    return resultSet;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) X509CertStoreSelector(com.github.zhenwei.provider.x509.X509CertStoreSelector) ArrayList(java.util.ArrayList) List(java.util.List) X509CertPairStoreSelector(com.github.zhenwei.provider.x509.X509CertPairStoreSelector)

Example 2 with X509CertPairStoreSelector

use of com.github.zhenwei.provider.x509.X509CertPairStoreSelector in project LinLong-Java by zhenwei1108.

the class X509StoreLDAPCertPairs method engineGetMatches.

/**
 * Returns a collection of matching cross certificate pairs from the LDAP location.
 * <p>
 * The selector must be a of type <code>X509CertPairStoreSelector</code>. If it is not an empty
 * collection is returned.
 * </p>
 * <p>
 * The subject should be a reasonable criteria for a selector.
 * </p>
 *
 * @param selector The selector to use for finding.
 * @return A collection with the matches.
 * @throws StoreException if an exception occurs while searching.
 */
public Collection engineGetMatches(Selector selector) throws StoreException {
    if (!(selector instanceof X509CertPairStoreSelector)) {
        return Collections.EMPTY_SET;
    }
    X509CertPairStoreSelector xselector = (X509CertPairStoreSelector) selector;
    Set set = new HashSet();
    set.addAll(helper.getCrossCertificatePairs(xselector));
    return set;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) X509CertPairStoreSelector(com.github.zhenwei.provider.x509.X509CertPairStoreSelector) HashSet(java.util.HashSet)

Example 3 with X509CertPairStoreSelector

use of com.github.zhenwei.provider.x509.X509CertPairStoreSelector in project LinLong-Java by zhenwei1108.

the class LDAPStoreHelper method createCrossCertificatePairs.

private Set createCrossCertificatePairs(List list, X509CertPairStoreSelector xselector) throws StoreException {
    Set certPairSet = new HashSet();
    int i = 0;
    while (i < list.size()) {
        X509CertificatePair pair;
        try {
            // first try to decode it as certificate pair
            try {
                X509CertPairParser parser = new X509CertPairParser();
                parser.engineInit(new ByteArrayInputStream((byte[]) list.get(i)));
                pair = (X509CertificatePair) parser.engineRead();
            } catch (StreamParsingException e) {
                // now try it to construct it the forward and reverse
                // certificate
                byte[] forward = (byte[]) list.get(i);
                byte[] reverse = (byte[]) list.get(i + 1);
                pair = new X509CertificatePair(new CertificatePair(Certificate.getInstance(new ASN1InputStream(forward).readObject()), Certificate.getInstance(new ASN1InputStream(reverse).readObject())));
                i++;
            }
            if (xselector.match((Object) pair)) {
                certPairSet.add(pair);
            }
        } catch (CertificateParsingException e) {
        // try next
        } catch (IOException e) {
        // try next
        }
        i++;
    }
    return certPairSet;
}
Also used : X509CertPairParser(com.github.zhenwei.provider.jce.provider.X509CertPairParser) ASN1InputStream(com.github.zhenwei.core.asn1.ASN1InputStream) HashSet(java.util.HashSet) Set(java.util.Set) X509CertificatePair(com.github.zhenwei.provider.x509.X509CertificatePair) CertificateParsingException(java.security.cert.CertificateParsingException) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) CertificatePair(com.github.zhenwei.core.asn1.x509.CertificatePair) X509CertificatePair(com.github.zhenwei.provider.x509.X509CertificatePair) HashSet(java.util.HashSet)

Example 4 with X509CertPairStoreSelector

use of com.github.zhenwei.provider.x509.X509CertPairStoreSelector in project LinLong-Java by zhenwei1108.

the class X509StoreLDAPCerts method getCertificatesFromCrossCertificatePairs.

private Collection getCertificatesFromCrossCertificatePairs(X509CertStoreSelector xselector) throws StoreException {
    Set set = new HashSet();
    X509CertPairStoreSelector ps = new X509CertPairStoreSelector();
    ps.setForwardSelector(xselector);
    ps.setReverseSelector(new X509CertStoreSelector());
    Set crossCerts = new HashSet(helper.getCrossCertificatePairs(ps));
    Set forward = new HashSet();
    Set reverse = new HashSet();
    Iterator it = crossCerts.iterator();
    while (it.hasNext()) {
        X509CertificatePair pair = (X509CertificatePair) it.next();
        if (pair.getForward() != null) {
            forward.add(pair.getForward());
        }
        if (pair.getReverse() != null) {
            reverse.add(pair.getReverse());
        }
    }
    set.addAll(forward);
    set.addAll(reverse);
    return set;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) X509CertificatePair(com.github.zhenwei.provider.x509.X509CertificatePair) X509CertStoreSelector(com.github.zhenwei.provider.x509.X509CertStoreSelector) Iterator(java.util.Iterator) X509CertPairStoreSelector(com.github.zhenwei.provider.x509.X509CertPairStoreSelector) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)4 Set (java.util.Set)4 X509CertPairStoreSelector (com.github.zhenwei.provider.x509.X509CertPairStoreSelector)3 X509CertStoreSelector (com.github.zhenwei.provider.x509.X509CertStoreSelector)2 X509CertificatePair (com.github.zhenwei.provider.x509.X509CertificatePair)2 ASN1InputStream (com.github.zhenwei.core.asn1.ASN1InputStream)1 CertificatePair (com.github.zhenwei.core.asn1.x509.CertificatePair)1 X509CertPairParser (com.github.zhenwei.provider.jce.provider.X509CertPairParser)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 CertificateParsingException (java.security.cert.CertificateParsingException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1