[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Small patch to enable use of gpg-agent with pgg
From: |
Simon Josefsson |
Subject: |
Re: Small patch to enable use of gpg-agent with pgg |
Date: |
Tue, 21 Mar 2006 15:32:22 +0100 |
User-agent: |
Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux) |
Sascha Wilde <address@hidden> 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"
- Small patch to enable use of gpg-agent with pgg, Sascha Wilde, 2006/03/18
- Re: Small patch to enable use of gpg-agent with pgg,
Simon Josefsson <=
- Re: Small patch to enable use of gpg-agent with pgg, Sascha Wilde, 2006/03/22
- Re: Small patch to enable use of gpg-agent with pgg, Daiki Ueno, 2006/03/22
- Re: Small patch to enable use of gpg-agent with pgg, Simon Josefsson, 2006/03/22
- Re: Small patch to enable use of gpg-agent with pgg, Sascha Wilde, 2006/03/22
- Re: Small patch to enable use of gpg-agent with pgg, Simon Josefsson, 2006/03/27
- Re: Small patch to enable use of gpg-agent with pgg, Daiki Ueno, 2006/03/22
- Re: Small patch to enable use of gpg-agent with pgg, Daiki Ueno, 2006/03/23
- Re: Small patch to enable use of gpg-agent with pgg, Simon Josefsson, 2006/03/23
- Re: Small patch to enable use of gpg-agent with pgg, Daiki Ueno, 2006/03/23
- Re: Small patch to enable use of gpg-agent with pgg, Simon Josefsson, 2006/03/23