Subject: [sup-talk] Bug: Messages using inline GPG are not decrypted

From: [email-masked] (Michael Stapelberg)
Date: Tue, 22 Sep 2009 19:05:48 +0200

Hi,

I noticed that emails sent by Thunderbird which contain inline GPG messages
are not decrypted at all. I?ve attached such a message so you can verify
it. Unfortunately my ruby skills did not suffice to fix this on my own.

Thanks and best regards,
Michael
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: crypted.txt
URL: <http://rubyforge.org/pipermail/sup-talk/attachments/20090922/628024f2/attachment.txt>

---

From: [email-masked] (Michael Stapelberg)
Date: Tue, 22 Sep 2009 19:24:24 +0200

Hi,

> it. Unfortunately my ruby skills did not suffice to fix this on my own.
Addition: Probably I was able to fix it, but the other bug I reported about
not being able to open GPG encrypted email at all was the one I was seeing.
So, fix should be easy (untested, because of the other bug):

--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -436,6 +436,16 @@ private
       end
 
       chunks
+    elsif m.header.content_type == "application/pgp"
+     notice, sig, decryptedm = CryptoManager.decrypt m.body
+     if decryptedm # managed to decrypt
+       children = message_to_chunks(decryptedm, true)
+       chunks = [notice, sig, children]
+     else
+       chunks = [notice]
+     end
+
+     chunks
     elsif m.header.content_type == "message/rfc822"
       if m.body
         payload = RMail::Parser.read(m.body)

Best regards,
Michael

---

From: [email-masked] (Michael Stapelberg)
Date: Fri, 25 Sep 2009 21:10:11 +0200

Hi,

after fixing the other bug related to GPG messages, this patch has to be
modified, too:

--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
 
       chunks
+       chunks = [notice, sig, children].flatten.compact

Best regards,
Michael

---

From: [email-masked] (William Morgan)
Date: Sat, 26 Sep 2009 11:09:36 -0700

> after fixing the other bug related to GPG messages, this patch has to be

I believe I've fixed this in git. Thunderbird is not producing
RFC3156-compliant encrypted emails, but by the Postel's Law we will
accomodate their errors. Let me know if it doesn't work.
-- 
William <wmorgan-sup at masanjin.net>

---

From: [email-masked] (Michael Stapelberg)
Date: Sat, 26 Sep 2009 22:28:54 +0200

Hi,

> accomodate their errors. Let me know if it doesn't work.
The changes basically work. The message itself is opened and decrypted
correctly. However, when handling some messages, an exception occurs
(downcase called on NilClass), which can be fixed like this:

--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -436,7 +436,7 @@ private
       end
 
       chunks
-    elsif m.header.content_type.downcase == "message/rfc822"
+    elsif m.header.content_type && m.header.content_type.downcase == "message/rfc822"
       if m.body
         payload = RMail::Parser.read(m.body)
         from = payload.header.from.first ? payload.header.from.first.format : ""
@@ -456,7 +456,7 @@ private
         debug "no body for message/rfc822 enclosure; skipping"
         []
       end
-    elsif m.header.content_type.downcase == "application/pgp" && m.body
+    elsif m.header.content_type && m.header.content_type.downcase == "application/pgp" && m.body
       ## apparently some versions of Thunderbird generate encryped email that
       ## does not follow RFC3156, e.g. messages with X-Enigmail-Version: 0.95.0
       ## they have no MIME multipart and just set the body content type to

Best regards,
Michael

---

From: [email-masked] (Ben Walton)
Date: Sat, 26 Sep 2009 17:37:53 -0400

> (downcase called on NilClass), which can be fixed like this:

+1 for this patch.  I need it after updating too.

-Ben
-- 
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302

GPG Key Id: 8E89F6D2; Key Server: pgp.mit.edu
Contact me to arrange for a CAcert assurance meeting.

---

From: [email-masked] (Michael Stapelberg)
Date: Sat, 26 Sep 2009 23:41:58 +0200

Hi,

> (downcase called on NilClass), which can be fixed like this:
I noticed that this is not the only place where this was wrong. Complete
patch attached (also fixes mixups like control.header.downcase.content_type
vs. control.header.content_type.downcase).

Best regards,
Michael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sup-downcase.patch
Type: application/octet-stream
Size: 2375 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/sup-talk/attachments/20090926/da544580/attachment.obj>

---

From: [email-masked] (William Morgan)
Date: Sat, 26 Sep 2009 18:40:06 -0700

> vs. control.header.content_type.downcase).

Applied, thanks. BTW it will be slightly easier on me if you commit
changes and use git format-patch to send them (or git send-email). That
will also put your name in the automatically-generated contributors
list.
-- 
William <wmorgan-sup at masanjin.net>