use of java.security.cert.X509CRL in project nhin-d by DirectProject.
the class CRLRevocationManager_getCrlFromUriTest method testGetCrlFromUri_fromURL_assertCRLFound.
public void testGetCrlFromUri_fromURL_assertCRLFound() throws Exception {
CRLRevocationManager.initCRLCacheLocation();
X509CRL crl = (X509CRL) TestUtils.loadCRL("certs.crl");
KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC");
KeyPair pair = kpGen.generateKeyPair();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + 10);
X509V2CRLGenerator crlGen = new X509V2CRLGenerator();
crlGen.setIssuerDN(new X500Principal("CN=Test CRL"));
crlGen.setNextUpdate(cal.getTime());
crlGen.setSignatureAlgorithm("SHA256withRSAEncryption");
crlGen.setThisUpdate(Calendar.getInstance().getTime());
crlGen.addCRL(crl);
crl = crlGen.generate(pair.getPrivate(), "BC");
String fileName = UUID.randomUUID().toString();
final File crlFile = new File("target/" + fileName + ".crl");
FileUtils.writeByteArrayToFile(crlFile, crl.getEncoded());
CRLRevocationManager mgr = new CRLRevocationManager() {
@Override
protected String getNameString(String generalNameString) {
return "file:///" + crlFile.getAbsolutePath();
}
};
String uri = crlFile.getAbsolutePath();
X509CRL retCRL = mgr.getCrlFromUri("file:///" + uri);
assertEquals(crl, retCRL);
String cacheFileName = CRLRevocationManager.getCacheFileName("file:///" + uri);
File cacheFile = new File(cacheFileName);
assertTrue(cacheFile.exists());
}
use of java.security.cert.X509CRL in project nhin-d by DirectProject.
the class CRLRevocationManager_writeCRLCacheFileTest method testWriteCRLCacheFile_writeToFile.
public void testWriteCRLCacheFile_writeToFile() throws Exception {
CRLRevocationManager.initCRLCacheLocation();
CRL crlToWrite = TestUtils.loadCRL("certs.crl");
String distURI = "http://localhost:8080/config";
CRLRevocationManager.getInstance().writeCRLCacheFile(distURI, (X509CRL) crlToWrite);
// make sure the file exists
File crlFile = new File(CRLRevocationManager.getCacheFileName(distURI));
assertTrue(crlFile.exists());
}
use of java.security.cert.X509CRL in project nhin-d by DirectProject.
the class CRLRevocationManager_getCrlFromUriTest method testGetCrlFromUri_notInCache_assertCRLNotFound.
public void testGetCrlFromUri_notInCache_assertCRLNotFound() {
String uri = "http://localhost:8080/master.crl";
X509CRL retCrl = CRLRevocationManager.getInstance().getCrlFromUri(uri);
assertNull(retCrl);
}
use of java.security.cert.X509CRL in project nhin-d by DirectProject.
the class CRLRevocationManager_removeCRLCacheFileTest method testRemoveCRLCacheFile_removeExistingFile.
public void testRemoveCRLCacheFile_removeExistingFile() throws Exception {
CRLRevocationManager.initCRLCacheLocation();
CRL crlToWrite = TestUtils.loadCRL("certs.crl");
String distURI = "http://localhost:8080/config";
CRLRevocationManager.getInstance().writeCRLCacheFile(distURI, (X509CRL) crlToWrite);
// make sure the file exists
File crlFile = new File(CRLRevocationManager.getCacheFileName(distURI));
assertTrue(crlFile.exists());
// now delete the file
CRLRevocationManager.getInstance().removeCrlCacheFile(distURI);
// make sure the file does not exist
crlFile = new File(CRLRevocationManager.getCacheFileName(distURI));
assertFalse(crlFile.exists());
}
Aggregations