Search in sources :

Example 1 with X509CertificatePair

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

the class X509CertPairParser method engineReadAll.

public Collection engineReadAll() throws StreamParsingException {
    X509CertificatePair pair;
    List certs = new ArrayList();
    while ((pair = (X509CertificatePair) engineRead()) != null) {
        certs.add(pair);
    }
    return certs;
}
Also used : X509CertificatePair(com.github.zhenwei.provider.x509.X509CertificatePair) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with X509CertificatePair

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

the class X509CertPairParser method readDERCrossCertificatePair.

private X509CertificatePair readDERCrossCertificatePair(InputStream in) throws IOException, CertificateParsingException {
    ASN1InputStream dIn = new ASN1InputStream(in);
    ASN1Sequence seq = (ASN1Sequence) dIn.readObject();
    CertificatePair pair = CertificatePair.getInstance(seq);
    return new X509CertificatePair(pair);
}
Also used : ASN1InputStream(com.github.zhenwei.core.asn1.ASN1InputStream) ASN1Sequence(com.github.zhenwei.core.asn1.ASN1Sequence) X509CertificatePair(com.github.zhenwei.provider.x509.X509CertificatePair) X509CertificatePair(com.github.zhenwei.provider.x509.X509CertificatePair) CertificatePair(com.github.zhenwei.core.asn1.x509.CertificatePair)

Example 3 with X509CertificatePair

use of com.github.zhenwei.provider.x509.X509CertificatePair 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 4 with X509CertificatePair

use of com.github.zhenwei.provider.x509.X509CertificatePair 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 5 with X509CertificatePair

use of com.github.zhenwei.provider.x509.X509CertificatePair 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

X509CertificatePair (com.github.zhenwei.provider.x509.X509CertificatePair)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 ASN1InputStream (com.github.zhenwei.core.asn1.ASN1InputStream)2 CertificatePair (com.github.zhenwei.core.asn1.x509.CertificatePair)2 X509CertPairStoreSelector (com.github.zhenwei.provider.x509.X509CertPairStoreSelector)2 X509CertStoreSelector (com.github.zhenwei.provider.x509.X509CertStoreSelector)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)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 Iterator (java.util.Iterator)1