From 52258be0f23a50947dc0e8b8aca97da98da7a5fa Mon Sep 17 00:00:00 2001 From: Wassilios Lytras Date: Tue, 4 Jun 2019 14:04:50 +0200 Subject: [PATCH 1/4] Prevent RuntimeWarning: DateTimeField received a naive datetime in django-pyas2 --- pyas2lib/utils.py | 4 ++-- tests/test_advanced.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pyas2lib/utils.py b/pyas2lib/utils.py index d289795..f03d111 100644 --- a/pyas2lib/utils.py +++ b/pyas2lib/utils.py @@ -224,9 +224,9 @@ def extract_certificate_info(cert): # 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%S%z") 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%S%z") cert_info['subject'] = [ tuple(item.decode('utf8') for item in sets) for sets in certificate.get_subject().get_components()] diff --git a/tests/test_advanced.py b/tests/test_advanced.py index 06fd12f..f5fd1ac 100644 --- a/tests/test_advanced.py +++ b/tests/test_advanced.py @@ -331,8 +331,8 @@ def test_extract_certificate_info(self): 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), + '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'), From 6cd2cb09ac59d347304c3bd746dc0d2245f566fd Mon Sep 17 00:00:00 2001 From: Wassilios Lytras Date: Tue, 4 Jun 2019 16:07:26 +0200 Subject: [PATCH 2/4] Prevent RuntimeWarning: DateTimeField received a naive datetime in django-pyas2 --- pyas2lib/utils.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pyas2lib/utils.py b/pyas2lib/utils.py index f03d111..22eca06 100644 --- a/pyas2lib/utils.py +++ b/pyas2lib/utils.py @@ -8,7 +8,7 @@ from io import BytesIO from pyas2lib.exceptions import AS2Exception -from datetime import datetime +from datetime import datetime, timezone def unquote_as2name(quoted_name): @@ -196,8 +196,8 @@ def extract_certificate_info(cert): :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) @@ -224,9 +224,11 @@ def extract_certificate_info(cert): # 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%S%z") + 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%S%z") + 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()] From bb365f3d4d588af7351f56c458ebdce9cbd71637 Mon Sep 17 00:00:00 2001 From: Wassilios Lytras Date: Fri, 7 Jun 2019 21:15:28 +0200 Subject: [PATCH 3/4] Adding option to pass/define disposition notification to when creating AS2 message. --- pyas2lib/as2.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pyas2lib/as2.py b/pyas2lib/as2.py index 4d06edf..7e946c9 100644 --- a/pyas2lib/as2.py +++ b/pyas2lib/as2.py @@ -305,7 +305,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. @@ -326,6 +327,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 @@ -441,7 +446,7 @@ def build(self, data, filename=None, subject='AS2 Message', self.message_id, 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'] = \ 'signed-receipt-protocol=required, pkcs7-signature; ' \ From f21ee0ed01364f87fc4fe978e1aac814430cfa3c Mon Sep 17 00:00:00 2001 From: Wassilios Lytras Date: Mon, 10 Jun 2019 15:31:28 +0200 Subject: [PATCH 4/4] Remove unused variable. --- pyas2lib/as2.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyas2lib/as2.py b/pyas2lib/as2.py index 7e946c9..23c3dbc 100644 --- a/pyas2lib/as2.py +++ b/pyas2lib/as2.py @@ -555,7 +555,6 @@ def parse(self, raw_content, find_org_cb, find_partner_cb, self.enc_alg, decrypted_content = decrypt_message( encrypted_data, self.receiver.decrypt_key) - raw_content = decrypted_content self.payload = parse_mime(decrypted_content) if self.payload.get_content_type() == 'text/plain':