mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-08 14:31:06 +00:00
apps/wallet/cipher_key_value: added confirm dialog and text breaking
This commit is contained in:
parent
0c9cc99bd7
commit
5d992c45c7
@ -53,8 +53,8 @@ def dispatch_SignIdentity(*args, **kwargs):
|
||||
|
||||
@unimport
|
||||
def dispatch_CipherKeyValue(*args, **kwargs):
|
||||
from .cipher_key_value import layout_cipher_key_value
|
||||
return layout_cipher_key_value(*args, **kwargs)
|
||||
from .cipher_key_value import cipher_key_value
|
||||
return cipher_key_value(*args, **kwargs)
|
||||
|
||||
|
||||
def boot():
|
||||
|
@ -1,11 +1,36 @@
|
||||
from trezor import ui
|
||||
from trezor import ui, wire
|
||||
from trezor.crypto import hmac
|
||||
from trezor.crypto.aes import AES_CBC_Decrypt, AES_CBC_Encrypt
|
||||
from trezor.crypto.hashlib import sha512
|
||||
from trezor.messages.CipheredKeyValue import CipheredKeyValue
|
||||
from trezor.messages.FailureType import DataError
|
||||
from trezor.ui.text import Text
|
||||
from apps.common import seed
|
||||
from apps.common.confirm import require_confirm
|
||||
|
||||
from ubinascii import hexlify
|
||||
|
||||
|
||||
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
|
||||
async def cipher_key_value(ctx, msg):
|
||||
if len(msg.value) % 16 > 0:
|
||||
raise wire.FailureError(
|
||||
DataError, 'Value length must be a multiple of 16')
|
||||
|
||||
encrypt = msg.encrypt
|
||||
decrypt = not msg.encrypt
|
||||
if (encrypt and msg.ask_on_encrypt) or (decrypt and msg.ask_on_decrypt):
|
||||
if encrypt:
|
||||
title = 'Encrypt value'
|
||||
else:
|
||||
title = 'Decrypt value'
|
||||
await require_confirm(ctx, Text(title, ui.ICON_DEFAULT, msg.key))
|
||||
|
||||
node = await seed.derive_node(ctx, msg.address_n)
|
||||
value = compute_cipher_key_value(msg, node.private_key())
|
||||
return CipheredKeyValue(value=value)
|
||||
|
||||
|
||||
def compute_cipher_key_value(msg, seckey: bytes) -> bytes:
|
||||
data = msg.key
|
||||
data += 'E1' if msg.ask_on_encrypt else 'E0'
|
||||
data += 'D1' if msg.ask_on_decrypt else 'D0'
|
||||
@ -22,22 +47,3 @@ def cipher_key_value(msg, seckey: bytes) -> bytes:
|
||||
aes = AES_CBC_Decrypt(key=key, iv=iv)
|
||||
|
||||
return aes.update(msg.value)
|
||||
|
||||
|
||||
async def layout_cipher_key_value(ctx, 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.BG)
|
||||
ui.display.text(10, 60, msg.key, ui.MONO, ui.FG, ui.BG)
|
||||
|
||||
node = await seed.derive_node(ctx, msg.address_n)
|
||||
|
||||
value = cipher_key_value(msg, node.private_key())
|
||||
|
||||
return CipheredKeyValue(value=value)
|
||||
|
@ -1,6 +1,8 @@
|
||||
from micropython import const
|
||||
from trezor import ui
|
||||
from trezor.ui import display
|
||||
|
||||
DISPLAY_WIDTH = const(240)
|
||||
TEXT_HEADER_HEIGHT = const(48)
|
||||
TEXT_LINE_HEIGHT = const(26)
|
||||
TEXT_MARGIN_LEFT = const(14)
|
||||
|
Loading…
Reference in New Issue
Block a user