From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sascha Wilde Newsgroups: gmane.emacs.devel,gmane.emacs.gnus.general Subject: Re: Small patch to enable use of gpg-agent with pgg Date: Wed, 22 Mar 2006 09:36:51 +0100 Message-ID: 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> <87pskfq361.fsf@latte.josefsson.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1143016659 13550 80.91.229.2 (22 Mar 2006 08:37:39 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 22 Mar 2006 08:37:39 +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 Wed Mar 22 09:37:37 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 1FLyqU-0006tv-27 for ged-emacs-devel@m.gmane.org; Wed, 22 Mar 2006 09:37:34 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FLyqh-0004xf-TO for ged-emacs-devel@m.gmane.org; Wed, 22 Mar 2006 03:37:48 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FLyqJ-0004vF-CA for emacs-devel@gnu.org; Wed, 22 Mar 2006 03:37:23 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FLyqH-0004uJ-VD for emacs-devel@gnu.org; Wed, 22 Mar 2006 03:37:22 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FLyqH-0004tx-DT for emacs-devel@gnu.org; Wed, 22 Mar 2006 03:37:21 -0500 Original-Received: from [62.141.58.119] (helo=km1136.keymachine.de) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1FLyqN-00042J-07 for emacs-devel@gnu.org; Wed, 22 Mar 2006 03:37:27 -0500 Original-Received: from kenny.sha-bang.de (xdsld149.osnanet.de [212.95.103.149]) (authenticated bits=0) by km1136.keymachine.de (8.12.11/8.12.10) with ESMTP id k2M8aoXt025259; Wed, 22 Mar 2006 09:36:50 +0100 Original-Received: from wilde by kenny.sha-bang.de with local (Kenny MUA v.0409034.42) ID 1FLypn-0002RK-QK; Wed, 22 Mar 2006 09:36:51 +0100 Original-To: Simon Josefsson In-Reply-To: <87pskfq361.fsf@latte.josefsson.org> (Simon Josefsson's message of "Tue, 21 Mar 2006 15:32:22 +0100") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) 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:51951 gmane.emacs.gnus.general:62351 Archived-At: --=-=-= Simon Josefsson wrote: Hi Simon, first of all, fore some reasons you got lost from the list of CC's so you missed some important messages in this thread, including a more elaborated version of my patch... > 1) Non-agent mode didn't work at all (the args list contained 'nil' so > invoking gpg failed with a lisp error). Yes. This was fixed in my second patch. (and in the attached, of cause) > 2) After fixing the above, the patch made the passphrase be 't', which > broke the passphrase cache, causing a lisp error. Thanks, I used your strategy to fix this issue in my new patch (which I attached). > How about this patch instead? It works for me. I've also improved > the pgg-use-agent default value. This is very error prone. As I wrote before on emacs-devel: there are certain situations in which using the agent will fail -- even if it is available: for example: on an text console running the standard pin-entry program (which uses curses) from within emacs won't work. That's why I think this option should be explicitly enabled by the user. Another problem is, that checking for $GPG_AGENT_INFO is not sufficient, the environment variable will stay set, even is the agent was killed. Could you please consider committing the attached patch, which reverses the default of pgg-gpg-use-agent to nil, and adds an check if the agent is _really_ available, when pgg-gpg-use-agent is set to t? (The patch is against the latest CVS, including your patch that is) cheers sascha --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=pgg-gpg-agent.patch Index: pgg-gpg.el =================================================================== RCS file: /sources/emacs/emacs/lisp/pgg-gpg.el,v retrieving revision 1.6 diff -c -r1.6 pgg-gpg.el --- pgg-gpg.el 21 Mar 2006 21:24:27 -0000 1.6 +++ pgg-gpg.el 22 Mar 2006 08:14:59 -0000 @@ -4,7 +4,8 @@ ;; 2005, 2006 Free Software Foundation, Inc. ;; Author: Daiki Ueno -;; Symmetric encryption added by: Sascha Wilde +;; Symmetric encryption and gpg-agent support added by: +;; Sascha Wilde ;; Created: 1999/10/28 ;; Keywords: PGP, OpenPGP, GnuPG @@ -51,10 +52,8 @@ :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." +(defcustom pgg-gpg-use-agent nil + "Whether to use gnupg agent for key caching." :group 'pgg-gpg :type 'boolean) @@ -62,10 +61,11 @@ "GnuPG ID of your default identity.") (defun pgg-gpg-process-region (start end passphrase program args) - (let* ((output-file-name (pgg-make-temp-file "pgg-output")) + (let* ((use-agent (pgg-gpg-use-agent-p)) + (output-file-name (pgg-make-temp-file "pgg-output")) (args `("--status-fd" "2" - ,@(if pgg-gpg-use-agent '("--use-agent") + ,@(if use-agent '("--use-agent") (if passphrase '("--passphrase-fd" "0"))) "--yes" ; overwrite "--output" ,output-file-name @@ -189,7 +189,7 @@ passphrase cache or user." (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id)) (passphrase (or passphrase - (when (and sign (not pgg-gpg-use-agent)) + (when (and sign (not (pgg-gpg-use-agent-p))) (pgg-read-passphrase (format "GnuPG passphrase for %s: " pgg-gpg-user-id) @@ -221,7 +221,7 @@ 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) + (when (not (pgg-gpg-use-agent-p)) (pgg-read-passphrase "GnuPG passphrase for symmetric encryption: ")))) (args @@ -250,7 +250,7 @@ (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) + (when (not (pgg-gpg-use-agent-p)) (pgg-read-passphrase (format (if (pgg-gpg-symmetric-key-p message-keys) "Passphrase for symmetric decryption: " @@ -286,7 +286,7 @@ "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) + (when (not (pgg-gpg-use-agent-p)) (pgg-read-passphrase (format "GnuPG passphrase for %s: " pgg-gpg-user-id) @@ -356,6 +356,25 @@ (append-to-buffer pgg-output-buffer (point-min)(point-max)) (pgg-process-when-success))) +(defun pgg-gpg-update-agent () + "Try to connet to gpg-agent and send UPDATESTARTUPTTY." + (let* ((agent-info (getenv "GPG_AGENT_INFO")) + (socket (and agent-info + (string-match "^\\([^:]*\\)" agent-info) + (match-string 1 agent-info))) + (conn (and socket + (make-network-process :name "gpg-agent-process" + :host 'local :family 'local + :service socket)))) + (when (and conn (eq (process-status conn) 'open)) + (process-send-string conn "UPDATESTARTUPTTY\n") + (delete-process conn) + t))) + +(defun pgg-gpg-use-agent-p () + "Return t if `pgg-gpg-use-agent' is t and gpg-agent is available." + (and pgg-gpg-use-agent (pgg-gpg-update-agent))) + (provide 'pgg-gpg) ;;; arch-tag: 2aa5d5d8-93a0-4865-9312-33e29830e000 --=-=-= -- Sascha Wilde "Unix was the first OS where you could carry the media and system documentation around in a briefcase. This was fixed in BSD4.2." --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --=-=-=--