Unable to send message specific signed MDN response in Apache Camel AS2 library

I am using the Apache Camel AS2 library in my Java project where I have implemented an AS2 server.
Currently, I’m generating a signed MDN response by configuring the certificate and algorithm in the server endpoint configuration, and it is working fine. However, I want to sign the MDN based on the AS2 request, where in headers, I will get the Mic algorithm that the user has requested. So, I want to sign using one of those algorithm at runtime, instead of hard-coding the algorithm at the endpoint creation.

I have also gone through the library code, and checked online, but I was not able to find any solution.

I have seen online server https://mendelson-e-c.com/as2_testserver which does the same, and signs according to the AS2 message, please help me in implementing this.

My server code is something like below, with signing defined in the endpoint configuration.

@Singleton
public class As2Server extends RouteBuilder {
    private final CamelContext camelContext;

    @Inject
    public As2Server(CamelContext camelContext) {
        this.camelContext = camelContext;
    }

    @Override
    public void configure() {
        try {
            from(configureServerEndpoint()).process(exchange -> {

            // processing logic

            });
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    private Endpoint configureServerEndpoint() throws Exception {
        AS2Configuration endpointConfiguration = new AS2Configuration();
        endpointConfiguration.setApiName(AS2ApiName.SERVER);
        endpointConfiguration.setMethodName(AS2ServerManagerApiMethod.LISTEN.name());
        endpointConfiguration.setDecryptingPrivateKey(getPrivateKey());
        endpointConfiguration.setSigningPrivateKey(getPrivateKey());
        endpointConfiguration.setSigningCertificateChain(getCertificateChain());
        endpointConfiguration.setSigningAlgorithm(AS2SignatureAlgorithm.MD5WITHRSA);
        endpointConfiguration.setMdnMessageTemplate("Your AS2 message has been received");

        try (AS2Component as2Component = new AS2Component()) {
            as2Component.setCamelContext(camelContext);
            as2Component.setConfiguration(endpointConfiguration);
            return as2Component.createEndpoint(STR."as2://server/listen?serverPortNumber=11080&requestUriPattern=*");
        }
    }

}

New contributor

Harshil Kapasi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

In this moment we have a issue with the mic cause we are using the AS2SignatureAlgorithm.SHA256WITHRSA and its possible that when you try to send the algorithm directly from the message you start to get issues. if you know that MD5 works why is required to change it?

By the way like i told you we are testing with SHA256WITHRSA and apparently doesnt works. i just make some changes to use SHA2WITHRSA cause in some article i read that the support algorithm for signature are SHA-1 and MD5, did you test any other the error that we are receiving is the next one.

org.apache.http.HttpException: Failed to encode MIC
at org.apache.camel.component.as2.api.util.MicUtils.createReceivedContentMic(MicUtils.java:111)
at org.apache.camel.component.as2.api.entity.AS2MessageDispositionNotificationEntity.<init>(AS2MessageDispositionNotificationEntity.java:95)
at org.apache.camel.component.as2.api.entity.DispositionNotificationMultipartReportEntity.<init>(DispositionNotificationMultipartReportEntity.java:66)
at org.apache.camel.component.as2.api.protocol.ResponseMDN.process(ResponseMDN.java:157)
at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:142)
at org.apache.http.protocol.HttpService.handleRequest(HttpService.java:360)
at org.apache.camel.component.as2.api.AS2ServerConnection$RequestHandlerThread.run(AS2ServerConnection.java:163)
Caused by: java.lang.IllegalArgumentException: Data must be specified
at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:153)
at org.apache.camel.component.as2.api.util.EntityUtils.encode(EntityUtils.java:89)
at org.apache.camel.component.as2.api.util.MicUtils$ReceivedContentMic.<init>(MicUtils.java:48)
at org.apache.camel.component.as2.api.util.MicUtils.createReceivedContentMic(MicUtils.java:109)
... 6 common frames omitted

Let me know if you test with other algorithms before to try to do the thing that you want to do.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật