Search in sources :

Example 1 with X509CertPairParser

use of com.github.zhenwei.provider.jce.provider.X509CertPairParser 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)

Aggregations

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 X509CertificatePair (com.github.zhenwei.provider.x509.X509CertificatePair)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 CertificateParsingException (java.security.cert.CertificateParsingException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1