From 1c6ed659213f24c27d52e955d9532b5963a0857c Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 7 Nov 2014 01:59:28 +0100 Subject: [PATCH] add more tests to test_msg_verifymessage --- tests/test_msg_verifymessage.py | 104 ++++++++++++++++++++++++++++++-- trezorlib/client.py | 5 +- 2 files changed, 104 insertions(+), 5 deletions(-) diff --git a/tests/test_msg_verifymessage.py b/tests/test_msg_verifymessage.py index 02e1f1774..7760dad7e 100644 --- a/tests/test_msg_verifymessage.py +++ b/tests/test_msg_verifymessage.py @@ -21,7 +21,7 @@ class TestMsgVerifymessage(common.TrezorTest): ret = self.client.verify_message('moRDikgmxcpouFtqnKnVVzLYgkDD2gQ3sk', sig, 'Ahoj') self.assertTrue(ret) - def test_message_verify(self): + def test_message_verify_address(self): self.setup_mnemonic_nopin_nopassphrase() # uncompressed pubkey - OK @@ -32,7 +32,7 @@ class TestMsgVerifymessage(common.TrezorTest): ) self.assertTrue(res) - # uncompressed pubkey - FAIL + # uncompressed pubkey - FAIL - wrong sig res = self.client.verify_message( '1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T', binascii.unhexlify('1ba77e01a9e17ba158b96200000000dfed676ffc2b4bada24e58f784458b52b97421470d001d53d5880cf5e10e76f02be3e80bf21e18398cbd41e8c3b4af74c8c2'), @@ -40,6 +40,14 @@ class TestMsgVerifymessage(common.TrezorTest): ) self.assertFalse(res) + # uncompressed pubkey - FAIL - wrong msg + res = self.client.verify_message( + '1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T', + binascii.unhexlify('1ba77e01a9e17ba158b962cfef5f13dfed676ffc2b4bada24e58f784458b52b97421470d001d53d5880cf5e10e76f02be3e80bf21e18398cbd41e8c3b4af74c8c2'), + 'This is an example of a signed message!' + ) + self.assertFalse(res) + # compressed pubkey - OK res = self.client.verify_message( '1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8', @@ -47,7 +55,7 @@ class TestMsgVerifymessage(common.TrezorTest): 'This is an example of a signed message.') self.assertTrue(res) - # compressed pubkey - FAIL + # compressed pubkey - FAIL - wrong sig res = self.client.verify_message( '1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8', binascii.unhexlify('1f44e3e461f7ca9f57c472000000004df1de1dadefb6551a32d1907b80c74d5a1fbfd6daaba12dd8cb06699ce3f6941fbe0f3957b5802d13076181046e741eaaaf'), @@ -55,6 +63,13 @@ class TestMsgVerifymessage(common.TrezorTest): ) self.assertFalse(res) + # compressed pubkey - FAIL - wrong msg + res = self.client.verify_message( + '1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8', + binascii.unhexlify('1f44e3e461f7ca9f57c472ce1a28214df1de1dadefb6551a32d1907b80c74d5a1fbfd6daaba12dd8cb06699ce3f6941fbe0f3957b5802d13076181046e741eaaaf'), + 'This is an example of a signed message!') + self.assertFalse(res) + # trezor pubkey - OK res = self.client.verify_message( '14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e', @@ -63,7 +78,7 @@ class TestMsgVerifymessage(common.TrezorTest): ) self.assertTrue(res) - # trezor pubkey - FAIL + # trezor pubkey - FAIL - wrong sig res = self.client.verify_message( '14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e', binascii.unhexlify('209e23edf0e4e47ff1de000002cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80'), @@ -71,6 +86,87 @@ class TestMsgVerifymessage(common.TrezorTest): ) self.assertFalse(res) + # trezor pubkey - FAIL - wrong msg + res = self.client.verify_message( + '14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e', + binascii.unhexlify('209e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80'), + 'This is an example of a signed message!' + ) + self.assertFalse(res) + + def test_message_verify_noaddress(self): + self.setup_mnemonic_nopin_nopassphrase() + + # uncompressed pubkey - OK + res = self.client.verify_message( + None, + binascii.unhexlify('1ba77e01a9e17ba158b962cfef5f13dfed676ffc2b4bada24e58f784458b52b97421470d001d53d5880cf5e10e76f02be3e80bf21e18398cbd41e8c3b4af74c8c2'), + 'This is an example of a signed message.' + ) + self.assertTrue(res) + + # uncompressed pubkey - FAIL - wrong sig + res = self.client.verify_message( + None, + binascii.unhexlify('1ba77e01a9e17ba158b96200000000dfed676ffc2b4bada24e58f784458b52b97421470d001d53d5880cf5e10e76f02be3e80bf21e18398cbd41e8c3b4af74c8c2'), + 'This is an example of a signed message.' + ) + self.assertFalse(res) + + # uncompressed pubkey - FAIL - wrong msg + res = self.client.verify_message( + None, + binascii.unhexlify('1ba77e01a9e17ba158b962cfef5f13dfed676ffc2b4bada24e58f784458b52b97421470d001d53d5880cf5e10e76f02be3e80bf21e18398cbd41e8c3b4af74c8c2'), + 'This is an example of a signed message!' + ) + self.assertFalse(res) + + # compressed pubkey - OK + res = self.client.verify_message( + None, + binascii.unhexlify('1f44e3e461f7ca9f57c472ce1a28214df1de1dadefb6551a32d1907b80c74d5a1fbfd6daaba12dd8cb06699ce3f6941fbe0f3957b5802d13076181046e741eaaaf'), + 'This is an example of a signed message.') + self.assertTrue(res) + + # compressed pubkey - FAIL - wrong sig + res = self.client.verify_message( + None, + binascii.unhexlify('1f44e3e461f7ca9f57c472000000004df1de1dadefb6551a32d1907b80c74d5a1fbfd6daaba12dd8cb06699ce3f6941fbe0f3957b5802d13076181046e741eaaaf'), + 'This is an example of a signed message.' + ) + self.assertFalse(res) + + # compressed pubkey - FAIL - wrong msg + res = self.client.verify_message( + None, + binascii.unhexlify('1f44e3e461f7ca9f57c472ce1a28214df1de1dadefb6551a32d1907b80c74d5a1fbfd6daaba12dd8cb06699ce3f6941fbe0f3957b5802d13076181046e741eaaaf'), + 'This is an example of a signed message!') + self.assertFalse(res) + + # trezor pubkey - OK + res = self.client.verify_message( + None, + binascii.unhexlify('209e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80'), + 'This is an example of a signed message.' + ) + self.assertTrue(res) + + # trezor pubkey - FAIL - wrong sig + res = self.client.verify_message( + None, + binascii.unhexlify('209e23edf0e4e47ff1de000002cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80'), + 'This is an example of a signed message.' + ) + self.assertFalse(res) + + # trezor pubkey - FAIL - wrong msg + res = self.client.verify_message( + None, + binascii.unhexlify('209e23edf0e4e47ff1dec27f32cd78c50e74ef018ee8a6adf35ae17c7a9b0dd96f48b493fd7dbab03efb6f439c6383c9523b3bbc5f1a7d158a6af90ab154e9be80'), + 'This is an example of a signed message!' + ) + self.assertFalse(res) + """ def test_verify_bitcoind(self): self.setup_mnemonic_nopin_nopassphrase() diff --git a/trezorlib/client.py b/trezorlib/client.py index f6e2511d7..eefbcbdbc 100644 --- a/trezorlib/client.py +++ b/trezorlib/client.py @@ -451,7 +451,10 @@ class ProtocolMixin(object): pass # it was not UTF8 string try: - resp = self.call(proto.VerifyMessage(address=address, signature=signature, message=message)) + if address: + resp = self.call(proto.VerifyMessage(address=address, signature=signature, message=message)) + else: + resp = self.call(proto.VerifyMessage(signature=signature, message=message)) except CallException as e: resp = e if isinstance(resp, proto.Success):