[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sup-devel] more gpgme fixes



I've pushed a couple more patches to the gpgme branch and to next. 

One fixes the issue where sup would send a message you wanted signed 
or encrypted without signing or encrypting it when the key (or 
gpg-agent) is not available. For some reason GPGME doesn't complain
but just returns an empty string. The patch checks for this case and
complains.

The other one shows the full fingerprint of keys used to sign messages 
if the key is not trusted.

Hamish Downer



commit ac321bd89a72dba74e9b2ff182be0b5fc89a61fc
Author: Hamish Downer <dmishd@gmail.com>
Date:   Sun Jan 30 23:37:45 2011 +0000

    Catch case where gpg-agent not running or key not available

    GPGME does not raise an Error when the key is not available (say
    gpg-agent is not running, or the key is on removable media and has
    been removed). In these cases GPGME returns a zero length string.
    This patch checks the returned string and raises an error if it has
    zero length.

diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index 5f1b730..6f6797b 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -68,6 +68,13 @@ EOS
       raise Error, "GPG command failed. See log for details."
     end
 
+    # if the key (or gpg-agent) is not available GPGME does not complain 
+    # but just returns a zero length string. Let's catch that
+    if sig.length == 0
+      info "GPG failed to generate signature: check that gpg-agent is running and your key is available."
+      raise Error, "GPG command failed. See log for details."
+    end
+
     envelope = RMail::Message.new
     envelope.header["Content-Type"] = 'multipart/signed; protocol=application/pgp-signature'
 
@@ -96,6 +103,13 @@ EOS
       raise Error, "GPG command failed. See log for details."
     end
 
+    # if the key (or gpg-agent) is not available GPGME does not complain 
+    # but just returns a zero length string. Let's catch that
+    if cipher.length == 0
+      info "GPG failed to generate cipher text: check that gpg-agent is running and your key is available."
+      raise Error, "GPG command failed. See log for details."
+    end
+
     encrypted_payload = RMail::Message.new
     encrypted_payload.header["Content-Type"] = "application/octet-stream"
     encrypted_payload.header["Content-Disposition"] = 'inline; filename="msg.asc"'






commit 9b1721cce09fc18bd9975d9b24918c8c314aaabe
Author: Hamish Downer <dmishd@gmail.com>
Date:   Sun Jan 30 23:43:14 2011 +0000

    Add full fingerprint for untrusted keys
    
    When the key that signed a message is not trusted, show the full
    fingerprint, as the gpg binary does.

diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
index 6f6797b..5a38f27 100644
--- a/lib/sup/crypto.rb
+++ b/lib/sup/crypto.rb
@@ -307,6 +307,7 @@ private
       if signature.validity != GPGME::GPGME_VALIDITY_FULL && signature.validity != GPGME::GPGME_VALIDITY_MARGINAL
         output_lines << "WARNING: This key is not certified with a trusted signature!"
         output_lines << "There is no indication that the signature belongs to the owner"
+        output_lines << "Full fingerprint is: " + (0..9).map {|i| signature.fpr[(i*2),2]}.join(":")
       else
         trusted = true
       end
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel