Re: template questions -- hashcash and gpg ?

Corey Halpin <[email protected]>
Newsgroups gmane.mail.spam.tmda.user
Message-ID <[email protected]>
On 2008-01-24, Corey Halpin wrote:
>   The documentation reading that I've done leads me to suspect that what I'm 
> asking is not (currently) possible.  If this is in fact true, I'd appreciate 
> some pointers as to where in the tmda code I'll need to start hacking.
 
  Attached is a (mostly working) patch to optionally gpg-sign autoreplies 
generated by TMDA.

  I've followed the 'passwordless signing subkeys' instructions from:
  http://fortytwo.ch/gpg/subkeys

  I'm following (or rather, attempting to follow) RFC 3156 with respect to the 
signature format: http://www.faqs.org/rfcs/rfc3156.html
  It's proving more difficult than I thought.
  The signatures I generate are invalid.  I think this is due to white-space 
differences in how the payload of my text/plain part is encoded in the message 
vs what I get back from body_text.as_string().
  If anyone has suggestions as to how this should be worked around, I'm all 
ears.

  Once I figure out how to make this actually work, I'll write up a page on 
the wiki.

  Thanks for any help.

~crh
patch-gpg_signed_autoreply (text/plain, 2.7 KB)
Index: tmda-1.1.12/TMDA/AutoResponse.py
===================================================================
--- tmda-1.1.12.orig/TMDA/AutoResponse.py	2008-01-24 23:46:03.166814000 -0600
+++ tmda-1.1.12/TMDA/AutoResponse.py	2008-01-25 10:34:38.000000000 -0600
@@ -23,12 +23,14 @@
 
 
 from email import message_from_string
+from email import encoders
 from email.charset import add_alias
 from email.errors import MessageError
 from email.header import Header, decode_header
 from email.mime.message import MIMEMessage
 from email.mime.multipart import MIMEMultipart
 from email.mime.text import MIMEText
+from email.mime.application import MIMEApplication
 from email.utils import formataddr, parseaddr
 
 import os
@@ -121,8 +123,7 @@
         for h in bad_headers:
             if self.bouncemsg.has_key(h):
                 del self.bouncemsg[h]
-        textpart = MIMEText(self.bouncemsg.get_payload(), 'plain',
-                            self.bodycharset)
+        textpart = self.create_text();
         bodyparts = 1 + Defaults.AUTORESPONSE_INCLUDE_SENDER_COPY
         if bodyparts == 1:
             # A single text/plain entity.
@@ -242,3 +243,25 @@
                                response_filename), 'w')
         fp.close()
 
+    def create_text(self):
+        """
+        Create the body part of the MIME entity for the auto reply.
+        """
+        rc = None
+        if Defaults.USE_GPG_SIGNATURES:
+            rc=MIMEMultipart('signed', micalg='pgp-sha1',
+                              protocol='application/pgp-signature')
+            body_text = MIMEText(self.bouncemsg.get_payload(),'plain',
+                                 self.bodycharset)
+            (gpg_in, gpg_out)=os.popen2('gpg -a -b')
+            gpg_in.write(body_text.as_string()); gpg_in.close()
+            signature = gpg_out.read();         gpg_out.close()
+            body_signature = MIMEApplication(signature, 'pgp-signature',
+                             encoders.encode_noop )
+            rc.attach(body_text);
+            rc.attach(body_signature);
+        else:
+            rc = MIMEText(self.bouncemsg.get_payload(), 'plain',
+                          self.bodycharset)
+        return rc
+
Index: tmda-1.1.12/TMDA/Defaults.py
===================================================================
--- tmda-1.1.12.orig/TMDA/Defaults.py	2008-01-24 23:57:06.000000000 -0600
+++ tmda-1.1.12/TMDA/Defaults.py	2008-01-24 23:57:31.000000000 -0600
@@ -1571,6 +1571,9 @@
 if not vars().has_key('CRYPT_KEY_FILE'):
     CRYPT_KEY_FILE = os.path.join(DATADIR, 'crypt_key')
 
+if not vars().has_key('USE_GPG_SIGNATURES'):
+    USE_GPG_SIGNATURES = False
+
 ###################################
 # END of user configurable settings
 ###################################
signature.asc (application/pgp-signature, 187 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4 (FreeBSD)

iD8DBQFHmhGEQ/a2GD73knsRAgNKAKDDkMAeGEX+rcjK9AUyz3y9cnAlqgCfXWUr
VX0m4RKQsJpR++CsovraaQI=
=oao+
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.