mirror of
https://github.com/romanz/amodem.git
synced 2026-04-21 05:36:42 +08:00
trezor: fix assertions
This commit is contained in:
@@ -19,7 +19,8 @@ class TrezorLibrary(object):
|
|||||||
from trezorlib.transport_hid import HidTransport
|
from trezorlib.transport_hid import HidTransport
|
||||||
devices = HidTransport.enumerate()
|
devices = HidTransport.enumerate()
|
||||||
if len(devices) != 1:
|
if len(devices) != 1:
|
||||||
raise ValueError('{:d} Trezor devices found'.format(len(devices)))
|
msg = '{:d} Trezor devices found'.format(len(devices))
|
||||||
|
raise IOError(msg)
|
||||||
return TrezorClient(HidTransport(devices[0]))
|
return TrezorClient(HidTransport(devices[0]))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -55,6 +56,7 @@ class Client(object):
|
|||||||
return self.factory.parse_identity(label)
|
return self.factory.parse_identity(label)
|
||||||
|
|
||||||
def get_public_key(self, identity):
|
def get_public_key(self, identity):
|
||||||
|
assert identity.proto == 'ssh'
|
||||||
label = _identity_to_string(identity)
|
label = _identity_to_string(identity)
|
||||||
log.info('getting "%s" public key from Trezor...', label)
|
log.info('getting "%s" public key from Trezor...', label)
|
||||||
addr = _get_address(identity)
|
addr = _get_address(identity)
|
||||||
@@ -64,13 +66,13 @@ class Client(object):
|
|||||||
return formats.export_public_key(pubkey=pubkey, label=label)
|
return formats.export_public_key(pubkey=pubkey, label=label)
|
||||||
|
|
||||||
def sign_ssh_challenge(self, identity, blob):
|
def sign_ssh_challenge(self, identity, blob):
|
||||||
|
assert identity.proto == 'ssh'
|
||||||
label = _identity_to_string(identity)
|
label = _identity_to_string(identity)
|
||||||
msg = _parse_ssh_blob(blob)
|
msg = _parse_ssh_blob(blob)
|
||||||
|
|
||||||
log.info('please confirm user %s connection to "%s" using Trezor...',
|
log.info('please confirm user %s connection to "%s" using Trezor...',
|
||||||
msg['user'], label)
|
msg['user'], label)
|
||||||
|
|
||||||
assert identity.proto == 'ssh'
|
|
||||||
visual = identity.path # not signed when proto='ssh'
|
visual = identity.path # not signed when proto='ssh'
|
||||||
result = self.client.sign_identity(identity=identity,
|
result = self.client.sign_identity(identity=identity,
|
||||||
challenge_hidden=blob,
|
challenge_hidden=blob,
|
||||||
@@ -109,7 +111,6 @@ def _string_to_identity(s):
|
|||||||
|
|
||||||
|
|
||||||
def _identity_to_string(identity):
|
def _identity_to_string(identity):
|
||||||
assert identity.proto == 'ssh'
|
|
||||||
result = [identity.proto + '://']
|
result = [identity.proto + '://']
|
||||||
if identity.user:
|
if identity.user:
|
||||||
result.append(identity.user + '@')
|
result.append(identity.user + '@')
|
||||||
|
|||||||
Reference in New Issue
Block a user