Subject: bug#5592: gnus mml2015 epg: Trying and failing to encrypt email to disabled pgp-key

From: Christian von Roques <[email-masked]>
Date: Wed, 17 Feb 2010 16:41:00 -0400

Package: emacs,gnus
Version: 23.1.1
Severity: minor
Tags: patch

"GNU Emacs 23.1.1 (i486-pc-linux-gnu, GTK+ Version 2.12.12) of
2009-10-19 on debian-build.int-office-er.priv, modified by Debian"

When trying to send a pgp-encrypted email to a friend, using gnus,
mml2015, and epg, sending the email fails with the error message:
"Encrypt failed: exit"

My friend has two pgp-keys, of which the first has been disabled from
within "gpg --edit-key [email-masked]".  mml2015 picks this disabled
key, tries to encrypt to it and fails.

I expected mml2015 to choose the second, not disabled, key.

The patch below (relative to revno 99512 of emacs/trunk) adds 'disabled'
to epg-key-capability-alist for disabled keys and uses it in
mml2015-epg-find-usable-key to skip disabled keys.

Note: epg already tries to determine which key is disabled using the 'd'
flag in field 2 of lines from the output of "gpg --list-keys
--with-colons".  But this is not used by mml2015, does not work with
version 1.4.9 of gnupg and according to doc/DETAILS of gnupg-1.4.9 the
'd' flag in field 2 is deprecated and the 'D' in field 12 should be used
instead, which is exactly what my patch is doing.  My changes should be
safe with older versions of gnupg because they just don't put 'D' in
field 12.

	Christian.

=== modified file 'lisp/epg.el'
--- old/lisp/epg.el	2010-01-13 08:35:10 +0000
+++ new/lisp/epg.el	2010-02-17 19:18:09 +0000
@@ -136,9 +136,10 @@
 (defvar epg-key-capablity-alist
   '((?e . encrypt)
     (?s . sign)
     (?c . certify)
-    (?a . authentication)))
+    (?a . authentication)
+    (?D . disabled)))
 
 (defvar epg-new-signature-type-alist
   '((?D . detached)
     (?C . clear)

=== modified file 'lisp/gnus/mml2015.el'
--- old/lisp/gnus/mml2015.el	2010-01-13 08:35:10 +0000
+++ new/lisp/gnus/mml2015.el	2010-02-17 19:18:09 +0000
@@ -1018,8 +1018,9 @@
     (while keys
       (let ((pointer (epg-key-sub-key-list (car keys))))
 	(while pointer
 	  (if (and (memq usage (epg-sub-key-capability (car pointer)))
+		   (not (memq 'disabled (epg-sub-key-capability (car pointer))))
 		   (not (memq (epg-sub-key-validity (car pointer))
 			      '(revoked expired))))
 	      (throw 'found (car keys)))
 	  (setq pointer (cdr pointer))))