1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-13 19:18:56 +00:00

verify_message now requires coin_name

This commit is contained in:
Pavol Rusnak 2016-10-10 11:01:40 +02:00
parent 101c8b1344
commit c6094dc9ad
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
5 changed files with 26 additions and 9 deletions

View File

@ -11,7 +11,7 @@ else:
setup(
name='trezor',
version='0.7.4',
version='0.7.5',
author='Bitcoin TREZOR',
author_email='info@bitcointrezor.com',
description='Python library for communicating with TREZOR Bitcoin Hardware Wallet',

1
tests/.gitignore vendored
View File

@ -1 +1,2 @@
*.out
*.err

View File

@ -9,7 +9,9 @@ class TestMsgVerifymessage(common.TrezorTest):
def test_message_long(self):
self.setup_mnemonic_nopin_nopassphrase()
ret = self.client.verify_message('1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T',
ret = self.client.verify_message(
'Bitcoin',
'1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T',
binascii.unhexlify('1bddc0aed9cf4e10dc9f57770934f4fb72a27c4510a0f4a81e09c163552416f799cd3f211ffeed0f411e9af9b927407d67115fb6d0ab1897137048efe33417fcc1'),
"VeryLongMessage!" * 64
)
@ -18,7 +20,11 @@ class TestMsgVerifymessage(common.TrezorTest):
def test_message_testnet(self):
self.setup_mnemonic_nopin_nopassphrase()
sig = base64.b64decode('IFP/nvQalDo9lWCI7kScOzRkz/fiiScdkw7tFAKPoGbl6S8AY3wEws43s2gR57AfwZP8/8y7+F+wvGK9phQghN4=')
ret = self.client.verify_message('moRDikgmxcpouFtqnKnVVzLYgkDD2gQ3sk', sig, 'Ahoj')
ret = self.client.verify_message(
'Testnet',
'moRDikgmxcpouFtqnKnVVzLYgkDD2gQ3sk',
sig,
'Ahoj')
self.assertTrue(ret)
def test_message_verify(self):
@ -26,6 +32,7 @@ class TestMsgVerifymessage(common.TrezorTest):
# uncompressed pubkey - OK
res = self.client.verify_message(
'Bitcoin',
'1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T',
binascii.unhexlify('1ba77e01a9e17ba158b962cfef5f13dfed676ffc2b4bada24e58f784458b52b97421470d001d53d5880cf5e10e76f02be3e80bf21e18398cbd41e8c3b4af74c8c2'),
'This is an example of a signed message.'
@ -34,6 +41,7 @@ class TestMsgVerifymessage(common.TrezorTest):
# uncompressed pubkey - FAIL - wrong sig
res = self.client.verify_message(
'Bitcoin',
'1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T',
binascii.unhexlify('1ba77e01a9e17ba158b96200000000dfed676ffc2b4bada24e58f784458b52b97421470d001d53d5880cf5e10e76f02be3e80bf21e18398cbd41e8c3b4af74c8c2'),
'This is an example of a signed message.'
@ -42,6 +50,7 @@ class TestMsgVerifymessage(common.TrezorTest):
# uncompressed pubkey - FAIL - wrong msg
res = self.client.verify_message(
'Bitcoin',
'1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T',
binascii.unhexlify('1ba77e01a9e17ba158b962cfef5f13dfed676ffc2b4bada24e58f784458b52b97421470d001d53d5880cf5e10e76f02be3e80bf21e18398cbd41e8c3b4af74c8c2'),
'This is an example of a signed message!'
@ -50,6 +59,7 @@ class TestMsgVerifymessage(common.TrezorTest):
# compressed pubkey - OK
res = self.client.verify_message(
'Bitcoin',
'1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8',
binascii.unhexlify('1f44e3e461f7ca9f57c472ce1a28214df1de1dadefb6551a32d1907b80c74d5a1fbfd6daaba12dd8cb06699ce3f6941fbe0f3957b5802d13076181046e741eaaaf'),
'This is an example of a signed message.')
@ -57,6 +67,7 @@ class TestMsgVerifymessage(common.TrezorTest):
# compressed pubkey - FAIL - wrong sig
res = self.client.verify_message(
'Bitcoin',
'1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8',
binascii.unhexlify('1f44e3e461f7ca9f57c472000000004df1de1dadefb6551a32d1907b80c74d5a1fbfd6daaba12dd8cb06699ce3f6941fbe0f3957b5802d13076181046e741eaaaf'),
'This is an example of a signed message.'
@ -65,6 +76,7 @@ class TestMsgVerifymessage(common.TrezorTest):
# compressed pubkey - FAIL - wrong msg
res = self.client.verify_message(
'Bitcoin',
'1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8',
binascii.unhexlify('1f44e3e461f7ca9f57c472ce1a28214df1de1dadefb6551a32d1907b80c74d5a1fbfd6daaba12dd8cb06699ce3f6941fbe0f3957b5802d13076181046e741eaaaf'),
'This is an example of a signed message!')
@ -72,6 +84,7 @@ class TestMsgVerifymessage(common.TrezorTest):
# trezor pubkey - OK
res = self.client.verify_message(
'Bitcoin',
'14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e',
binascii.unhexlify('209e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80'),
'This is an example of a signed message.'
@ -80,6 +93,7 @@ class TestMsgVerifymessage(common.TrezorTest):
# trezor pubkey - FAIL - wrong sig
res = self.client.verify_message(
'Bitcoin',
'14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e',
binascii.unhexlify('209e23edf0e4e47ff1de000002cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80'),
'This is an example of a signed message.'
@ -88,6 +102,7 @@ class TestMsgVerifymessage(common.TrezorTest):
# trezor pubkey - FAIL - wrong msg
res = self.client.verify_message(
'Bitcoin',
'14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e',
binascii.unhexlify('209e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80'),
'This is an example of a signed message!'
@ -99,6 +114,7 @@ class TestMsgVerifymessage(common.TrezorTest):
self.setup_mnemonic_nopin_nopassphrase()
res = self.client.verify_message(
'Bitcoin',
'1KzXE97kV7DrpxCViCN3HbGbiKhzzPM7TQ',
binascii.unhexlify('1cc694f0f23901dfe3603789142f36a3fc582d0d5c0ec7215cf2ccd641e4e37228504f3d4dc3eea28bbdbf5da27c49d4635c097004d9f228750ccd836a8e1460c0'),
u'\u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy'
@ -113,12 +129,14 @@ class TestMsgVerifymessage(common.TrezorTest):
words_nfc = u'P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f'
res_nfkd = self.client.verify_message(
'Bitcoin',
'14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e',
binascii.unhexlify('1fd0ec02ed8da8df23e7fe9e680e7867cc290312fe1c970749d8306ddad1a1eda4e39588e4ec2b6a22dda4ec4f562f06e91129eea9a844a7193812de82d47c496b'),
words_nfkd
)
res_nfc = self.client.verify_message(
'Bitcoin',
'14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e',
binascii.unhexlify('1fd0ec02ed8da8df23e7fe9e680e7867cc290312fe1c970749d8306ddad1a1eda4e39588e4ec2b6a22dda4ec4f562f06e91129eea9a844a7193812de82d47c496b'),
words_nfc

View File

@ -255,7 +255,7 @@ class Commands(object):
def verify_message(self, args):
signature = base64.b64decode(args.signature)
return self.client.verify_message(args.address, signature, args.message)
return self.client.verify_message(args.coin, args.address, signature, args.message)
def encrypt_message(self, args):
pubkey = binascii.unhexlify(args.pubkey)
@ -442,6 +442,7 @@ class Commands(object):
)
verify_message.arguments = (
(('-c', '--coin'), {'type': str, 'default': 'Bitcoin'}),
(('address',), {'type': str}),
(('signature',), {'type': str}),
(('message',), {'type': str}),

View File

@ -526,14 +526,11 @@ class ProtocolMixin(object):
ret = self.call(proto.SetU2FCounter(u2f_counter = u2f_counter))
return ret
def verify_message(self, address, signature, message):
def verify_message(self, coin_name, address, signature, message):
# Convert message to UTF8 NFC (seems to be a bitcoin-qt standard)
message = normalize_nfc(message).encode("utf-8")
try:
if address:
resp = self.call(proto.VerifyMessage(address=address, signature=signature, message=message))
else:
resp = self.call(proto.VerifyMessage(signature=signature, message=message))
resp = self.call(proto.VerifyMessage(address=address, signature=signature, message=message, coin_name=coin_name))
except CallException as e:
resp = e
if isinstance(resp, proto.Success):