use of org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGeneratorFactory in project nhin-d by DirectProject.
the class SMIMECryptographerImpl_constructTest method testContructSMIMECryptographerImpl_setDecFactory.
public void testContructSMIMECryptographerImpl_setDecFactory() {
SMIMECryptographerImpl impl = new SMIMECryptographerImpl(EncryptionAlgorithm.RSA_3DES, DigestAlgorithm.SHA384, new SplitProviderDirectSignedDataGeneratorFactory(), new SplitDirectRecipientInformationFactory());
assertEquals(DigestAlgorithm.SHA384, impl.getDigestAlgorithm());
assertEquals(EncryptionAlgorithm.RSA_3DES, impl.getEncryptionAlgorithm());
assertTrue(impl.getSignedDataGeneratorFactory() instanceof SplitProviderDirectSignedDataGeneratorFactory);
assertTrue(impl.getRecipientInformationFactory() instanceof SplitDirectRecipientInformationFactory);
}
use of org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGeneratorFactory in project nhin-d by DirectProject.
the class SMIMECryptographerImpl_createSignatureEntityTest method testCreateSignatureEntity_hsmSignatureGenerator_assertEntityCreatedAndMatchesControl.
public void testCreateSignatureEntity_hsmSignatureGenerator_assertEntityCreatedAndMatchesControl() throws Exception {
final String installedAlias = "JunitTestKey";
/**
* 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());
// delete the entry in case it exists
try {
ks.deleteEntry(installedAlias);
} catch (Exception e) {
/*no-op */
}
// add the signing cert and private key into the token
final X509Certificate sigCertBPrivate = (X509CertificateEx) TestUtils.loadCertificate("certCheckB.p12");
try {
ks.setKeyEntry(installedAlias, ((X509CertificateEx) sigCertBPrivate).getPrivateKey(), null, new Certificate[] { sigCertBPrivate });
final KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) ks.getEntry(installedAlias, null);
final X509Certificate signerCert = X509CertificateEx.fromX509Certificate((X509Certificate) entry.getCertificate(), entry.getPrivateKey());
SplitProviderDirectSignedDataGeneratorFactory factory = new SplitProviderDirectSignedDataGeneratorFactory(pkcs11ProvName, "BC");
final SMIMECryptographerImpl impl = new SMIMECryptographerImpl();
impl.setSignedDataGeneratorFactory(factory);
final String testMessage = TestUtils.readResource("MultipartMimeMessage.txt");
final MimeEntity ent = new Message(new ByteArrayInputStream(testMessage.getBytes())).extractEntityForSignature(true);
byte[] bytesToSign = EntitySerializer.Default.serializeToBytes(ent);
final MimeMultipart mm = impl.createSignatureEntity(bytesToSign, Arrays.asList(signerCert));
assertNotNull(mm);
assertEquals(2, mm.getCount());
validatedSignatureHeaders(mm);
// now create the control
final SMIMECryptographerImpl controllImpl = new SMIMECryptographerImpl();
final MimeMultipart controllmm = controllImpl.createSignatureEntity(bytesToSign, Arrays.asList(sigCertBPrivate));
assertNotNull(controllmm);
assertEquals(2, controllmm.getCount());
// make sure the signatures can be verified
// the actual byte data may not be the same due to
// randomness in the signature
validateSignature(deserializeSignatureEnvelope(mm), sigCertBPrivate);
validateSignature(deserializeSignatureEnvelope(controllmm), sigCertBPrivate);
} finally {
ks.deleteEntry(installedAlias);
}
}
}
use of org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGeneratorFactory in project nhin-d by DirectProject.
the class SplitProviderDirectSignedDataGeneratorFactory_createGenTest method testCreateGenerator_emptyProvider_assertDefaultProvider.
public void testCreateGenerator_emptyProvider_assertDefaultProvider() throws Exception {
final SplitProviderDirectSignedDataGeneratorFactory factory = new SplitProviderDirectSignedDataGeneratorFactory();
final SplitProviderDirectSignedDataGenerator gen = (SplitProviderDirectSignedDataGenerator) factory.createInstance();
assertEquals(CryptoExtensions.getJCESensitiveProviderName(), gen.sigProvider);
assertEquals(CryptoExtensions.getJCEProviderName(), gen.digestProvider);
}
use of org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGeneratorFactory in project nhin-d by DirectProject.
the class SplitProviderDirectSignedDataGeneratorFactory_createGenTest method testCreateGenerator_customeProvider_assertProviders.
public void testCreateGenerator_customeProvider_assertProviders() throws Exception {
final SplitProviderDirectSignedDataGeneratorFactory factory = new SplitProviderDirectSignedDataGeneratorFactory("TestProvider1", "TestProvider2");
final SplitProviderDirectSignedDataGenerator gen = (SplitProviderDirectSignedDataGenerator) factory.createInstance();
assertEquals("TestProvider1", gen.sigProvider);
assertEquals("TestProvider2", gen.digestProvider);
}
use of org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGeneratorFactory in project nhin-d by DirectProject.
the class SMIMECryptographerImpl_constructTest method testContructSMIMECryptographerImpl_setSigningFactory.
public void testContructSMIMECryptographerImpl_setSigningFactory() {
SMIMECryptographerImpl impl = new SMIMECryptographerImpl(EncryptionAlgorithm.RSA_3DES, DigestAlgorithm.SHA384, new SplitProviderDirectSignedDataGeneratorFactory(), null);
assertEquals(DigestAlgorithm.SHA384, impl.getDigestAlgorithm());
assertEquals(EncryptionAlgorithm.RSA_3DES, impl.getEncryptionAlgorithm());
assertTrue(impl.getSignedDataGeneratorFactory() instanceof SplitProviderDirectSignedDataGeneratorFactory);
assertTrue(impl.getRecipientInformationFactory() instanceof SplitDirectRecipientInformationFactory);
}
Aggregations