diff --git a/pyas2lib/as2.py b/pyas2lib/as2.py index a81dee1..8173f5d 100644 --- a/pyas2lib/as2.py +++ b/pyas2lib/as2.py @@ -288,7 +288,8 @@ def headers_str(self): return message_header.encode('utf-8') def build(self, data, filename=None, subject='AS2 Message', - content_type='application/edi-consent', additional_headers=None): + content_type='application/edi-consent', additional_headers=None, + disposition_notification_to='no-reply@pyas2.com'): """Function builds the AS2 message. Compresses, signs and encrypts the payload if applicable. @@ -309,6 +310,10 @@ def build(self, data, filename=None, subject='AS2 Message', :param additional_headers: Any additional headers to be included as part of the AS2 message. + :param disposition_notification_to: + Email address for disposition-notification-to header entry. + (default "no-reply@pyas2.com") + """ # Validations @@ -413,7 +418,7 @@ def build(self, data, filename=None, subject='AS2 Message', f'Encrypted message {self.message_id} payload as:\n{self.payload.as_string()}') if self.receiver.mdn_mode: - as2_headers['disposition-notification-to'] = 'no-reply@pyas2.com' + as2_headers['disposition-notification-to'] = disposition_notification_to if self.receiver.mdn_digest_alg: as2_headers['disposition-notification-options'] = \ f'signed-receipt-protocol=required, pkcs7-signature; ' \ diff --git a/pyas2lib/tests/test_advanced.py b/pyas2lib/tests/test_advanced.py index 8417051..fd15f24 100644 --- a/pyas2lib/tests/test_advanced.py +++ b/pyas2lib/tests/test_advanced.py @@ -457,8 +457,7 @@ def xtest_process_message(self): def test_process_mdn(self): """ Test processing mdn received from Sterling Integrator""" msg = as2.Message(sender=self.org, receiver=self.partner) - msg.message_id = '151694007918.24690.7052273208458909245@' \ - 'ip-172-31-14-209.ec2.internal' + msg.message_id = '151694007918.24690.7052273208458909245@ip-172-31-14-209.ec2.internal' as2mdn = as2.Mdn() # Parse the mdn and get the message status diff --git a/pyas2lib/tests/test_utils.py b/pyas2lib/tests/test_utils.py index c14a246..8222af2 100644 --- a/pyas2lib/tests/test_utils.py +++ b/pyas2lib/tests/test_utils.py @@ -52,12 +52,10 @@ def test_extract_certificate_info(): in PEM or DER format""" cert_info = { - 'valid_from': datetime.datetime(2019, 6, 3, 11, 32, 57), - 'valid_to': datetime.datetime(2029, 5, 31, 11, 32, 57), - 'subject': [('C', 'AU'), ('ST', 'Some-State'), - ('O', 'pyas2lib'), ('CN', 'test')], - 'issuer': [('C', 'AU'), ('ST', 'Some-State'), - ('O', 'pyas2lib'), ('CN', 'test')], + 'valid_from': datetime.datetime(2019, 6, 3, 11, 32, 57, tzinfo=datetime.timezone.utc), + 'valid_to': datetime.datetime(2029, 5, 31, 11, 32, 57, tzinfo=datetime.timezone.utc), + 'subject': [('C', 'AU'), ('ST', 'Some-State'), ('O', 'pyas2lib'), ('CN', 'test')], + 'issuer': [('C', 'AU'), ('ST', 'Some-State'), ('O', 'pyas2lib'), ('CN', 'test')], 'serial': 13747137503594840569 } cert_empty = { diff --git a/pyas2lib/utils.py b/pyas2lib/utils.py index 073747c..72b33f0 100644 --- a/pyas2lib/utils.py +++ b/pyas2lib/utils.py @@ -10,7 +10,7 @@ from io import BytesIO from pyas2lib.exceptions import AS2Exception -from datetime import datetime +from datetime import datetime, timezone def unquote_as2name(quoted_name: str): @@ -205,8 +205,8 @@ def extract_certificate_info(cert: bytes): :param cert: the certificate as byte string in PEM or DER format :return: a dictionary holding certificate information: - valid_from (datetime) - valid_to (datetime) + valid_from (datetime) - UTC + valid_to (datetime) - UTC subject (list of name, value tuples) issuer (list of name, value tuples) serial (int) @@ -233,9 +233,11 @@ def extract_certificate_info(cert: bytes): # on successful load, extract the various fields into the dictionary cert_info['valid_from'] = datetime.strptime( - certificate.get_notBefore().decode('utf8'), "%Y%m%d%H%M%SZ") + certificate.get_notBefore().decode('utf8'), "%Y%m%d%H%M%SZ").\ + replace(tzinfo=timezone.utc) cert_info['valid_to'] = datetime.strptime( - certificate.get_notAfter().decode('utf8'), "%Y%m%d%H%M%SZ") + certificate.get_notAfter().decode('utf8'), "%Y%m%d%H%M%SZ").\ + replace(tzinfo=timezone.utc) cert_info['subject'] = [ tuple(item.decode('utf8') for item in sets) for sets in certificate.get_subject().get_components()]