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: Sun, 19 Mar 2006 18:30:10 +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> <877j6rxre3.fsf@rimspace.net> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0727951353==" X-Trace: sea.gmane.org 1142789441 10430 80.91.229.2 (19 Mar 2006 17:30:41 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 19 Mar 2006 17:30:41 +0000 (UTC) Cc: ding@gnus.org, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Mar 19 18:30:38 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 1FL1jc-0000hu-VE for ged-emacs-devel@m.gmane.org; Sun, 19 Mar 2006 18:30:33 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FL1jc-0005A8-96 for ged-emacs-devel@m.gmane.org; Sun, 19 Mar 2006 12:30:32 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FL1jP-00059s-0B for emacs-devel@gnu.org; Sun, 19 Mar 2006 12:30:19 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FL1jN-00058q-Dp for emacs-devel@gnu.org; Sun, 19 Mar 2006 12:30:18 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FL1jN-00058n-A0 for emacs-devel@gnu.org; Sun, 19 Mar 2006 12:30:17 -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 1FL1ok-0004qI-1w for emacs-devel@gnu.org; Sun, 19 Mar 2006 12:35:50 -0500 Original-Received: from kenny.sha-bang.de (xdsle180.osnanet.de [212.95.104.180]) (authenticated bits=0) by km1136.keymachine.de (8.12.11/8.12.10) with ESMTP id k2JHU9KO028948; Sun, 19 Mar 2006 18:30:09 +0100 Original-Received: from wilde by kenny.sha-bang.de with local (Kenny MUA v.0409034.42) ID 1FL1jM-0000bs-Lh; Sun, 19 Mar 2006 18:30:16 +0100 Original-To: Daniel Pittman In-Reply-To: (Sascha Wilde's message of "Sun, 19 Mar 2006 10:49:11 +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:51855 gmane.emacs.gnus.general:62302 Archived-At: --===============0727951353== Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Sascha Wilde wrote: > Daniel Pittman wrote: >>> Sascha Wilde writes: >> >>> 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 am not convinced that this is the best idea -- so far as I can see, if >> I were to set `pgg-gpg-use-agent' to `t' then I *must* use the agent. >> >> Is it not possible to enable gpg to try the agent first, then to prompt >> for a passphrase? > > Yes, that would be good. I'll try to implement it. I attached a patch which performs a test if gpg-agent is really available when pgg-gpg-use-agent is set to t. Please note, this new patch also fixees a bug, which was introduced by the original patch and broke non agent use... cheers sascha --=-=-= Content-Type: text/x-patch; charset=iso-8859-1 Content-Disposition: inline; filename=pgg-gpg-agent.patch Content-Transfer-Encoding: quoted-printable *** pgg-gpg.el 11 Feb 2006 17:01:56 +0100 1.4 =2D-- pgg-gpg.el 19 M=E4r 2006 17:05:38 +0100=09 *************** *** 4,10 **** ;; 2005, 2006 Free Software Foundation, Inc. =20=20 ;; Author: Daiki Ueno ! ;; Symmetric encryption added by: Sascha Wilde ;; Created: 1999/10/28 ;; Keywords: PGP, OpenPGP, GnuPG =20=20 =2D-- 4,11 ---- ;; 2005, 2006 Free Software Foundation, Inc. =20=20 ;; Author: Daiki Ueno ! ;; Symmetric encryption and gpg-agent support added by:=20 ! ;; Sascha Wilde ;; Created: 1999/10/28 ;; Keywords: PGP, OpenPGP, GnuPG =20=20 *************** *** 51,64 **** :type '(choice (const :tag "New `--recipient' option" "--recipient") (const :tag "Old `--remote-user' option" "--remote-user"))) =20=20 (defvar pgg-gpg-user-id nil "GnuPG ID of your default identity.") =20=20 (defun pgg-gpg-process-region (start end passphrase program args) ! (let* ((output-file-name (pgg-make-temp-file "pgg-output")) (args `("--status-fd" "2" ! ,@(if passphrase '("--passphrase-fd" "0")) "--yes" ; overwrite "--output" ,output-file-name ,@pgg-gpg-extra-args ,@args)) =2D-- 52,73 ---- :type '(choice (const :tag "New `--recipient' option" "--recipient") (const :tag "Old `--remote-user' option" "--remote-user"))) =20=20 + (defcustom pgg-gpg-use-agent nil + "Whether to use gnupg agent for key caching." + :group 'pgg-gpg + :type 'boolean) +=20 (defvar pgg-gpg-user-id nil "GnuPG ID of your default identity.") =20=20 (defun pgg-gpg-process-region (start end passphrase program args) ! (let* ((use-agent (pgg-gpg-use-agent-p))=20 ! (output-file-name (pgg-make-temp-file "pgg-output")) (args `("--status-fd" "2" ! ,@(if (and passphrase (not use-agent))=20 ! '("--passphrase-fd" "0")) ! ,@(if use-agent '("--use-agent")) "--yes" ; overwrite "--output" ,output-file-name ,@pgg-gpg-extra-args ,@args)) *************** *** 77,83 **** (input (buffer-substring-no-properties start end)) (default-enable-multibyte-characters nil)) (with-temp-buffer ! (when passphrase (insert passphrase "\n")) (insert input) (setq exit-status =2D-- 86,92 ---- (input (buffer-substring-no-properties start end)) (default-enable-multibyte-characters nil)) (with-temp-buffer ! (when (and passphrase (not (pgg-gpg-use-agent-p))) (insert passphrase "\n")) (insert input) (setq exit-status *************** *** 181,187 **** If optional PASSPHRASE is not specified, it will be obtained from the passphrase cache or user." (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id)) ! (passphrase (or passphrase (when sign (pgg-read-passphrase (format "GnuPG passphrase for %s: " =2D-- 190,197 ---- If optional PASSPHRASE is not specified, it will be obtained from the passphrase cache or user." (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id)) ! (passphrase (or (pgg-gpg-use-agent-p) ! passphrase (when sign (pgg-read-passphrase (format "GnuPG passphrase for %s: " *************** *** 213,219 **** =20=20 If optional PASSPHRASE is not specified, it will be obtained from the passphrase cache or user." ! (let* ((passphrase (or passphrase (pgg-read-passphrase "GnuPG passphrase for symmetric encryption: "))) (args =2D-- 223,230 ---- =20=20 If optional PASSPHRASE is not specified, it will be obtained from the passphrase cache or user." ! (let* ((passphrase (or (pgg-gpg-use-agent-p) ! passphrase (pgg-read-passphrase "GnuPG passphrase for symmetric encryption: "))) (args *************** *** 241,247 **** (key-id (pgg-gpg-key-id-from-key-owner key-owner)) (pgg-gpg-user-id (or key-id key pgg-gpg-user-id pgg-default-user-id)) ! (passphrase (or passphrase (pgg-read-passphrase (format (if (pgg-gpg-symmetric-key-p message-ke= ys) "Passphrase for symmetric decryptio= n: " =2D-- 252,259 ---- (key-id (pgg-gpg-key-id-from-key-owner key-owner)) (pgg-gpg-user-id (or key-id key pgg-gpg-user-id pgg-default-user-id)) ! (passphrase (or (pgg-gpg-use-agent-p) ! passphrase (pgg-read-passphrase (format (if (pgg-gpg-symmetric-key-p message-ke= ys) "Passphrase for symmetric decryptio= n: " *************** *** 276,282 **** (defun pgg-gpg-sign-region (start end &optional cleartext passphrase) "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 (pgg-read-passphrase (format "GnuPG passphrase for %s: " pgg-gpg-use= r-id) pgg-gpg-user-id))) =2D-- 288,295 ---- (defun pgg-gpg-sign-region (start end &optional cleartext passphrase) "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 (pgg-gpg-use-agent-p) ! passphrase (pgg-read-passphrase (format "GnuPG passphrase for %s: " pgg-gpg-use= r-id) pgg-gpg-user-id))) *************** *** 345,350 **** =2D-- 358,382 ---- (append-to-buffer pgg-output-buffer (point-min)(point-max)) (pgg-process-when-success))) =20=20 + (defun pgg-gpg-update-agent () + "Try to connet to gpg-agent and send UPDATESTARTUPTTY." + (let* ((agent-info (getenv "GPG_AGENT_INFO"))=20 + (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))) +=20 + (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))) +=20 (provide 'pgg-gpg) =20=20 ;;; arch-tag: 2aa5d5d8-93a0-4865-9312-33e29830e000 --=-=-= Content-Transfer-Encoding: quoted-printable =2D-=20 Sascha Wilde : VI is to EMACS as masturbation is to making love: : effective and always available but probably not your : first choice... --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQFEHZUochutvmkRUCQRArUHAJ9ElqQThfPpQd40Dt55E23PaLnYEgCdFVlA tKyD676sMTExZfoqKfVav3o= =rGCS -----END PGP SIGNATURE----- --==-=-=-- --===============0727951353== 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 --===============0727951353==--