Code Monkey home page Code Monkey logo

django-pyas2's Introduction

django-pyAS2

Latest Docs https://travis-ci.org/abhishek-ram/django-pyas2.svg?branch=master https://github.com/abhishek-ram/django-pyas2/actions/workflows/run-tests.yml/badge.svg?branch=master&event=push

django-pyas2 is an AS2 server/client written in python and built on the django framework. The application supports AS2 version 1.2 as defined in the RFC 4130. Our goal is to provide a native python library for implementing the AS2 protocol. It supports Python 3.6+

django-pyas2 includes a set of django-admin commands that can be used to send files as a client, send asynchronous MDNs and so on. It also has a web based front end interface for configuring partners and organizations, monitoring message transfers and also initiating new transfers.

Features

  • Technical
    • Asynchronous and Synchronous MDN
    • Partner and Organization management
    • Digital signatures
    • Message encryption
    • Secure transport (SSL)
    • Support for SSL client authentication
    • System task to auto clear old log entries
    • Data compression (AS2 1.1)
    • Multinational support: Uses Django's internationalization feature
  • Integration
    • Easy integration to existing systems, using a partner based file system interface
    • Message post processing (scripting on receipt)
  • Monitoring
    • Web interface for transaction monitoring
    • Email event notification
  • The following encryption algorithms are supported:
    • Triple DES
    • RC2-128
    • RC4-128
    • AES-128
    • AES-192
    • AES-256
  • The following hash algorithms are supported:
    • SHA-1
    • SHA-224
    • SHA-256
    • SHA-384
    • SHA-512

Documentation

You can find more information in the documentation.

Discussion

If you run into bugs, you can file them in our issue tracker.

Contribute

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
  2. Fork the repository on GitHub to start making your changes to the master branch (or branch off of it).
  3. Create your feature branch: git checkout -b my-new-feature
  4. Commit your changes: git commit -am 'Add some feature'
  5. Push to the branch: git push origin my-new-feature
  6. Send a pull request and bug the maintainer until it gets merged and published. :) Make sure to add yourself to AUTHORS.

Running Tests

Install django-environ and pytest into your environment to support the example.settings module and test framework.

To run django-pyas2's test suite:

django-admin.py test pyas2 --settings=example.settings --pythonpath=.

License

GNU GENERAL PUBLIC LICENSE

Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

django-pyas2's People

Contributors

abhishek-ram avatar adiroiban avatar bkc avatar chadgates avatar kenyonit avatar loop0 avatar pouldenton avatar timfanda35 avatar vlel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-pyas2's Issues

Error receiving messages with duplicate filenames

One of our partners always sends us AS2 messages with the same filename, even though the contents are different. To handle this use case, we make sure that the "Keeo Original Filename" is NOT set for the partner.

This works well in the Inbox as it create a new file for every message with filename: <msg_id>.msg.

However, there is a problem with the Message model's payload FileField. The logic used for the file field overwrites the previous file if it is sent on the same day. Here is the relevant code:
payload = models.FileField(upload_to=get_message_store, null=True, blank=True)

def get_message_store(instance, filename):
    current_date = timezone.now().strftime("%Y%m%d")
    if instance.direction == "OUT":
        target_dir = os.path.join(
            "messages", "__store", "payload", "sent", current_date
        )
    else:
        target_dir = os.path.join(
            "messages", "__store", "payload", "received", current_date
        )
    return "{0}/{1}".format(target_dir, filename)

This code will generate the same filename for multiple records, which results in the last record overwriting files from previous ones.

Perhaps the msg_id should be added to the target_dir?

Handle timeout

I had recently had a connection timeout with a partner.

The message status is in a error state and I can't retry it.
image

Disabling local file storage

Just started using pyas2. Thanks for all the work.

I was wondering if there is a way to disable all local storage. I am using django-storages to store FileFields to S3. It seems the calls to "store_file" are storing copies of data that are already stored in the models. In my case, the server's file system is ephemeral.

Encryption of messages is enabled but encrypt key is not set for the receiver.

Is this an issue with the Partner's certificate (public certificate)?

A partner sent over two .cer files (cert.cer and ca.cer), I'm getting a 'Partner Certificate Invalid: unable to get local issuer certificate' when attempted to validate the two.

If I do not validate them when adding the certs, and attempt to send a message to that Partner, an exception is thrown when building the message:

as2.Message.build ->

if self.receiver.encrypt and not self.receiver.encrypt_cert:
raise ImproperlyConfigured(
"Encryption of messages is enabled but encrypt key is not set for the receiver."
)

Standalone Pyas2 Server

I have noticed that people are finding it difficult sometimes to setup django-pyas2 because they have to setup django, settings and so on. I was wondering if we should have a standalone version of django-pyas2 where the django project is all setup and you just need to run a bin command like run_pyas2_server to get it running.

What do you guys think?

No MDN found in the received message

HI,
Trying to configure an Amazon Vendor Central connection and keep getting "No MDN found in the received message" when receiving a test message from Amazon.

Sending a test file to them works fine, and we are also receiving back an MDN from them.
However, when we send, we keep getting the error, and when we downloaded the received messege, it decripted properly and looks fine.

Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/pyas2/views.py", line 90, in post
status, detailed_status = as2mdn.parse(request_body, self.find_message)
File "/usr/lib/python3.6/site-packages/pyas2lib/as2.py", line 774, in parse
self.orig_message_id, orig_recipient = self.detect_mdn()
File "/usr/lib/python3.6/site-packages/pyas2lib/as2.py", line 856, in detect_mdn
raise MDNNotFound('No MDN found in the received message')
pyas2lib.exceptions.MDNNotFound: No MDN found in the received message

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/pyas2lib/as2.py", line 559, in parse
mic_content, signature, verify_cert)
File "/usr/lib/python3.6/site-packages/pyas2lib/cms.py", line 360, in verify_message
for attr in signed_attributes.native:
File "/usr/lib/python3.6/site-packages/asn1crypto/core.py", line 4243, in native
raise e
File "/usr/lib/python3.6/site-packages/asn1crypto/core.py", line 4239, in native
self._native = [child.native for child in self]
File "/usr/lib/python3.6/site-packages/asn1crypto/core.py", line 4239, in <listcomp>
self._native = [child.native for child in self]
File "/usr/lib/python3.6/site-packages/asn1crypto/core.py", line 3777, in native
raise e
File "/usr/lib/python3.6/site-packages/asn1crypto/core.py", line 3773, in native
self._native[name] = child.native
File "/usr/lib/python3.6/site-packages/asn1crypto/core.py", line 4243, in native
raise e
File "/usr/lib/python3.6/site-packages/asn1crypto/core.py", line 4239, in native
self._native = [child.native for child in self]
File "/usr/lib/python3.6/site-packages/asn1crypto/core.py", line 4239, in <listcomp>
self._native = [child.native for child in self]
File "/usr/lib/python3.6/site-packages/asn1crypto/core.py", line 870, in native
self.parse()
File "/usr/lib/python3.6/site-packages/asn1crypto/core.py", line 935, in parse
raise e
File "/usr/lib/python3.6/site-packages/asn1crypto/core.py", line 919, in parse
spec_params=passed_params
File "/usr/lib/python3.6/site-packages/asn1crypto/core.py", line 5242, in _parse_build
return (_build(*info, spec=spec, spec_params=spec_params), new_pointer)
File "/usr/lib/python3.6/site-packages/asn1crypto/core.py", line 5178, in _build
tag
ValueError: Unknown element - context class, constructed method, tag 0
while parsing asn1crypto.core.Any
while parsing asn1crypto.cms.SetOfAny
while parsing asn1crypto.cms.CMSAttribute
while parsing asn1crypto.cms.CMSAttributes

can you help me with this error?

Request Method: POST
http://127.0.0.1:8000/pyas2/as2send/?partner_id=CDETEST
2.1
AttributeError
'PublicKeyInfo' object has no attribute 'keys'
D:\Anaconda3\lib\site-packages\asn1crypto\core.py in init, line 3067
D:\Anaconda3\python.exe
3.6.3
['D:\PycharmProjects\django-pyas2-master', 'D:\Anaconda3\python36.zip', 'D:\Anaconda3\DLLs', 'D:\Anaconda3\lib', 'D:\Anaconda3', 'D:\Anaconda3\lib\site-packages', 'D:\Anaconda3\lib\site-packages\Babel-2.5.0-py3.6.egg', 'D:\Anaconda3\lib\site-packages\django_pyas2-1.0.0b2-py3.6.egg', 'D:\Anaconda3\lib\site-packages\pyas2lib-1.0.3-py3.6.egg', 'D:\Anaconda3\lib\site-packages\pyopenssl-17.5.0-py3.6.egg', 'D:\Anaconda3\lib\site-packages\oscrypto-0.19.1-py3.6.egg', 'D:\Anaconda3\lib\site-packages\asn1crypto-0.24.0-py3.6.egg', 'D:\Anaconda3\lib\site-packages\cryptography-2.3.1-py3.6-win-amd64.egg', 'D:\Anaconda3\lib\site-packages\win32', 'D:\Anaconda3\lib\site-packages\win32\lib', 'D:\Anaconda3\lib\site-packages\Pythonwin']
Wed, 3 Oct 2018 10:10:07 +0000

Failed to parse AS2 MDN

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'

Use variables in Command on Message Receipt

I'm confused about the variables $sender and $receiver in Command on Message Receipt .

Would the $sender be Partner AS2 Identifier, and the $receiver be Organization AS2 Identifier?

My test

  • Organization AS2 Identifier: supplier
  • Partner AS2 Identifier: tradingpartner

Advanced Settings - Command on Message Receipt

echo "$receiver got a message from $sender"

When I send the message from tradingpartner to supplier, I expect the log would be

supplier got a message from tradingpartner

but I got:

tradingpartner got a message from supplier

Code Trace

The variables are defined at /pyas2/utils.py:

def run_post_receive(message, full_filename):
    """Execute command after successful receive, can be used to call the
    edi program for further processing"""

    command = message.partner.cmd_receive
    if command:
        logger.debug(f"Execute post successful receive command {command}")

        # Create command template and replace variables in the command
        command = Template(command)
        variables = {
            "filename": os.path.basename(full_filename),
            "fullfilename": full_filename,
            "sender": message.organization.as2_name,
            "receiver": message.partner.as2_name,
            "messageid": message.message_id,
        }
        variables.update(message.as2message.headers)

        # Execute the command
        os.system(command.safe_substitute(variables))

To swap sender and receiver values would more fit the meaning.

        command = Template(command)
        variables = {
            "filename": os.path.basename(full_filename),
            "fullfilename": full_filename,
            "sender": message.partner.as2_name,
            "receiver": message.organization.as2_name,
            "messageid": message.message_id,
        }

Sending async MDN's fails and stops working when a read fails on an object

Have a regular job running to send async MDNs. However, the job fails, if the latest entry is faulty and all subsequent MDN's will not be sent anymore.

In order to handle this, I suggest to catch exception, try to update the record with error and process to the next one.

Folllowing error is raised:

Traceback (most recent call last):
File "manage.py", line 22, in
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.7/site-packages/django/core/management/init.py", line 401, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.7/site-packages/django/core/management/init.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.7/site-packages/pyas2/management/commands/manageas2server.py", line 114, in handle
data=pending_mdn.payload.read(),
File "/usr/local/lib/python3.7/site-packages/django/core/files/utils.py", line 16, in
read = property(lambda self: self.file.read)
File "/usr/local/lib/python3.7/site-packages/django/db/models/fields/files.py", line 41, in _get_file
self._require_file()
File "/usr/local/lib/python3.7/site-packages/django/db/models/fields/files.py", line 38, in _require_file
raise ValueError("The '%s' attribute has no file associated with it." % self.field.name)
ValueError: The 'payload' attribute has no file associated with it.

Python3 - ImportError raised when trying to load 'pyas2.templatetags.pyas2_extras': No module named 'cStringIO'

does pyAs2 require python2 or support python3? Looks like cStringIO was removed in Python3.

python3 manage.py migrate
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/django/template/utils.py", line 66, in getitem
return self._engines[alias]
KeyError: 'django'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/django/template/backends/django.py", line 121, in get_package_libraries
module = import_module(entry[1])
File "/usr/lib/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 975, in _find_and_load_unlocked
File "", line 671, in _load_unlocked
File "", line 783, in exec_module
File "", line 219, in _call_with_frames_removed
File "/usr/local/lib/python3.8/dist-packages/pyas2/templatetags/pyas2_extras.py", line 2, in
from pyas2 import pyas2init
File "/usr/local/lib/python3.8/dist-packages/pyas2/pyas2init.py", line 5, in
from pyas2 import as2utils
File "/usr/local/lib/python3.8/dist-packages/pyas2/as2utils.py", line 13, in
from cStringIO import StringIO
ModuleNotFoundError: No module named 'cStringIO'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "manage.py", line 22, in
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.8/dist-packages/django/core/management/init.py", line 401, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.8/dist-packages/django/core/management/init.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.8/dist-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.8/dist-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.8/dist-packages/django/core/management/base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/django/core/management/commands/migrate.py", line 75, in handle
self.check(databases=[database])
File "/usr/local/lib/python3.8/dist-packages/django/core/management/base.py", line 392, in check
all_issues = checks.run_checks(
File "/usr/local/lib/python3.8/dist-packages/django/core/checks/registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/usr/local/lib/python3.8/dist-packages/django/contrib/admin/checks.py", line 78, in check_dependencies
for engine in engines.all():
File "/usr/local/lib/python3.8/dist-packages/django/template/utils.py", line 90, in all
return [self[alias] for alias in self]
File "/usr/local/lib/python3.8/dist-packages/django/template/utils.py", line 90, in
return [self[alias] for alias in self]
File "/usr/local/lib/python3.8/dist-packages/django/template/utils.py", line 81, in getitem
engine = engine_cls(params)
File "/usr/local/lib/python3.8/dist-packages/django/template/backends/django.py", line 25, in init
options['libraries'] = self.get_templatetag_libraries(libraries)
File "/usr/local/lib/python3.8/dist-packages/django/template/backends/django.py", line 43, in get_templatetag_libraries
libraries = get_installed_libraries()
File "/usr/local/lib/python3.8/dist-packages/django/template/backends/django.py", line 108, in get_installed_libraries
for name in get_package_libraries(pkg):
File "/usr/local/lib/python3.8/dist-packages/django/template/backends/django.py", line 123, in get_package_libraries
raise InvalidTemplateLibrary(
django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'pyas2.templatetags.pyas2_extras': No module named 'cStringIO'

Unsupported Media Type error for application/octet-stream

Attaching the trace that gives unsupported media type when tried to send message to partner.

Failed to send message, error:
Traceback (most recent call last):
File "/django_pyas2/pyas2/models.py", line 480, in send_message
response.raise_for_status()
File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 960, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 415 Client Error: Unsupported Media Type for url: https://:/file

Partner Host (non PyAS2 internal AS2 Application) expects Content-Type to be "application/octet-stream". So, selected "binary" option in the Content-Type to send message. But ended up with the above mentioned error - Unsupported media type.

@abhishek-ram Can you please help resolving this?

Schedule change of certificates

Suggest to add a functionality for handling change of certificates in a smooth way. I have been approached by a partner as follows:

We will change our Production environment on Oct 22, 2019 from 11-13 UTC.

So when they change, messages will fail in both directions. The exact time is not set.

An idea of how this could be handled:

1.) Partner-specific "maintenance window" during which a change of certificate is anticipated.

2.) On partner level have multiple certificates where one is ACTIVE, while the other one is in "sleep" mode.

3.) During Maintenance Window, when messages decryption fails, a retry with the "sleep" certificate could be done - if successful, the SLEEP certificate becomes active, the ACTIVE one becomes SLEEP.

4.) During Maintenance Window, when message submission on sync MDN fails, retry with SLEEP certificate - if message passes, ACTIVE/SLEEP certificates are swapped.

5.) After Maintenance Window ends, and no message was sent/received that would trigger the switch, the certificates are switched.

6.) Make it optionally selectable that no messages are sent during the maintenance window.

Any thoughts on this ?

Why private key password is required?

I've tried to add private key without password and I got 500:

File "/src/django-pyas2/pyas2/forms.py", line 98, in clean
    cleaned_data["key_file"], cleaned_data["key_pass"]

Exception Type: KeyError at /en/admin/pyas2/privatekey/add/
Exception Value: 'key_pass'

Could the key_pass be optional?

Thanks!

Callback when message has been received

Hi,
There is a more elegant way to trigger a received message event without monkey patching 'run_post_receive' like I did below?

from pyas2 import utils
import requests


old_run_post_receive = utils.run_post_receive


def new_run_post_receive(message, full_filename):
    old_run_post_receive(message, full_filename)
    payload = dict(
        id='1',
        access_token='xyz'
    )
    r = requests.post('http://127.0.0.1/url/to/post', data=payload)


utils.run_post_receive = new_run_post_receive

Cannot exchange encrypted data with some AS2 solutions: missing signature.

Problem with sending AS2 messages to solution like rssbus.
With rssbus, cannot send messages anymore and error "[2019-05-29T10:35:37] [Error] [ReceiveFile - TestAS2] Error: A signature was expected and not provided." is thrown if signature is mandatory. (LoggingExample.zip)
When requirements for signature is removed, it seems the file is received but the file is the Mime instead of the file. (attachment AS21.zip)

In pyas2, sending as base64 (did not try updated version with binary content), the exchange had no problems.

LoggingExample.zip
AS21.zip

How to add custom headers to an AS2 request

Hi all

I am currently trying to communicate with the US Food and Drug Agency FDA via AS2.

I need to send specific information via an extra header, that I need to add to the AS2 post request, that django-as2 is doing againt fda's AS2 gateway.

How could I add such an extra header to the request? It would be very help if someone could point to a file / function where I can add my custom code, in case that there is no such functionality already available in the package.

More information about fda's header handling can be found here:
https://www.fda.gov/industry/about-esg/esg-appendix-f-as2-header-attributes

Cheers
James

File Size in PyAS2

Would like to know about

  • max file size that pyAS2 support
  • max number of concurrent file transfers that pyAS2 support

@abhishek-ram Can you please share some insights based on your performance/load tests reports.

Do we have REST API reference for pyAS2 Django Server?

Do we have REST API reference for pyAS2 Django Server?

I see in the logs, API is been hit.
Some of them that I found in logs, like
GET /admin/pyas2/publiccertificate/add/ HTTP/1.1
POST /admin/pyas2/partner//change/

Can I get that full list of REST API reference to add/view/delete public certs, private certs, partner, organisation, send message etc.

Is there any way to pull out that information? Thanks in advance

Incoming Asynchronous AS2 Message

We just turned on Async with a trading partner using OpenText. They send us an async MDN payload that does not have an MDN header for Message-ID. When that header is missing, the code in pyas2lib.as2.Mdn.parse fails to pick up any Message ID:

            # Extract the headers and save it
            mdn_headers = {}
            for k, v in self.payload.items():
                k = k.lower()
                if k == "message-id":
                    self.message_id = v.lstrip("<").rstrip(">")
                mdn_headers[k] = v

With as2.Mdn.message_id set to None, the code in pyas2.models.MdnManager.create_from_as2mdn will fail with a database "not null" constraint:

        mdn, _ = self.update_or_create(
            message=message,
            defaults=dict(
                mdn_id=as2mdn.message_id,
                status=status,
                signed=signed,
                return_url=return_url,
            ),
        )

I'm not an AS2 expert, but it seems like there would be an expectation that the incoming MDN would have a Message-ID to go along with the Original-Message-ID.

So this /may not/ be a but. It might just be a poorly configured server. So the question is:

When creating the pyas2lib.as2.Mdn object through it's "parse" method, should a message_id be filled in if one is not provided on the header? If so I'll go to that project and add that PR.

OR, should the manager method be updated in this project to allow for an Mdn payload to have a null message_id value, inserting it's own when writing to the database? I can make that PR here if that makes sense.

OR, is this a scenario where the client system is truly misconfigured, and this code is doing what it should (other than possible handling the error and throwing a more meaningful exception).

Thanks for you help and all the work you put into this project. It's awesome!

TypeError: string argument without an encoding

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?

Error stating self signed certificate in certificate chain for valid certs

We tried setting up PYAS2 in two different hosts. We used valid venafi generated certificates for both the hosts and configured private key and public certificate for the respective hosts, as mentioned in the documentation.

It gives me the below error stating 'self signed certificate in certificate chain'. Can you please let me know, why it gives this error even though we used venafi generated certs? Please find the detailed trace below.

Failed to send message, error:
Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 710, in urlopen
chunked=chunked,
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 386, in _make_request
self.validate_conn(conn)
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 1040, in validate_conn
conn.connect()
File "/usr/lib/python3.7/site-packages/urllib3/connection.py", line 424, in connect
tls_in_tls=tls_in_tls,
File "/usr/lib/python3.7/site-packages/urllib3/util/ssl
.py", line 450, in ssl_wrap_socket
sock, context, tls_in_tls, server_hostname=server_hostname
File "/usr/lib/python3.7/site-packages/urllib3/util/ssl
.py", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/lib/python3.7/ssl.py", line 423, in wrap_socket
session=session
File "/usr/lib/python3.7/ssl.py", line 870, in _create
self.do_handshake()
File "/usr/lib/python3.7/ssl.py", line 1139, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/requests/adapters.py", line 450, in send
timeout=timeout
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 786, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/usr/lib/python3.7/site-packages/urllib3/util/retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='HOST_DNS_HERE', port=443): Max retries exceeded with url: /pyas2/as2receive/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/pyas2/models.py", line 478, in send_message
verify=self.partner.https_verify_ssl,
File "/usr/lib/python3.7/site-packages/requests/api.py", line 117, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/lib/python3.7/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3.7/site-packages/requests/sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3.7/site-packages/requests/sessions.py", line 645, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3.7/site-packages/requests/adapters.py", line 517, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='HOST_DNS_HERE', port=443): Max retries exceeded with url: /pyas2/as2receive/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)')))

SSL handshake error when sending message thru https

Hi
I have installed pyas2 server. I am trying to send a file to a trading partner that i setup. When I am sending the message it throws an error . I have included full chain in public certificates(host, intermediate and root ca) . Even though I uncheck “Verify Certificate” it still throwing same error. Note that public certificate is self signed certificate. The certificate i used in PEM format.

Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 603, in urlopen
chunked=chunked)
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 344, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 843, in validate_conn
conn.connect()
File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 370, in connect
ssl_context=context)
File "/usr/local/lib/python3.7/site-packages/urllib3/util/ssl
.py", line 355, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/local/lib/python3.7/site-packages/urllib3/contrib/pyopenssl.py", line 478, in wrap_socket
raise ssl.SSLError('bad handshake: %r' % e)
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 641, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 399, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='myhostname.com', port=4080): Max retries exceeded with url: /dmz/X12 (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))

Has anyone got this error before. I am stuck here and not able to progress without this issue being resolved.

Note that I am able to test pyas2 using https://django-pyas2.readthedocs.io/en/latest/quickstart.html by setting up two instances using orgs P1 and P2. But when I am trying to test with an real trading partner it fails.

Regards,
Satyendra

Parse MDN from response headers

I have the following use case:

Sending a file from pyas2 to a partner, without any signature and encryption.
MDN is requested in sync mode, without any signature.

The message is:

Content-Type: application/edi-consent
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="Screenshot_2020-07-29 Domain test running.png"
AS2-Version: 1.2
ediint-features: CMS
Message-ID: <159602463146.13.8225888991652769525@f70d978e28f8>
AS2-From: pyas2-docker
AS2-To: "SP Adi"
Subject: EDI Message sent using pyas2
Date: Wed, 29 Jul 2020 12:10:31 +0000
disposition-notification-to: [email protected]

The response headers are like this, without any body:

Content-Type: message/disposition-notification
Content-Transfer-Encoding: 7bit

Reporting-UA: AS2 Server
Original-Recipient: rfc822; "SP Adi"
Final-Recipient: rfc822; "SP Adi"
Original-Message-ID: <159602463146.13.8225888991652769525@f70d978e28f8>
Disposition: automatic-action/MDN-sent-automatically;processed

Since this is only a simple MDN without any signature, it does not need to be wrapped into a multi part.

But I think that pyas2 tries to extract it from the multipart body.

The error from pyas2 is Partner failed to process message: mdn-not-found


Thanks for this great project.

CA Private Certificate

Good day,

I am having the following issue with one of our vendors. They are using IBM AS2 communication with us.
We can send EDI files just fine to them, however when they try send something to us we get this error.

We used a CA authority (GoDaddy) to obtain the public and private keys. What we didn't do is send them all the files, we
just sent them the public key.

Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/pyas2lib/cms.py", line 513, in verify_message
verify_cert, sig, signed_data, digest_alg
File "/usr/local/lib/python3.7/site-packages/oscrypto/_openssl/asymmetric.py", line 1079, in rsa_pkcs1v15_verify
return _verify(certificate_or_public_key, signature, data, hash_algorithm)
File "/usr/local/lib/python3.7/site-packages/oscrypto/_openssl/asymmetric.py", line 1437, in _verify
raise SignatureError('Signature is invalid')
oscrypto.errors.SignatureError: Signature is invalid

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/pyas2lib/as2.py", line 637, in parse
self.digest_alg = verify_message(mic_content, signature, verify_cert)
File "/usr/local/lib/python3.7/site-packages/pyas2lib/cms.py", line 522, in verify_message
) from e
pyas2lib.exceptions.IntegrityError: Failed to verify message signature: Signature is invalid

Also, when we had a meeting with them they said this maybe the issue.

Cause
IBM Sterling B2B Integrator is compliant with AS2 RFC as outlined in: https://www.ietf.org/rfc/rfc4130.txt

Non-compliant headers were received in the inbound MDN message.

Diagnosing The Problem
Check the MDN received by viewing the Primary Document at the EDIINTPipelineParse service in error, verify that it contains an header like below:

X-Content-Type-Options: nosniff

Anything would help!

Async MDN - use of a queue instead of a schedules job?

Am wondering about the way currently ASYNC MDN's are sent. Currently I do have the MDN sending job run every 10 minutes to clean up, which works fine. But is this the way we should be doing this, or would it not make more sense to queue a task on request for async MDN which would be handled by workers to that job?

Was thinking of looking into django-q for this for the reason of Django ORM being the broker, so that no additional broker is initially needed.

Any thoughts ?

unsupported operand type(s) for +: 'NoneType' and 'bytes' trying to add public certificate

I've just installed the new django-pyas2 project and I'm attempting to configure it for the first time. When I attempt to install a public certificate and ca file currently in use by the older pyas2 project, I get the following error:

TypeError at /admin/pyas2/publiccertificate/add/
unsupported operand type(s) for +: 'NoneType' and 'bytes'

Request Method:	POST
Request URL:	http://as2-dev.kwikee.com/admin/pyas2/publiccertificate/add/
Django Version:	2.2.2
Exception Type:	TypeError
Exception Value:	
unsupported operand type(s) for +: 'NoneType' and 'bytes'
Exception Location:	/projects/as2/env/lib/python3.6/site-packages/oscrypto/keys.py in _unarmor_pem_openssl_private, line 397
Python Executable:	/usr/local/bin/python3
Python Version:	3.6.8
Python Path:	
['/raid/0/www/docs/projects/as2',
 '/raid/0/www/docs/projects/as2/env/lib/python3.6/site-packages',
 '/usr/local/lib/python3.6',
 '/usr/local/lib/python36.zip',
 '/usr/local/lib/python3.6/lib-dynload',
 '/usr/local/lib/python3.6/site-packages']
Server time:	Wed, 3 Jul 2019 10:06:26 -0500

I'm using the latest package available via pip, which is 1.1.1 and I used a .pem certificate file and a .der CA file. It doesn't seem to matter if I select "verify certificate" or not.

pyOpenSSL==17.5.0
OpenSSL 1.0.2h

Please advise.

Make partner specific setting to check for duplication or not

Sometimes, a message transfer mail be successful but not processed as such by the partner. May connection being terminated before synchronous MDN sending has finished or that an MDN is not properly handled or ...

In other AS2 solutions, I found the option to disabled duplicate check per partner. Not exactly sure what that does, but I would suggest a partner specific setting:

  • Option to send "positive" MDN for duplicate message, but handle internally like when duplicate message is received.

Any thoughts on this?

URLResolver errors when receiving messages

When the instance receives a message attempt (either from another testing django-pyas2 I have or from a real third party partner), I am getting the following errors in the logs with DEBUG logging level:

Exception while resolving variable 'name' in template 'unknown'.
 Traceback (most recent call last):
  File "/projects/as2/env/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/projects/as2/env/lib/python3.6/site-packages/django/core/handlers/base.py", line 100, in _get_response
    resolver_match = resolver.resolve(request.path_info)
  File "/projects/as2/env/lib/python3.6/site-packages/django/urls/resolvers.py", line 566, in resolve
    raise Resolver404({'tried': tried, 'path': new_path})
 django.urls.exceptions.Resolver404: {'tried': [[<URLResolver <module 'pyas2.urls' from '/projects/as2/env/lib/python3.6/site-packages/pyas2/urls.py'> (None:None) 'pyas2/'>], [<URLResolver <URLPattern list> (admin:admin) 'admin/'>]], 'path': ''}

 During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/projects/as2/env/lib/python3.6/site-packages/django/template/base.py", line 829, in _resolve_lookup
    current = current[bit]
 TypeError: 'URLResolver' object is not subscriptable

and

Traceback (most recent call last):
   File "/raid/0/www/docs/projects/as2/env/lib/python3.6/site-packages/django/template/base.py", line 837, in _resolve_lookup
     current = getattr(current, bit)
 AttributeError: 'URLResolver' object has no attribute 'name'

and

Traceback (most recent call last):
  File "/raid/0/www/docs/projects/as2/env/lib/python3.6/site-packages/django/template/base.py", line 843, in _resolve_lookup
    current = current[int(bit)]
 ValueError: invalid literal for int() with base 10: 'name'

It seems like I am able to successfully send messages from this instance and use the admin URLs with no problem, it just seems to be related to receiving messages.

I don't believe I've done anything wrong following the installation/quickstart instructions, but since nobody has seemingly ran into this issue, I'm not sure.

Please advise.

Thanks

SMIME File

How do I get the SMIME file, I can't find it anywhere. I am also unable to see if the file has been encrypted when I did a test run I could not see if the message has been encrypted. I want to see if the encryption algorithm is actually working.

when upload private.pem get error "Invalid Private key file or Public key not included."

I generate the pem file as instruction:

openssl req -x509 -newkey rsa:2048 -sha256 -keyout private.pem -out public.pem -days 365

cat public.pem >> private.pem

when I use the private.pem in Add private key page got an error

Invalid Private key file or Public key not included.

the error happened in as2.py
`
def load_key(key_str: bytes, key_pass: str):
"""Function to load password protected key file in p12 or pem format."""

    try:
        # First try to parse as a p12 file
        key, cert, _ = asymmetric.load_pkcs12(key_str, key_pass)
    except ValueError as e:    **#'Error parsing asn1crypto.pkcs12.Pfx - tag should have been 16, but 13 was found'**  _I don't understand this error means_
        # If it fails due to invalid password raise error here
        if e.args[0] == "Password provided is invalid":     
            raise AS2Exception("Password not valid for Private Key.") from e

        # if not try to parse as a pem file
        key, cert = None, None
        for kc in split_pem(key_str):
            try:
                cert = asymmetric.load_certificate(kc)
            except (ValueError, TypeError) as e:
                try:
                    key = asymmetric.load_private_key(kc, key_pass)
                except OSError:
                    raise AS2Exception(
                        "Invalid Private Key or password is not correct."
                    ) from e

    if not key or not cert:
        raise AS2Exception("Invalid Private key file or Public key not included.")

    return key, cert

`
the cert is always None, is there anything I make wrong?

Thank you

Remove support for RC2 and RC4 - signed attributes fail with Sterling

When sending signed message to Sterling B2B Integrator, the ASN1 code for RC4 Cipher is not being picked up and message transmission fails.

Removing the attribute by commenting line 248-250 in pyas2-lib - cms.py, leads to a successful transmission.

As RC2 and RC4 are not secure algorithms and support for same is being removed in most common places, the support for same should be removed from django-pyas2 and pyas2-lib as well.

Wrong "Sign Message" field?

Hello!

In the Security Settings, there is the "Sign Message" field which prompts for a method to CHECK the message signature.

  1. I think it should be named "Signature Verification" instead of "Sign Message". The partner signed the message, not the Django-PyAS2 instance. The public key (next field) lets you verify a signature, not sign.
  2. I believe the docs are wrong: it should say "the hash algorithm to be used for verifying signed messages" received from partners instead of "the hash algorithm to be used for signing messages".

I hope I didn't confuse things and waste your time. Thank you for this useful piece of software!

Handling of duplicate messages in case first transmission had an error.

When file is transferred and an error happens in processing, an MDN is triggered to the sender, stating that there was an error. Therefore the partner will resend the message.
However, when the partner resends, the new message is considered a "duplicate".

Shouldn't duplicate check check for successful messages only? Currently it seems it applies to all messages, irrespective of their status. Suggest to add the status to the filter criteria.

example of processing error, that seems to happen under some circumstances that I could not yet identify, usually around the time when a new folder was created, but it does not always happen on the first one:

An error occurred during the AS2 message processing: [Errno 17] File exists '/data/messages/__store/payload/received/20190530'

Too small field length restrictions on models.FileField

Hello!
By default Django models.FileField is limited to 100 chars.
In some cases this limit is too small for payload fields in Mdn and Message tables.
This cause problems with long filenames (update query fails and field left blank) and prevent normal message/mdn view and mdn sending:

ValueError: The 'payload' attribute has no file associated with it.
Internal Server Error: /admin/pyas2/mdn/290276/change/

Sending all pending asynchronous MDNs
Traceback (most recent call last):
File "/var/www/pyas2/manage.py", line 22, in
main()
File "/var/www/pyas2/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/opt/pyvenv/as2/lib64/python3.6/site-packages/django/core/management/init.py", line 419, in execute_from_command_line
utility.execute()
File "/opt/pyvenv/as2/lib64/python3.6/site-packages/django/core/management/init.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/pyvenv/as2/lib64/python3.6/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/pyvenv/as2/lib64/python3.6/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/opt/pyvenv/as2/lib64/python3.6/site-packages/pyas2/management/commands/manageas2server.py", line 125, in handle
data=pending_mdn.payload.read(),
File "/opt/pyvenv/as2/lib64/python3.6/site-packages/django/core/files/utils.py", line 42, in
read = property(lambda self: self.file.read)
File "/opt/pyvenv/as2/lib64/python3.6/site-packages/django/db/models/fields/files.py", line 43, in _get_file
self._require_file()
File "/opt/pyvenv/as2/lib64/python3.6/site-packages/django/db/models/fields/files.py", line 40, in _require_file
raise ValueError("The '%s' attribute has no file associated with it." % self.field.name)
ValueError: The 'payload' attribute has no file associated with it.

Seems like maximum full path length on various filesystems is about 4096 characters.

I propose to set max_length for payload fields in pyas2/models.py to 4096 like this:

payload = models.FileField(upload_to=get_mdn_store, null=True, blank=True, max_length=4096)

payload = models.FileField(upload_to=get_message_store, null=True, blank=True, max_length=4096)

Encrypted File

I am unable to see the EDI documents encrypted from my end. I need to have a record of the file being encrypted.

Message Digest does not match

Hi,

For some reason pyas2 throws an error message and sends a failure MDN, allthough the payload is received correctly and can be processed.
"pyas2lib.exceptions.IntegrityError: Failed to verify message signature: Message Digest does not match."
Can this have something to do with the compression of the message? the partner only had the option to set compression levels 1-9. Or maybe because they are using HTTPS? I checked and unchecked "Verify SSL Certificate", but that didn't help.

Does anyone has an idea?

`2020-12-31 13:08:01,605 pyas2lib DEBUG Compressed message [email protected] payload as:
b'MIME-Version: 1.0\r\nContent-Type: application/pkcs7-mime; name="smime.p7z"; smime-type="compressed-data"\r\nContent-Disposition: attachment; filename="smime.p7z"\r\nContent-Transfer-Encoding: binary\r\n\r\n0\x81\xc4\x06\x0b*.....'
2020-12-31 13:08:01,618 pyas2lib DEBUG Signed message [email protected] payload as:
b'Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg="sha512"; boundary="===============1985204697163016904=="\r\n\r\n--===============1985204697163016904==\r\nMIME-Version: 1.0\r\nContent-Type: application/pkcs7-mime; name="smime.p7z"; smime-type="compressed-data"\r\nContent-Disposition: attachment; filename="smime.p7z"\r\nContent-Transfer-Encoding: binary\r\n\r\n0\x81\xc4\x06\x0b*\x86H\x86\xf7\r\x01.........x0fc<\x03\r\n--===============1985204697163016904==\r\nContent-Type: application/pkcs7-signature; name="smime.p7s"; smime-type="signed-data"\r\nContent-Disposition: attachment; filename="smime.p7s"\r\nContent-Transfer-Encoding: base64\r\n\r\nMIIHZwYJKoZIhvcNAQcCoII..........\r\n\r\n--===============1985204697163016904==--\r\n'
2020-12-31 13:08:01,622 pyas2lib DEBUG Encrypted message [email protected] payload as:
b'MIME-Version: 1.0\r\nContent-Type: application/pkcs7-mime; name="smime.p7m"; smime-type="enveloped-data"\r\nContent-Disposition: attachment; filename="smime.p7m"\r\nContent-Transfer-Encoding: binary\r\n\r\n0\x82\x0f_\x06\t*\x86H\x86\xf7\r\x01............\xd8\xad'
2020-12-31 13:08:01,622 pyas2 INFO Sending message [email protected] from organization "organisation Entertainment" to partner "partner TEST".
2020-12-31 13:08:01,871 pyas2 DEBUG Received an HTTP POST from 85.158.120.86 with payload :
b'user-agent: curl/7.23.1 (i686-pc-linux-gnu) libcurl/7.23.1 OpenSSL/1.0.2a zlib/1.1.4 libssh2/1.3.0\nhost: as2.organisation.nl:5443\naccept: /\nas2-from: partnerB2B.NET_SECU\nas2-to: 8719329013005\nas2-version: 1.2\ncontent-disposition: attachment;filename="smime.p7m"\ncontent-transfer-encoding: binary\ncontent-type: application/pkcs7-mime;smime-type=enveloped-data;name="smime.p7m"\ndate: Thu, 31 Dec 2020 12:08:01 GMT\ndisposition-notification-options: signed-receipt-protocol=optional,pkcs7-signature;signed-receipt-micalg=optional,sha1\ndisposition-notification-to: ediint-sync-mdn\nediint-features: multiple-attachments\nmessage-id: [email protected]\nsubject: partner-MPRP TO organisation\ncontent-length: 5162\n\r\n0\x82\x14&\x06\t*\x86H\x86\xf7\r\x01...........'
2020-12-31 13:08:01,871 pyas2 DEBUG Check to see if payload is an Asynchronous MDN.
2020-12-31 13:08:01,872 pyas2 DEBUG Payload is not an MDN parse it as an AS2 Message
2020-12-31 13:08:01,894 pyas2lib DEBUG Decrypting message [email protected] payload :
b'user-agent: curl/7.23.1 (i686-pc-linux-gnu) libcurl/7.23.1 OpenSSL/1.0.2a zlib/1.1.4 libssh2/1.3.0\r\nhost: as2.organisation.nl:5443\r\naccept: /\r\nas2-from: partnerB2B.NET_SECU\r\nas2-to: 8719329013005\r\nas2-version: 1.2\r\ncontent-disposition: attachment;filename="smime.p7m"\r\ncontent-transfer-encoding: binary\r\ncontent-type: application/pkcs7-mime;smime-type=enveloped-data;name="smime.p7m"\r\ndate: Thu, 31 Dec 2020 12:08:01 GMT\r\ndisposition-notification-options: signed-receipt-protocol=optional,pkcs7-signature;signed-receipt-micalg=optional,sha1\r\ndisposition-notification-to: ediint-sync-mdn\r\nediint-features: multiple-attachments\r\nmessage-id: [email protected]\r\nsubject: partner-MPRP TO organisation\r\ncontent-length: 5162\r\n\r\n0\x82\x14&\x06\t*\x86H\x86..............'
2020-12-31 13:08:01,898 pyas2lib DEBUG Verifying signed message [email protected] payload:
b'Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-512; boundary="------15FEDBF21822FA6D11609416481B3C3D1"\r\n\r\n\r\n--------15FEDBF21822FA6D11609416481B3C3D1\r\nContent-Disposition: attachment; filename="test_as2.txt"\r\nContent-Type: Application/octet-stream\r\n\r\n..................................this is an AS2 test file by partner......................................\r\n......................................please ignore this message...........................................\r\n...........................................................................................................\r\n...............................................................................((((/.......................\r\n................................................................................./(//......................\r\n...........................................................................................................\r\n......../((((((((((((//.(((((((((....(((...((/((((/......(/(((/(((.../(((...(/((/((/(.((((/.....((((.......\r\n....../(((...../(((../((((.....((((../(((((/...(((((../((((.....(/((./(((((((....((((...(((/../(((/........\r\n...../(/(/....../(((/(((/........(((/((((......./(((//(((......../(((/((((.......((((....((..((((..........\r\n....../(((......((/(/(((((((((((((((/((((........((((((((((/(((((((((/(((........((((......//((/...........\r\n........((/(((((/(..(((/.............((((........(((((((/............/(((........((((...../.((((/..........\r\n....../((/........../((//............((((......./((///(((/.........../(((........((((....(((./((((.........\r\n......((((............(((((/..../(/..((((........((((..(/(/(/..../(/./(((/.......((((..(((/....((//........\r\n......./(((/(((((/((/(...(((/((/(/...(((/........((((.....((((((((/../(((........((((/(((......./((((......\r\n.....(((/..........((((....................................................................................\r\n.....(((/.........(/((.....................................................................................\r\n.......(((((/((((((/.......................................................................................\r\n...........................................................................................................\r\n--------15FEDBF21822FA6D11609416481B3C3D1\r\nContent-Transfer-Encoding: binary\r\nContent-Disposition: attachment; filename="smime.p7s"\r\nContent-Type: application/pkcs7-signature; name="smime.p7s"\r\n\r\n0\x82\x08=\x06\t*\x86H\x86..............\r\n--------15FEDBF21822FA6D11609416481B3C3D1--\r\n'
2020-12-31 13:08:01,899 pyas2lib ERROR Failed to parse AS2 message
: Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/pyas2lib/as2.py", line 629, in parse
self.digest_alg = verify_message(mic_content, signature, verify_cert)
File "/usr/local/lib/python3.6/dist-packages/pyas2lib/cms.py", line 488, in verify_message
"Failed to verify message signature: Message Digest does not match."
pyas2lib.exceptions.IntegrityError: Failed to verify message signature: Message Digest does not match.

2020-12-31 13:08:01,900 pyas2lib DEBUG Building the MDN for message [email protected] with status processed/Error and detailed-status authentication-failed.
2020-12-31 13:08:01,900 pyas2lib DEBUG MDN report for message [email protected] created:
b'Content-Type: message/disposition-notification\r\nContent-Transfer-Encoding: 7bit\r\n\r\nReporting-UA: pyAS2 Open Source AS2 Software\r\nOriginal-Recipient: rfc822; 8719329013005\r\nFinal-Recipient: rfc822; 8719329013005\r\nOriginal-Message-ID: [email protected]\r\nDisposition: automatic-action/MDN-sent-automatically; processed/Error: authentication-failed\r\n'
2020-12-31 13:08:01,910 pyas2lib DEBUG Signing the MDN for message [email protected]
2020-12-31 13:08:01,912 pyas2lib DEBUG MDN generated for message [email protected] with content:
b'Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg="sha1"; boundary="===============0089551447359942500=="\r\nAS2-Version: 1.2\r\nediint-features: CMS\r\nMessage-ID: [email protected]\r\nAS2-From: 8719329013005\r\nAS2-To: partnerB2B.NET_SECU\r\nDate: Thu, 31 Dec 2020 13:08:01 +0100\r\nuser-agent: pyAS2 Open Source AS2 Software\r\n\r\n--===============0089551447359942500==\r\nContent-Type: multipart/report; report-type="disposition-notification"; boundary="===============7671050814658493779=="\r\nMIME-Version: 1.0\r\n\r\n--===============7671050814658493779==\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--===============7671050814658493779==\r\nContent-Type: message/disposition-notification\r\nContent-Transfer-Encoding: 7bit\r\n\r\nReporting-UA: pyAS2 Open Source AS2 Software\r\nOriginal-Recipient: rfc822; 8719329013005\r\nFinal-Recipient: rfc822; 8719329013005\r\nOriginal-Message-ID: [email protected]\r\nDisposition: automatic-action/MDN-sent-automatically; processed/Error: authentication-failed\r\n\r\n--===============7671050814658493779==--\r\n\r\n--===============0089551447359942500==\r\nContent-Type: application/pkcs7-signature; name="smime.p7s"; smime-type="signed-data"\r\nContent-Disposition: attachment; filename="smime.p7s"\r\nContent-Transfer-Encoding: base64\r\n\r\nMIIHMwYJKoZIhvcNAQc............=\r\n\r\n--===============0089551447359942500==--\r\n'
2020-12-31 13:08:01,912 pyas2 INFO Received an AS2 message with id [email protected] for organization 8719329013005 from partner partnerB2B.NET_SECU.
2020-12-31 13:08:01,962 pyas2 DEBUG Received MDN response for message [email protected] with content: b'message-id: [email protected]\ncontent-type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha512; boundary="------15FEDBF2182020F511609416481B3C501"\n\n\r\n--------15FEDBF2182020F511609416481B3C501\r\nContent-Type: multipart/report; report-type=disposition-notification; boundary="------25FEDBF2182020F521609416481B3C502"\r\n\r\n\r\n--------25FEDBF2182020F521609416481B3C502\r\nContent-Type: text/plain\r\n\r\nMessage [email protected] was authenticated and decrypted;\r\nEDI processing was initiated.\r\n\r\n\r\n--------25FEDBF2182020F521609416481B3C502\r\nContent-Type: message/disposition-notification\r\n\r\nOriginal-Message-ID: [email protected]\r\nOriginal-Recipient: rfc822; partnerB2B.NET_SECU\r\nFinal-Recipient: rfc822; partnerB2B.NET_SECU\r\nReceived-content-MIC: +mQvTwObpKabsK/S0UnsQ2t1lJsuEwf1i1ZTGlSCvH9o4gh5E2vcA6CzuqiyTa7Btscr3F+/0VnLsTY7AqhUXA==,sha512\r\nDisposition: automatic-action/MDN-sent-automatically;processed\r\n\r\n\r\n--------25FEDBF2182020F521609416481B3C502--\r\n\r\n--------15FEDBF2182020F511609416481B3C501\r\nContent-Transfer-Encoding: binary\r\nContent-Disposition: attachment; filename="smime.p7s"\r\nContent-Type: application/pkcs7-signature; name="smime.p7s"\r\n\r\n0\x82\x08=\x06\t*\x86H\x86..................\r\n--------15FEDBF2182020F511609416481B3C501--\r\n'
2020-12-31 13:08:01,970 pyas2lib DEBUG Verifying signed MDN:
b'message-id: [email protected]\r\ncontent-type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha512; boundary="------15FEDBF2182020F511609416481B3C501"\r\n\r\n\r\n--------15FEDBF2182020F511609416481B3C501\r\nContent-Type: multipart/report; report-type=disposition-notification; boundary="------25FEDBF2182020F521609416481B3C502"\r\n\r\n\r\n--------25FEDBF2182020F521609416481B3C502\r\nContent-Type: text/plain\r\n\r\nMessage [email protected] was authenticated and decrypted;\r\nEDI processing was initiated.\r\n\r\n\r\n--------25FEDBF2182020F521609416481B3C502\r\nContent-Type: message/disposition-notification\r\n\r\nOriginal-Message-ID: [email protected]\r\nOriginal-Recipient: rfc822; partnerB2B.NET_SECU\r\nFinal-Recipient: rfc822; partnerB2B.NET_SECU\r\nReceived-content-MIC: +mQvTwObpKabsK/S0UnsQ2t1lJsuEwf1i1ZTGlSCvH9o4gh5E2vcA6CzuqiyTa7Btscr3F+/0VnLsTY7AqhUXA==,sha512\r\nDisposition: automatic-action/MDN-sent-automatically;processed\r\n\r\n\r\n--------25FEDBF2182020F521609416481B3C502--\r\n\r\n--------15FEDBF2182020F511609416481B3C501\r\nContent-Transfer-Encoding: binary\r\nContent-Disposition: attachment; filename="smime.p7s"\r\nContent-Type: application/pkcs7-signature; name="smime.p7s"\r\n\r\n0\x82\x08=\x06\t*\x86H\x86\xf7\r.................\xfc\xceI\r\n--------15FEDBF2182020F511609416481B3C501--\r\n'
2020-12-31 13:08:01,971 pyas2lib DEBUG MDN report for message [email protected]:
Content-Type: message/disposition-notification

Original-Message-ID: [email protected]
Original-Recipient: rfc822; partnerB2B.NET_SECU
Final-Recipient: rfc822; partnerB2B.NET_SECU
Received-content-MIC: +mQvTwObpKabsK/S0UnsQ2t1lJsuEwf1i1ZTGlSCvH9o4gh5E2vcA6CzuqiyTa7Btscr3F+/0VnLsTY7AqhUXA==,sha512
Disposition: automatic-action/MDN-sent-automatically;processed
`

TypeError: 'unicode' does not have the buffer interface

I'm following the Quickstart to send a test message between P1 and P2. I got this error when I hit the Send Message button.

Performing system checks...

System check identified no issues (0 silenced).
June 08, 2019 - 12:52:31
Django version 1.11.21, using settings 'django_pyas2.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Internal Server Error: /pyas2/as2send/
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/views/generic/edit.py", line 183, in post
    return self.form_valid(form)
  File "/usr/local/lib/python2.7/dist-packages/pyas2/views.py", line 207, in form_valid
    content_type=form.cleaned_data['partner'].content_type
  File "/usr/local/lib/python2.7/dist-packages/pyas2lib-1.1.0-py2.7.egg/pyas2lib/as2.py", line 402, in build
    mic_content = canonicalize(self.payload)
  File "/usr/local/lib/python2.7/dist-packages/pyas2lib-1.1.0-py2.7.egg/pyas2lib/utils.py", line 78, in canonicalize
    return mime_to_bytes(message, 0).replace(
  File "/usr/local/lib/python2.7/dist-packages/pyas2lib-1.1.0-py2.7.egg/pyas2lib/utils.py", line 58, in mime_to_bytes
    g.flatten(msg)
  File "/usr/lib/python2.7/email/generator.py", line 83, in flatten
    self._write(msg)
  File "/usr/lib/python2.7/email/generator.py", line 115, in _write
    self._write_headers(msg)
  File "/usr/lib/python2.7/email/generator.py", line 145, in _write_headers
    print >> self._fp, v
TypeError: 'unicode' does not have the buffer interface
[08/Jun/2019 12:53:08] "POST /pyas2/as2send/?partner_id=p2as2 HTTP/1.1" 500 107315

Send messages from py file

Hello,

I can now send message either from Django Admin or from Command-Line. I'm trying to send/receive message from py file. Does anyone know how to do that? It should be something like this:

import os

method = "sendas2message"
sender = "p1as2"
receiver = "p2as2"
path_to_payload = "test_message/outbound/out_message1.txt"


def send(_method, _sender, _receiver, _path_to_payload):
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_pyas2.settings')
    try:
        from django.core.management import ManagementUtility
    except ImportError as exc:
        raise ImportError(
                "Couldn't import Django. Are you sure it's installed and "
                "available on your PYTHONPATH environment variable? Did you "
                "forget to activate a virtual environment?"
                ) from exc
    ManagementUtility.execute(_method, _sender, _receiver, _path_to_payload)

if __name__ == '__main__':
    send(method, sender, receiver, path_to_payload)

It obviously that ManagementUtility.execute() takes command line input argv, I am trying to find somewhere takes direct input like above.

Thank you!

Best,

'content-type' key error when using sync MDN

When I set up a partner with a sync MDN, I get the following error:

Request URL: http://someserver.com/pyas2/as2send/?partner_id=1234

Django Version: 2.2.7
Python Version: 3.6.8
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'pyas2']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback:

File "/projects/as2/env/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/projects/as2/env/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "/projects/as2/env/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/projects/as2/env/lib/python3.6/site-packages/django/views/generic/base.py" in view
  71.             return self.dispatch(request, *args, **kwargs)

File "/projects/as2/env/lib/python3.6/site-packages/django/views/generic/base.py" in dispatch
  97.         return handler(request, *args, **kwargs)

File "/projects/as2/env/lib/python3.6/site-packages/django/views/generic/edit.py" in post
  142.             return self.form_valid(form)

File "/projects/as2/env/lib/python3.6/site-packages/pyas2/views.py" in form_valid
  209.         message.send_message(as2message.headers, as2message.content)

File "/projects/as2/env/lib/python3.6/site-packages/pyas2/models.py" in send_message
  407.                 mdn_content += f'content-type: {mdn_headers["content-type"]}\n\n'

Exception Type: KeyError at /pyas2/as2send/
Exception Value: 'content-type'

pip freeze output is:

certifi==2019.9.11
cffi==1.13.2
chardet==3.0.4
cryptography==2.8
dataclasses==0.6
Django==2.2.7
django-pyas2==1.1.1
idna==2.8
oscrypto==0.19.1
pyas2lib==1.2.2
pycparser==2.19
pyOpenSSL==17.5.0
pytz==2019.3
requests==2.22.0
six==1.13.0
sqlparse==0.3.0
urllib3==1.25.7

If I turn off the MDN, I do not get this error, but we'd like to have the MDN functioning.

Is there an issue with the configuration or is this a truly a bug in django-pyas2?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.