Search in sources :

Example 6 with CertificateResolver

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

the class DefaultNHINDAgent_bindAddressesOutgoingMessageTest method testBindAddresses_noPrivateCerts_assertNoBoundPrivateCerts.

public void testBindAddresses_noPrivateCerts_assertNoBoundPrivateCerts() throws Exception {
    final CertificateResolver publicCertResolver = mock(CertificateResolver.class);
    when(publicCertResolver.getCertificates((InternetAddress) any())).thenReturn(new ArrayList<X509Certificate>());
    final CertificateResolver privateCertResolver = mock(CertificateResolver.class);
    when(privateCertResolver.getCertificates((InternetAddress) any())).thenReturn(new ArrayList<X509Certificate>());
    final DefaultNHINDAgent agent = new DefaultNHINDAgent("Cerner.com", privateCertResolver, publicCertResolver, mock(TrustAnchorResolver.class));
    final OutgoingMessage message = buildOutgoingMessage("MultipartMimeMessage.txt");
    message.setAgent(agent);
    agent.bindAddresses(message);
    assertEquals(0, message.getSender().getCertificates().size());
}
Also used : TrustAnchorResolver(org.nhindirect.stagent.trust.TrustAnchorResolver) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) X509Certificate(java.security.cert.X509Certificate)

Example 7 with CertificateResolver

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

the class DefaultNHINDAgent_bindAddressesOutgoingMessageTest method testBindAddresses_singlePublicCerts_notFiltered_assertSingleBoundPublicCerts.

public void testBindAddresses_singlePublicCerts_notFiltered_assertSingleBoundPublicCerts() throws Exception {
    final X509Certificate cert = mock(X509Certificate.class);
    final CertificateResolver publicCertResolver = mock(CertificateResolver.class);
    when(publicCertResolver.getCertificates((InternetAddress) any())).thenReturn(Arrays.asList(cert));
    final CertificateResolver privateCertResolver = mock(CertificateResolver.class);
    when(privateCertResolver.getCertificates((InternetAddress) any())).thenReturn(new ArrayList<X509Certificate>());
    final DefaultNHINDAgent agent = new DefaultNHINDAgent("Cerner.com", privateCertResolver, publicCertResolver, mock(TrustAnchorResolver.class));
    final OutgoingMessage message = buildOutgoingMessage("MultipartMimeMessage.txt");
    message.setAgent(agent);
    agent.bindAddresses(message);
    for (NHINDAddress recipient : message.getRecipients()) assertEquals(1, recipient.getCertificates().size());
}
Also used : TrustAnchorResolver(org.nhindirect.stagent.trust.TrustAnchorResolver) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) X509Certificate(java.security.cert.X509Certificate)

Example 8 with CertificateResolver

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

the class DefaultNHINDAgent_bindAddressesOutgoingMessageTest method testBindAddresses_noPublicCerts_assertNoBoundPublicCerts.

public void testBindAddresses_noPublicCerts_assertNoBoundPublicCerts() throws Exception {
    final CertificateResolver publicCertResolver = mock(CertificateResolver.class);
    when(publicCertResolver.getCertificates((InternetAddress) any())).thenReturn(new ArrayList<X509Certificate>());
    final CertificateResolver privateCertResolver = mock(CertificateResolver.class);
    when(privateCertResolver.getCertificates((InternetAddress) any())).thenReturn(new ArrayList<X509Certificate>());
    final DefaultNHINDAgent agent = new DefaultNHINDAgent("Cerner.com", privateCertResolver, publicCertResolver, mock(TrustAnchorResolver.class));
    final OutgoingMessage message = buildOutgoingMessage("MultipartMimeMessage.txt");
    message.setAgent(agent);
    agent.bindAddresses(message);
    for (NHINDAddress recipient : message.getRecipients()) assertEquals(0, recipient.getCertificates().size());
}
Also used : TrustAnchorResolver(org.nhindirect.stagent.trust.TrustAnchorResolver) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) X509Certificate(java.security.cert.X509Certificate)

Example 9 with CertificateResolver

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

the class NHINDAgentTest method testIncomingMDN_incomingNotTrusted_outgoingTrusted_assertMDNMessageTrusted.

public void testIncomingMDN_incomingNotTrusted_outgoingTrusted_assertMDNMessageTrusted() throws Exception {
    OptionsManager.getInstance().setOptionsParameter(new OptionsParameter(OptionsParameter.USE_OUTGOING_POLICY_FOR_INCOMING_NOTIFICATIONS, "true"));
    // first create the encyrpted message
    DefaultNHINDAgent agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "starugh-stateline.com" }));
    String testMessage = TestUtils.readResource("MDNMessage.txt");
    final OutgoingMessage SMIMEenvMessage = agent.processOutgoing(testMessage);
    ;
    assertNotNull(SMIMEenvMessage);
    // now send received the MDN
    agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "Cerner.com" }));
    DefaultTrustAnchorResolver resolver = (DefaultTrustAnchorResolver) agent.getTrustAnchors();
    CertificateResolver mockResolver = mock(CertificateResolver.class);
    DefaultTrustAnchorResolver newResolver = new DefaultTrustAnchorResolver(resolver.getOutgoingAnchors(), mockResolver);
    agent.setTrustAnchorResolver(newResolver);
    IncomingMessage incomingMessage = agent.processIncoming(SMIMEenvMessage.getMessage());
    assertNotNull(incomingMessage);
}
Also used : OptionsParameter(org.nhindirect.stagent.options.OptionsParameter) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) DefaultNHINDAgent(org.nhindirect.stagent.DefaultNHINDAgent) DefaultTrustAnchorResolver(org.nhindirect.stagent.trust.DefaultTrustAnchorResolver)

Example 10 with CertificateResolver

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

the class NHINDAgentTest method testIncomingDSN_incomingNotTrusted_outgoingTrusted_assertMDNMessageTrusted.

public void testIncomingDSN_incomingNotTrusted_outgoingTrusted_assertMDNMessageTrusted() throws Exception {
    OptionsManager.getInstance().setOptionsParameter(new OptionsParameter(OptionsParameter.USE_OUTGOING_POLICY_FOR_INCOMING_NOTIFICATIONS, "true"));
    // first create the encyrpted message
    DefaultNHINDAgent agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "starugh-stateline.com" }));
    String testMessage = TestUtils.readResource("DSNMessage.txt");
    final OutgoingMessage SMIMEenvMessage = agent.processOutgoing(testMessage);
    ;
    assertNotNull(SMIMEenvMessage);
    // now send received the MDN
    agent = TestUtils.getStockAgent(Arrays.asList(new String[] { "Cerner.com" }));
    DefaultTrustAnchorResolver resolver = (DefaultTrustAnchorResolver) agent.getTrustAnchors();
    CertificateResolver mockResolver = mock(CertificateResolver.class);
    DefaultTrustAnchorResolver newResolver = new DefaultTrustAnchorResolver(resolver.getOutgoingAnchors(), mockResolver);
    agent.setTrustAnchorResolver(newResolver);
    IncomingMessage incomingMessage = agent.processIncoming(SMIMEenvMessage.getMessage());
    assertNotNull(incomingMessage);
}
Also used : OptionsParameter(org.nhindirect.stagent.options.OptionsParameter) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver) DefaultNHINDAgent(org.nhindirect.stagent.DefaultNHINDAgent) DefaultTrustAnchorResolver(org.nhindirect.stagent.trust.DefaultTrustAnchorResolver)

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