use of java.security.cert.X509CRL in project nhin-d by DirectProject.
the class CRLRevocationManager method loadCRLs.
/**
* Extract and fetch all CRLs stored within a given certificate. Cache is
* updated per policy or if the cached CRL has passed planned update date.
* This method is thread safe.
*
* @param certificate
* The certificate from which to extract and fetch CRLs.
* @return The first CRL loaded from the certificate CRL distribution points
* @throws CRLException
*/
protected X509CRL loadCRLs(X509Certificate certificate) {
if (certificate == null)
return null;
X509CRL retVal = null;
try {
// get the distribution points extension
CRLDistPoint distPoints = CRLDistPoint.getInstance(getExtensionValue(certificate, X509Extensions.CRLDistributionPoints.getId()));
// Add CRL distribution point(s)
if (distPoints != null) {
// iterate through the distribution points and get the first CRL that can be obtained
for (DistributionPoint distPoint : distPoints.getDistributionPoints()) {
String distPointURL = distPoint.getDistributionPoint().getName().toString();
if (distPointURL.startsWith("General")) {
// get the actual URL associated with the name
distPointURL = getNameString(distPointURL);
}
// get the CRL from the distribution point CRL
retVal = getCrlFromUri(distPointURL);
if (retVal != null)
// do we need to retrieve the list from each CRL, or is each dist point identical?
return retVal;
}
}
} catch (Exception e) {
if (LOGGER.isWarnEnabled())
LOGGER.warn("Unable to handle CDP CRL(s): " + e.getMessage());
}
return null;
}
use of java.security.cert.X509CRL in project cas by apereo.
the class CRLDistributionPointRevocationChecker method getCRLs.
@Override
@SneakyThrows
protected List<X509CRL> getCRLs(final X509Certificate cert) {
final URI[] urls = getDistributionPoints(cert);
LOGGER.debug("Distribution points for [{}]: [{}].", CertUtils.toString(cert), CollectionUtils.wrap(urls));
final List<X509CRL> listOfLocations = new ArrayList<>(urls.length);
boolean stopFetching = false;
for (int index = 0; !stopFetching && index < urls.length; index++) {
final URI url = urls[index];
final Element item = this.crlCache.get(url);
if (item != null) {
LOGGER.debug("Found CRL in cache for [{}]", CertUtils.toString(cert));
final byte[] encodedCrl = (byte[]) item.getObjectValue();
final X509CRL crlFetched = this.fetcher.fetch(new ByteArrayResource(encodedCrl));
if (crlFetched != null) {
listOfLocations.add(crlFetched);
} else {
LOGGER.warn("Could fetch X509 CRL for [{}]. Returned value is null", url);
}
} else {
LOGGER.debug("CRL for [{}] is not cached. Fetching and caching...", CertUtils.toString(cert));
try {
final X509CRL crl = this.fetcher.fetch(url);
if (crl != null) {
LOGGER.info("Success. Caching fetched CRL at [{}].", url);
addCRL(url, crl);
listOfLocations.add(crl);
}
} catch (final Exception e) {
LOGGER.error("Error fetching CRL at [{}]", url, e);
if (this.throwOnFetchFailure) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
if (!this.checkAll && !listOfLocations.isEmpty()) {
LOGGER.debug("CRL fetching is configured to not check all locations.");
stopFetching = true;
}
}
LOGGER.debug("Found [{}] CRLs", listOfLocations.size());
return listOfLocations;
}
use of java.security.cert.X509CRL in project cxf by apache.
the class FileCertificateRepo method getCRLs.
@Override
public List<X509CRL> getCRLs() {
List<X509CRL> results = new ArrayList<>();
File[] list = getX509Files();
for (File crlFile : list) {
try {
if (crlFile.isDirectory()) {
continue;
}
if (crlFile.getParent().endsWith(CRLS_PATH)) {
X509CRL crl = readCRL(crlFile);
results.add(crl);
}
} catch (Exception e) {
LOG.warn(String.format("Cannot load CRL from file: %s. Error: %s", crlFile, e.getMessage()));
}
}
return results;
}
Aggregations