changeset 112133:0057170b4509

gnus/mml2015.el: Fix secret key validity check (Bug#7797). * mml2015.el (epg-sub-key-fingerprint): Autoload. (mml2015-epg-find-usable-secret-key): New function. (mml2015-epg-sign): Use mml2015-epg-find-usable-secret-key instead of mml2015-epg-find-usable-key (Bug#7797). (mml2015-epg-encrypt): Ditto.
author Daiki Ueno <ueno@unixuser.org>
date Fri, 07 Jan 2011 18:28:29 +0900
parents 4ef5cb86f2e8
children 4c86fe2e7016
files lisp/gnus/ChangeLog lisp/gnus/mml2015.el
diffstat 2 files changed, 33 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/gnus/ChangeLog	Thu Jan 06 19:10:39 2011 -0800
+++ b/lisp/gnus/ChangeLog	Fri Jan 07 18:28:29 2011 +0900
@@ -1,3 +1,11 @@
+2011-01-07  Daiki Ueno  <ueno@unixuser.org>
+
+	* mml2015.el (epg-sub-key-fingerprint): Autoload.
+	(mml2015-epg-find-usable-secret-key): New function.
+	(mml2015-epg-sign): Use mml2015-epg-find-usable-secret-key instead of
+	mml2015-epg-find-usable-key (Bug#7797).
+	(mml2015-epg-encrypt): Ditto.
+
 2011-01-03  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
 	* flow-fill.el (fill-flowed-encode): Do encoding citation-aware.
--- a/lisp/gnus/mml2015.el	Thu Jan 06 19:10:39 2011 -0800
+++ b/lisp/gnus/mml2015.el	Fri Jan 07 18:28:29 2011 +0900
@@ -742,6 +742,7 @@
 (autoload 'epg-key-sub-key-list "epg")
 (autoload 'epg-sub-key-capability "epg")
 (autoload 'epg-sub-key-validity "epg")
+(autoload 'epg-sub-key-fingerprint "epg")
 (autoload 'epg-configuration "epg-config")
 (autoload 'epg-expand-group "epg-config")
 (autoload 'epa-select-keys "epa")
@@ -784,6 +785,24 @@
 	  (setq pointer (cdr pointer))))
       (setq keys (cdr keys)))))
 
+;; XXX: since gpg --list-secret-keys does not return validity of each
+;; key, `mml2015-epg-find-usable-key' defined above is not enough for
+;; secret keys.  The function `mml2015-epg-find-usable-secret-key'
+;; below looks at appropriate public keys to check usability.
+(defun mml2015-epg-find-usable-secret-key (context name usage)
+  (let ((secret-keys (epg-list-keys context name t))
+	secret-key)
+    (while (and (not secret-key) secret-keys)
+      (if (mml2015-epg-find-usable-key
+	   (epg-list-keys context (epg-sub-key-fingerprint
+				   (car (epg-key-sub-key-list
+					 (car secret-keys)))))
+	   usage)
+	  (setq secret-key (car secret-keys)
+		secret-keys nil)
+	(setq secret-keys (cdr secret-keys))))
+    secret-key))
+
 (defun mml2015-epg-decrypt (handle ctl)
   (catch 'error
     (let ((inhibit-redisplay t)
@@ -960,9 +979,9 @@
 		     (delq nil
 			   (mapcar
 			    (lambda (signer)
-			      (setq signer-key (mml2015-epg-find-usable-key
-						(epg-list-keys context signer t)
-						'sign))
+			      (setq signer-key
+				    (mml2015-epg-find-usable-secret-key
+				     context signer 'sign))
 			      (unless (or signer-key
 					  (y-or-n-p
 					   (format
@@ -1081,9 +1100,9 @@
 		       (delq nil
 			     (mapcar
 			      (lambda (signer)
-				(setq signer-key (mml2015-epg-find-usable-key
-						  (epg-list-keys context signer t)
-						  'sign))
+				(setq signer-key
+				      (mml2015-epg-find-usable-secret-key
+				       context signer 'sign))
 				(unless (or signer-key
 					    (y-or-n-p
 					     (format