Menu

Send attachments with main document (within single AS2 message)

2015-11-19
2015-11-20
  • Janaka Priyadarshana

    I am working with OpenAS2Server-1.3.3 library. There sending a single document is working fine..

    Now I wanted to modify it to send document with attachments, like we do with emails. In this scenario, all the decription work well, but signature verification failed (MIC is not matched)
    Does the AS2 protocol support for sending attachment within single AS2 message ???

    This is how I am tring to send attachments with main doc: Create a MimeMultipart and add two MimeBodyPart into it. (main document and the attachment) Finally wrap the MimeMultipart within a MimeBodyPart (I am not sure this is the way to do this, but anyway Bouncycastle do not have API to sign MimeMultipart )

    Could anyone tell me the correct way to sign a message with attachment ?


    This is how I modify the 'updateMessage' method in 'src/org/openas2/processor/receiver/DirectoryPollingModule.java'

        MimeBodyPart mainBody = new MimeBodyPart();
        mainBody.setDataHandler(new DataHandler(byteSource));
    
        MimeBodyPart attachemt1 = new MimeBodyPart();
        attachemt1.attachFile("/home/user/Desktop/Test1.txt");
    
        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(mainBody);
        multipart.addBodyPart(attachemt1);
    
        MimeBodyPart body = new MimeBodyPart();
        body.setContent(multipart);
        body.setHeader("Content-Type", multipart.getContentType());
        logger.info("--------------Attaching the file...  Done");
    
     
    • Christopher Broderick

      As far as we are aware this not standard AS2 which you are trying to implement so it will probably only work using 2 customised OpenAS2 servers to talk to each other.
      AS2 protocol does provide for multiple attachments but it is not implemented in OpenAS2 as yet.

      If you want to pursue your method then it is suggested you need to create the message with attachment PRIOR to the call to AS2SenderModule.secure() method and extract it AFTER the call to AS2ReceiverHandler.decryptAndVerify() method.

       
      • Janaka Priyadarshana

        Hi,
        Thanks for quick answer. Where can I read about 'multiple attachment' support with AS2. I didnt find anything about attachments in the RFC (https://www.ietf.org/rfc/rfc4130)

         
    • Christopher Broderick

      Note that in AS2 concepts, a message is an attachment so effectively what you are trying to do is add an attachment to an attachment as opposed to sending multiple attachments.

       
      • Janaka Priyadarshana

        "in AS2 concepts, a message is an attachment" .. what you mean here.. ?
        The signed data is a Multipart which contain the message as a one BodyPart and signature as the second BodyPart. Is that you mean ?

         
  • Janaka Priyadarshana

    Hi,
    I was able to notice some differences in the data which we used to calculate the MIC. This output was taken from the 'calculateMIC' method in 'BCCryptoHelper.java'
    The attached image shows feeding the same data file in two different times.

     
    • Christopher Broderick

      The point at which you are extracting is probably not the same point at which you are adding the attachment in the overall chain of events.

      NOTE: Upgrade to version 1.3.5 to solve MIC calculation issues when using compression.

       
  • Janaka Priyadarshana

    Hi,
    I was able to get the issue and solution. I am just putting it here for anyone else who will try to do this kind of work.

    I just dump the data that use for calculating MIC, at both sending side and receiving side. So the attached image will show the problem clearly.

    So I added those header fields manually for all the attachments and main doc, at the sending side, as bellow.

    mainBody.setHeader("Content-Type", "application/EDI-X12");
    mainBody.setHeader("Content-Transfer-Encoding", "7bit");

    Now it solved and "MIC is matched".

     

Log in to post a comment.