Search in sources :

Example 71 with X509CRL

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());
}
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) File(java.io.File) X509V2CRLGenerator(org.bouncycastle.x509.X509V2CRLGenerator)

Example 72 with X509CRL

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

Example 73 with X509CRL

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

Example 74 with X509CRL

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