Search in sources :

Example 1 with BootstrappedKeyStoreProtectionManager

use of org.nhindirect.common.crypto.impl.BootstrappedKeyStoreProtectionManager in project nhin-d by DirectProject.

the class CertificateDaoImp_saveWithProtectionMgr method testStripP12ProtectionTest_NoP12ProtectionWithManager_assertP12Returned.

@Test
public void testStripP12ProtectionTest_NoP12ProtectionWithManager_assertP12Returned() throws Exception {
    final EntityManager manager = mock(EntityManager.class);
    doAnswer(new Answer<Object>() {

        public Object answer(InvocationOnMock invocation) {
            persistedCert = (Certificate) invocation.getArguments()[0];
            return "";
        }
    }).when(manager).persist(any());
    final BootstrappedKeyStoreProtectionManager mgr = new BootstrappedKeyStoreProtectionManager();
    mgr.setKeyStoreProtectionKey("12345");
    mgr.setPrivateKeyProtectionKey("67890");
    CertificateDaoImpl daoImpl = new CertificateDaoImpl();
    daoImpl.setKeyStoreProtectionManager(mgr);
    daoImpl.setEntityManager(manager);
    daoImpl.save(populateCert("gm2552.der", "gm2552Key.der"));
    assert (persistedCert.getData() != null);
    // make sure we can't access the P12 without a passphrase
    boolean exceptionOccured = false;
    try {
        CertUtils.toCertContainer(persistedCert.getData());
    } catch (CertificateConversionException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : EntityManager(javax.persistence.EntityManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CertificateConversionException(org.nhindirect.config.model.exceptions.CertificateConversionException) CertificateDaoImpl(org.nhindirect.config.store.dao.impl.CertificateDaoImpl) BootstrappedKeyStoreProtectionManager(org.nhindirect.common.crypto.impl.BootstrappedKeyStoreProtectionManager) Test(org.junit.Test)

Example 2 with BootstrappedKeyStoreProtectionManager

use of org.nhindirect.common.crypto.impl.BootstrappedKeyStoreProtectionManager in project nhin-d by DirectProject.

the class CacheableKeyStoreManagerCertificateStore_addTest method testAdd_nonMutableStore_assertException.

public void testAdd_nonMutableStore_assertException() throws Exception {
    if (store != null) {
        final BootstrappedKeyStoreProtectionManager mgr = new BootstrappedKeyStoreProtectionManager();
        store.setKeyStoreManager(mgr);
        boolean exceptionOccured = false;
        try {
            final X509CertificateEx user1 = (X509CertificateEx) TestUtils.getInternalCert("user1");
            store.add(user1);
        } catch (IllegalStateException ex) {
            exceptionOccured = true;
        }
        assertTrue(exceptionOccured);
    }
}
Also used : X509CertificateEx(org.nhindirect.stagent.cert.X509CertificateEx) BootstrappedKeyStoreProtectionManager(org.nhindirect.common.crypto.impl.BootstrappedKeyStoreProtectionManager)

Example 3 with BootstrappedKeyStoreProtectionManager

use of org.nhindirect.common.crypto.impl.BootstrappedKeyStoreProtectionManager in project nhin-d by DirectProject.

the class CacheableKeyStoreManagerCertificateStore_removeTest method testRemove_nonMutableStore_assertException.

public void testRemove_nonMutableStore_assertException() throws Exception {
    if (store != null) {
        final BootstrappedKeyStoreProtectionManager mgr = new BootstrappedKeyStoreProtectionManager();
        store.setKeyStoreManager(mgr);
        boolean exceptionOccured = false;
        try {
            final X509Certificate cacert = TestUtils.getInternalCACert("cacert");
            store.remove(cacert);
        } catch (IllegalStateException ex) {
            exceptionOccured = true;
        }
        assertTrue(exceptionOccured);
    }
}
Also used : BootstrappedKeyStoreProtectionManager(org.nhindirect.common.crypto.impl.BootstrappedKeyStoreProtectionManager) X509Certificate(java.security.cert.X509Certificate)

Example 4 with BootstrappedKeyStoreProtectionManager

use of org.nhindirect.common.crypto.impl.BootstrappedKeyStoreProtectionManager in project nhin-d by DirectProject.

the class CacheableKeyStoreManagerCertificateStore_constructTest method testContrust_providedStore_assertNonEmptyStore.

public void testContrust_providedStore_assertNonEmptyStore() throws Exception {
    final BootstrappedKeyStoreProtectionManager mgr = new BootstrappedKeyStoreProtectionManager();
    final CacheableKeyStoreManagerCertificateStore store = new CacheableKeyStoreManagerCertificateStore(mgr);
    assertNotNull(store.storeMgr);
    assertNotNull(store.cachePolicy);
    assertEquals(CacheableKeyStoreManagerCertificateStore.DEFAULT_MAX_CAHCE_ITEMS, store.cachePolicy.getMaxItems());
    assertEquals(CacheableKeyStoreManagerCertificateStore.DEFAULT_CACHE_TTL, store.cachePolicy.getSubjectTTL());
}
Also used : BootstrappedKeyStoreProtectionManager(org.nhindirect.common.crypto.impl.BootstrappedKeyStoreProtectionManager)

Example 5 with BootstrappedKeyStoreProtectionManager

use of org.nhindirect.common.crypto.impl.BootstrappedKeyStoreProtectionManager in project nhin-d by DirectProject.

the class CacheableKeyStoreManagerCertificateStore_constructTest method testContrust_providedStoreAndCachePolicy_assertNonEmptyStoreAndCustomPolicy.

public void testContrust_providedStoreAndCachePolicy_assertNonEmptyStoreAndCustomPolicy() throws Exception {
    DefaultCertStoreCachePolicy policy = new DefaultCertStoreCachePolicy();
    policy.setMaxItems(456);
    policy.setSubjectTTL(999);
    final BootstrappedKeyStoreProtectionManager mgr = new BootstrappedKeyStoreProtectionManager();
    final CacheableKeyStoreManagerCertificateStore store = new CacheableKeyStoreManagerCertificateStore(mgr, policy);
    assertNotNull(store.storeMgr);
    assertNotNull(store.cachePolicy);
    assertEquals(456, store.cachePolicy.getMaxItems());
    assertEquals(999, store.cachePolicy.getSubjectTTL());
}
Also used : DefaultCertStoreCachePolicy(org.nhindirect.stagent.cert.DefaultCertStoreCachePolicy) BootstrappedKeyStoreProtectionManager(org.nhindirect.common.crypto.impl.BootstrappedKeyStoreProtectionManager)

Aggregations

BootstrappedKeyStoreProtectionManager (org.nhindirect.common.crypto.impl.BootstrappedKeyStoreProtectionManager)5 X509Certificate (java.security.cert.X509Certificate)1 EntityManager (javax.persistence.EntityManager)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 CertificateConversionException (org.nhindirect.config.model.exceptions.CertificateConversionException)1 CertificateDaoImpl (org.nhindirect.config.store.dao.impl.CertificateDaoImpl)1 DefaultCertStoreCachePolicy (org.nhindirect.stagent.cert.DefaultCertStoreCachePolicy)1 X509CertificateEx (org.nhindirect.stagent.cert.X509CertificateEx)1