Skip to content

Commit

Permalink
Added the used cryptoFactories into the IncomingMessageState
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Nov 4, 2024
1 parent 8b241a0 commit 9135738
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.helger.commons.datetime.XMLOffsetDateTime;
import com.helger.phase4.attachment.EAS4CompressionMode;
import com.helger.phase4.attachment.WSS4JAttachment;
import com.helger.phase4.crypto.IAS4CryptoFactory;
import com.helger.phase4.ebms3header.Ebms3Messaging;
import com.helger.phase4.mgr.MetaAS4Manager;
import com.helger.phase4.model.ESoapVersion;
Expand Down Expand Up @@ -85,7 +86,9 @@ public final class AS4IncomingMessageState extends AttributeContainerAny <String
private static final String KEY_AS4_MESSAGE_TIMESTAMP = "phase4.message.timestamp";
private static final String KEY_IS_PING_MESSAGE = "phase4.is.ping.message";
private static final String KEY_SOAP_BODY_PAYLOAD_NODE = "phase4.soap.body.first.child";
private static final String KEY_SOEAP_HEADER_ELEMENT_PROCESSING_SUCCESSFUL = "phase4.soap.header.element.processing.successful";
private static final String KEY_SOAP_HEADER_ELEMENT_PROCESSING_SUCCESSFUL = "phase4.soap.header.element.processing.successful";
private static final String KEY_CRYPTO_FACTORY_SIGN = "phase4.crypto-factory.sign";
private static final String KEY_CRYPTO_FACTORY_CRYPT = "phase4.crypto-factory.crypt";

private final OffsetDateTime m_aReceiptDT;
private final ESoapVersion m_eSoapVersion;
Expand Down Expand Up @@ -409,12 +412,36 @@ public void setSoapBodyPayloadNode (@Nullable final Node aPayloadNode)

public boolean isSoapHeaderElementProcessingSuccessful ()
{
return getAsBoolean (KEY_SOEAP_HEADER_ELEMENT_PROCESSING_SUCCESSFUL, false);
return getAsBoolean (KEY_SOAP_HEADER_ELEMENT_PROCESSING_SUCCESSFUL, false);
}

public void setSoapHeaderElementProcessingSuccessful (final boolean bSuccess)
{
putIn (KEY_SOEAP_HEADER_ELEMENT_PROCESSING_SUCCESSFUL, bSuccess);
putIn (KEY_SOAP_HEADER_ELEMENT_PROCESSING_SUCCESSFUL, bSuccess);
}

@Nullable
public IAS4CryptoFactory getCryptoFactorySign ()
{
return getCastedValue (KEY_CRYPTO_FACTORY_SIGN);
}

@Nullable
public void setCryptoFactorySign (@Nullable final IAS4CryptoFactory aCryptoFactorySign)
{
putIn (KEY_CRYPTO_FACTORY_SIGN, aCryptoFactorySign);
}

@Nullable
public IAS4CryptoFactory getCryptoFactoryCrypt ()
{
return getCastedValue (KEY_CRYPTO_FACTORY_CRYPT);
}

@Nullable
public void setCryptoFactoryCrypt (@Nullable final IAS4CryptoFactory aCryptoFactoryCrypt)
{
putIn (KEY_CRYPTO_FACTORY_CRYPT, aCryptoFactoryCrypt);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.helger.commons.string.StringHelper;
import com.helger.phase4.attachment.EAS4CompressionMode;
import com.helger.phase4.attachment.WSS4JAttachment;
import com.helger.phase4.crypto.IAS4CryptoFactory;
import com.helger.phase4.ebms3header.Ebms3Error;
import com.helger.phase4.ebms3header.Ebms3Messaging;
import com.helger.phase4.ebms3header.Ebms3PullRequest;
Expand Down Expand Up @@ -485,4 +486,25 @@ default String getProfileID ()
* @since v0.9.7
*/
boolean isSoapHeaderElementProcessingSuccessful ();

/**
* @return The crypto factory that was used to verify an eventually contained
* signature. May be <code>null</code>. If this is
* non-<code>null</code> it is NO indicator, whether a message was
* signed or not.
* @see #isSoapSignatureChecked()
* @since 3.0.0-beta6
*/
@Nullable
IAS4CryptoFactory getCryptoFactorySign ();

/**
* @return The crypto factory that was used to decrypt an eventually encrypted
* message. May be <code>null</code>. If this is non-<code>null</code>
* it is NO indicator, whether a message was encrypted or not.
* @see #isSoapDecrypted()
* @since 3.0.0-beta6
*/
@Nullable
IAS4CryptoFactory getCryptoFactoryCrypt ();
}
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,14 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc,
@Nonnull final AS4IncomingMessageState aIncomingState,
@Nonnull final ICommonsList <Ebms3Error> aProcessingErrorMessagesTarget)
{
// Remember the crypto factories used for this message
aIncomingState.setCryptoFactorySign (m_aCryptoFactorySign);
aIncomingState.setCryptoFactoryCrypt (m_aCryptoFactoryCrypt);

// Make sure a PMode is selected
IPMode aPMode = aIncomingState.getPMode ();
if (aPMode == null)
aPMode = m_aFallbackPModeProvider.get ();

// Safety Check
if (aPMode == null)
throw new IllegalStateException ("No PMode contained in AS4 state - seems like Ebms3 Messaging header is missing!");

Expand Down

0 comments on commit 9135738

Please sign in to comment.