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