Pass environment variables from rbw to rbw-agent #221
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I use
rbw
on a workstation with X.org, but also regularly connect through SSH from my laptop. This setup causes issues with therbw-agent
, since it is started by the firstrbw
command, and inherits the environment from there.rbw-agent
is responsible for startingpinentry
. If I runrbw
first in my X session,rbw-agent
will always startpinentry
in the X session, even if I runrbw
from an SSH session. Vice-versa, when first startingrbw
from an SSH session,rbw-agent
, and thereforepinentry
never inherits the X session and it will always prompt through its curses UI.I never had this issue when I was still using
pass
with GPG, even though GPG's architecture is similar torbw
in that thegpg-agent
process is responsible for starting thepinentry
process. I investigated the GPG source code to see whatgpg-agent
does differently compared torbw
to makepinentry
always use the environment wheregpg
was executed.As it turns out, GPG maintains a list of environment variables that are read from the
gpg
process and passed throughgpg-agent
to thepinentry
process. Sincerbw
already does something similar with the TTY, I extended that functionality in this PR to add environment variables as well. In addition, GPG allows overriding the TTY through theGPG_TTY
environment variable, so I added anRBW_TTY
variable as well.It's fairly hard to grok the GPG source code, since it mostly interacts with
pinentry
through libassuan (which is the protocol used bypinentry
), so not everything is communicated through environment variables and there are multiple entry points (gpg
is not the only process that usesgpg-agent
). However, I am reasonably confident that I've extracted the relevant parts, and the current state of this PR should be functional. That said, I haven't tested all the different environment variables. You can try the main idea by switching between X and non-X TTYs and interacting withrbw
. I haven't tested Wayland, so if someone has a Wayland desktop, I'd like to know if that works as expected.Finally, I've updated
rbw-pinentry-keyring
such that thepinentry
invocations inherit the arguments passed into the script. This should resolve the issue described in #196.