You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/12/25 08:24:38 UTC
[camel] branch main updated: [CAMEL-18842] Checks for compression before throwing exception (#8947)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 358077fce57 [CAMEL-18842] Checks for compression before throwing exception (#8947)
358077fce57 is described below
commit 358077fce57dcde64d5d951d5d3ab7a1ca94238d
Author: Yasser Zamani <ya...@apache.org>
AuthorDate: Sun Dec 25 11:54:26 2022 +0330
[CAMEL-18842] Checks for compression before throwing exception (#8947)
* add CAMEL-18842 reproducer test case
* checking for compression before throwing exception
fixes CAMEL-18842
---
.../component/as2/api/util/HttpMessageUtils.java | 8 +++++
.../camel/component/as2/api/AS2MessageTest.java | 42 ++++++++++++++++++++++
2 files changed, 50 insertions(+)
diff --git a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/HttpMessageUtils.java b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/HttpMessageUtils.java
index a4999f990da..4c05a9f1af4 100644
--- a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/HttpMessageUtils.java
+++ b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/HttpMessageUtils.java
@@ -212,6 +212,10 @@ public final class HttpMessageUtils {
MimeEntity mimeEntity = multipartSignedEntity.getSignedDataEntity();
if (mimeEntity instanceof ApplicationEDIEntity) {
ediEntity = (ApplicationEDIEntity) mimeEntity;
+ } else if (mimeEntity instanceof ApplicationPkcs7MimeCompressedDataEntity) {
+ ApplicationPkcs7MimeCompressedDataEntity compressedDataEntity
+ = (ApplicationPkcs7MimeCompressedDataEntity) mimeEntity;
+ ediEntity = extractEdiPayloadFromCompressedEntity(compressedDataEntity);
} else {
throw new HttpException(
"Failed to extract EDI payload: invalid content type '" + mimeEntity.getContentTypeValue()
@@ -244,6 +248,10 @@ public final class HttpMessageUtils {
MimeEntity mimeEntity = multipartSignedEntity.getSignedDataEntity();
if (mimeEntity instanceof ApplicationEDIEntity) {
ediEntity = (ApplicationEDIEntity) mimeEntity;
+ } else if (mimeEntity instanceof ApplicationPkcs7MimeCompressedDataEntity) {
+ ApplicationPkcs7MimeCompressedDataEntity compressedDataEntity
+ = (ApplicationPkcs7MimeCompressedDataEntity) mimeEntity;
+ ediEntity = extractEdiPayloadFromCompressedEntity(compressedDataEntity);
} else {
throw new HttpException(
diff --git a/components/camel-as2/camel-as2-api/src/test/java/org/apache/camel/component/as2/api/AS2MessageTest.java b/components/camel-as2/camel-as2-api/src/test/java/org/apache/camel/component/as2/api/AS2MessageTest.java
index 022c9f04b1e..2894b676102 100644
--- a/components/camel-as2/camel-as2-api/src/test/java/org/apache/camel/component/as2/api/AS2MessageTest.java
+++ b/components/camel-as2/camel-as2-api/src/test/java/org/apache/camel/component/as2/api/AS2MessageTest.java
@@ -1046,4 +1046,46 @@ public class AS2MessageTest {
assertFalse(signatureEntity.isMainBody(), "First mime type set as main body of request");
}
+ @ParameterizedTest
+ @CsvSource({ "false,false", "false,true", "true,false", "true,true" })
+ void compressionSignatureOrderTest(boolean encrypt, boolean compressBeforeSign) {
+ // test with as2-lib because Camel AS2 client doesn't support different orders at the moment
+ // inspired from https://github.com/phax/as2-lib/wiki/Submodule-as2%E2%80%90lib#as2-client
+
+ // Start client configuration
+ final AS2ClientSettings aSettings = new AS2ClientSettings();
+ aSettings.setKeyStore(EKeyStoreType.PKCS12, keystoreFile, "test");
+
+ // Fixed sender
+ aSettings.setSenderData(AS2_NAME, FROM, "openas2a_alias");
+
+ // Fixed receiver
+ aSettings.setReceiverData(AS2_NAME, "openas2b_alias", "http://" + TARGET_HOST + ":" + TARGET_PORT + "/");
+ aSettings.setReceiverCertificate(issueCert);
+
+ // AS2 stuff
+ aSettings.setPartnershipName(aSettings.getSenderAS2ID() + "_" + aSettings.getReceiverAS2ID());
+
+ // Build client request
+ final AS2ClientRequest aRequest = new AS2ClientRequest("AS2 test message from as2-lib");
+ aRequest.setData(EDI_MESSAGE, StandardCharsets.US_ASCII);
+ aRequest.setContentType(AS2MediaType.APPLICATION_EDIFACT);
+
+ // reproduce https://issues.apache.org/jira/browse/CAMEL-18842
+ aSettings.setEncryptAndSign(encrypt ? ECryptoAlgorithmCrypt.CRYPT_AES128_GCM : null,
+ ECryptoAlgorithmSign.DIGEST_SHA_512);
+ aSettings.setCompress(ECompressionType.ZLIB, compressBeforeSign);
+ aRequest.setContentTransferEncoding(EContentTransferEncoding.BINARY);
+
+ // Send message
+ ediEntity = null;
+ final AS2ClientResponse aResponse = new AS2Client().sendSynchronous(aSettings, aRequest);
+
+ // Assertions
+ if (aResponse.hasException()) {
+ fail(aResponse.getException());
+ }
+ assertEquals(EDI_MESSAGE, ediEntity.getEdiMessage().replaceAll("\r", ""));
+ }
+
}