use of java.security.cert.X509CRL in project nhin-d by DirectProject.
the class CRLRevocationManager_getCrlFromUriTest method testGetCrlFromUri_fromURL_uriNotAvailable_assertCRLNotFound.
public void testGetCrlFromUri_fromURL_uriNotAvailable_assertCRLNotFound() throws Exception {
CRLRevocationManager.initCRLCacheLocation();
X509CRL retCRL = CRLRevocationManager.getInstance().getCrlFromUri("file://target/bogusURI");
assertNull(retCRL);
}
use of java.security.cert.X509CRL 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 java.security.cert.X509CRL in project nhin-d by DirectProject.
the class CRLRevocationManager_getCrlFromUriTest method testGetCrlFromUri_existsInCache_softRefRemoved_assertCRLNotFound.
@SuppressWarnings("unchecked")
public void testGetCrlFromUri_existsInCache_softRefRemoved_assertCRLNotFound() {
String uri = "http://localhost:8080/master.crl";
SoftReference<X509CRL> softRef = mock(SoftReference.class);
when(softRef.get()).thenReturn(null);
CRLRevocationManager.cache.put(uri, softRef);
X509CRL retCrl = CRLRevocationManager.getInstance().getCrlFromUri(uri);
assertNull(retCrl);
//make sure it got removed from the cache
assertEquals(0, CRLRevocationManager.cache.size());
}
use of java.security.cert.X509CRL in project nhin-d by DirectProject.
the class CRLRevocationManager_getCrlFromUriTest method testGetCrlFromUri_existsInCache_assertCRLFound.
public void testGetCrlFromUri_existsInCache_assertCRLFound() {
String uri = "http://localhost:8080/master.crl";
Calendar nextUpdateDate = Calendar.getInstance();
nextUpdateDate.set(Calendar.YEAR, nextUpdateDate.get(Calendar.YEAR) + 10);
X509CRL crl = mock(X509CRL.class);
when(crl.getNextUpdate()).thenReturn(nextUpdateDate.getTime());
CRLRevocationManager.cache.put(uri, new SoftReference<X509CRL>(crl));
X509CRL retCrl = CRLRevocationManager.getInstance().getCrlFromUri(uri);
assertNotNull(retCrl);
assertEquals(crl, retCrl);
}
use of java.security.cert.X509CRL in project nhin-d by DirectProject.
the class CRLRevocationManager_getCrlFromUriTest method testGetCrlFromUri_notInCache_loadFromCacheFile_expiredCRL_assertCRLFound.
public void testGetCrlFromUri_notInCache_loadFromCacheFile_expiredCRL_assertCRLFound() throws Exception {
CRLRevocationManager.initCRLCacheLocation();
String uri = "http://localhost:8080/certs.crl";
X509CRL crl = (X509CRL) TestUtils.loadCRL("certs.crl");
CRLRevocationManager.INSTANCE.writeCRLCacheFile(uri, crl);
String fileName = CRLRevocationManager.getCacheFileName(uri);
File writeFile = new File(fileName);
assertTrue(writeFile.exists());
X509CRL retCrl = CRLRevocationManager.getInstance().getCrlFromUri(uri);
assertNull(retCrl);
writeFile = new File(fileName);
assertFalse(writeFile.exists());
}
Aggregations