use of org.nhindirect.stagent.cert.X509CertificateEx in project nhin-d by DirectProject.
the class CacheableKeyStoreManagerCertificateStore_removeTest method testRemove_removingExistingCert_assertRemoved.
public void testRemove_removingExistingCert_assertRemoved() throws Exception {
if (store != null) {
// add a certificate
final X509CertificateEx user1 = (X509CertificateEx) TestUtils.getInternalCert("user1");
store.add(user1);
final Collection<X509Certificate> retrievedCerts = store.getAllCertificates();
final X509Certificate retrievedCert = retrievedCerts.iterator().next();
assertEquals(user1, retrievedCert);
// remove it
store.remove(user1);
assertTrue(store.getAllCertificates().isEmpty());
}
}
use of org.nhindirect.stagent.cert.X509CertificateEx in project nhin-d by DirectProject.
the class CacheableKeyStoreManagerCertificateStore_removeTest method testRemove_removingNonExistantCert_assertNotRemoved.
public void testRemove_removingNonExistantCert_assertNotRemoved() throws Exception {
if (store != null) {
// add a certificate
final X509CertificateEx user1 = (X509CertificateEx) TestUtils.getInternalCert("user1");
store.add(user1);
final Collection<X509Certificate> retrievedCerts = store.getAllCertificates();
final X509Certificate retrievedCert = retrievedCerts.iterator().next();
assertEquals(user1, retrievedCert);
// try removing another non existant cert
final X509Certificate cacert = TestUtils.getInternalCACert("cacert");
store.remove(cacert);
assertFalse(store.getAllCertificates().isEmpty());
}
}
use of org.nhindirect.stagent.cert.X509CertificateEx in project nhin-d by DirectProject.
the class SplitDirectRecipientInformation_getDecryptedContentTest method testGetDecryptedContent_sameDefaultEncAndKeyEncProvider_assertDecrypted.
public void testGetDecryptedContent_sameDefaultEncAndKeyEncProvider_assertDecrypted() throws Exception {
final SMIMEEnveloped env = createSMIMEEnv();
final RecipientInformation recipient = (RecipientInformation) env.getRecipientInfos().getRecipients().iterator().next();
final SplitDirectRecipientInformationFactory factory = new SplitDirectRecipientInformationFactory();
final SplitDirectRecipientInformation recInfo = (SplitDirectRecipientInformation) factory.createInstance(recipient, env);
// this will be non-null if it works correctly
assertNotNull(recInfo.getDecryptedContent(((X509CertificateEx) encCert).getPrivateKey()));
}
use of org.nhindirect.stagent.cert.X509CertificateEx in project nhin-d by DirectProject.
the class SplitDirectRecipientInformation_getDecryptedContentTest method testGetDecryptedContent_safeNetHSMKeyEncProvider_differntEncCert_assertNotDecrypted.
public void testGetDecryptedContent_safeNetHSMKeyEncProvider_differntEncCert_assertNotDecrypted() throws Exception {
/**
* This test is only run if a specific SafeNet eToken Pro HSM is connected to the testing
* system. This can be modified for another specific machine and/or token.
*/
pkcs11ProvName = TestUtils.setupSafeNetToken();
if (!StringUtils.isEmpty(pkcs11ProvName)) {
// get a certificate from the key store
final KeyStore ks = KeyStore.getInstance("PKCS11");
ks.load(null, "1Kingpuff".toCharArray());
// get the decryption cert
X509CertificateEx decryptCert = null;
final Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
Certificate pkcs11Cert = ks.getCertificate(alias);
if (pkcs11Cert != null && pkcs11Cert instanceof X509Certificate) {
// check if there is private key
Key key = ks.getKey(alias, null);
if (key != null && key instanceof PrivateKey && CryptoExtensions.certSubjectContainsName((X509Certificate) pkcs11Cert, "user1@cerner.com")) {
decryptCert = X509CertificateEx.fromX509Certificate((X509Certificate) pkcs11Cert, (PrivateKey) key);
break;
}
}
}
encCert = TestUtils.getInternalCert("gm2552");
final SMIMEEnveloped env = createSMIMEEnv(encCert);
final RecipientInformation recipient = (RecipientInformation) env.getRecipientInfos().getRecipients().iterator().next();
final SplitDirectRecipientInformationFactory factory = new SplitDirectRecipientInformationFactory(pkcs11ProvName, "BC");
final SplitDirectRecipientInformation recInfo = (SplitDirectRecipientInformation) factory.createInstance(recipient, env);
boolean exceptionOccured = false;
try {
recInfo.getDecryptedContent(decryptCert.getPrivateKey());
} catch (Exception e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
}
}
use of org.nhindirect.stagent.cert.X509CertificateEx in project nhin-d by DirectProject.
the class SplitDirectRecipientInformation_getDecryptedContentTest method testGetDecryptedContent_differentEncAndKeyEncProvider_assertDecrypted.
public void testGetDecryptedContent_differentEncAndKeyEncProvider_assertDecrypted() throws Exception {
final SMIMEEnveloped env = createSMIMEEnv();
final RecipientInformation recipient = (RecipientInformation) env.getRecipientInfos().getRecipients().iterator().next();
final SplitDirectRecipientInformationFactory factory = new SplitDirectRecipientInformationFactory("SunJCE", "BC");
final SplitDirectRecipientInformation recInfo = (SplitDirectRecipientInformation) factory.createInstance(recipient, env);
// this will be non-null if it works correctly
assertNotNull(recInfo.getDecryptedContent(((X509CertificateEx) encCert).getPrivateKey()));
}
Aggregations