CertStore cs = CertStore.getInstance("X509LDAP", params1, "BC"); X509CertSelector sl = new X509CertSelector(); CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC"); X509Certificate xcert = (X509Certificate)cf .generateCertificate(new ByteArrayInputStream(cert1)); sl.setCertificate(xcert); Collection coll = cs.getCertificates(sl); if (coll.isEmpty() || !coll.iterator().next().equals(xcert)) { fail("certificate could not be picked from LDAP directory."); }    sl.setCertificate(null); sl.setSubject(xcert.getSubjectX500Principal().getEncoded()); coll = cs.getCertificates(sl); if (coll.isEmpty() || !coll.iterator().next().equals(xcert)) { fail("certificate could not be picked from LDAP directory."); } X509CRLSelector sl2 = new X509CRLSelector();    coll = cs.getCRLs(sl2); if (!coll.iterator().hasNext()) { fail("CRL could not be picked from LDAP directory."); }   cs = CertStore.getInstance("X509LDAP", params2, "BC"); sl = new X509CertSelector(); xcert = (X509Certificate)cf .generateCertificate(new ByteArrayInputStream(cert2)); sl.setCertificate(xcert); coll = cs.getCertificates(sl); if (coll.isEmpty() || !coll.iterator().next().equals(xcert)) { fail("certificate could not be picked from LDAP directory."); }    cs = CertStore.getInstance("X509LDAP", params3, "BC"); sl = new X509CertSelector(); xcert = (X509Certificate)cf .generateCertificate(new ByteArrayInputStream(cert3)); sl.setCertificate(xcert); coll = cs.getCertificates(sl); if (coll.isEmpty() || !coll.iterator().next().equals(xcert)) { fail("certificate could not be picked from LDAP directory."); }    xcert = (X509Certificate)cf .generateCertificate(new ByteArrayInputStream(caCert3)); sl = new X509CertSelector(); sl.setSubject(xcert.getSubjectX500Principal().getEncoded()); coll = cs.getCertificates(sl); boolean found = false; if (coll.isEmpty()) { fail("certificate could not be picked from LDAP directory."); }  for (Iterator it = coll.iterator(); it.hasNext();) { if (it.next().equals(xcert)) { found = true; break; } } if (!found) { fail("certificate could not be picked from LDAP directory."); }    sl = new X509CertSelector(); xcert = (X509Certificate)cf .generateCertificate(new ByteArrayInputStream(crossCert3)); sl = new X509CertSelector(); sl.setSubject(xcert.getSubjectX500Principal().getEncoded()); coll = cs.getCertificates(sl); if (coll.isEmpty()) { fail("certificate could not be picked from LDAP directory."); } found = false; for (Iterator it = coll.iterator(); it.hasNext();) { if (it.next().equals(xcert)) { found = true; break; } } if (!found) { fail("certificate could not be picked from LDAP directory."); }
certStoretest(); x509StoreTest();
    public void performTest() throws Exception    {        CertStore cs = CertStore.getInstance("X509LDAP", params1, "BC");        X509CertSelector sl = new X509CertSelector();        CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC");        X509Certificate xcert = (X509Certificate)cf            .generateCertificate(new ByteArrayInputStream(cert1));        sl.setCertificate(xcert);        Collection coll = cs.getCertificates(sl);        if (coll.isEmpty() || !coll.iterator().next().equals(xcert))        {            fail("certificate could not be picked from LDAP directory.");        }        // System.out.println(coll.toArray()[0]);        sl.setCertificate(null);        sl.setSubject(xcert.getSubjectX500Principal().getEncoded());        coll = cs.getCertificates(sl);        if (coll.isEmpty() || !coll.iterator().next().equals(xcert))        {            fail("certificate could not be picked from LDAP directory.");        }        X509CRLSelector sl2 = new X509CRLSelector();        // X509CRL crl = (X509CRL)cf.generateCRL(new        // ByteArrayInputStream(directCRL));        // sl2.addIssuer(crl.getIssuerX500Principal());        coll = cs.getCRLs(sl2);        if (!coll.iterator().hasNext())        {            fail("CRL could not be picked from LDAP directory.");        }        // //System.out.println(coll.toArray()[0]);        cs = CertStore.getInstance("X509LDAP", params2, "BC");        sl = new X509CertSelector();        xcert = (X509Certificate)cf            .generateCertificate(new ByteArrayInputStream(cert2));        sl.setCertificate(xcert);        coll = cs.getCertificates(sl);        if (coll.isEmpty() || !coll.iterator().next().equals(xcert))        {            fail("certificate could not be picked from LDAP directory.");        }        // System.out.println(coll.toArray()[0]);        cs = CertStore.getInstance("X509LDAP", params3, "BC");        sl = new X509CertSelector();        xcert = (X509Certificate)cf            .generateCertificate(new ByteArrayInputStream(cert3));        sl.setCertificate(xcert);        coll = cs.getCertificates(sl);        if (coll.isEmpty() || !coll.iterator().next().equals(xcert))        {            fail("certificate could not be picked from LDAP directory.");        }        // System.out.println(coll.toArray()[0]);        xcert = (X509Certificate)cf            .generateCertificate(new ByteArrayInputStream(caCert3));        sl = new X509CertSelector();        sl.setSubject(xcert.getSubjectX500Principal().getEncoded());        coll = cs.getCertificates(sl);        boolean found = false;        if (coll.isEmpty())        {            fail("certificate could not be picked from LDAP directory.");        }        for (Iterator it = coll.iterator(); it.hasNext();)        {            if (it.next().equals(xcert))            {                found = true;                break;            }        }        if (!found)        {            fail("certificate could not be picked from LDAP directory.");        }        // System.out.println(coll.toArray()[0]);        sl = new X509CertSelector();        xcert = (X509Certificate)cf            .generateCertificate(new ByteArrayInputStream(crossCert3));        sl = new X509CertSelector();        sl.setSubject(xcert.getSubjectX500Principal().getEncoded());        coll = cs.getCertificates(sl);        if (coll.isEmpty())        {            fail("certificate could not be picked from LDAP directory.");        }        found = false;        for (Iterator it = coll.iterator(); it.hasNext();)        {            if (it.next().equals(xcert))            {                found = true;                break;            }        }        if (!found)        {            fail("certificate could not be picked from LDAP directory.");        }        // System.out.println(coll.toArray()[0]);    }