From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Simon Josefsson Newsgroups: gmane.emacs.devel,gmane.emacs.gnus.general Subject: Re: Small patch to enable use of gpg-agent with pgg Date: Tue, 21 Mar 2006 15:32:22 +0100 Message-ID: <87pskfq361.fsf@latte.josefsson.org> References: <2cd46e7f0510031250u66ea1349yb437d539ce4027ef@mail.gmail.com> <2cd46e7f0510061541w73bb6a92wb6d22829b6e804ae@mail.gmail.com> <20051007100014.GB4850@kenny.sha-bang.local> <2cd46e7f0510071106k3d4d3e6agc36f16a37d8b6bc6@mail.gmail.com> <20051007214952.GA30235@kenny.sha-bang.local> <20051008103627.GA1218@kenny.sha-bang.local> <2cd46e7f0510081131h14e2bbeaga7f1a33ebd6347c8@mail.gmail.com> <2cd46e7f0510101415t76825ea7u9749fe23da54ce@mail.gmail.com> <2cd46e7f0510121647x3c51fb65pc883ed61f4e864ab@mail.gmail.com> <2cd46e7f0510200708x4640d1c2t50743cf439e52dd4@mail.gmail.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1142951585 20851 80.91.229.2 (21 Mar 2006 14:33:05 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 21 Mar 2006 14:33:05 +0000 (UTC) Cc: "Daiki Ueno \(pgg author\)" , ding@gnus.org, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 21 15:33:03 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FLhun-0008Mk-6X for ged-emacs-devel@m.gmane.org; Tue, 21 Mar 2006 15:32:53 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FLhuu-000147-Et for ged-emacs-devel@m.gmane.org; Tue, 21 Mar 2006 09:33:00 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FLhug-00013T-Dw for emacs-devel@gnu.org; Tue, 21 Mar 2006 09:32:46 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FLhud-000134-AV for emacs-devel@gnu.org; Tue, 21 Mar 2006 09:32:45 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FLhud-000131-3u for emacs-devel@gnu.org; Tue, 21 Mar 2006 09:32:43 -0500 Original-Received: from [217.13.230.178] (helo=yxa.extundo.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1FLhue-0000pg-Os for emacs-devel@gnu.org; Tue, 21 Mar 2006 09:32:45 -0500 Original-Received: from localhost.localdomain (yxa.extundo.com [217.13.230.178]) (authenticated bits=0) by yxa.extundo.com (8.13.4/8.13.4/Debian-3) with ESMTP id k2LEWMJ0012177; Tue, 21 Mar 2006 15:32:22 +0100 Original-To: Sascha Wilde OpenPGP: id=B565716F; url=http://josefsson.org/key.txt X-Hashcash: 1:21:060321:emacs-devel@gnu.org::0GXNNt47TGcyG/1X:3XOW X-Hashcash: 1:21:060321:wilde@sha-bang.de::0agwFp59GiKUWUM3:59FA X-Hashcash: 1:21:060321:ueno@unixuser.org::zzHKNbjK+aJYGKQ5:E8u2 X-Hashcash: 1:21:060321:ding@gnus.org::AV78NSgzVeOaEG1w:KKDt In-Reply-To: (Sascha Wilde's message of "Sat, 18 Mar 2006 22:17:02 +0100") User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux) X-Virus-Scanned: ClamAV version 0.88, clamav-milter version 0.87 on yxa.extundo.com X-Virus-Status: Clean X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:51930 gmane.emacs.gnus.general:62336 Archived-At: Sascha Wilde writes: > Hi, > > I wrote a small patch, which makes it possible to use the GnuPG agent > (which is part of gpg 1.9 and considered ready to use by Werner) with > the GnuPG backend of pgg. > > I have done very little testing yet, but it seems to work fine.[0] > > To test it: > set up your gpg-agent as usual and set pgg-gpg-use-agent to t. Your patch didn't work well for me: 1) Non-agent mode didn't work at all (the args list contained 'nil' so invoking gpg failed with a lisp error). 2) After fixing the above, the patch made the passphrase be 't', which broke the passphrase cache, causing a lisp error. How about this patch instead? It works for me. I've also improved the pgg-use-agent default value. I've installed this on Emacs CVS trunk, Gnus v5-10 and Gnus CVS. Thanks for working on this, it is quite useful. --- pgg-gpg.el 21 Mar 2006 14:53:00 +0100 1.4 +++ pgg-gpg.el 21 Mar 2006 15:22:38 +0100 @@ -51,6 +51,13 @@ :type '(choice (const :tag "New `--recipient' option" "--recipient") (const :tag "Old `--remote-user' option" "--remote-user"))) +(defcustom pgg-gpg-use-agent (if (getenv "GPG_AGENT_INFO") t nil) + "Whether to use gnupg agent for key caching. +By default, it will be enabled iff the environment variable +\"GPG_AGENT_INFO\" is set." + :group 'pgg-gpg + :type 'boolean) + (defvar pgg-gpg-user-id nil "GnuPG ID of your default identity.") @@ -58,7 +65,8 @@ (let* ((output-file-name (pgg-make-temp-file "pgg-output")) (args `("--status-fd" "2" - ,@(if passphrase '("--passphrase-fd" "0")) + ,@(if pgg-gpg-use-agent '("--use-agent") + (if passphrase '("--passphrase-fd" "0"))) "--yes" ; overwrite "--output" ,output-file-name ,@pgg-gpg-extra-args ,@args)) @@ -100,7 +108,8 @@ (set-default-file-modes orig-mode)))) (defun pgg-gpg-possibly-cache-passphrase (passphrase &optional key notruncate) - (if (and pgg-cache-passphrase + (if (and passphrase + pgg-cache-passphrase (progn (goto-char (point-min)) (re-search-forward "^\\[GNUPG:] \\(GOOD_PASSPHRASE\\>\\)\\|\\(SIG_CREATED\\)" nil t))) @@ -182,7 +191,7 @@ passphrase cache or user." (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id)) (passphrase (or passphrase - (when sign + (when (and sign (not pgg-gpg-use-agent)) (pgg-read-passphrase (format "GnuPG passphrase for %s: " pgg-gpg-user-id) @@ -214,8 +223,9 @@ If optional PASSPHRASE is not specified, it will be obtained from the passphrase cache or user." (let* ((passphrase (or passphrase + (when (not pgg-gpg-use-agent) (pgg-read-passphrase - "GnuPG passphrase for symmetric encryption: "))) + "GnuPG passphrase for symmetric encryption: ")))) (args (append (list "--batch" "--armor" "--symmetric" ) (if pgg-text-mode (list "--textmode"))))) @@ -242,12 +252,13 @@ (pgg-gpg-user-id (or key-id key pgg-gpg-user-id pgg-default-user-id)) (passphrase (or passphrase + (when (not pgg-gpg-use-agent) (pgg-read-passphrase (format (if (pgg-gpg-symmetric-key-p message-keys) "Passphrase for symmetric decryption: " "GnuPG passphrase for %s: ") (or key-owner "??")) - pgg-gpg-user-id))) + pgg-gpg-user-id)))) (args '("--batch" "--decrypt"))) (pgg-gpg-process-region start end passphrase pgg-gpg-program args) (with-current-buffer pgg-errors-buffer @@ -277,9 +288,11 @@ "Make detached signature from text between START and END." (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id)) (passphrase (or passphrase + (when (not pgg-gpg-use-agent) (pgg-read-passphrase - (format "GnuPG passphrase for %s: " pgg-gpg-user-id) - pgg-gpg-user-id))) + (format "GnuPG passphrase for %s: " + pgg-gpg-user-id) + pgg-gpg-user-id)))) (args (append (list (if cleartext "--clearsign" "--detach-sign") "--armor" "--batch" "--verbose"