trezor-agent icon indicating copy to clipboard operation
trezor-agent copied to clipboard

using `pass` outside terminal results in `TypeError: handle_option() takes 2 positional arguments but 4 were given`

Open afreakk opened this issue 3 years ago • 1 comments

Using pass with trezor-gpg outside of a terminal does not work (because GPG_TTY is not set). Pass runs the following code:

export GPG_TTY="${GPG_TTY:-$(tty 2>/dev/null)}"

here https://git.zx2c4.com/password-store/tree/src/password-store.sh#n11 and tty outside of a terminal gives not a tty, so GPG_TTY gets set to not a tty. Which then causes error in handle_option()

Context

❯ trezor-agent --version
trezor-agent=0.11.0 libagent=0.14.1

Using model T

Reproduce

#!/usr/bin/env bash
pass -c someSecret 

put script in $PATH, and run it with something that is not a child of a terminal emulator.

Or if you dont have pass you can reproduce the issue with:

#!/usr/bin/env bash
export GPG_TTY=$(tty)
gpg -d /some/secret

(and run outside of a tty)

Or if you want to reproduce inside a terminal, make a script like this and run it:

#!/usr/bin/env bash
export GPG_TTY="not a tty"
gpg -d /some/secret

Either of these methods should produce similar to the following stacktrace in ~/.gnupg/trezor/gpg-agent.log:

2021-03-24 15:37:27,321 DEBUG        waiting for connection on /run/user/1000/gnupg/d.wu4no9py1cz591u7io9rsjpm/S.gpg-agent                [agent.py:14]
2021-03-24 15:37:27,322 DEBUG        accepted connection on /run/user/1000/gnupg/d.wu4no9py1cz591u7io9rsjpm/S.gpg-agent                   [agent.py:20]
2021-03-24 15:37:27,322 DEBUG        <- b'OK'                                                                                             [keyring.py:53]
2021-03-24 15:37:27,322 DEBUG        -> b'RESET'                                                                                          [keyring.py:71]
2021-03-24 15:37:27,322 DEBUG        <- b'OK'                                                                                             [keyring.py:53]
2021-03-24 15:37:27,322 DEBUG        -> b'OPTION ttyname=not a tty'                                                                       [keyring.py:71]
2021-03-24 15:37:27,322 ERROR        handler failed: handle_option() takes 2 positional arguments but 4 were given                        [__init__.py:271]
Traceback (most recent call last):
  File "/nix/store/i623x14ay25nlkvlmasjv8sbyxzxihcp-python3.8-libagent-0.14.1/lib/python3.8/site-packages/libagent/gpg/__init__.py", line 263, in run_agent
    handler.handle(conn)
  File "/nix/store/i623x14ay25nlkvlmasjv8sbyxzxihcp-python3.8-libagent-0.14.1/lib/python3.8/site-packages/libagent/gpg/agent.py", line 242, in handle
    handler(conn, args)
  File "/nix/store/i623x14ay25nlkvlmasjv8sbyxzxihcp-python3.8-libagent-0.14.1/lib/python3.8/site-packages/libagent/gpg/agent.py", line 92, in <lambda>
    b'OPTION': lambda _, args: self.handle_option(*args),
TypeError: handle_option() takes 2 positional arguments but 4 were given
2021-03-24 15:37:27,322 DEBUG        waiting for connection on /run/user/1000/gnupg/d.wu4no9py1cz591u7io9rsjpm/S.gpg-agent                [agent.py:14]

OPTION ttyname=not a tty seems to split into multiple arguments, which handle_option does not like.

Workarounds

  • It works if I write export GPG_TTY="any_value" inside the script. (as long as its not words splitted by whitespace)
  • It also works if i prepend pass by unbuffer in scripts, but that causes other issues if pass is trying to read from stdin.

afreakk avatar Mar 24 '21 14:03 afreakk

You need to set export GPG_TTY=$(tty) in your shell rc file (e.g. ~/.bashrc) unfortunately. Setting it in ~/.profile as one should does not necessarily work as it depends on whether your graphical display starts a login shell or not (see the top answer here https://superuser.com/questions/183870/difference-between-bashrc-and-bash-profile?answertab=active#tab-top). On my Debian 11 (stable) machine with LightDM+Mate does not for example.

doolio avatar Apr 26 '22 12:04 doolio