abhishek-ram / django-pyas2

AS2 file transfer Server built on Python and Django.
https://django-pyas2.readthedocs.io
GNU General Public License v3.0
83 stars 31 forks source link

TypeError: string argument without an encoding #22

Closed hgooijen closed 4 years ago

hgooijen commented 4 years ago

Hi,

I'm fairly new to AS2. A couple of years ago i've succesfully tested with the previous pyas2. However because of the higher algorithm support of this version, we freshly installed en new server with this version of django-pyas2 and started all over.

When i receive a message of want to send one, i'n getting the same error message: Traceback (most recent call last): File "/var/venv/pyas2/venv/lib/python3.6/site-packages/pyas2lib/as2.py", line 496, in parse self.receiver = find_org_cb(org_id) File "/var/venv/pyas2/venv/lib/python3.6/site-packages/pyas2/views.py", line 59, in find_organization return org.as2org File "/var/venv/pyas2/venv/lib/python3.6/site-packages/pyas2/models.py", line 99, in as2org params['sign_key'] = bytes(self.signature_key.key) TypeError: string argument without an encoding

I thought it had something to do with the private certificate on out organization, but whatever i do or recreate certificates, i always get the same error.

Does someone knows a solution to my issue?

chadgates commented 4 years ago

Hi @hgooijen

Just want to rule out some things:

The next question would be:

Suggest you extend the logging as suggested here: https://github.com/abhishek-ram/django-pyas2/issues/13#issuecomment-503885199

That might give better description of what is missing.

I cannot recreate the issue myself, as it works for me.... so I would assume that either the certificate keys are not stored in the DB, or something is indeed wrong with the certificates.

hgooijen commented 4 years ago

Hi @chadgates,

Thanks for your reply.

I've created the certificates exactly as documentation detailed guide. When i log into the MariaDB i can also see the organisation certificate with pass.

I'm not really a programmer, but i tried to do some editing in the models.py. The error looks like to come from bytes, but even if i remove the command, i still get the same error. As if the error comes from the array creation.

chadgates commented 4 years ago

Hi @hgooijen

A problem might be with the database migration. The database should be created by Django, as the ORM might use different types of fields depending on the specific backend. Can you remove the MariaDB database and let django create it and then do the test with that ?

hgooijen commented 4 years ago

Hi @chadgates

We've let django recreate the MariaDB database, but got the same issue again. We then let django recreate a default SQLite database, now we get a different error. I don't know if it's further or earlier in the process then the previous error.

File "/var/venv/pyas2/venv/lib/python3.6/site-packages/pyas2lib/as2.py", line 523, in parse encrypted_data, self.receiver.decrypt_key) File "/var/venv/pyas2/venv/lib/python3.6/site-packages/pyas2lib/cms.py", line 195, in decrypt_message raise AS2Exception('Unsupported Encryption Algorithm') pyas2lib.exceptions.AS2Exception: Unsupported Encryption Algorithm

We use AES-256 for encryption, so it should be supported?

chadgates commented 4 years ago

Hi @hgooijen

Yes, AES-256 should be supported. Was the transmission from a django-pyas2 instance or from a third party system? It would make sense if it was from a third party that provides values not known.

Also, suggest you enable the logging as mentioned earlier, as this will give you way more insights into what is sent/received and where things might go wrong.

hgooijen commented 4 years ago

Hi @chadgates

Sorry for the delayed reaction, busy times. The transmission came from Amazon Vendor AS2, which should work fine reading several threads. I've enabled the debug log, but doesn't show much more info then i allready found, but maybe you'll see something i don't.

` 2019-11-13 15:59:04,589 pyas2lib DEBUG Decrypting message f050fe3b-16ca-4c75-a5f9-58d96dfef085 payload : b'date: 13 Nov 2019 14:59:02 GMT\r\nfrom: as2@10.1.41.163\r\nmessage-id: \r\nsubject: AS2 Message\r\nas2-version: 1.1\r\nas2-from: \r\nas2-to: \r\ndisposition-notification-to: as2@10.1.41.163\r\ndisposition-notification-options: signed-receipt-protocol=optional, pkcs7-signature; signed-receipt-micalg=optional, sha256\r\ncontent-type: application/pkcs7-mime; name="smime.p7m"; smime-type=enveloped-data\r\ncontent-transfer-encoding: binary\r\ncontent-disposition: attachment; filename="smime.p7m"\r\ncontent-description: S/MIME Encrypted Message\r\ncontent-length: 3547\r\nhost: **\r\nconnection: Keep-Alive\r\nuser-agent: Apache-HttpAsyncClient/UNAVAILABLE (Java/1.8.0_231)\r\n\r\n0\x80\x06......\x00\x00\x00\x00' 2019-11-13 15:59:04,626 pyas2lib ERROR Failed to parse AS2 message : Traceback (most recent call last): File "/var/venv/pyas2/venv/lib/python3.6/site-packages/pyas2lib/as2.py", line 523, in parse encrypted_data, self.receiver.decrypt_key) File "/var/venv/pyas2/venv/lib/python3.6/site-packages/pyas2lib/cms.py", line 195, in decrypt_message raise AS2Exception('Unsupported Encryption Algorithm') pyas2lib.exceptions.AS2Exception: Unsupported Encryption Algorithm

2019-11-13 15:59:04,626 pyas2lib DEBUG Building the MDN for message f050fe3b-16ca-4c75-a5f9-58d96dfef085 with status failed/Failure and detailed-status . 2019-11-13 15:59:04,690 pyas2lib DEBUG MDN report for message f050fe3b-16ca-4c75-a5f9-58d96dfef085 created: b'Content-Type: message/disposition-notification\r\nContent-Transfer-Encoding: 7bit\r\n\r\nReporting-UA: EDI AS2 Agent\r\nOriginal-Recipient: rfc822; \r\nFinal-Recipient: rfc822; \r\nOriginal-Message-ID: \r\nDisposition: automatic-action/MDN-sent-automatically; failed/Failure\r\n' 2019-11-13 16:00:47,686 pyas2lib DEBUG Decrypting message 4d069586-2f79-4c7c-b9f3-cd536cb57434 payload : b'date: 13 Nov 2019 15:00:46 GMT\r\nfrom: as2@10.1.20.234\r\nmessage-id: <4d069586-2f79-4c7c-b9f3-cd536cb57434>\r\nsubject: AS2 Message\r\nas2-version: 1.1\r\nas2-from: \r\nas2-to: \r\ndisposition-notification-to: as2@10.1.20.234\r\ndisposition-notification-options: signed-receipt-protocol=optional, pkcs7-signature; signed-receipt-micalg=optional, sha256\r\ncontent-type: application/pkcs7-mime; name="smime.p7m"; smime-type=enveloped-data\r\ncontent-transfer-encoding: binary\r\ncontent-disposition: attachment; filename="smime.p7m"\r\ncontent-description: S/MIME Encrypted Message\r\ncontent-length: 3563\r\nhost: \r\nconnection: Keep-Alive\r\nuser-agent: Apache-HttpAsyncClient/UNAVAILABLE (Java/1.8.0_231)\r\n\r\n0\x80\x06\t*.....\xa1\x87F\x91\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' 2019-11-13 16:00:47,687 pyas2lib ERROR Failed to parse AS2 message : Traceback (most recent call last): File "/var/venv/pyas2/venv/lib/python3.6/site-packages/pyas2lib/as2.py", line 523, in parse encrypted_data, self.receiver.decrypt_key) File "/var/venv/pyas2/venv/lib/python3.6/site-packages/pyas2lib/cms.py", line 195, in decrypt_message raise AS2Exception('Unsupported Encryption Algorithm') pyas2lib.exceptions.AS2Exception: Unsupported Encryption Algorithm

2019-11-13 16:00:47,687 pyas2lib DEBUG Building the MDN for message 4d069586-2f79-4c7c-b9f3-cd536cb57434 with status failed/Failure and detailed-status . 2019-11-13 16:00:47,689 pyas2lib DEBUG MDN report for message 4d069586-2f79-4c7c-b9f3-cd536cb57434 created: b'Content-Type: message/disposition-notification\r\nContent-Transfer-Encoding: 7bit\r\n\r\nReporting-UA: EDI AS2 Agent\r\nOriginal-Recipient: rfc822; \r\nFinal-Recipient: rfc822; \r\nOriginal-Message-ID: <4d069586-2f79-4c7c-b9f3-cd536cb57434>\r\nDisposition: automatic-action/MDN-sent-automatically; failed/Failure\r\n' 2019-11-13 16:00:47,691 pyas2lib DEBUG MDN generated for message 4d069586-2f79-4c7c-b9f3-cd536cb57434 with content: b'Content-Type: multipart/report; report-type="disposition-notification"; boundary="===============5783652948977281909=="\r\nMIME-Version: 1.0\r\nAS2-Version: 1.2\r\nediint-features: CMS\r\nMessage-ID: <157365724768.51992.6404459904940777749@>\r\nAS2-From: \r\nAS2-To: \r\nDate: Wed, 13 Nov 2019 16:00:47 +0100\r\nuser-agent: EDI AS2 Agent\r\n\r\n--===============5783652948977281909==\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: 7bit\r\n\r\nThe AS2 message could not be processed. The disposition-notification report has additional details.\r\n\r\n--===============5783652948977281909==\r\nContent-Type: message/disposition-notification\r\nContent-Transfer-Encoding: 7bit\r\n\r\nReporting-UA: EDI AS2 Agent\r\nOriginal-Recipient: rfc822; \r\nFinal-Recipient: rfc822; \r\nOriginal-Message-ID: <4d069586-2f79-4c7c-b9f3-cd536cb57434>\r\nDisposition: automatic-action/MDN-sent-automatically; failed/Failure\r\n\r\n--===============5783652948977281909==--\r\n' `

hgooijen commented 4 years ago

I guess it had something to do with the setup in venv. We've reinstalled the server without venv and it worked right away.