mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-16 11:28:14 +00:00
add EncryptMessage and DecryptMessage
This commit is contained in:
parent
1aee7956e9
commit
8ea46f34a2
29
cmdtr.py
29
cmdtr.py
@ -149,6 +149,19 @@ class Commands(object):
|
||||
signature = base64.b64decode(args.signature)
|
||||
return self.client.verify_message(args.address, signature, args.message)
|
||||
|
||||
def encrypt_message(self, args):
|
||||
address_n = self.client.expand_path(args.n)
|
||||
pubkey = binascii.unhexlify(args.pubkey)
|
||||
ret = self.client.encrypt_message(address_n, pubkey, args.message)
|
||||
return binascii.hexlify(ret)
|
||||
|
||||
def decrypt_message(self, args):
|
||||
address_n = self.client.expand_path(args.n)
|
||||
pubkey = binascii.unhexlify(args.pubkey)
|
||||
message = binascii.unhexlify(args.message)
|
||||
ret = self.client.decrypt_message(address_n, pubkey, message, args.show_only)
|
||||
return ret
|
||||
|
||||
def encrypt_keyvalue(self, args):
|
||||
address_n = self.client.expand_path(args.n)
|
||||
ret = self.client.encrypt_keyvalue(address_n, args.key, args.value)
|
||||
@ -156,7 +169,6 @@ class Commands(object):
|
||||
|
||||
def decrypt_keyvalue(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
|
||||
|
||||
@ -185,6 +197,8 @@ class Commands(object):
|
||||
reset_device.help = 'Perform device setup and generate new seed'
|
||||
sign_message.help = 'Sign message using address of given path'
|
||||
verify_message.help = 'Verify message'
|
||||
encrypt_message.help = 'Encrypt message'
|
||||
decrypt_message.help = 'Decrypt message'
|
||||
encrypt_keyvalue.help = 'Encrypt value by given key and path'
|
||||
decrypt_keyvalue.help = 'Decrypt value by given key and path'
|
||||
firmware_update.help = 'Upload new firmware to device (must be in bootloader mode)'
|
||||
@ -249,6 +263,19 @@ class Commands(object):
|
||||
(('message',), {'type': str}),
|
||||
)
|
||||
|
||||
encrypt_message.arguments = (
|
||||
(('-n', '-address'), {'type': str}),
|
||||
(('pubkey',), {'type': str}),
|
||||
(('message',), {'type': str}),
|
||||
)
|
||||
|
||||
decrypt_message.arguments = (
|
||||
(('-n', '-address'), {'type': str}),
|
||||
(('pubkey',), {'type': str}),
|
||||
(('message',), {'type': str}),
|
||||
(('-s', '--show-only'), {'action': 'store_true', 'default': False}),
|
||||
)
|
||||
|
||||
verify_message.arguments = (
|
||||
(('address',), {'type': str}),
|
||||
(('signature',), {'type': str}),
|
||||
|
@ -412,6 +412,18 @@ class ProtocolMixin(object):
|
||||
return True
|
||||
return False
|
||||
|
||||
@field('payload')
|
||||
@expect(proto.Success)
|
||||
def encrypt_message(self, n, pubkey, message):
|
||||
n = self._convert_prime(n)
|
||||
return self.call(proto.EncryptMessage(address_n=n, pubkey=pubkey, message=message))
|
||||
|
||||
@field('payload')
|
||||
@expect(proto.Success)
|
||||
def decrypt_message(self, n, pubkey, message, show_only):
|
||||
n = self._convert_prime(n)
|
||||
return self.call(proto.DecryptMessage(address_n=n, pubkey=pubkey, message=message, show_only=show_only))
|
||||
|
||||
@field('payload')
|
||||
@expect(proto.Success)
|
||||
def encrypt_keyvalue(self, n, key, value, ask_on_encrypt=True, ask_on_decrypt=True):
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user