use of org.nhindirect.stagent.trust.TrustException in project nhin-d by DirectProject.
the class DefaultNHINDAgent method processMessage.
/*
* Process the incoming message by apply the security and trust algorithms.
*
*/
protected void processMessage(IncomingMessage message) {
///CLOVER:OFF
if (message.getSender() == null) {
throw new TrustException(TrustError.UntrustedSender);
}
///CLOVER:ON
message.categorizeRecipients(this.getDomains());
if (!message.hasDomainRecipients()) {
throw new AgentException(AgentError.NoTrustedRecipients);
}
//
// Map each address to its certificates/trust settings
//
this.bindAddresses(message);
//
// Extract signed content from the message
//
this.decryptSignedContent(message);
message.setMessage(this.unwrapMessage(message.getMessage()));
// Enforce trust requirements, including checking signatures
//
// need to decide if this message is a notification and message and
// if outgoing policy can be used for trust enforcement
final boolean allowOutgoingPolicyForIncomingNotifications = OptionsParameter.getParamValueAsBoolean(OptionsManager.getInstance().getParameter(OptionsParameter.USE_OUTGOING_POLICY_FOR_INCOMING_NOTIFICATIONS), false);
if (allowOutgoingPolicyForIncomingNotifications) {
final TxMessageType msgType = TxUtil.getMessageType(message.getMessage());
// determine if this message is a notification message
if (msgType.equals(TxMessageType.DSN) || msgType.equals(TxMessageType.MDN)) {
// need to apply outgoing anchor policy to each recipient
for (NHINDAddress recipient : message.getDomainRecipients()) {
try {
final Collection<X509Certificate> anchors = new ArrayList<X509Certificate>(trustAnchors.getIncomingAnchors().getCertificates(recipient));
anchors.addAll(trustAnchors.getOutgoingAnchors().getCertificates(recipient));
recipient.setTrustAnchors(anchors);
} catch (Exception e) {
LOGGER.warn("Exception getting anchors for inbound notification policy.", e);
}
}
}
}
// for incoming messages, headers may have been re-written
// by a man in the middle attack. The authoritative headers are in the unwrapped message, so they need to be compared to the header in
// Enveloped message to ensure that they have not been tampered
// Policy will dictate what the STA will do with the message if a tamper has been detected
enforceTamperPolicy(message);
this.trustModel.enforce(message);
//
if (message.hasDomainRecipients()) {
message.categorizeRecipients(this.minTrustRequirement);
}
if (!message.hasDomainRecipients()) {
throw new TrustException(TrustError.NoTrustedRecipients);
}
message.updateRoutingHeaders();
}
Aggregations