use of com.github.zhenwei.core.util.Encodable in project LinLong-Java by zhenwei1108.
the class CertPathValidatorUtilities method findCertificates.
/**
* Return a Collection of all certificates or attribute certificates found in the X509Store's that
* are matching the certSelect criteriums.
*
* @param certSelect a {@link Selector} object that will be used to select the certificates
* @param certStores a List containing only {@link X509Store} objects. These are used to search
* for certificates.
* @return a Collection of all found {@link X509Certificate} or {@link
* com.github.zhenwei.provider.x509.X509AttributeCertificate} objects. May be empty but never
* <code>null</code>.
*/
protected static Collection findCertificates(X509CertStoreSelector certSelect, List certStores) throws AnnotatedException {
Set certs = new HashSet();
Iterator iter = certStores.iterator();
com.github.zhenwei.provider.jcajce.provider.asymmetric.x509.CertificateFactory certFact = new com.github.zhenwei.provider.jcajce.provider.asymmetric.x509.CertificateFactory();
while (iter.hasNext()) {
Object obj = iter.next();
if (obj instanceof Store) {
Store certStore = (Store) obj;
try {
for (Iterator it = certStore.getMatches(certSelect).iterator(); it.hasNext(); ) {
Object cert = it.next();
if (cert instanceof Encodable) {
certs.add(certFact.engineGenerateCertificate(new ByteArrayInputStream(((Encodable) cert).getEncoded())));
} else if (cert instanceof Certificate) {
certs.add(cert);
} else {
throw new AnnotatedException("Unknown object found in certificate store.");
}
}
} catch (StoreException e) {
throw new AnnotatedException("Problem while picking certificates from X.509 store.", e);
} catch (IOException e) {
throw new AnnotatedException("Problem while extracting certificates from X.509 store.", e);
} catch (CertificateException e) {
throw new AnnotatedException("Problem while extracting certificates from X.509 store.", e);
}
} else {
CertStore certStore = (CertStore) obj;
try {
certs.addAll(certStore.getCertificates(certSelect));
} catch (CertStoreException e) {
throw new AnnotatedException("Problem while picking certificates from certificate store.", e);
}
}
}
return certs;
}
Aggregations