tty_get_ttyname breaks gpg-agent/pinentry?

Hank Leininger hlein@progressive-comp.com
Thu Jul 3 11:30:12 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, 2 Jul 2003, Werner Koch wrote:

> On Wed, 2 Jul 2003 11:28:56 -0400, Hank Leininger said:
>
> > It appears that tty_get_ttyname added in 1.2.2 breaks gpg-agent / pinentry
>
> @smallexample
> GPG_TTY=`tty`
> export GPG_TTY
> @end smallexample
>
> It is important that this environment variable always reflects the
> output of the @code{tty} command.
>
> Did you set it?

Doh, no I didn't; I see that now in newpg-0.9.4/doc/gpg-agent.texi
I had bad experiences earlier running gpg-agent in the expected ways; if
pinentry died in certain ways gpg-agent would exit, so I got used to
starting it and then manually updating ~/.gnupg/options rather than
relying on GPG_AGENT_INFO env vars (which I can't change on-the-fly for
longrunning processes like pine, which stays up in screen, restarted
only when pine needs to be upgraded... so a few weeks at a time :-P).

However, setting GPG_TTY still doesn't seem to work for me:

timmy:~(5)$ echo $GPG_TTY
/dev/pts/17
timmy:~(6)$ gpg -d foo.asc

You need a passphrase to unlock the secret key for
user: "Hank Leininger <hlein@progressive-comp.com>"
2048-bit ELG-E key, ID 1ADFB931, created 2001-07-09 (main key ID 861AA6F1)

gpg: cancelled by user
gpg: encrypted with 2048-bit ELG-E key, ID 1ADFB931, created 2001-07-09
      "Hank Leininger <hlein@progressive-comp.com>"
gpg: public key decryption failed: bad passphrase
gpg: decryption failed: secret key not available


Hm.  The only places I see GPG_TTY referenced in gnupg-1.2.2,
newpg-0.9.4, and pinentry-0.6.8 (latest releases all AFAIK) is in
newpg-0.9.4/sm/call-agent.c and newpg-0.9.4/agent/simple-pwquery.c
I would have expected some code in gnupg-1.2.2/g10/passphrase.c ?
Is gnupg-1.2.x not expected to interoperate with newpg's agent any more?

Perhaps something like this (based on how dft_ttyname is checked && set
in newpg sm/call-agent.c):

- --- gnupg-1.2.2/g10/passphrase.c.orig	2003-04-10 04:25:40.000000000 -0400
+++ gnupg-1.2.2/g10/passphrase.c	2003-07-02 16:45:02.000000000 -0400
@@ -374,7 +374,11 @@
     }

   if (!opt.ttyname)
- -    dft_ttyname = tty_get_ttyname ();
+    {
+      dft_ttyname = getenv ("GPG_TTY");
+      if (!dft_ttyname || !*dft_ttyname)
+        dft_ttyname = tty_get_ttyname ();
+    }
   if (opt.ttyname || dft_ttyname)
     {
       if (agent_send_option (fd, "ttyname",


The above compiles, and seems to behave properly (gpg + gpg-agent +
pinentry-curses workie).  However it might well be the wrong fix, or I
could be overlooking some other key documentation :-P

Thanks,

Hank Leininger <hlein@progressive-comp.com>
E407 AEF4 761E D39C D401  D4F4 22F8 EF11 861A A6F1
-----BEGIN PGP SIGNATURE-----

iD8DBQE/A0d+IvjvEYYapvERAgPQAJ9X0dX8fQQMNGRFu4P41E0hzSUGXwCfcSJV
X/oXnFEebdl1KD3ocw9mbsg=
=9aE4
-----END PGP SIGNATURE-----