Search in sources :

Example 1 with SplitProviderDirectSignedDataGenerator

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);
    }
}
Also used : SplitProviderDirectSignedDataGenerator(org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGenerator) MimeBodyPart(javax.mail.internet.MimeBodyPart) KeyStore(java.security.KeyStore) CMSSignedData(org.bouncycastle.cms.CMSSignedData) X509Certificate(java.security.cert.X509Certificate) CMSProcessableBodyPart(org.bouncycastle.mail.smime.CMSProcessableBodyPart)

Example 2 with SplitProviderDirectSignedDataGenerator

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);
}
Also used : SplitProviderDirectSignedDataGenerator(org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGenerator) MimeBodyPart(javax.mail.internet.MimeBodyPart) CMSSignedData(org.bouncycastle.cms.CMSSignedData) CMSProcessableBodyPart(org.bouncycastle.mail.smime.CMSProcessableBodyPart)

Example 3 with SplitProviderDirectSignedDataGenerator

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);
}
Also used : SplitProviderDirectSignedDataGenerator(org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGenerator) SplitProviderDirectSignedDataGeneratorFactory(org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGeneratorFactory)

Example 4 with SplitProviderDirectSignedDataGenerator

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);
}
Also used : SplitProviderDirectSignedDataGenerator(org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGenerator) MimeBodyPart(javax.mail.internet.MimeBodyPart) CMSSignedData(org.bouncycastle.cms.CMSSignedData) CMSProcessableBodyPart(org.bouncycastle.mail.smime.CMSProcessableBodyPart)

Example 5 with SplitProviderDirectSignedDataGenerator

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);
}
Also used : SplitProviderDirectSignedDataGenerator(org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGenerator) SplitProviderDirectSignedDataGeneratorFactory(org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGeneratorFactory)

Aggregations

SplitProviderDirectSignedDataGenerator (org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGenerator)5 MimeBodyPart (javax.mail.internet.MimeBodyPart)3 CMSSignedData (org.bouncycastle.cms.CMSSignedData)3 CMSProcessableBodyPart (org.bouncycastle.mail.smime.CMSProcessableBodyPart)3 SplitProviderDirectSignedDataGeneratorFactory (org.nhindirect.stagent.cryptography.activekeyops.SplitProviderDirectSignedDataGeneratorFactory)2 KeyStore (java.security.KeyStore)1 X509Certificate (java.security.cert.X509Certificate)1