abhishek-ram/django-pyas2

Failed to parse AS2 MDN

Closed this issue · 12 comments

Hi,

I'm getting an error with receiving asynch MDN. "Failed to parse AS2 MDN"
It looks like the incoming message does not contain 'Original-Recipient'.
But how do i troubleshoot this issue? the message is encoded and i don't know how i can decode it.
I hope someone can help.

Best regards,
Hans

pyas2lib DEBUG Encrypted message 159844662164.148827.10615077895181858208@as2... payload as:b'
MIME-Version: 1.0\r\n
Content-Type: application/pkcs7-mime; name="smime.p7m"; smime-type="enveloped-data"\r\n
Content-Disposition: attachment; filename="smime.p7m"\r\n
Content-Transfer-Encoding: binary\r\n\r\n0\x82\x19!\x06\t*\x86H\x86....'

2020-08-26 14:57:01,923 pyas2lib ERROR Failed to parse AS2 MDN
: Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/pyas2lib/as2.py", line 777, in parse
self.orig_message_id, orig_recipient = self.detect_mdn()
File "/usr/local/lib/python3.6/dist-packages/pyas2lib/as2.py", line 873, in detect_mdn
message_recipient = mdn.get('Original-Recipient').
AttributeError: 'NoneType' object has no attribute 'split'

seems the issue is from the package upstream:pyas2lib

Can you attach the MDN msg? the file can be found by referring: https://django-pyas2.readthedocs.io/en/latest/detailed-guide/configuration.html

note: MDN is in the sub folder: message/__store/mdn/received/

Hi @gainskills,

Thanks for your reply.
I would like to send you the MDN message, but it's not stored in the data folder. I guess because the process couldn't finish because of the error?

Hi @gainskills,

Thanks for your reply.
I would like to send you the MDN message, but it's not stored in the data folder. I guess because the process couldn't finish because of the error?

oh... my bad. or try the log file, you can capture the log by configuring Django (pseudocode)

LOGGING = {
"handlers": {
"as2log": {
"level": "DEBUG",
"filename": "logs/as2.log",
},
},
},
"loggers": {
"pyas2": {"handlers": ["as2log"], "level": "DEBUG",},
"pyas2lib": {"handlers": ["as2log"], "level": "DEBUG",} },
}

Hi @gainskills,

Sorry for the late reply, just got back from vacation.
I've added the log MDN captured from the log file as you mentioned.
The error message is still the same as in the first port. I you need more information, let me know.

b'as2-version: 1.1\n
as2-from: Partner\n
as2-to: 1234567891234\n
content-type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha1; boundary="1BouNdary1"\n
date: Wed, 23 Sep 2020 13:11:49 GMT\n
host: :443\n
content-length: 1237\n
connection: Keep-Alive\n
\r\n--1BouNdary1\r\n
Content-Type: multipart/report; report-type="disposition-notification"; boundary="2BouNdary2"\r\n
Content-Length: 592\r\n\r\n
--2BouNdary2\r\n
Content-Type: text/plain\r\n\r\n
Message <160086672221.58265.4307416709486910693@
> was successfully preprocessed.\r\n\r\n
--2BouNdary2\r\n
Content-Type: message/disposition-notification\r\n
Content-Disposition: attachment; filename="mdn.txt"\r\n\r\n
Reporting-UA: * AS2 Server\r\n
Final-Recipient: rfc822; \r\n
Original-Message-Id: <160086672221.58265.4307416709486910693@
>\r\n
Disposition: automatic-action/MDN-sent-automatically; processed\r\n
Received-Content-MIC: oBlWvGltDrGeP6j0ydFFbOzrwv4=, sha1\r\n\r\n
--2BouNdary2--\r\n\r\n
--1BouNdary1\r\n
Content-Type: application/pkcs7-signature; name="smime.p7s"\r\n
Content-Disposition: attachment; filename="smime.p7s"\r\n\r\n
0\x82\x01-....\r\n
--1BouNdary1--\r\n'

Hi @hgooijen ,
Please check and confirm recipient is configured on your peer.

It's blank now:

Final-Recipient: rfc822; \r\n

Hi @gainskills

I guess you mean that we've to send the final-recipient in the msg header we send to the partner?
I've copied the header of the message we've send, but don't see the recipient.
I don't know how to change this.

MIME-Version: 1.0
Content-Type: application/pkcs7-mime; name="smime.p7m"; smime-type="enveloped-data"
Content-Disposition: attachment; filename="smime.p7m"
Content-Transfer-Encoding: binary
AS2-Version: 1.2
ediint-features: CMS
Message-ID: 160086672221.58265.4307416709486910693@domain.com
AS2-From: 1234567891234
AS2-To: partner
Subject: EDI Message sent from
Date: Wed, 23 Sep 2020 15:12:02 +0200
disposition-notification-to: user@domain.com
disposition-notification-options: signed-receipt-protocol=required, pkcs7-signature; signed-receipt-micalg=optional, sha1
receipt-delivery-option: https://*:444/pyas2/as2receive

can you check with the partner side to see how they configured your identifier?

Check on this because I found there is neither Original-Recipient nor Final-Recipient valid in the msg header. The fields are two required fields in Django-AS2, hence wonder how your partner configures the identifier.

Thanks,

Hi @gainskills,

i tried to get the info from our partner, but no luck.
I do however now get a value back in final-recipient "Final-Recipient: rfc822; TRANSUS". i still don't get a original-recipient.

When i read the documentation however i see there is a situation where the original-recipient value isn't required.
Why is it required then by Django-AS2?
https://tools.ietf.org/html/rfc8098#section-3.2.3

Is there en option to skip this check? maybe only use the final-recipient value?

Thanks,
Hans

Hi @gainskills,

i tried to get the info from our partner, but no luck.
I do however now get a value back in final-recipient "Final-Recipient: rfc822; TRANSUS". i still don't get a original-recipient.

When i read the documentation however i see there is a situation where the original-recipient value isn't required.
Why is it required then by Django-AS2?
https://tools.ietf.org/html/rfc8098#section-3.2.3

Is there en option to skip this check? maybe only use the final-recipient value?

Thanks,
Hans

I would say, from my understanding, the fields work as ID to identify the messages.
Allow me some time to check on this.

related code: https://github.com/abhishek-ram/pyas2-lib/blob/35f2982667d10e03e93350025e6fb48ec7edfe34/pyas2lib/as2.py#L981

original-recipient

Hi @hgooijen ,
I would say EDI message structure referred MIME with some different.

From the code:

    mdn_report += f'Original-Recipient: rfc822; {message.headers.get("as2-to")}\r\n'

pyas2 grab Original-Recipient info from AS2-To field which is the required field. Related description in RFC:

To aid the receiving system in identifying the sending system, AS2-From and AS2-To headers are used.

The AS2-To and AS2-From header fields MUST be present in all AS2 messages and AS2 MDNs whether asynchronous or synchronous in nature, except for asynchronous MDNs, which are sent using SMTP.

https://tools.ietf.org/html/rfc4130#section-6.2

The final and original recipient values SHOULD be the same value.

https://tools.ietf.org/html/rfc4130#section-5.3.2

Depends on this, check with your peer and make sure EDI info is configured properly. Attached Django-PYAS2 UI for reference:

image

Have made a pull request for pyas2lib to accommodate this case abhishek-ram/pyas2-lib#24.
Could not see that "Original-Recipient" is mandatory, however "Final-Recipient" is.
Therefore checking first for "Original-Recipient" and then for "Final-Recipient".

Right after the AS2 partner left me stranding with saying "you're the only one with this issue, so gl with it". They suddenly DO send original-recipient! We finnally got some succesfull send AS2 messages:)
@chadgates thx for the change, i've implemented it right away, just to be sure.