Skip to content

The Message Integrity Code (MIC) does not match the sent AS2 message #40

@Jaimies

Description

@Jaimies

Overview

When sending a message with an attachment, the following error occurs:

The Message Integrity Code (MIC) does not match the sent AS2 message (required: **required_mic**, sha256, returned: **returned_mic**, sha256) {"message_id":"**message_id**"}

Meanwhile, sending a message without an attachment does not produce an error.

Steps to reproduce

This issue can be reproduced with the example, included in the library. To do that, run the following commands:

git clone https://github.com/tiamo/phpas2.git phpas2_issue_reproduction
cd phpas2_issue_reproduction/example
composer install
chmod +x ./bin/console
# run the server in the background with no output
php -S 127.0.0.1:8000 ./public/index.php >& /dev/null &
echo "This is the message" > example_message.txt
php bin/console send-message --from mycompanyAS2 --to phpas2 --file example_message.txt

The last command produces the following output:

[2022-11-19 17:34:33] app.DEBUG: Build the AS2 message to send to the partner
[2022-11-19 17:34:33] app.DEBUG: Signing the message using partner key
[2022-11-19 17:34:33] app.DEBUG: Calculate MIC {"mic":"**mic**, sha256"}
[2022-11-19 17:34:33] app.DEBUG: Compressing outbound message after signing...
[2022-11-19 17:34:33] app.DEBUG: Encrypting the message using partner public key
[2022-11-19 17:34:33] app.DEBUG: AS2 message has been built successfully
[2022-11-19 17:34:33] app.DEBUG: AS2 message successfully sent to partner
[2022-11-19 17:34:33] app.DEBUG: Synchronous MDN received from partner
[2022-11-19 17:34:33] app.DEBUG: Found MDN report for message ["**message_id**"]
[2022-11-19 17:34:33] app.DEBUG: Message has been successfully processed, verifying the MIC if present.
[2022-11-19 17:34:33] app.ERROR: The Message Integrity Code (MIC) does not match the sent AS2 message (required: **required_mic**, sha256, returned: **returned_mic**, sha256) {"message_id":"**message_id**"}

However, if one were to run bin/console send-message --from mycompanyAS2 --to phpas2 (sending a message without an attachment) instead of the last command, the message would be sent successfully:

[2022-11-19 17:42:47] app.DEBUG: Build the AS2 message to send to the partner
[2022-11-19 17:42:47] app.DEBUG: Signing the message using partner key
[2022-11-19 17:42:47] app.DEBUG: Calculate MIC {"mic":"**mic**, sha256"} []
[2022-11-19 17:42:47] app.DEBUG: Compressing outbound message after signing...
[2022-11-19 17:42:47] app.DEBUG: Encrypting the message using partner public key
[2022-11-19 17:42:47] app.DEBUG: AS2 message has been built successfully
[2022-11-19 17:42:47] app.DEBUG: AS2 message successfully sent to partner
[2022-11-19 17:42:47] app.DEBUG: Synchronous MDN received from partner
[2022-11-19 17:42:47] app.DEBUG: Found MDN report for message ["**message_id**"]
[2022-11-19 17:42:47] app.DEBUG: Message has been successfully processed, verifying the MIC if present.
[2022-11-19 17:42:47] app.DEBUG: File Transferred successfully to the partner

System information

OS: Ubuntu 20.04.5 LTS
PHP: PHP 8.1.12 (cli) (built: Oct 28 2022 17:39:37) (NTS)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions