sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 8afdb020c0e44d7625d32c9c6f0e2d44a7ceea49
parent 9908a6b96d8b5bfacf0e819734675f6bd23161bc
Author: Hamish Downer <dmishd@gmail.com>
Date:   Tue, 16 Nov 2010 20:58:01 +0000

improved signature messages

Diffstat:
M lib/sup/crypto.rb | 31 ++++++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
@@ -242,8 +242,7 @@ private
 
   # remove the hex key_id and info in ()
   def simplify_sig_line sig_line
-    sig_line = sig_line.sub(/from [0-9A-F]{16} /, "from ")
-    sig_line.sub(/\(.+\) </, "<")
+    sig_line.sub(/from [0-9A-F]{16} /, "from ")
   end
 
   def sig_output_lines signature
@@ -253,21 +252,43 @@ private
     begin
       from_key = ctx.get_key(signature.fingerprint)
       first_sig = signature.to_s.sub(/from [0-9A-F]{16} /, 'from "') + '"'
-    rescue EOFError => error
+    rescue EOFError 
+      from_key = nil
       first_sig = "No public key available for #{signature.fingerprint}"
     end
 
     time_line = "Signature made " + signature.timestamp.strftime("%a %d %b %Y %H:%M:%S %Z") +
-                " using key ID " + signature.fingerprint[-8..-1]
+                " using " + key_type(from_key, signature.fingerprint) + 
+                "key ID " + signature.fingerprint[-8..-1]
     output_lines = [time_line, first_sig]
 
     if from_key 
+      # first list all the uids
       if from_key.uids.length > 1
         aka_list = from_key.uids[1..-1]
         aka_list.each { |aka| output_lines << '                aka "' + aka.uid + '"' }
       end
+
+      # now we want to look at the trust of that key
+      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"
+      end
+    end
+    output_lines
+  end
+
+  def key_type key, fpr
+    return "" if key.nil?
+    subkey = key.subkeys.find {|subkey| subkey.fpr == fpr || subkey.keyid == fpr }
+    return "" if subkey.nil?
+
+    case subkey.pubkey_algo
+    when GPGME::PK_RSA then "RSA "
+    when GPGME::PK_DSA then "DSA "
+    when GPGME::PK_ELG then "ElGamel "
+    when GPGME::PK_ELG_E then "ElGamel "
     end
-    output_lines.flatten!
   end
 
   # logic is: