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