use of java.security.cert.CRL in project vert.x by eclipse.
the class SSLHelper method getTrustMgrFactory.
private TrustManagerFactory getTrustMgrFactory(VertxInternal vertx) throws Exception {
TrustManagerFactory fact;
if (trustAll) {
TrustManager[] mgrs = new TrustManager[] { createTrustAllTrustManager() };
fact = new VertxTrustManagerFactory(mgrs);
} else if (trustOptions != null) {
fact = trustOptions.getTrustManagerFactory(vertx);
} else {
return null;
}
if (crlPaths != null && crlValues != null && (crlPaths.size() > 0 || crlValues.size() > 0)) {
Stream<Buffer> tmp = crlPaths.stream().map(path -> vertx.resolveFile(path).getAbsolutePath()).map(vertx.fileSystem()::readFileBlocking);
tmp = Stream.concat(tmp, crlValues.stream());
CertificateFactory certificatefactory = CertificateFactory.getInstance("X.509");
ArrayList<CRL> crls = new ArrayList<>();
for (Buffer crlValue : tmp.collect(Collectors.toList())) {
crls.addAll(certificatefactory.generateCRLs(new ByteArrayInputStream(crlValue.getBytes())));
}
TrustManager[] mgrs = createUntrustRevokedCertTrustManager(fact.getTrustManagers(), crls);
fact = new VertxTrustManagerFactory(mgrs);
}
return fact;
}
use of java.security.cert.CRL in project java-chassis by ServiceComb.
the class KeyStoreUtil method createCRL.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static CRL[] createCRL(String crlfile) {
InputStream is = null;
try {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
is = new FileInputStream(crlfile);
Collection c = cf.generateCRLs(is);
CRL[] crls = (CRL[]) c.toArray(new CRL[c.size()]);
return crls;
} catch (CertificateException e) {
throw new IllegalArgumentException("bad cert file.");
} catch (FileNotFoundException e) {
throw new IllegalArgumentException("crl file not found.");
} catch (CRLException e) {
throw new IllegalArgumentException("bad crl file.");
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
ignore();
}
}
}
}
use of java.security.cert.CRL in project nhin-d by DirectProject.
the class CRLRevocationManager_getCrlFromUriTest method testGetCrlFromUri_nullURI_assertNull.
public void testGetCrlFromUri_nullURI_assertNull() {
CRL crl = CRLRevocationManager.getInstance().getCrlFromUri(null);
assertNull(crl);
}
use of java.security.cert.CRL in project nhin-d by DirectProject.
the class CRLRevocationManager_writeCRLCacheFileTest method testWriteCRLCacheFile_writeToFile_deleteExisting.
public void testWriteCRLCacheFile_writeToFile_deleteExisting() throws Exception {
CRLRevocationManager.initCRLCacheLocation();
CRL crlToWrite = TestUtils.loadCRL("certs.crl");
String distURI = "http://localhost:8080/config";
// make sure it doesn't exist
File crlFile = new File(CRLRevocationManager.getCacheFileName(distURI));
assertFalse(crlFile.exists());
CRLRevocationManager.getInstance().writeCRLCacheFile(distURI, (X509CRL) crlToWrite);
// make sure the file exists
assertTrue(crlFile.exists());
// mark the date
long originalFileDate = crlFile.lastModified();
// sleep 2000 ms to make sure we get a new date
Thread.sleep(2000);
// write it again
CRLRevocationManager.getInstance().writeCRLCacheFile(distURI, (X509CRL) crlToWrite);
// make sure the file exists
crlFile = new File(CRLRevocationManager.getCacheFileName(distURI));
assertTrue(crlFile.exists());
// mark the date
long newFileDate = crlFile.lastModified();
// make sure the dates aren't the same
assertTrue(originalFileDate != newFileDate);
}
use of java.security.cert.CRL in project nhin-d by DirectProject.
the class TestUtils method loadCRL.
public static CRL loadCRL(String certFileName) throws Exception {
File fl = new File(crlBasePath + certFileName);
InputStream str = FileUtils.openInputStream(fl);
CRL retVal = CertificateFactory.getInstance("X.509").generateCRL(str);
str.close();
return retVal;
}
Aggregations