diff --git a/trezor_agent/gpg/agent.py b/trezor_agent/gpg/agent.py index d2a2112..2583d73 100644 --- a/trezor_agent/gpg/agent.py +++ b/trezor_agent/gpg/agent.py @@ -109,6 +109,7 @@ def handle_connection(conn): keygrip = None digest = None algo = None + version = keyring.gpg_version() keyring.sendline(conn, b'OK') for line in iterlines(conn): @@ -118,7 +119,7 @@ def handle_connection(conn): if command in {'RESET', 'OPTION', 'HAVEKEY', 'SETKEYDESC'}: pass # reply with OK elif command == 'GETINFO': - keyring.sendline(conn, b'D 2.1.11') + keyring.sendline(conn, b'D ' + version) elif command == 'AGENT_ID': keyring.sendline(conn, b'D TREZOR') elif command in {'SIGKEY', 'SETKEY'}: diff --git a/trezor_agent/gpg/keyring.py b/trezor_agent/gpg/keyring.py index 4e33f74..3384b18 100644 --- a/trezor_agent/gpg/keyring.py +++ b/trezor_agent/gpg/keyring.py @@ -158,6 +158,14 @@ def get_keygrip(user_id, sp=subprocess): return re.findall(r'Keygrip = (\w+)', output)[0] +def gpg_version(sp=subprocess): + """Get a keygrip of the primary GPG key of the specified user.""" + args = ['gpg2', '--version'] + output = sp.check_output(args).decode('ascii') + line = output.split(b'\n')[0] # b'gpg (GnuPG) 2.1.11' + return line.split(b' ')[-1] # b'2.1.11' + + def export_public_key(user_id, sp=subprocess): """Export GPG public key for specified `user_id`.""" args = ['gpg2', '--export'] + ([user_id] if user_id else [])