gpg: use local version

This commit is contained in:
Roman Zeyde
2016-06-04 19:45:03 +03:00
parent 04af6b737b
commit bc281d4411
2 changed files with 10 additions and 1 deletions

View File

@@ -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'}:

View File

@@ -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 [])