use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.
the class DefaultNHINDAgent_bindAddressesOutgoingMessageTest method testBindAddresses_singlePrivateCerts_policyFiltered_assertNoBoundPrivateCerts.
public void testBindAddresses_singlePrivateCerts_policyFiltered_assertNoBoundPrivateCerts() throws Exception {
final X509Certificate cert = mock(X509Certificate.class);
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(Arrays.asList(cert));
final DefaultNHINDAgent agent = new DefaultNHINDAgent("Cerner.com", privateCertResolver, publicCertResolver, mock(TrustAnchorResolver.class)) {
@Override
protected Collection<X509Certificate> filterCertificatesByPolicy(InternetAddress sender, PolicyResolver resolver, Collection<X509Certificate> certsToFilter, boolean incoming) {
return Collections.emptyList();
}
};
final OutgoingMessage message = buildOutgoingMessage("MultipartMimeMessage.txt");
message.setAgent(agent);
agent.bindAddresses(message);
assertEquals(0, message.getSender().getCertificates().size());
}
use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.
the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_outgoingPolicyCompliant_assertNoCertsFiltered.
public void testFilterCertificateByPolicy_outgoingPolicyCompliant_assertNoCertsFiltered() throws Exception {
final PolicyFilter filter = mock(PolicyFilter.class);
when(filter.isCompliant((X509Certificate) any(), (PolicyExpression) any())).thenReturn(true);
final PolicyExpression expression = mock(PolicyExpression.class);
final X509Certificate cert = mock(X509Certificate.class);
final Collection<X509Certificate> certs = Arrays.asList(cert);
final PolicyResolver resolver = mock(PolicyResolver.class);
when(resolver.getOutgoingPolicy((InternetAddress) any())).thenReturn(Arrays.asList(expression));
final DefaultNHINDAgent agent = new DefaultNHINDAgent("", mock(CertificateResolver.class), mock(CertificateResolver.class), mock(TrustAnchorResolver.class));
agent.setPolicyFilter(filter);
Collection<X509Certificate> filteredCerts = agent.filterCertificatesByPolicy(new InternetAddress("me@you.com"), resolver, certs, false);
assertEquals(1, filteredCerts.size());
}
use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.
the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_notCompliant_assertNoCertsFiltered.
public void testFilterCertificateByPolicy_notCompliant_assertNoCertsFiltered() throws Exception {
final PolicyFilter filter = mock(PolicyFilter.class);
when(filter.isCompliant((X509Certificate) any(), (PolicyExpression) any())).thenReturn(false);
final PolicyExpression expression = mock(PolicyExpression.class);
final X509Certificate cert = mock(X509Certificate.class);
final Collection<X509Certificate> certs = Arrays.asList(cert);
final PolicyResolver resolver = mock(PolicyResolver.class);
when(resolver.getIncomingPolicy((InternetAddress) any())).thenReturn(Arrays.asList(expression));
final DefaultNHINDAgent agent = new DefaultNHINDAgent("", mock(CertificateResolver.class), mock(CertificateResolver.class), mock(TrustAnchorResolver.class));
agent.setPolicyFilter(filter);
Collection<X509Certificate> filteredCerts = agent.filterCertificatesByPolicy(new InternetAddress("me@you.com"), resolver, certs, true);
assertEquals(0, filteredCerts.size());
}
use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.
the class DefaultNHINDAgent_filterCertificateByPolicyTest method testFilterCertificateByPolicy_noOutgoingExpressions_assertNoCertsFiltered.
public void testFilterCertificateByPolicy_noOutgoingExpressions_assertNoCertsFiltered() throws Exception {
final X509Certificate cert = mock(X509Certificate.class);
final Collection<X509Certificate> certs = Arrays.asList(cert);
final PolicyResolver resolver = mock(PolicyResolver.class);
when(resolver.getOutgoingPolicy((InternetAddress) any())).thenReturn(new ArrayList<PolicyExpression>());
final DefaultNHINDAgent agent = new DefaultNHINDAgent("", mock(CertificateResolver.class), mock(CertificateResolver.class), mock(TrustAnchorResolver.class));
Collection<X509Certificate> filteredCerts = agent.filterCertificatesByPolicy(new InternetAddress("me@you.com"), resolver, certs, false);
assertEquals(1, filteredCerts.size());
}
use of javax.mail.internet.InternetAddress in project nhin-d by DirectProject.
the class DNSCertDumper method main.
public static void main(String[] args) {
if (args.length == 0) {
printUsage();
System.exit(-1);
}
//String emailAddress = "Richard_Campbell@direct.healthvault-stage.com";
//String emailAddress = "ca.direct.healthvault-stage.com";
//String emailAddress = "ca.direct.healthvault-stage.com";
//"beau@direct3.h1sp.com";
String emailAddress = "";
String[] servers = null;
String outFile = null;
// Check parameters
for (int i = 0; i < args.length; i++) {
String arg = args[i];
// Options
if (!arg.startsWith("-")) {
System.err.println("Error: Unexpected argument [" + arg + "]\n");
printUsage();
System.exit(-1);
} else if (arg.equalsIgnoreCase("-add")) {
if (i == args.length - 1 || args[i + 1].startsWith("-")) {
System.err.println("Error: Missing email address");
System.exit(-1);
}
emailAddress = args[++i];
} else if (arg.equals("-server")) {
if (i == args.length - 1 || args[i + 1].startsWith("-")) {
System.err.println("Error: Missing DNS server list");
System.exit(-1);
}
servers = args[++i].split(",");
} else if (arg.equals("-out")) {
if (i == args.length - 1 || args[i + 1].startsWith("-")) {
System.err.println("Error: Missing output file.");
System.exit(-1);
}
outFile = args[++i];
} else if (arg.equals("-help")) {
printUsage();
System.exit(-1);
} else {
System.err.println("Error: Unknown argument " + arg + "\n");
printUsage();
System.exit(-1);
}
}
if (emailAddress == null || emailAddress.isEmpty()) {
System.err.println("You must provide an email address.");
printUsage();
} else {
DNSCertificateStore dnsStore = (servers != null) ? new DNSCertificateStore(Arrays.asList(servers)) : new DNSCertificateStore();
try {
Collection<X509Certificate> certs = dnsStore.getCertificates(new InternetAddress(emailAddress));
if (certs == null || certs.size() == 0) {
System.out.println("No certs found");
} else {
int idx = 1;
for (X509Certificate cert : certs) {
String certFileName = "";
String certFileHold = (outFile == null || outFile.isEmpty()) ? emailAddress + ".der" : outFile;
if (certs.size() > 1) {
int index = certFileHold.lastIndexOf(".");
if (index < 0)
certFileHold += "(" + idx + ")";
else {
certFileName = certFileHold.substring(0, index - 1) + "(" + idx + ")" + certFileHold.substring(index);
}
} else
certFileName = certFileHold;
File certFile = new File(certFileName);
if (certFile.exists())
certFile.delete();
System.out.println("Writing cert file: " + certFile.getAbsolutePath());
FileUtils.writeByteArrayToFile(certFile, cert.getEncoded());
++idx;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
System.exit(0);
}
Aggregations