From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/82897 Path: news.gmane.org!not-for-mail From: Daiki Ueno Newsgroups: gmane.emacs.gnus.general Subject: Re: [BUG] mml2015-epg-find-usable-key finds unusable key Date: Fri, 15 Feb 2013 13:05:11 +0900 Message-ID: References: <87fw106la1.fsf%stlman@poczta.fm> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-2022-jp-2 X-Trace: ger.gmane.org 1360901190 19958 80.91.229.3 (15 Feb 2013 04:06:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 15 Feb 2013 04:06:30 +0000 (UTC) Cc: ding@gnus.org To: =?iso-2022-jp-2?B?GyQoRCkoGyhCdWthc3o=?= Stelmach Original-X-From: ding-owner+M31163@lists.math.uh.edu Fri Feb 15 05:06:49 2013 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1U6CZU-0007Dg-AO for ding-account@gmane.org; Fri, 15 Feb 2013 05:06:48 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1U6CYB-0007xM-2v; Thu, 14 Feb 2013 22:05:27 -0600 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1U6CY8-0007x9-7U for ding@lists.math.uh.edu; Thu, 14 Feb 2013 22:05:24 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1U6CY3-00043W-N4 for ding@lists.math.uh.edu; Thu, 14 Feb 2013 22:05:24 -0600 Original-Received: from fencepost.gnu.org ([208.118.235.10] ident=Debian-exim) by quimby.gnus.org with esmtp (Exim 4.72) (envelope-from ) id 1U6CY1-0002RQ-Tv for ding@gnus.org; Fri, 15 Feb 2013 05:05:18 +0100 Original-Received: from [2001:e41:db5e:fb14::1] (port=43519 helo=localhost.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1U6CXz-0006Dh-N6; Thu, 14 Feb 2013 23:05:16 -0500 In-Reply-To: <87fw106la1.fsf%stlman@poczta.fm> (=?iso-2022-jp-2?B?Ig==?= =?iso-2022-jp-2?B?GyQoRCkoGyhCdWthc3o=?= Stelmach"'s message of "Wed, 13 Feb 2013 20:55:50 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-Spam-Score: -7.9 (-------) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:82897 Archived-At: $(D)((Bukasz Stelmach writes: > It looks like there is a sort of bug in mml2015-epg-encrypt at line > 1117. > > http://git.gnus.org/cgit/gnus.git/tree/lisp/mml2015.el?id=6e422932976e94d6dbb7ad602c5be3eb481fe46c#n1117) > > The whole form that begins at line 1113 converts list of recipients > provided as email addresses, key IDs or anything gpg can digest into epg > "objects". Unfortunately there is one corner case that makes this code > fail. That is when a key is valid but a uid on it has been revoked. Thanks for the report. > epg.el is a part of emacs, mml2015.el belongs to gnus. IMHO it is > mml2015-epg-find-usable-key that should be fixed. The function should > accept and additional (optional?) parameter with a recipient uid as > passed to epg-list-keys and reject keys with all uids matching the > recipient parameter revoked. Sounds reasonable. I plan to apply the attached patch. Regards, -- Daiki Ueno >From 9440de44c8dc03a5b77e662539d3d388f6718549 Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Fri, 15 Feb 2013 12:58:09 +0900 Subject: [PATCH] mml2015.el (mml2015-epg-find-usable-key): handle revoked user-id --- lisp/ChangeLog | 9 +++++++++ lisp/mml2015.el | 57 +++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5edf6f6..3fda767 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2013-02-15 Daiki Ueno + + * mml2015.el (mml2015-epg-check-user-id): New function. + (mml2015-epg-check-sub-key): New function split from + mml2015-epg-find-usable-key. + (mml2015-epg-find-usable-key): Accept context, recipient, and usage, to + handle the case when user-id is unusable (all callers changed). + Reported by $(D)((Bukasz Stelmach . + 2013-02-14 Katsumi Yamaoka * gnus-util.el (gnus-define-keys): Convert [?\S-\ ] to [(shift space)] diff --git a/lisp/mml2015.el b/lisp/mml2015.el index 275a486..6310ff3 100644 --- a/lisp/mml2015.el +++ b/lisp/mml2015.el @@ -786,21 +786,47 @@ If set, it overrides the setting of `mml2015-sign-with-sender'." (cons password-cache-key-id mml2015-epg-secret-key-id-list)) (copy-sequence passphrase))))) -(defun mml2015-epg-find-usable-key (keys usage) - (catch 'found +(defun mml2015-epg-check-user-id (key recipient) + (let ((pointer (epg-key-user-id-list key)) + result) + (while pointer + (if (and (equal (car (mail-header-parse-address + (epg-user-id-string (car pointer)))) + (car (mail-header-parse-address + recipient))) + (not (memq (epg-user-id-validity (car pointer)) + '(revoked expired)))) + (setq result t + pointer nil) + (setq pointer (cdr pointer)))) + result)) + +(defun mml2015-epg-check-sub-key (key usage) + (let ((pointer (epg-key-sub-key-list key)) + result) + ;; The primary key will be marked as disabled, when the entire + ;; key is disabled (see 12 Field, Format of colon listings, in + ;; gnupg/doc/DETAILS) + (unless (memq 'disabled (epg-sub-key-capability (car pointer))) + (while pointer + (if (and (memq usage (epg-sub-key-capability (car pointer))) + (not (memq (epg-sub-key-validity (car pointer)) + '(revoked expired)))) + (setq result t + pointer nil) + (setq pointer (cdr pointer))))) + result)) + +(defun mml2015-epg-find-usable-key (context recipient usage) + (let ((keys (epg-list-keys context recipient)) + key) (while keys - (let ((pointer (epg-key-sub-key-list (car keys)))) - ;; The primary key will be marked as disabled, when the entire - ;; key is disabled (see 12 Field, Format of colon listings, in - ;; gnupg/doc/DETAILS) - (unless (memq 'disabled (epg-sub-key-capability (car pointer))) - (while pointer - (if (and (memq usage (epg-sub-key-capability (car pointer))) - (not (memq (epg-sub-key-validity (car pointer)) - '(revoked expired)))) - (throw 'found (car keys))) - (setq pointer (cdr pointer))))) - (setq keys (cdr keys))))) + (if (and (mml2015-epg-check-user-id (car keys) recipient) + (mml2015-epg-check-sub-key (car keys) usage)) + (setq key (car keys) + keys nil) + (setq keys (cdr keys)))) + key)) ;; XXX: since gpg --list-secret-keys does not return validity of each ;; key, `mml2015-epg-find-usable-key' defined above is not enough for @@ -1115,8 +1141,7 @@ If no one is selected, symmetric encryption will be performed. " (mapcar (lambda (recipient) (setq recipient-key (mml2015-epg-find-usable-key - (epg-list-keys context recipient) - 'encrypt)) + context recipient 'encrypt)) (unless (or recipient-key (y-or-n-p (format "No public key for %s; skip it? " -- 1.8.1.2