Search in sources :

Example 21 with X509CRL

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);
}
Also used : X509CRL(java.security.cert.X509CRL)

Example 22 with X509CRL

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);
}
Also used : KeyPair(java.security.KeyPair) X509CRL(java.security.cert.X509CRL) Calendar(java.util.Calendar) X500Principal(javax.security.auth.x500.X500Principal) KeyPairGenerator(java.security.KeyPairGenerator) X509V2CRLGenerator(org.bouncycastle.x509.X509V2CRLGenerator)

Example 23 with X509CRL

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());
}
Also used : X509CRL(java.security.cert.X509CRL)

Example 24 with X509CRL

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);
}
Also used : X509CRL(java.security.cert.X509CRL) Calendar(java.util.Calendar)

Example 25 with X509CRL

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());
}
Also used : X509CRL(java.security.cert.X509CRL) File(java.io.File)

Aggregations

X509CRL (java.security.cert.X509CRL)74 IOException (java.io.IOException)23 CRLException (java.security.cert.CRLException)14 X509Certificate (java.security.cert.X509Certificate)14 File (java.io.File)12 GeneralSecurityException (java.security.GeneralSecurityException)8 CertificateException (java.security.cert.CertificateException)8 CRL (java.security.cert.CRL)7 CertificateFactory (java.security.cert.CertificateFactory)7 Iterator (java.util.Iterator)7 Calendar (java.util.Calendar)6 HashSet (java.util.HashSet)6 Set (java.util.Set)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 LocalizedIllegalArgumentException (org.forgerock.i18n.LocalizedIllegalArgumentException)5 LdapException (org.forgerock.opendj.ldap.LdapException)5 FileInputStream (java.io.FileInputStream)4