diff --git a/scripts/gpg-shell b/scripts/gpg-shell index 68cbb8f..3dafb94 100755 --- a/scripts/gpg-shell +++ b/scripts/gpg-shell @@ -4,4 +4,7 @@ set -eu export GNUPGHOME=~/.gnupg/trezor gpg2 --list-public-keys +# Make sure that the device is unlocked before starting the shell +trezor-gpg-unlock + ${SHELL} diff --git a/setup.py b/setup.py index 87fc7d1..c3772ba 100644 --- a/setup.py +++ b/setup.py @@ -33,5 +33,6 @@ setup( 'trezor-git = trezor_agent.__main__:run_git', 'trezor-gpg-create = trezor_agent.gpg.__main__:main_create', 'trezor-gpg-agent = trezor_agent.gpg.__main__:main_agent', + 'trezor-gpg-unlock = trezor_agent.gpg.__main__:auto_unlock', ]}, ) diff --git a/trezor_agent/gpg/__main__.py b/trezor_agent/gpg/__main__.py index a31e781..b41dceb 100755 --- a/trezor_agent/gpg/__main__.py +++ b/trezor_agent/gpg/__main__.py @@ -11,7 +11,7 @@ import time import semver from . import agent, decode, client, encode, keyring, protocol -from .. import formats, server, util +from .. import device, formats, server, util log = logging.getLogger(__name__) @@ -114,3 +114,14 @@ def main_agent(): agent.handle_connection(conn) except Exception as e: # pylint: disable=broad-except log.exception('gpg-agent failed: %s', e) + + +def auto_unlock(): + """Automatically unlock first found device (used for `gpg-shell`).""" + p = argparse.ArgumentParser() + p.add_argument('-v', '--verbose', default=0, action='count') + + args = p.parse_args() + util.setup_logging(verbosity=args.verbose) + d = device.detect(identity_str='', curve_name='') + log.info('unlocked %s device', d)