mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
apps.wallet: add CipherKeyValue
This commit is contained in:
parent
8618248504
commit
6e79da8df1
@ -3,7 +3,8 @@ from trezor.utils import unimport
|
||||
from trezor.messages.wire_types import \
|
||||
GetPublicKey, GetAddress, SignTx, EstimateTxSize, \
|
||||
SignMessage, VerifyMessage, \
|
||||
SignIdentity
|
||||
SignIdentity, \
|
||||
CipherKeyValue
|
||||
|
||||
|
||||
@unimport
|
||||
@ -51,6 +52,12 @@ def dispatch_SignIdentity(*args, **kwargs):
|
||||
return layout_sign_identity(*args, **kwargs)
|
||||
|
||||
|
||||
@unimport
|
||||
def dispatch_CipherKeyValue(*args, **kwargs):
|
||||
from .layout_cipherkeyvalue import layout_cipherkeyvalue
|
||||
return layout_cipherkeyvalue(*args, **kwargs)
|
||||
|
||||
|
||||
def boot():
|
||||
register_type(GetPublicKey, protobuf_handler, dispatch_GetPublicKey)
|
||||
register_type(GetAddress, protobuf_handler, dispatch_GetAddress)
|
||||
@ -59,3 +66,4 @@ def boot():
|
||||
register_type(SignMessage, protobuf_handler, dispatch_SignMessage)
|
||||
register_type(VerifyMessage, protobuf_handler, dispatch_VerifyMessage)
|
||||
register_type(SignIdentity, protobuf_handler, dispatch_SignIdentity)
|
||||
register_type(CipherKeyValue, protobuf_handler, dispatch_CipherKeyValue)
|
||||
|
41
src/apps/wallet/layout_cipherkeyvalue.py
Normal file
41
src/apps/wallet/layout_cipherkeyvalue.py
Normal file
@ -0,0 +1,41 @@
|
||||
from trezor import wire, ui
|
||||
from trezor.utils import unimport
|
||||
|
||||
|
||||
@unimport
|
||||
async def layout_cipherkeyvalue(msg, session_id):
|
||||
from trezor.messages.CipheredKeyValue import CipheredKeyValue
|
||||
from ..common.seed import get_node
|
||||
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 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'
|
||||
data = hmac.new(seckey, data, sha512).digest()
|
||||
key = data[:32]
|
||||
if msg.iv and len(msg.iv) == 16:
|
||||
iv = msg.iv
|
||||
else:
|
||||
iv = data[32:48]
|
||||
|
||||
if msg.encrypt:
|
||||
aes = AES_CBC_Encrypt(key=key, iv=iv)
|
||||
else:
|
||||
aes = AES_CBC_Decrypt(key=key, iv=iv)
|
||||
|
||||
value = aes.update(msg.value)
|
||||
|
||||
return CipheredKeyValue(value=value)
|
Loading…
Reference in New Issue
Block a user