From 3ee3083e8c7f230fd2e403be2e8de439b42a54e3 Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Mon, 14 May 2018 16:52:59 +0200 Subject: [PATCH] tests/device/stellar: verify message --- .../test_msg_stellar_sign_message.py | 5 ++ .../test_msg_stellar_verify_message.py | 70 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 trezorlib/tests/device_tests/test_msg_stellar_verify_message.py diff --git a/trezorlib/tests/device_tests/test_msg_stellar_sign_message.py b/trezorlib/tests/device_tests/test_msg_stellar_sign_message.py index f754cb474a..29af3c2152 100644 --- a/trezorlib/tests/device_tests/test_msg_stellar_sign_message.py +++ b/trezorlib/tests/device_tests/test_msg_stellar_sign_message.py @@ -29,3 +29,8 @@ class TestMsgStellarSignMessage(TrezorTest): response = self.client.stellar_sign_message(self.client.expand_path("m/44'/148'/0'"), msg) assert hexlify(response.public_key) == b'15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469' assert hexlify(response.signature) == b'3565f5885786fba6cc40c5656fe5444faec882d5e006de509c7fd6420e500179891ada79933024909cd2b57705254cd53cada422f4a7de7790e31c8c1d0c5004' + + msg = 'LongMessage ' * 80 # but shorter than 1024 + response = self.client.stellar_sign_message(self.client.expand_path("m/44'/148'/0'"), msg) + assert hexlify(response.public_key) == b'15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469' + assert hexlify(response.signature) == b'c1e5c477b0451a1cf4b0d8328176470ad3e5aa493c65d64125af57599dfbe5ca2c5c82887aae7e3fa519bbfc3752f1f1188f48efbe4105aa91351319fcd51507' diff --git a/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py b/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py new file mode 100644 index 0000000000..b43fa124e6 --- /dev/null +++ b/trezorlib/tests/device_tests/test_msg_stellar_verify_message.py @@ -0,0 +1,70 @@ +# This file is part of the TREZOR project. +# +# This library is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library. If not, see . + +from .common import TrezorTest +from .conftest import TREZOR_VERSION +from binascii import unhexlify, hexlify +from trezorlib import messages as proto +from trezorlib.client import CallException +import pytest + + +# @pytest.mark.xfail(TREZOR_VERSION == 2, reason="T2 support is not yet finished") +class TestMsgStellarVerifyMessage(TrezorTest): + + def test_stellar_verify_message(self): + self.setup_mnemonic_nopin_nopassphrase() + + msg = 'Hello world!' + pubkey = unhexlify('15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469') + signature = unhexlify('3565f5885786fba6cc40c5656fe5444faec882d5e006de509c7fd6420e500179891ada79933024909cd2b57705254cd53cada422f4a7de7790e31c8c1d0c5004') + response = self.client.stellar_verify_message(pubkey, signature, msg) + assert response is True + + msg = 'LongMessage ' * 80 # but shorter than 1024 + pubkey = unhexlify('15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469') + signature = unhexlify('c1e5c477b0451a1cf4b0d8328176470ad3e5aa493c65d64125af57599dfbe5ca2c5c82887aae7e3fa519bbfc3752f1f1188f48efbe4105aa91351319fcd51507') + response = self.client.stellar_verify_message(pubkey, signature, msg) + assert response is True + + def test_stellar_verify_message_invalid(self): + msg = 'abc' + pubkey = unhexlify('15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469') + signature = unhexlify('0000000000000000') # invalid length + try: + self.client.stellar_verify_message(pubkey, signature, msg) + except CallException as exc: + assert exc.args[0] == proto.FailureType.DataError + else: + assert False + + # invalid signature + signature = unhexlify('00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000') + try: + self.client.stellar_verify_message(pubkey, signature, msg) + except CallException as exc: + assert exc.args[0] == proto.FailureType.DataError + else: + assert False + + # invalid pubkey + pubkey = unhexlify('00') + signature = unhexlify('00') + try: + self.client.stellar_verify_message(pubkey, signature, msg) + except CallException as exc: + assert exc.args[0] == proto.FailureType.DataError + else: + assert False