Search in sources :

Example 1 with X509V2CRLGenerator

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);
}
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 2 with X509V2CRLGenerator

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());
}
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)

Aggregations

KeyPair (java.security.KeyPair)2 KeyPairGenerator (java.security.KeyPairGenerator)2 X509CRL (java.security.cert.X509CRL)2 Calendar (java.util.Calendar)2 X500Principal (javax.security.auth.x500.X500Principal)2 X509V2CRLGenerator (org.bouncycastle.x509.X509V2CRLGenerator)2 File (java.io.File)1