use of org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGenerator in project nhin-d by DirectProject.
the class SplitProviderDirectSignedDataGenerator_generateTest method testGenerate_safeNetHSMSignatureProvider_assertGenerated.
public void testGenerate_safeNetHSMSignatureProvider_assertGenerated() 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());
final Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
final String alias = aliases.nextElement();
final KeyStore.Entry entry = ks.getEntry(alias, null);
if (entry instanceof KeyStore.PrivateKeyEntry) {
KeyStore.PrivateKeyEntry ent = (KeyStore.PrivateKeyEntry) entry;
signerCert = X509CertificateEx.fromX509Certificate((X509Certificate) ent.getCertificate(), ent.getPrivateKey());
break;
}
}
final SplitProviderDirectSignedDataGenerator gen = new SplitProviderDirectSignedDataGenerator(pkcs11ProvName, "BC");
setupSigningInfo(gen);
// create the content
final MimeBodyPart signedContent = new MimeBodyPart();
signedContent.addHeader("To:", "me@you.com");
signedContent.addHeader("From", "test.test.com");
signedContent.setText("Some Text To Sign");
final CMSProcessableBodyPart content = new CMSProcessableBodyPart(signedContent);
final CMSSignedData signedData = gen.generate(content);
validateSignature(signedData);
}
}
use of org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGenerator in project nhin-d by DirectProject.
the class SplitProviderDirectSignedDataGenerator_generateTest method testGenerate_differentDefaultSigAndDigestProvider_assertGenerated.
public void testGenerate_differentDefaultSigAndDigestProvider_assertGenerated() throws Exception {
final SplitProviderDirectSignedDataGenerator gen = new SplitProviderDirectSignedDataGenerator("SunRsaSign", "BC");
setupSigningInfo(gen);
// create the content
final MimeBodyPart signedContent = new MimeBodyPart();
signedContent.addHeader("To:", "me@you.com");
signedContent.addHeader("From", "test.test.com");
signedContent.setText("Some Text To Sign");
final CMSProcessableBodyPart content = new CMSProcessableBodyPart(signedContent);
final CMSSignedData signedData = gen.generate(content);
validateSignature(signedData);
}
use of org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGenerator 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.SplitProviderDirectSignedDataGenerator in project nhin-d by DirectProject.
the class SplitProviderDirectSignedDataGenerator_generateTest method testGenerate_sameDefaultSigAndDigestProvider_assertGenerated.
public void testGenerate_sameDefaultSigAndDigestProvider_assertGenerated() throws Exception {
final SplitProviderDirectSignedDataGenerator gen = new SplitProviderDirectSignedDataGenerator("", "");
setupSigningInfo(gen);
// create the content
final MimeBodyPart signedContent = new MimeBodyPart();
signedContent.addHeader("To:", "me@you.com");
signedContent.addHeader("From", "test.test.com");
signedContent.setText("Some Text To Sign");
final CMSProcessableBodyPart content = new CMSProcessableBodyPart(signedContent);
final CMSSignedData signedData = gen.generate(content);
validateSignature(signedData);
}
use of org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGenerator 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);
}
Aggregations