Move decompression into device.pubkey()
This commit is contained in:
@@ -7,6 +7,7 @@ import struct
|
||||
from ledgerblue import comm # pylint: disable=import-error
|
||||
|
||||
from . import interface
|
||||
from .. import formats
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -64,7 +65,9 @@ class LedgerNanoS(interface.Device):
|
||||
log.debug('apdu: %r', apdu)
|
||||
result = bytearray(self.conn.exchange(bytes(apdu)))
|
||||
log.debug('result: %r', result)
|
||||
return _convert_public_key(curve_name, result[1:])
|
||||
return formats.decompress_pubkey(
|
||||
pubkey=_convert_public_key(curve_name, result[1:]),
|
||||
curve_name=identity.curve_name)
|
||||
|
||||
def sign(self, identity, blob):
|
||||
"""Sign given blob and return the signature (as bytes)."""
|
||||
|
||||
@@ -6,6 +6,7 @@ import logging
|
||||
import semver
|
||||
|
||||
from . import interface
|
||||
from .. import formats
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -87,7 +88,8 @@ class Trezor(interface.Device):
|
||||
n=addr,
|
||||
ecdsa_curve_name=curve_name)
|
||||
log.debug('result: %s', result)
|
||||
return bytes(result.node.public_key)
|
||||
pubkey = bytes(result.node.public_key)
|
||||
return formats.decompress_pubkey(pubkey=pubkey, curve_name=identity.curve_name)
|
||||
|
||||
def _identity_proto(self, identity):
|
||||
result = self._defs.IdentityType()
|
||||
|
||||
@@ -25,9 +25,7 @@ class Client:
|
||||
def pubkey(self, identity, ecdh=False):
|
||||
"""Return public key as VerifyingKey object."""
|
||||
with self.device:
|
||||
pubkey = self.device.pubkey(ecdh=ecdh, identity=identity)
|
||||
return formats.decompress_pubkey(
|
||||
pubkey=pubkey, curve_name=identity.curve_name)
|
||||
return self.device.pubkey(ecdh=ecdh, identity=identity)
|
||||
|
||||
def sign(self, identity, digest):
|
||||
"""Sign the digest and return a serialized signature."""
|
||||
|
||||
@@ -20,16 +20,14 @@ class Client:
|
||||
|
||||
def export_public_keys(self, identities):
|
||||
"""Export SSH public keys from the device."""
|
||||
public_keys = []
|
||||
pubkeys = []
|
||||
with self.device:
|
||||
for i in identities:
|
||||
pubkey = self.device.pubkey(identity=i)
|
||||
vk = formats.decompress_pubkey(pubkey=pubkey,
|
||||
curve_name=i.curve_name)
|
||||
public_key = formats.export_public_key(vk=vk,
|
||||
label=i.to_string())
|
||||
public_keys.append(public_key)
|
||||
return public_keys
|
||||
vk = self.device.pubkey(identity=i)
|
||||
label = i.to_string()
|
||||
pubkey = formats.export_public_key(vk=vk, label=label)
|
||||
pubkeys.append(pubkey)
|
||||
return pubkeys
|
||||
|
||||
def sign_ssh_challenge(self, blob, identity):
|
||||
"""Sign given blob using a private key on the device."""
|
||||
|
||||
@@ -22,7 +22,7 @@ class MockDevice(device.interface.Device): # pylint: disable=abstract-method
|
||||
|
||||
def pubkey(self, identity, ecdh=False): # pylint: disable=unused-argument
|
||||
assert self.conn
|
||||
return PUBKEY
|
||||
return formats.decompress_pubkey(pubkey=PUBKEY, curve_name=identity.curve_name)
|
||||
|
||||
def sign(self, identity, blob):
|
||||
"""Sign given blob and return the signature (as bytes)."""
|
||||
|
||||
Reference in New Issue
Block a user