Page MenuHome GnuPG

GPG hangs if the provided TTY is invalid
Open, LowPublic

Description

When GPG_TTY is set to an invalid TTY, GPG will hang upon any invocation that requires the use of private keys. I suspect it is doing so as it does not know which TTY to send pinentry to.

Reproduction steps:

  • Set GPG_TTY to an invalid value (such as "not a tty") in the shell init script (such as .zshrc)
  • Invoke any GPG command that requires the use of private keys (such as gpg -vvv -K)
  • GPG will start up and hang indefinitely until Control-C is issued

More reproduction steps:

  • Set GPG_TTY to $(tty)
  • Install a ZSH theme such as Powerlevel10k that late-inits tty, which means the above will be set to "not a tty"
  • Invoke any GPG command that requires the use of private keys (such as gpg -vvv -K)
  • GPG will start up and hang indefinitely until Control-C is issued
  • Workaround: set GPG_TTY to $TTY, which is a ZSH variable for the TTY and is compatible with late-init

Expected behavior: GPG should detect that the given TTY is invalid, let the user know, and exit cleanly.

Details

Version
2.4.3

Event Timeline

werner added a subscriber: werner.

gpg -v -K does not require a pinentry. You can check this by adding debug-pinentry and log-file /some/file to the gpg-agent.conf - you should not see any pinentry invocation.

BTW, which pinentry are you using - most pinentries are implementing a timeout which you can sen as a gpg-agent option.

I'm using the standard pinentry provided by Homebrew: https://formulae.brew.sh/formula/pinentry#default

Again, I didn't know it wasn't the pinentry – GPG would give no indication as to what had gone wrong. It just hung right after invocation.

werner added a project: Info Needed.