mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-15 19:08:07 +00:00
Added client.encrypt_keyvalue, client.decrypt_keyvalue
This commit is contained in:
parent
0f24602832
commit
e4fe84cb52
31
cmdtr.py
31
cmdtr.py
@ -5,7 +5,7 @@ import argparse
|
|||||||
import json
|
import json
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
from trezorlib.client import TrezorClientDebug
|
from trezorlib.client import TrezorClient
|
||||||
from trezorlib.tx_api import TXAPIBitcoin
|
from trezorlib.tx_api import TXAPIBitcoin
|
||||||
from trezorlib.protobuf_json import pb2json
|
from trezorlib.protobuf_json import pb2json
|
||||||
|
|
||||||
@ -148,6 +148,17 @@ class Commands(object):
|
|||||||
signature = base64.b64decode(args.signature)
|
signature = base64.b64decode(args.signature)
|
||||||
return self.client.verify_message(args.address, signature, args.message)
|
return self.client.verify_message(args.address, signature, args.message)
|
||||||
|
|
||||||
|
def encrypt(self, args):
|
||||||
|
address_n = self.client.expand_path(args.n)
|
||||||
|
ret = self.client.encrypt_keyvalue(address_n, args.key, args.value)
|
||||||
|
return binascii.hexlify(ret)
|
||||||
|
|
||||||
|
def decrypt(self, args):
|
||||||
|
address_n = self.client.expand_path(args.n)
|
||||||
|
value = binascii.unhexlify(args.value)
|
||||||
|
ret = self.client.decrypt_keyvalue(address_n, args.key, value)
|
||||||
|
return ret
|
||||||
|
|
||||||
def firmware_update(self, args):
|
def firmware_update(self, args):
|
||||||
if not args.file:
|
if not args.file:
|
||||||
raise Exception("Must provide firmware filename")
|
raise Exception("Must provide firmware filename")
|
||||||
@ -173,6 +184,8 @@ class Commands(object):
|
|||||||
reset_device.help = 'Perform device setup and generate new seed'
|
reset_device.help = 'Perform device setup and generate new seed'
|
||||||
sign_message.help = 'Sign message using address of given path'
|
sign_message.help = 'Sign message using address of given path'
|
||||||
verify_message.help = 'Verify message'
|
verify_message.help = 'Verify message'
|
||||||
|
encrypt.help = 'Encrypt value by given key and path'
|
||||||
|
decrypt.help = 'Decrypt value by given key and path'
|
||||||
firmware_update.help = 'Upload new firmware to device (must be in bootloader mode)'
|
firmware_update.help = 'Upload new firmware to device (must be in bootloader mode)'
|
||||||
|
|
||||||
get_address.arguments = (
|
get_address.arguments = (
|
||||||
@ -241,6 +254,18 @@ class Commands(object):
|
|||||||
(('message',), {'type': str}),
|
(('message',), {'type': str}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
encrypt.arguments = (
|
||||||
|
(('-n', '-address'), {'type': str}),
|
||||||
|
(('key',), {'type': str}),
|
||||||
|
(('value',), {'type': str}),
|
||||||
|
)
|
||||||
|
|
||||||
|
decrypt.arguments = (
|
||||||
|
(('-n', '-address'), {'type': str}),
|
||||||
|
(('key',), {'type': str}),
|
||||||
|
(('value',), {'type': str}),
|
||||||
|
)
|
||||||
|
|
||||||
get_public_node.arguments = (
|
get_public_node.arguments = (
|
||||||
(('-n', '-address'), {'type': str}),
|
(('-n', '-address'), {'type': str}),
|
||||||
)
|
)
|
||||||
@ -271,7 +296,7 @@ class PinMatrixThread(threading.Thread):
|
|||||||
from PyQt4.QtCore import QObject, SIGNAL
|
from PyQt4.QtCore import QObject, SIGNAL
|
||||||
|
|
||||||
a = QApplication(sys.argv)
|
a = QApplication(sys.argv)
|
||||||
|
pass
|
||||||
matrix = PinMatrixWidget()
|
matrix = PinMatrixWidget()
|
||||||
|
|
||||||
def clicked():
|
def clicked():
|
||||||
@ -324,7 +349,7 @@ def main():
|
|||||||
return
|
return
|
||||||
|
|
||||||
transport = get_transport(args.transport, args.path)
|
transport = get_transport(args.transport, args.path)
|
||||||
client = TrezorClientDebug(transport)
|
client = TrezorClient(transport)
|
||||||
client.set_tx_api(TXAPIBitcoin())
|
client.set_tx_api(TXAPIBitcoin())
|
||||||
cmds = Commands(client)
|
cmds = Commands(client)
|
||||||
|
|
||||||
|
@ -407,6 +407,28 @@ class ProtocolMixin(object):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@field('payload')
|
||||||
|
@expect(proto.Success)
|
||||||
|
def encrypt_keyvalue(self, n, key, value, ask_on_encrypt=True, ask_on_decrypt=True):
|
||||||
|
n = self._convert_prime(n)
|
||||||
|
return self.call(proto.CipherKeyValue(address_n=n,
|
||||||
|
key=key,
|
||||||
|
value=value,
|
||||||
|
encrypt=True,
|
||||||
|
ask_on_encrypt=ask_on_encrypt,
|
||||||
|
ask_on_decrypt=ask_on_decrypt))
|
||||||
|
|
||||||
|
@field('payload')
|
||||||
|
@expect(proto.Success)
|
||||||
|
def decrypt_keyvalue(self, n, key, value, ask_on_encrypt=True, ask_on_decrypt=True):
|
||||||
|
n = self._convert_prime(n)
|
||||||
|
return self.call(proto.CipherKeyValue(address_n=n,
|
||||||
|
key=key,
|
||||||
|
value=value,
|
||||||
|
encrypt=False,
|
||||||
|
ask_on_encrypt=ask_on_encrypt,
|
||||||
|
ask_on_decrypt=ask_on_decrypt))
|
||||||
|
|
||||||
@field('tx_size')
|
@field('tx_size')
|
||||||
@expect(proto.TxSize)
|
@expect(proto.TxSize)
|
||||||
def estimate_tx_size(self, coin_name, inputs, outputs):
|
def estimate_tx_size(self, coin_name, inputs, outputs):
|
||||||
|
Loading…
Reference in New Issue
Block a user