Page MenuHome GnuPG

homedir path needs sanitation
Closed, ResolvedPublic

Description

Currently homedir specified with and without trailing slash will lead to duplicate agents being run, which causes issues e.g with smartcard / scdaemon locking. I'm seeing this in particular when using git , which results in need to pull and re-insert smartcard as it shifts between the agents.

Steps to reproduce:
kristianf@ares ~ $ rm -rf /run/user/1000/gnupg/
kristianf@ares ~ $ export GNUPGHOME=$HOME/.gnupg
kristianf@ares ~ $ gpg-connect-agent /bye
gpg-connect-agent: no running gpg-agent - starting '/usr/bin/gpg-agent'
gpg-connect-agent: waiting for the agent to come up ... (5s)
gpg-connect-agent: connection to agent established
kristianf@ares ~ $ export GNUPGHOME=$HOME/.gnupg/
kristianf@ares ~ $ gpg-connect-agent /bye
gpg-connect-agent: no running gpg-agent - starting '/usr/bin/gpg-agent'
gpg-connect-agent: waiting for the agent to come up ... (5s)
gpg-connect-agent: connection to agent established
kristianf@ares ~ $ ls /run/user/1000/gnupg/
d.kb3e7bjorwnzw8nu7ky1hcqi S.gpg-agent.browser S.gpg-agent.ssh
S.gpg-agent S.gpg-agent.extra
kristianf@ares ~ $
kristianf@ares ~ $ ps aux | grep gpg-agent
kristia+ 6491 0.0 0.0 91616 432 ? Ss 16:03 0:00 gpg-agent --homedir /home/kristianf/.gnupg --use-standard-socket --daemon
kristia+ 6496 0.0 0.0 91616 500 ? Ss 16:04 0:00 gpg-agent --homedir /home/kristianf/.gnupg/ --use-standard-socket --daemon

Expected behavior:
Since the paths are pointing at the same directory the same agent should be used (if this was a symbolic link, the same expectation would still hold, so comparison should be done on absolute path basis after unwinding of links)

Event Timeline

as a quick fix something like the attached seems to avoid the immediate issue{F166535}

werner claimed this task.
werner added a subscriber: werner.

We now strip trailing slashes (and backslashes on Windows) when setting the home directory with --homedir and when retrieving it from GNUPGHOME.