use of org.bouncycastle.x509.X509V2CRLGenerator in project nhin-d by DirectProject.
the class CRLRevocationManager_getCrlFromUriTest method testGetCrlFromUri_notInCache_loadFromCacheFile_assertCRLFound.
public void testGetCrlFromUri_notInCache_loadFromCacheFile_assertCRLFound() throws Exception {
CRLRevocationManager.initCRLCacheLocation();
String uri = "http://localhost:8080/certs.crl";
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");
CRLRevocationManager.INSTANCE.writeCRLCacheFile(uri, crl);
X509CRL retCrl = CRLRevocationManager.getInstance().getCrlFromUri(uri);
assertNotNull(retCrl);
assertEquals(crl, retCrl);
}
use of org.bouncycastle.x509.X509V2CRLGenerator 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());
}
Aggregations