After upgrading gnupg2 to 2.1, the gpg-agent stopped exporting GPG_AGENT_INFO
variable. Therefore gpg (version 1.4.19) cannot finf the agent anymore and
reports an error:
$ "gpg-agent" "--disable-scdaemon" "--allow-preset" "--daemon"
$ /usr/libexec/gpg-preset-passphrase -P passphrase --preset
8E136E6F34C0D4CD941A9DB749539D60EFEA4EAD
$ "gpg" "--batch" "--no-tty" "--armor" "--default-key" "49539D60EFEA4EAD"
"--use-agent" "--detach-sign" test_file
gpg: gpg-agent is not available in this session
[...]
Adding proper --gpg-agent-info argument allows the gpg to work again. Installed
packages:
gnupg-1.4.19
gnupg2-2.1.3
I found this issue when solving Mail-GnuPG's test failure
https://rt.cpan.org/Public/Bug/Display.html?id=102719.
This is because of this code from g10/passphrase.c:
if (opt.gpg_agent_info) infostr = xstrdup (opt.gpg_agent_info); else { infostr = getenv ( "GPG_AGENT_INFO" ); if (!infostr || !*infostr) { if (!try) {
#ifdef ENABLE_NLS
if (orig_codeset) bind_textdomain_codeset (PACKAGE, orig_codeset);
#endif /*ENABLE_NLS*/
log_info (_("gpg-agent is not available in this session\n")); opt.use_agent = 0; } return NULL; } infostr = xstrdup ( infostr ); }
Obviously, gpg requires GPG_AGENT_INFO environment variable or --gpg-agent-info
argument.
I propose to add a fallback to "${GNUPGHOME}/S.gpg-agent::1" value which is now
hard-coded by all gnupg-2 tools.