Page MenuHome GnuPG

gpg-1 should fallback to ~/.gnupg/S.gpg-agent
Closed, ResolvedPublic

Description

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.

Details

Event Timeline

ppisar set External Link to https://bugzilla.redhat.com/show_bug.cgi?id=1221234.May 14 2015, 9:37 AM
ppisar set Version to 1.4.19.
ppisar added projects: Feature Request, Fedora, gnupg.
ppisar added a subscriber: ppisar.

Please start gpg-agent manually (gpgconf --launch gpg-agent) and set a fixed
GPG_AGENT_INFO envvar in your login script.

On Mon, May 18, 2015 at 10:37:08AM +0000, Werner Koch via BTS wrote:

Please start gpg-agent manually (gpgconf --launch gpg-agent) and set a fixed
GPG_AGENT_INFO envvar in your login script.

Exactly this thing I reported as a workaound. I'd like to see working gpg
without setting the GPG_AGENT_INFO variable before.

  • Petr
werner renamed this task from gpg-1 cannot locate gpg-agent-2.1 to gpg-1 should fallback to ~/.gnupg/S.gpg-agent.May 21 2015, 8:57 AM

That might be possible. However outstarting gpg-agent won't be implemented for 1.4.

I would suggest to add

gpgconf --launch gpg-agent
GPG_AGENT_INFO="$(gpgconf --list-dirs agent-socket):-1:1"
export GPG_AGENT_INFO

to your startup script. This starts gpg-agent and sets the correct socket name
into the envar.

werner claimed this task.