use of org.nhindirect.common.crypto.PKCS11Credential in project nhin-d by DirectProject.
the class ConfigServiceRESTCertificateStore_getCertificateWithHSMKeyTest method getCertService.
protected ConfigServiceRESTCertificateStore getCertService() throws Exception {
if (StringUtils.isEmpty(TestUtils.setupSafeNetToken()))
return null;
final ConfigServiceRESTCertificateStore certService = new ConfigServiceRESTCertificateStore(proxy);
final PKCS11Credential cred = new BootstrappedPKCS11Credential("1Kingpuff");
final StaticPKCS11TokenKeyStoreProtectionManager mgr = new StaticPKCS11TokenKeyStoreProtectionManager(cred, "KeyStoreProtKey", "PrivKeyProtKey");
certService.setKeyStoreProectionManager(mgr);
return certService;
}
use of org.nhindirect.common.crypto.PKCS11Credential in project nhin-d by DirectProject.
the class StaticPKCS11TokenKeyStoreProtectionManagerTest method testSetKeysAsByteArrayAndGetFromToken.
@Test
public void testSetKeysAsByteArrayAndGetFromToken() throws Exception {
final String pkcs11ProvName = TestUtils.setupSafeNetToken();
if (!StringUtils.isEmpty(pkcs11ProvName)) {
PKCS11Credential cred = new BootstrappedPKCS11Credential("1Kingpuff");
final StaticPKCS11TokenKeyStoreProtectionManager mgr = new StaticPKCS11TokenKeyStoreProtectionManager(cred, "KeyStoreProtKey", "PrivKeyProtKey");
// create the keys on the token
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
// cryptograph. secure random
SecureRandom random = new SecureRandom();
keyGen.init(random);
final SecretKey keyStoreSecretKey = keyGen.generateKey();
mgr.clearKeyStoreProtectionKey();
mgr.setKeyStoreProtectionKeyAsBytes(keyStoreSecretKey.getEncoded());
keyGen = KeyGenerator.getInstance("AES");
// cryptograph. secure random
random = new SecureRandom();
keyGen.init(random);
final SecretKey privKeySecretKey = keyGen.generateKey();
mgr.clearPrivateKeyProtectionKey();
mgr.setPrivateKeyProtectionKeyAsBytes(privKeySecretKey.getEncoded());
assertTrue(Arrays.equals(keyStoreSecretKey.getEncoded(), mgr.getKeyStoreProtectionKey().getEncoded()));
assertTrue(Arrays.equals(privKeySecretKey.getEncoded(), mgr.getPrivateKeyProtectionKey().getEncoded()));
}
}
use of org.nhindirect.common.crypto.PKCS11Credential in project nhin-d by DirectProject.
the class StaticPKCS11TokenKeyStoreProtectionManagerTest method testSetKeysAsKeyAndGetFromToken.
@Test
public void testSetKeysAsKeyAndGetFromToken() throws Exception {
final String pkcs11ProvName = TestUtils.setupSafeNetToken();
if (!StringUtils.isEmpty(pkcs11ProvName)) {
final PKCS11Credential cred = new BootstrappedPKCS11Credential("1Kingpuff");
final StaticPKCS11TokenKeyStoreProtectionManager mgr = new StaticPKCS11TokenKeyStoreProtectionManager(cred, "KeyStoreProtKey", "PrivKeyProtKey");
// create the keys on the token
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
// cryptograph. secure random
SecureRandom random = new SecureRandom();
keyGen.init(random);
final SecretKey keyStoreSecretKey = keyGen.generateKey();
mgr.clearKeyStoreProtectionKey();
mgr.setKeyStoreProtectionKey(keyStoreSecretKey);
keyGen = KeyGenerator.getInstance("AES");
// cryptograph. secure random
random = new SecureRandom();
keyGen.init(random);
final SecretKey privKeySecretKey = keyGen.generateKey();
mgr.clearPrivateKeyProtectionKey();
mgr.setPrivateKeyProtectionKey(privKeySecretKey);
assertTrue(Arrays.equals(keyStoreSecretKey.getEncoded(), mgr.getKeyStoreProtectionKey().getEncoded()));
assertTrue(Arrays.equals(privKeySecretKey.getEncoded(), mgr.getPrivateKeyProtectionKey().getEncoded()));
}
}
use of org.nhindirect.common.crypto.PKCS11Credential in project nhin-d by DirectProject.
the class StaticPKCS11TokenKeyStoreProtectionManagerTest method testGetAllKeys_secureRandomGenKeys.
@Test
public void testGetAllKeys_secureRandomGenKeys() throws Exception {
final String pkcs11ProvName = TestUtils.setupSafeNetToken();
if (!StringUtils.isEmpty(pkcs11ProvName)) {
PKCS11Credential cred = new BootstrappedPKCS11Credential("1Kingpuff");
final StaticPKCS11TokenKeyStoreProtectionManager mgr = new StaticPKCS11TokenKeyStoreProtectionManager(cred, "KeyStoreProtKey", "PrivKeyProtKey");
// create the keys on the token
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
// cryptograph. secure random
SecureRandom random = new SecureRandom();
keyGen.init(random);
final SecretKey keyStoreSecretKey = keyGen.generateKey();
mgr.clearKeyStoreProtectionKey();
mgr.setKeyStoreProtectionKey(keyStoreSecretKey);
keyGen = KeyGenerator.getInstance("AES");
// cryptograph. secure random
random = new SecureRandom();
keyGen.init(random);
final SecretKey privKeySecretKey = keyGen.generateKey();
mgr.clearPrivateKeyProtectionKey();
mgr.setPrivateKeyProtectionKey(privKeySecretKey);
final Map<String, Key> keys = mgr.getAllKeys();
assertEquals(2, keys.size());
Iterator<Entry<String, Key>> entryIter = keys.entrySet().iterator();
Key key = entryIter.next().getValue();
assertTrue(Arrays.equals(privKeySecretKey.getEncoded(), key.getEncoded()));
key = entryIter.next().getValue();
assertTrue(Arrays.equals(keyStoreSecretKey.getEncoded(), key.getEncoded()));
}
}
use of org.nhindirect.common.crypto.PKCS11Credential in project nhin-d by DirectProject.
the class BaseKeyStoreManagerCertStoreTest method setUp.
@Override
public void setUp() throws Exception {
CertCacheFactory.getInstance().flushAll();
if (!StringUtils.isEmpty(TestUtils.setupSafeNetToken())) {
// clean out the token of all private keys
final PKCS11Credential cred = new BootstrappedPKCS11Credential("1Kingpuff");
final MutableKeyStoreProtectionManager mgr = new StaticPKCS11TokenKeyStoreProtectionManager(cred, "", "");
store = new CacheableKeyStoreManagerCertificateStore(mgr);
store.remove(store.getAllCertificates());
assertTrue(store.getAllCertificates().isEmpty());
}
}
Aggregations