From 58070a150589fc9be4b93688fef104487b720c0c Mon Sep 17 00:00:00 2001 From: s3lph <1375407-s3lph@users.noreply.gitlab.com> Date: Fri, 22 Apr 2022 06:46:14 +0200 Subject: [PATCH] Don't base64 encode encrypted reports, it's not RFC 3156 compliant and some mailclients (e.g. K-9) have issues with that. --- CHANGELOG.md | 13 +++++++++++++ multischleuder/reporting.py | 14 +++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 466c3ed..a46245e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # MultiSchleuder Changelog + +## Version 0.1.3 + +Bugfix release + +### Changes + + +- RFC 3156 compliance: Don't base64-encode encrypted reports + + + + ## Version 0.1.2 diff --git a/multischleuder/reporting.py b/multischleuder/reporting.py index acafcb0..536c29d 100644 --- a/multischleuder/reporting.py +++ b/multischleuder/reporting.py @@ -2,6 +2,7 @@ from typing import Dict, List, Optional, Set import abc +import email.encoders import email.mime.base import email.mime.application import email.mime.multipart @@ -42,6 +43,7 @@ class Message(abc.ABC): try: self._mime = self._encrypt_message(content) except Exception: + logging.exception('Encryption failed; falling back to unencrypted message') self._mime = email.mime.text.MIMEText(content, _subtype='plain', _charset='utf-8') # Set all the email headers self._mime['From'] = self._from @@ -69,15 +71,21 @@ class Message(abc.ABC): del sessionkey # Build the MIME message # First the small "version" part ... - mp1 = email.mime.application.MIMEApplication('Version: 1', _subtype='pgp-encrypted') + mp1 = email.mime.application.MIMEApplication('Version: 1', + _subtype='pgp-encrypted', + _encoder=email.encoders.encode_noop) mp1['Content-Description'] = 'PGP/MIME version identification' mp1['Content-Disposition'] = 'attachment' # ... then the actual encrypted payload ... - mp2 = email.mime.application.MIMEApplication(str(pgp), _subtype='octet-stream', name='encrypted.asc') + mp2 = email.mime.application.MIMEApplication(str(pgp), + _subtype='octet-stream', + _encoder=email.encoders.encode_noop, + name='encrypted.asc') mp2['Content-Description'] = 'OpenPGP encrypted message' mp2['Content-Disposition'] = 'inline; filename="message.asc"' # ... and finally the root multipart container - mp0 = email.mime.multipart.MIMEMultipart(_subtype='encrypted', protocol='application/pgp-encrypted') + mp0 = email.mime.multipart.MIMEMultipart(_subtype='encrypted', + protocol='application/pgp-encrypted') mp0.attach(mp1) mp0.attach(mp2) return mp0