Search in sources :

Example 31 with CertificateResolver

use of org.nhindirect.stagent.cert.CertificateResolver in project nhin-d by DirectProject.

the class NHINDAgentTest method testIncomingNormalMessage_incomingNotTrusted_outgoingTrusted_assertMessageNotTrusted.

public void testIncomingNormalMessage_incomingNotTrusted_outgoingTrusted_assertMessageNotTrusted() throws Exception {
    // first create the encyrpted message
    DefaultNHINDAgent agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "cerner.com" }));
    String testMessage = TestUtils.readResource("MultipartMimeMessage.txt");
    final OutgoingMessage SMIMEenvMessage = agent.processOutgoing(testMessage);
    ;
    assertNotNull(SMIMEenvMessage);
    // now send received the MDN
    agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "starugh-stateline.com" }));
    DefaultTrustAnchorResolver resolver = (DefaultTrustAnchorResolver) agent.getTrustAnchors();
    CertificateResolver mockResolver = mock(CertificateResolver.class);
    DefaultTrustAnchorResolver newResolver = new DefaultTrustAnchorResolver(resolver.getOutgoingAnchors(), mockResolver);
    agent.setTrustAnchorResolver(newResolver);
    IncomingMessage incomingMessage = null;
    try {
        incomingMessage = agent.processIncoming(SMIMEenvMessage.getMessage());
    } catch (NHINDException e) {
        assertEquals(TrustError.NoTrustedRecipients, e.getError());
    }
    assertNull(incomingMessage);
}
Also used : CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) DefaultNHINDAgent(org.nhindirect.stagent.DefaultNHINDAgent) DefaultTrustAnchorResolver(org.nhindirect.stagent.trust.DefaultTrustAnchorResolver)

Example 32 with CertificateResolver

use of org.nhindirect.stagent.cert.CertificateResolver in project nhin-d by DirectProject.

the class LdapCertificateStoreTest method testPublicLdapSearch_orgLevelCert_assertCertExists.

public void testPublicLdapSearch_orgLevelCert_assertCertExists() throws Exception {
    addStockPublicLDAPCertificats();
    PublicLdapCertificateStoreProvider provider = new PublicLdapCertificateStoreProvider(null, null);
    CertificateResolver resolver = provider.get();
    Collection<X509Certificate> certs = resolver.getCertificates(new InternetAddress("testdomain.com"));
    assertEquals(1, certs.size());
    X509Certificate cert = certs.iterator().next();
    assertTrue(cert.getSubjectX500Principal().toString().contains("direct.fnhubapp01.qa.medplus.com"));
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) PublicLdapCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.PublicLdapCertificateStoreProvider) X509Certificate(java.security.cert.X509Certificate)

Example 33 with CertificateResolver

use of org.nhindirect.stagent.cert.CertificateResolver in project nhin-d by DirectProject.

the class PublicLdapCertifictaeStoreProvider_getResolver_Test method testGetResolverFromProvider.

public void testGetResolverFromProvider() throws Exception {
    PublicLdapCertificateStoreProvider provider = new PublicLdapCertificateStoreProvider(null, null);
    CertificateResolver resolver = provider.get();
    assertNotNull(resolver);
    assertTrue(resolver instanceof LDAPCertificateStore);
}
Also used : LDAPCertificateStore(org.nhindirect.stagent.cert.impl.LDAPCertificateStore) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver)

Example 34 with CertificateResolver

use of org.nhindirect.stagent.cert.CertificateResolver in project nhin-d by DirectProject.

the class TrustChainValidator_IntermidiateCert_Test method testValidateCertAgainstNonRootCA_CAInPublicResolver_OpenSSLCerts.

public void testValidateCertAgainstNonRootCA_CAInPublicResolver_OpenSSLCerts() throws Exception {
    X509Certificate anchor = certFromData(getCertificateFileData("cert-b.der"));
    X509Certificate certToValidate = certFromData(getCertificateFileData("cert-a.der"));
    // uniform cert store that will just spit out whatever we put in it
    // will put the anchor in the public resolver... validator should hit it
    CertificateResolver publicResolver = new UniformCertificateStore(anchor);
    TrustChainValidator validator = new TrustChainValidator();
    validator.setCertificateResolver(Arrays.asList(publicResolver));
    boolean isTrusted = false;
    try {
        isTrusted = validator.isTrusted(certToValidate, Arrays.asList(anchor));
    } catch (Exception e) {
    }
    assertTrue(isTrusted);
}
Also used : UniformCertificateStore(org.nhindirect.stagent.cert.impl.UniformCertificateStore) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) X509Certificate(java.security.cert.X509Certificate) NHINDException(org.nhindirect.stagent.NHINDException)

Aggregations

CertificateResolver (org.nhindirect.stagent.cert.CertificateResolver)34 X509Certificate (java.security.cert.X509Certificate)21 TrustAnchorResolver (org.nhindirect.stagent.trust.TrustAnchorResolver)12 InternetAddress (javax.mail.internet.InternetAddress)9 KeyStoreCertificateStoreProvider (org.nhindirect.stagent.cert.impl.provider.KeyStoreCertificateStoreProvider)6 ArrayList (java.util.ArrayList)5 AddressException (javax.mail.internet.AddressException)5 SmtpAgentException (org.nhindirect.gateway.smtp.SmtpAgentException)5 DefaultNHINDAgent (org.nhindirect.stagent.DefaultNHINDAgent)5 NHINDException (org.nhindirect.stagent.NHINDException)5 PublicLdapCertificateStoreProvider (org.nhindirect.stagent.cert.impl.provider.PublicLdapCertificateStoreProvider)5 DefaultTrustAnchorResolver (org.nhindirect.stagent.trust.DefaultTrustAnchorResolver)5 Collection (java.util.Collection)4 PolicyParseException (org.nhindirect.policy.PolicyParseException)4 OptionsParameter (org.nhindirect.stagent.options.OptionsParameter)4 PolicyResolver (org.nhindirect.stagent.policy.PolicyResolver)4 DNSCertificateStore (org.nhindirect.stagent.cert.impl.DNSCertificateStore)3 LDAPCertificateStore (org.nhindirect.stagent.cert.impl.LDAPCertificateStore)3 DNSCertStoreProvider (org.nhindirect.stagent.cert.impl.provider.DNSCertStoreProvider)3 PrivateCertStoreModule (org.nhindirect.stagent.module.PrivateCertStoreModule)3