# HG changeset patch # User Paul Boddie # Date 1388187811 -3600 # Node ID 9627f2e2d8741602ca8a23f1fbed3fa7cd1bd9e9 # Parent 4dcd98fcd994c547f968c27b5ee03e2f62993512 Attempt to employ a representation-insensitive payload for signed content. diff -r 4dcd98fcd994 -r 9627f2e2d874 MoinMessage.py --- a/MoinMessage.py Thu Dec 26 18:26:25 2013 +0100 +++ b/MoinMessage.py Sat Dec 28 00:43:31 2013 +0100 @@ -11,6 +11,7 @@ from email.mime.multipart import MIMEMultipart from email.mime.application import MIMEApplication from email.mime.base import MIMEBase +from email.parser import Parser from email.utils import formatdate, parsedate from subprocess import Popen, PIPE from tempfile import mkstemp @@ -278,7 +279,10 @@ # Verify the message. fingerprint, identity = self.verifyMessageText(signature.get_payload(), content.as_string()) - return fingerprint, identity, content + + # Extract the actual content inside the signed message. + + return fingerprint, identity, Parser().parsestr(content.get_payload(decode=True)) def signMessage(self, message, keyid): @@ -286,13 +290,19 @@ Return a signed version of 'message' using the given 'keyid'. """ + # Make a representation-insensitive container for the message. + text = message.as_string() - signature = self.run(["--armor", "-u", keyid, "--detach-sig"], text) + content = MIMEApplication(text) + + # Sign the container's representation. + + signature = self.run(["--armor", "-u", keyid, "--detach-sig"], content.as_string()) # Make the container for the message. signed_message = MIMEMultipart("signed", protocol="application/pgp-signature") - signed_message.attach(message) + signed_message.attach(content) signature_part = MIMEBase("application", "pgp-signature") signature_part.set_payload(signature)