From 27a3fddfa2c32922bd48a5e46bc95a90f24573e0 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Mon, 15 Aug 2016 21:39:34 +0300 Subject: [PATCH 1/6] gpg: add a note about restoring GPG keys with --time command-line flag --- trezor_agent/gpg/__main__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/trezor_agent/gpg/__main__.py b/trezor_agent/gpg/__main__.py index 3a170d5..bba0eb2 100755 --- a/trezor_agent/gpg/__main__.py +++ b/trezor_agent/gpg/__main__.py @@ -16,6 +16,9 @@ log = logging.getLogger(__name__) def run_create(args): """Generate a new pubkey for a new/existing GPG identity.""" user_id = os.environ['TREZOR_GPG_USER_ID'] + log.warning('NOTE: in order to re-generate the exact same GPG key later, ' + 'run this command with "--time=%d" commandline flag (to set ' + 'the timestamp of the GPG key manually).', args.time) conn = encode.HardwareSigner(user_id=user_id, curve_name=args.ecdsa_curve) verifying_key = conn.pubkey(ecdh=False) From 05fada91d267a7171e044c8f523d37c03b1e15ec Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Mon, 15 Aug 2016 21:51:32 +0300 Subject: [PATCH 2/6] gpg: use gpgconf to get correct GPG agent UNIX socket path --- trezor_agent/gpg/__main__.py | 5 ++--- trezor_agent/gpg/keyring.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/trezor_agent/gpg/__main__.py b/trezor_agent/gpg/__main__.py index bba0eb2..dd50309 100755 --- a/trezor_agent/gpg/__main__.py +++ b/trezor_agent/gpg/__main__.py @@ -60,9 +60,9 @@ def run_create(args): sys.stdout.write(protocol.armor(result, 'PUBLIC KEY BLOCK')) -def run_agent(args): +def run_agent(args): # pylint: disable=unused-argument """Run a simple GPG-agent server.""" - sock_path = os.path.expanduser(args.sock_path) + sock_path = keyring.get_agent_sock_path() with server.unix_domain_socket_server(sock_path) as sock: for conn in agent.yield_connections(sock): with contextlib.closing(conn): @@ -84,7 +84,6 @@ def main(): create_cmd.set_defaults(run=run_create) agent_cmd = subparsers.add_parser('agent') - agent_cmd.add_argument('-s', '--sock-path', default='~/.gnupg/S.gpg-agent') agent_cmd.set_defaults(run=run_agent) args = p.parse_args() diff --git a/trezor_agent/gpg/keyring.py b/trezor_agent/gpg/keyring.py index b5d21d0..f420fa2 100644 --- a/trezor_agent/gpg/keyring.py +++ b/trezor_agent/gpg/keyring.py @@ -13,9 +13,16 @@ from .. import util log = logging.getLogger(__name__) -def connect_to_agent(sock_path='~/.gnupg/S.gpg-agent', sp=subprocess): +def get_agent_sock_path(sp=subprocess): + """Parse gpgconf output to find out GPG agent UNIX socket path.""" + lines = sp.check_output(['gpgconf', '--list-dirs']).strip().split('\n') + dirs = dict(line.split(':', 1) for line in lines) + return dirs['agent-socket'] + + +def connect_to_agent(sp=subprocess): """Connect to GPG agent's UNIX socket.""" - sock_path = os.path.expanduser(sock_path) + sock_path = get_agent_sock_path(sp=sp) sp.check_call(['gpg-connect-agent', '/bye']) sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect(sock_path) From d63f048b7845646c91741415469749725157fd82 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Sat, 27 Aug 2016 20:59:25 +0300 Subject: [PATCH 3/6] gpg: update trezor-agent installation instruction (using pip) --- README-GPG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README-GPG.md b/README-GPG.md index ea06eb6..642c115 100644 --- a/README-GPG.md +++ b/README-GPG.md @@ -15,7 +15,7 @@ Update you TREZOR firmware to the latest version (at least [c720614](https://git Install latest `trezor-agent` package from [gpg-agent](https://github.com/romanz/trezor-agent/commits/gpg-agent) branch: ``` -$ pip install --user git+https://github.com/romanz/trezor-agent.git@gpg-agent +$ pip install --user git+https://github.com/romanz/trezor-agent.git ``` Define your GPG user ID as an environment variable: From ee347252b4eaa7d879e06b34099c1abc7c8aa653 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Thu, 1 Sep 2016 22:02:32 +0300 Subject: [PATCH 4/6] README: update gitter badge position --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f22adf8..35af86c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ [![Package Version](https://img.shields.io/pypi/v/trezor_agent.svg)](https://pypi.python.org/pypi/trezor_agent/) [![Development Status](https://img.shields.io/pypi/status/trezor_agent.svg)](https://pypi.python.org/pypi/trezor_agent/) [![Downloads](https://img.shields.io/pypi/dm/trezor_agent.svg)](https://pypi.python.org/pypi/trezor_agent/) -[![Chat](https://badges.gitter.im/romanz/trezor-agent.svg)](https://gitter.im/romanz/trezor-agent) See SatoshiLabs' blog posts about this feature: @@ -15,3 +14,5 @@ See SatoshiLabs' blog posts about this feature: For usage with SSH, see the [following instructions](README-SSH.md). For usage with GPG, see the [following instructions](README-GPG.md). + +Questions, suggestions and discussions are welcome: [![Chat](https://badges.gitter.im/romanz/trezor-agent.svg)](https://gitter.im/romanz/trezor-agent) From 73bdf417e438df41bece3ae7f3b3fd154cb91fde Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Fri, 2 Sep 2016 11:38:59 +0300 Subject: [PATCH 5/6] factory: require TREZOR firmware v1.4.0+ for GPG signatures and decryption --- trezor_agent/factory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trezor_agent/factory.py b/trezor_agent/factory.py index 43536b8..d000812 100644 --- a/trezor_agent/factory.py +++ b/trezor_agent/factory.py @@ -54,7 +54,7 @@ def _load_trezor(): hid_transport=HidTransport, passphrase_ack=PassphraseAck, identity_type=IdentityType, - required_version='>=1.3.4', + required_version='>=1.4.0', call_exception=CallException) except ImportError: log.exception('Missing module: install via "pip install trezor"') From adcbe6e7b26bce6295835b796657655aa5385b12 Mon Sep 17 00:00:00 2001 From: Nicolas Pouillard Date: Mon, 5 Sep 2016 17:04:06 +0200 Subject: [PATCH 6/6] gpg/decode/parse_subpackets: parse subpacket length according to RFC --- trezor_agent/gpg/decode.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/trezor_agent/gpg/decode.py b/trezor_agent/gpg/decode.py index d69050c..ded5c98 100644 --- a/trezor_agent/gpg/decode.py +++ b/trezor_agent/gpg/decode.py @@ -25,10 +25,17 @@ def parse_subpackets(s): while True: try: - subpacket_len = s.readfmt('B') + first = s.readfmt('B') except EOFError: break + if first < 192: + subpacket_len = first + elif first < 255: + subpacket_len = ((first - 192) << 8) + s.readfmt('B') + 192 + else: # first == 255 + subpacket_len = s.readfmt('>L') + subpackets.append(s.read(subpacket_len)) return subpackets