public Collection engineGetCertificates(CertSelector selector)
throws CertStoreException
{
if (!(selector instanceof X509CertSelector))
{
throw new CertStoreException("selector is not a X509CertSelector");
}
X509CertSelector xselector = (X509CertSelector)selector;
Set certSet = new HashSet();
Set set = getEndCertificates(xselector);
set.addAll(getCACertificates(xselector));
set.addAll(getCrossCertificates(xselector));
Iterator it = set.iterator();
try
{
CertificateFactory cf = CertificateFactory.getInstance("X.509",
BouncyCastleProvider.PROVIDER_NAME);
while (it.hasNext())
{
byte[] bytes = (byte[])it.next();
if (bytes == null || bytes.length == 0)
{
continue;
}
List bytesList = new ArrayList();
bytesList.add(bytes);
try
{
CertificatePair pair = CertificatePair
.getInstance(new ASN1InputStream(bytes)
.readObject());
bytesList.clear();
if (pair.getForward() != null)
{
bytesList.add(pair.getForward().getEncoded());
}
if (pair.getReverse() != null)
{
bytesList.add(pair.getReverse().getEncoded());
}
}
catch (IOException e)
{
}
catch (IllegalArgumentException e)
{
}
for (Iterator it2 = bytesList.iterator(); it2.hasNext();)
{
ByteArrayInputStream bIn = new ByteArrayInputStream(
(byte[])it2.next());
try
{
Certificate cert = cf.generateCertificate(bIn);
// System.out.println(((X509Certificate)
// cert).getSubjectX500Principal());
if (xselector.match(cert))
{
certSet.add(cert);
}
}
catch (Exception e)
{
}
}
}
}
catch (Exception e)
{
throw new CertStoreException(
"certificate cannot be constructed from LDAP result: " + e);
}
return certSet;
}