Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
* [sup-talk] [PATCH] more inline GPG madness
@ 2009-09-30 22:08 Michael Stapelberg
  2009-10-01 17:27 ` Michael Stapelberg
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Stapelberg @ 2009-09-30 22:08 UTC (permalink / raw)


Hi,

browsing some older emails, I noticed that the inline GPG patch I sent earlier
was not completely correct. It only handled messages which were encrypted *and*
signed, but not messages which were signed only.

Attached comes a patch which fixes the behaviour. However (!) the patch is not
well aligned, the error case (else) is untested and should probably be handled
differently and the old_charset line can probably be written more elegantly in
ruby. By the way, the charset stuff is necessary to get the correct character
set for messages which are sent inline. I really start to dislike Thunderbird
and other crappy software for that :-\.

So, please, clean up the patch and merge it. I have also attached a message
which was sent using thunderbird and contains inline crypto. If the patch works
correctly, you should be able to open it and see some umlauts.

Best regards,
Michael
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: sign.txt
URL: <http://rubyforge.org/pipermail/sup-talk/attachments/20091001/f9f6851c/attachment.txt>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: inline-gpg.patch
Type: application/octet-stream
Size: 1394 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/sup-talk/attachments/20091001/f9f6851c/attachment.obj>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [sup-talk] [PATCH] more inline GPG madness
  2009-09-30 22:08 [sup-talk] [PATCH] more inline GPG madness Michael Stapelberg
@ 2009-10-01 17:27 ` Michael Stapelberg
  2009-10-12 13:54   ` William Morgan
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Stapelberg @ 2009-10-01 17:27 UTC (permalink / raw)


Hi,

Excerpts from Michael Stapelberg's message of Do Okt 01 00:08:39 +0200 2009:
> Attached comes a patch which fixes the behaviour. However (!) the patch is not
> well aligned, the error case (else) is untested and should probably be handled
> differently and the old_charset line can probably be written more elegantly in
> ruby. By the way, the charset stuff is necessary to get the correct character
> set for messages which are sent inline. I really start to dislike Thunderbird
> and other crappy software for that :-\.

I am sorry for the confusion. Please do not merge this patch without close
review if these PGP headers are valid at all. Turns out the headers were
produced by a custom procmail rule I had forgotton about.

I will instead implement support for "correct" inline GPG.

Best regards,
Michael


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [sup-talk] [PATCH] more inline GPG madness
  2009-10-01 17:27 ` Michael Stapelberg
@ 2009-10-12 13:54   ` William Morgan
  2009-10-17 22:32     ` Michael Stapelberg
  0 siblings, 1 reply; 4+ messages in thread
From: William Morgan @ 2009-10-12 13:54 UTC (permalink / raw)
  To: sup-talk

Reformatted excerpts from Michael Stapelberg's message of 2009-10-01:
> I will instead implement support for "correct" inline GPG.

I've reworked this code a bit in recent commits, so make sure you have
an up-to-date copy.
-- 
William <wmorgan-sup@masanjin.net>
_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [sup-talk] [PATCH] more inline GPG madness
  2009-10-12 13:54   ` William Morgan
@ 2009-10-17 22:32     ` Michael Stapelberg
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Stapelberg @ 2009-10-17 22:32 UTC (permalink / raw)
  To: sup-talk

[-- Attachment #1: Type: text/plain, Size: 291 bytes --]

Hi,

Excerpts from William Morgan's message of Mo Okt 12 15:54:06 +0200 2009:
> Reformatted excerpts from Michael Stapelberg's message of 2009-10-01:
> > I will instead implement support for "correct" inline GPG.
See the attached patch. Please consider merging it :).

Best regards,
Michael

[-- Attachment #2: 0001-Implement-inline-GPG.patch --]
[-- Type: application/octet-stream, Size: 5354 bytes --]

From c981c69ebb163a88bef9dabb7fcf9db7c569f005 Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael@stapelberg.de>
Date: Sun, 18 Oct 2009 00:14:37 +0200
Subject: [PATCH] Implement inline GPG
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

The SIG_PATTERN had to be changed because GPG, when clearsigning (which
is what happens when you send inline GPG messages), kind of escapes
lines beginning with dashes (so that the -----BEGIN PGP MESSAGE-----
lines don’t get messed up). Therefore, signatures, starting with "-- "
will be escaped as "- -- ". The manpage of GPG states that the process
of clearsigning is not reversible. Thus, there is no method in GPG to
get the original message.
---
 lib/sup/crypto.rb  |   31 +++++++++++++++++++++----------
 lib/sup/message.rb |   31 ++++++++++++++++++++++++++++++-
 2 files changed, 51 insertions(+), 11 deletions(-)

diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index 64429a3..a410760 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -78,18 +78,24 @@ class CryptoManager
     encrypt from, to, payload, true
   end
 
-  def verify payload, signature # both RubyMail::Message objects
+  def verify payload, signature, detached=true # both RubyMail::Message objects
     return unknown_status(cant_find_binary) unless @cmd
 
-    payload_fn = Tempfile.new "redwood.payload"
-    payload_fn.write format_payload(payload)
-    payload_fn.close
+    if detached
+      payload_fn = Tempfile.new "redwood.payload"
+      payload_fn.write format_payload(payload)
+      payload_fn.close
+    end
 
     signature_fn = Tempfile.new "redwood.signature"
     signature_fn.write signature.decode
     signature_fn.close
 
-    output = run_gpg "--verify #{signature_fn.path} #{payload_fn.path}"
+    if detached
+      output = run_gpg "--verify #{signature_fn.path} #{payload_fn.path}"
+    else
+      output = run_gpg "--verify #{signature_fn.path}"
+    end
     output_lines = output.split(/\n/)
 
     if output =~ /^gpg: (.* signature from .*$)/
@@ -104,7 +110,7 @@ class CryptoManager
   end
 
   ## returns decrypted_message, status, desc, lines
-  def decrypt payload # a RubyMail::Message object
+  def decrypt payload, armor=false # a RubyMail::Message object
     return unknown_status(cant_find_binary) unless @cmd
 
     payload_fn = Tempfile.new "redwood.payload"
@@ -141,10 +147,15 @@ class CryptoManager
       # required. This causes for the part not to be detected as multipart,
       # hence being shown as an attachment. If we detect this is happening,
       # we force the decrypted payload to be interpreted as MIME.
-      msg = RMail::Parser.read(decrypted_payload)
-      if msg.header.content_type =~ %r{^multipart/} and not msg.multipart?
-        decrypted_payload = "MIME-Version: 1.0\n" + decrypted_payload
-        msg = RMail::Parser.read(decrypted_payload)
+      if !armor
+	msg = RMail::Parser.read(decrypted_payload)
+	if msg.header.content_type =~ %r{^multipart/} and not msg.multipart?
+	  decrypted_payload = "MIME-Version: 1.0\n" + decrypted_payload
+	  msg = RMail::Parser.read(decrypted_payload)
+	end
+      else
+        msg = RMail::Message.new
+        msg.body = decrypted_payload
       end
       notice = Chunk::CryptoNotice.new :valid, "This message has been decrypted for display"
       [notice, sig, msg]
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index a147c42..1d0a2c4 100644
--- a/lib/sup/message.rb
+++ b/lib/sup/message.rb
@@ -26,7 +26,7 @@ class Message
 
   QUOTE_PATTERN = /^\s{0,4}[>|\}]/
   BLOCK_QUOTE_PATTERN = /^-----\s*Original Message\s*----+$/
-  SIG_PATTERN = /(^-- ?$)|(^\s*----------+\s*$)|(^\s*_________+\s*$)|(^\s*--~--~-)|(^\s*--\+\+\*\*==)/
+  SIG_PATTERN = /(^(- )*-- ?$)|(^\s*----------+\s*$)|(^\s*_________+\s*$)|(^\s*--~--~-)|(^\s*--\+\+\*\*==)/
 
   MAX_SIG_DISTANCE = 15 # lines from the end
   DEFAULT_SUBJECT = ""
@@ -508,6 +508,35 @@ private
         ## this ensures that the body is normalized to avoid non-displayable
         ## characters
         body = Iconv.easy_decode($encoding, m.charset || $encoding, m.decode) if m.body
+	lines = body.split("\n")
+
+	## Check for inline-PGP
+	if body =~ /-----BEGIN PGP SIGNED MESSAGE-----/
+	  sign_start = lines.index("-----BEGIN PGP SIGNED MESSAGE-----")
+	  sign_end = lines.index("-----END PGP SIGNED MESSAGE-----") || lines.count
+	  msg = RMail::Message.new
+	  msg.body = lines[sign_start, sign_end+1].join("\n")
+
+	  sign_end = lines.index("-----BEGIN PGP SIGNATURE-----") || sign_end
+	  payload = RMail::Message.new
+	  payload.body = lines[sign_start+1, sign_end-1].join("\n")
+	  return [CryptoManager.verify(nil, msg, false), message_to_chunks(payload)].flatten.compact
+	end
+
+	if body =~ /-----BEGIN PGP MESSAGE-----/
+	  signstart = lines.index("-----BEGIN PGP MESSAGE-----")
+	  signend = lines.index("-----END PGP MESSAGE-----") || lines.count
+	  msg = RMail::Message.new
+	  msg.body = lines[signstart, signend+1].join("\n")
+	  notice, sig, decryptedm = CryptoManager.decrypt msg, true
+	  if decryptedm # managed to decrypt
+	    children = message_to_chunks(decryptedm, true)
+	    return [notice, sig].compact + children
+	  else
+	    return [notice]
+	  end
+	end
+
         text_to_chunks((body || "").normalize_whitespace.split("\n"), encrypted)
       end
     end
-- 
1.6.3.3


[-- Attachment #3: Type: text/plain, Size: 140 bytes --]

_______________________________________________
sup-talk mailing list
sup-talk@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-talk

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-10-17 22:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-30 22:08 [sup-talk] [PATCH] more inline GPG madness Michael Stapelberg
2009-10-01 17:27 ` Michael Stapelberg
2009-10-12 13:54   ` William Morgan
2009-10-17 22:32     ` Michael Stapelberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox