mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-03 12:00:59 +00:00
apps: accomodate latest seed changes
This commit is contained in:
parent
d2e31e24ee
commit
53c73b3b5c
@ -7,11 +7,10 @@ async def layout_ethereum_get_address(session_id, msg):
|
||||
from trezor.messages.EthereumAddress import EthereumAddress
|
||||
from trezor.crypto.curve import secp256k1
|
||||
from trezor.crypto.hashlib import sha3_256
|
||||
from ..common.seed import get_node
|
||||
from ..common import seed
|
||||
|
||||
address_n = msg.address_n or ()
|
||||
|
||||
node = await get_node(session_id, address_n)
|
||||
node = await seed.get_root(session_id)
|
||||
node.derive_path(msg.address_n or ())
|
||||
|
||||
seckey = node.private_key()
|
||||
public_key = secp256k1.publickey(seckey, False) # uncompressed
|
||||
|
@ -2,25 +2,11 @@ from trezor import ui
|
||||
from trezor.utils import unimport
|
||||
|
||||
|
||||
@unimport
|
||||
async def layout_cipher_key_value(session_id, msg):
|
||||
from trezor.messages.CipheredKeyValue import CipheredKeyValue
|
||||
from ..common import seed
|
||||
def cipher_key_value(msg, seckey: bytes) -> bytes:
|
||||
from trezor.crypto.hashlib import sha512
|
||||
from trezor.crypto import hmac
|
||||
from trezor.crypto.aes import AES_CBC_Encrypt, AES_CBC_Decrypt
|
||||
|
||||
if len(msg.value) % 16 > 0:
|
||||
raise ValueError('Value length must be a multiple of 16')
|
||||
|
||||
ui.display.clear()
|
||||
ui.display.text(10, 30, 'CipherKeyValue',
|
||||
ui.BOLD, ui.LIGHT_GREEN, ui.BLACK)
|
||||
ui.display.text(10, 60, msg.key, ui.MONO, ui.WHITE, ui.BLACK)
|
||||
|
||||
node = await seed.get_node(session_id, msg.address_n)
|
||||
seckey = node.private_key()
|
||||
|
||||
data = msg.key
|
||||
data += 'E1' if msg.ask_on_encrypt else 'E0'
|
||||
data += 'D1' if msg.ask_on_decrypt else 'D0'
|
||||
@ -36,6 +22,25 @@ async def layout_cipher_key_value(session_id, msg):
|
||||
else:
|
||||
aes = AES_CBC_Decrypt(key=key, iv=iv)
|
||||
|
||||
value = aes.update(msg.value)
|
||||
return aes.update(msg.value)
|
||||
|
||||
|
||||
@unimport
|
||||
async def layout_cipher_key_value(session_id, msg):
|
||||
from trezor.messages.CipheredKeyValue import CipheredKeyValue
|
||||
from ..common import seed
|
||||
|
||||
if len(msg.value) % 16 > 0:
|
||||
raise ValueError('Value length must be a multiple of 16')
|
||||
|
||||
ui.display.clear()
|
||||
ui.display.text(10, 30, 'CipherKeyValue',
|
||||
ui.BOLD, ui.LIGHT_GREEN, ui.BLACK)
|
||||
ui.display.text(10, 60, msg.key, ui.MONO, ui.WHITE, ui.BLACK)
|
||||
|
||||
node = await seed.get_root(session_id)
|
||||
node.derive_path(msg.address_n)
|
||||
|
||||
value = cipher_key_value(msg, node.private_key())
|
||||
|
||||
return CipheredKeyValue(value=value)
|
||||
|
@ -14,7 +14,9 @@ async def layout_get_address(session_id, msg):
|
||||
|
||||
address_n = msg.address_n or ()
|
||||
coin_name = msg.coin_name or 'Bitcoin'
|
||||
node = await seed.get_node(session_id, address_n)
|
||||
|
||||
node = await seed.get_root(session_id)
|
||||
node.derive_path(address_n)
|
||||
coin = coins.by_name(coin_name)
|
||||
address = node.address(coin.address_type)
|
||||
|
||||
|
@ -7,8 +7,8 @@ async def layout_get_public_key(session_id, msg):
|
||||
from trezor.messages.PublicKey import PublicKey
|
||||
from ..common import seed
|
||||
|
||||
address_n = msg.address_n or ()
|
||||
node = await seed.get_node(session_id, address_n)
|
||||
node = await seed.get_root(session_id)
|
||||
node.derive_path(msg.address_n or ())
|
||||
|
||||
node_xpub = node.serialize_public()
|
||||
node_type = HDNodeType(
|
||||
|
@ -1,52 +1,79 @@
|
||||
from typing import List
|
||||
|
||||
from trezor import ui
|
||||
from trezor.utils import unimport
|
||||
|
||||
@unimport
|
||||
async def layout_sign_identity(session_id, msg):
|
||||
from trezor.messages.SignedIdentity import SignedIdentity
|
||||
from trezor.crypto.curve import secp256k1
|
||||
from trezor.crypto.hashlib import sha256
|
||||
|
||||
def serialize_identity(identity):
|
||||
s = ''
|
||||
if identity.proto:
|
||||
s += identity.proto + '://'
|
||||
if identity.user:
|
||||
s += identity.user + '@'
|
||||
if identity.host:
|
||||
s += identity.host
|
||||
if identity.port:
|
||||
s += ':' + identity.port
|
||||
if identity.path:
|
||||
s += identity.path
|
||||
return s
|
||||
|
||||
|
||||
def display_identity(identity: str, challenge_visual: str):
|
||||
ui.display.clear()
|
||||
ui.display.text(10, 30, 'Identity:',
|
||||
ui.BOLD, ui.LIGHT_GREEN, ui.BLACK)
|
||||
ui.display.text(10, 60, challenge_visual, ui.MONO, ui.WHITE, ui.BLACK)
|
||||
ui.display.text(10, 80, identity, ui.MONO, ui.WHITE, ui.BLACK)
|
||||
|
||||
|
||||
def get_identity_path(identity: str, index: int) -> List[int]:
|
||||
from ustruct import pack, unpack
|
||||
from ..common import coins
|
||||
from ..common import seed
|
||||
from ..common.signverify import message_digest
|
||||
from trezor.crypto.hashlib import sha256
|
||||
|
||||
identity = ''
|
||||
if msg.identity.proto:
|
||||
identity += msg.identity.proto + '://'
|
||||
if msg.identity.user:
|
||||
identity += msg.identity.user + '@'
|
||||
if msg.identity.host:
|
||||
identity += msg.identity.host
|
||||
if msg.identity.port:
|
||||
identity += ':' + msg.identity.port
|
||||
if msg.identity.path:
|
||||
identity += msg.identity.path
|
||||
|
||||
index = msg.identity.index or 0
|
||||
identity_hash = sha256(pack('<I', index) + identity).digest()
|
||||
|
||||
address_n = (13, ) + unpack('<IIII', identity_hash[:16])
|
||||
address_n = [0x80000000 | x for x in address_n]
|
||||
|
||||
# TODO: proper handling of non-secp256k1 curves
|
||||
# this would need the change of common.seed.get_node function
|
||||
return address_n
|
||||
|
||||
ui.display.clear()
|
||||
ui.display.text(10, 30, 'Identity:',
|
||||
ui.BOLD, ui.LIGHT_GREEN, ui.BLACK)
|
||||
ui.display.text(10, 60, msg.challenge_visual, ui.MONO, ui.WHITE, ui.BLACK)
|
||||
ui.display.text(10, 80, identity, ui.MONO, ui.WHITE, ui.BLACK)
|
||||
|
||||
node = await seed.get_node(session_id, address_n)
|
||||
def sign_challenge(seckey: bytes,
|
||||
challenge_hidden: bytes,
|
||||
challenge_visual: str,
|
||||
coin) -> bytes:
|
||||
from trezor.crypto.hashlib import sha256
|
||||
from trezor.crypto.curve import secp256k1
|
||||
from ..common.signverify import message_digest
|
||||
|
||||
coin = coins.by_name('Bitcoin')
|
||||
address = node.address(coin.address_type) # hardcoded Bitcoin address type
|
||||
pubkey = node.public_key()
|
||||
seckey = node.private_key()
|
||||
challenge = sha256(msg.challenge_hidden).digest() + sha256(msg.challenge_visual).digest()
|
||||
challenge = sha256(challenge_hidden).digest() + \
|
||||
sha256(challenge_visual).digest()
|
||||
digest = message_digest(coin, challenge)
|
||||
|
||||
signature = secp256k1.sign(seckey, digest)
|
||||
|
||||
return signature
|
||||
|
||||
|
||||
@unimport
|
||||
async def layout_sign_identity(session_id, msg):
|
||||
from trezor.messages.SignedIdentity import SignedIdentity
|
||||
from ..common import coins
|
||||
from ..common import seed
|
||||
|
||||
identity = serialize_identity(msg.identity)
|
||||
display_identity(identity, msg.challenge_visual)
|
||||
|
||||
address_n = get_identity_path(identity, msg.identity.index or 0)
|
||||
node = await seed.get_root(session_id, msg.ecdsa_curve_name)
|
||||
node.derive_path(address_n)
|
||||
|
||||
coin = coins.by_name('Bitcoin')
|
||||
address = node.address(coin.address_type) # hardcoded bitcoin address type
|
||||
pubkey = node.public_key()
|
||||
seckey = node.private_key()
|
||||
|
||||
signature = sign_challenge(
|
||||
seckey, msg.challenge_hidden, msg.challenge_visual, coin)
|
||||
|
||||
return SignedIdentity(address=address, public_key=pubkey, signature=signature)
|
||||
|
@ -18,7 +18,9 @@ async def layout_sign_message(session_id, msg):
|
||||
coin_name = msg.coin_name or 'Bitcoin'
|
||||
coin = coins.by_name(coin_name)
|
||||
|
||||
node = await seed.get_node(session_id, msg.address_n)
|
||||
node = await seed.get_root(session_id)
|
||||
node.derive_path(msg.address_n)
|
||||
|
||||
seckey = node.private_key()
|
||||
address = node.address(coin.address_type)
|
||||
|
||||
|
@ -11,7 +11,7 @@ async def sign_tx(session_id, msg):
|
||||
from . import signing
|
||||
from . import layout
|
||||
|
||||
root = await seed.get_root_node(session_id)
|
||||
root = await seed.get_root(session_id)
|
||||
|
||||
signer = signing.sign_tx(msg, root)
|
||||
res = None
|
||||
|
Loading…
Reference in New Issue
Block a user