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;
}
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 jdk8u_jdk by JetBrains.
the class Pair method readCRLsFromCert.
/**
* Returns CRLs described in a X509Certificate's CRLDistributionPoints
* Extension. Only those containing a general name of type URI are read.
*/
public static List<CRL> readCRLsFromCert(X509Certificate cert) throws Exception {
List<CRL> crls = new ArrayList<>();
CRLDistributionPointsExtension ext = X509CertImpl.toImpl(cert).getCRLDistributionPointsExtension();
if (ext == null)
return crls;
List<DistributionPoint> distPoints = ext.get(CRLDistributionPointsExtension.POINTS);
for (DistributionPoint o : distPoints) {
GeneralNames names = o.getFullName();
if (names != null) {
for (GeneralName name : names.names()) {
if (name.getType() == GeneralNameInterface.NAME_URI) {
URIName uriName = (URIName) name.getName();
for (CRL crl : loadCRLs(uriName.getName())) {
if (crl instanceof X509CRL) {
crls.add((X509CRL) crl);
}
}
// Different name should point to same CRL
break;
}
}
}
}
return crls;
}
Aggregations