1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-18 11:21:11 +00:00

apps/wallet/{sign_identity, ecdh}: show protocol as part of the header

This commit is contained in:
Roman Zeyde 2018-03-10 18:44:26 +02:00 committed by Pavol Rusnak
parent 167411c6ed
commit a93e745532
2 changed files with 26 additions and 9 deletions

View File

@ -4,7 +4,7 @@ from trezor.messages.ECDHSessionKey import ECDHSessionKey
from ustruct import pack, unpack from ustruct import pack, unpack
from trezor.utils import chunks from trezor.utils import chunks
from apps.common.confirm import require_confirm from apps.common.confirm import require_confirm
from apps.wallet.sign_identity import serialize_identity from apps.wallet.sign_identity import serialize_identity, serialize_identity_without_proto
from trezor.ui.text import Text from trezor.ui.text import Text
from ..common import seed from ..common import seed
@ -16,7 +16,7 @@ async def get_ecdh_session_key(ctx, msg):
identity = serialize_identity(msg.identity) identity = serialize_identity(msg.identity)
await require_confirm_ecdh_session_key(ctx, identity) await require_confirm_ecdh_session_key(ctx, msg.identity)
address_n = get_ecdh_path(identity, msg.identity.index or 0) address_n = get_ecdh_path(identity, msg.identity.index or 0)
node = await seed.derive_node(ctx, address_n, msg.ecdsa_curve_name) node = await seed.derive_node(ctx, address_n, msg.ecdsa_curve_name)
@ -28,8 +28,10 @@ async def get_ecdh_session_key(ctx, msg):
async def require_confirm_ecdh_session_key(ctx, identity): async def require_confirm_ecdh_session_key(ctx, identity):
lines = chunks(identity, 18) lines = chunks(serialize_identity_without_proto(identity), 18)
content = Text('Decrypt', ui.ICON_DEFAULT, ui.MONO, *lines, max_lines=5) proto = identity.proto.upper() if identity.proto else 'identity'
header = 'Decrypt %s' % (proto,)
content = Text(header, ui.ICON_DEFAULT, ui.MONO, *lines, max_lines=5)
await require_confirm(ctx, content) await require_confirm(ctx, content)

View File

@ -1,5 +1,6 @@
from trezor import ui from trezor import ui
from trezor.crypto.hashlib import sha256 from trezor.crypto.hashlib import sha256
from trezor.messages.IdentityType import IdentityType
from trezor.messages.SignedIdentity import SignedIdentity from trezor.messages.SignedIdentity import SignedIdentity
from ustruct import pack, unpack from ustruct import pack, unpack
from trezor.utils import chunks from trezor.utils import chunks
@ -15,7 +16,7 @@ async def sign_identity(ctx, msg):
identity = serialize_identity(msg.identity) identity = serialize_identity(msg.identity)
await require_confirm_sign_identity(ctx, identity, msg.challenge_visual) await require_confirm_sign_identity(ctx, msg.identity, msg.challenge_visual)
address_n = get_identity_path(identity, msg.identity.index or 0) address_n = get_identity_path(identity, msg.identity.index or 0)
node = await seed.derive_node(ctx, address_n, msg.ecdsa_curve_name) node = await seed.derive_node(ctx, address_n, msg.ecdsa_curve_name)
@ -44,10 +45,16 @@ async def sign_identity(ctx, msg):
async def require_confirm_sign_identity(ctx, identity, challenge_visual): async def require_confirm_sign_identity(ctx, identity, challenge_visual):
lines = chunks(identity, 18) lines = []
content = Text('Sign identity', ui.ICON_DEFAULT, if challenge_visual:
challenge_visual, lines.append(challenge_visual)
ui.MONO, *lines, max_lines=5)
lines.append(ui.MONO)
lines.extend(chunks(serialize_identity_without_proto(identity), 18))
proto = identity.proto.upper() if identity.proto else 'identity'
header = 'Sign %s' % (proto,)
content = Text(header, ui.ICON_DEFAULT, *lines, max_lines=5)
await require_confirm(ctx, content) await require_confirm(ctx, content)
@ -66,6 +73,14 @@ def serialize_identity(identity):
return s return s
def serialize_identity_without_proto(identity):
proto = identity.proto
identity.proto = None # simplify serialized identity string
s = serialize_identity(identity)
identity.proto = proto
return s
def get_identity_path(identity: str, index: int): def get_identity_path(identity: str, index: int):
identity_hash = sha256(pack('<I', index) + identity).digest() identity_hash = sha256(pack('<I', index) + identity).digest()