}
private void certStoretest() 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(getSubject(xcert).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.addIssuerName(getCRLIssuer(crl).getEncoded());
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(getSubject(xcert).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(getSubject(xcert).getEncoded());
coll = cs.getCertificates(sl);
if (coll.isEmpty())
{
fail("Cross certificate pair could not be picked from LDAP directory.");
}