2018-06-21 14:28:34 +00:00
|
|
|
# This file is part of the Trezor project.
|
2017-07-17 12:40:35 +00:00
|
|
|
#
|
2019-05-29 16:44:09 +00:00
|
|
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
2017-07-17 12:40:35 +00:00
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
2018-06-21 14:28:34 +00:00
|
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
# as published by the Free Software Foundation.
|
2017-07-17 12:40:35 +00:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2018-06-21 14:28:34 +00:00
|
|
|
# You should have received a copy of the License along with this library.
|
|
|
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
|
|
|
|
2018-05-11 12:53:51 +00:00
|
|
|
import pytest
|
|
|
|
|
2018-08-10 12:04:58 +00:00
|
|
|
from trezorlib import ethereum
|
2017-07-17 12:40:35 +00:00
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
from .common import TrezorTest
|
|
|
|
|
2017-07-17 12:40:35 +00:00
|
|
|
|
2018-05-21 16:30:00 +00:00
|
|
|
@pytest.mark.ethereum
|
2017-12-23 20:20:49 +00:00
|
|
|
class TestMsgEthereumVerifymessage(TrezorTest):
|
2017-07-17 12:40:35 +00:00
|
|
|
|
2019-05-16 16:10:47 +00:00
|
|
|
ADDRESS = "0xEa53AF85525B1779eE99ece1a5560C0b78537C3b"
|
2018-05-25 12:23:16 +00:00
|
|
|
VECTORS = [
|
2018-08-13 16:21:24 +00:00
|
|
|
(
|
|
|
|
"This is an example of a signed message.",
|
2019-05-16 16:10:47 +00:00
|
|
|
"9bacd833b51fde010bab53bafd9d832eadd3b175d2af2e629bb2944fcc987dce7ff68bb3571ed25a720c220f2f9538bc8d04f582bee002c9af086590a49805901c",
|
2018-08-13 16:21:24 +00:00
|
|
|
),
|
|
|
|
(
|
|
|
|
"VeryLongMessage!" * 64,
|
2019-05-16 16:10:47 +00:00
|
|
|
"752d283b3aea1eb44fd09203f4d5c430a6544e399b8500b02722b54325f6d8d457fd83460a31045cb0d6e8356240954ba072fdfe5cdb3f16d416e2acf1a180a51c",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"MsgLenIs9",
|
|
|
|
"6570bd48d38a68ade78273fca18943ed36ec48cb2eb5b6792bc56f20588b1c75020f04b86740321e562eb2ec2022eec4ad673dc120c6895983856e5437cb95c91c",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"MsgLenIs10",
|
|
|
|
"5f26de400e53a333479ce9518ef0724b81615b3e3842c3205754f48a9ff1a3fc0e383ccb7dabdfd8e284abe69c0065f15f033f37210f5efeccfc9a6b0813a2af1b",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"MsgLenIs11!",
|
|
|
|
"7d8c1deec29c01c1982f46a91e1d9d99e399374b8aac875703ca947583ec6d944e7579d3934ac10e910a2959daa9e89fa5f4c0fc62bacdc8ec788d09b22e2ad61c",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"This message has length 99" + 73 * "!",
|
|
|
|
"ac255920b53788eb81f5debd3792554ee4666d38059c8c39f74abd4032483fce2365af2236b8edf83801ad6e57f1e126e55a7757f2a2ebc991efe495b48d16d01c",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"This message has length 100" + 73 * "!",
|
|
|
|
"47a70be8e7161a2c597de2237ba3846218e86561e9b5115b7fe9604ab63c05f85456204ba309e11e3b242a8c09a166ce611fb34bf1c54598162bbcce749549ea1b",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"This message has length 101" + 74 * "!",
|
|
|
|
"0f413d3eff519c52ba01333b8bd132d20c2e62e3a77483e6a803dc3b711e3c2e11548f21687764a7290347079c00fc9dd976e060600d774bf1ae2f99bd8803bf1c",
|
2018-08-13 16:21:24 +00:00
|
|
|
),
|
2018-05-25 12:23:16 +00:00
|
|
|
]
|
2017-07-17 12:40:35 +00:00
|
|
|
|
2018-05-25 12:23:16 +00:00
|
|
|
def test_verify(self):
|
2017-07-17 12:40:35 +00:00
|
|
|
self.setup_mnemonic_nopin_nopassphrase()
|
2018-05-25 12:23:16 +00:00
|
|
|
for msg, sig in self.VECTORS:
|
2018-08-10 12:04:58 +00:00
|
|
|
res = ethereum.verify_message(
|
2019-01-25 15:07:15 +00:00
|
|
|
self.client, self.ADDRESS, bytes.fromhex(sig), msg
|
2018-05-25 12:23:16 +00:00
|
|
|
)
|
|
|
|
assert res is True
|
2018-11-26 15:30:29 +00:00
|
|
|
|
|
|
|
def test_verify_invalid(self):
|
|
|
|
self.setup_mnemonic_nopin_nopassphrase()
|
|
|
|
signature = bytes.fromhex(self.VECTORS[0][1])
|
2018-11-26 16:01:10 +00:00
|
|
|
res = ethereum.verify_message(
|
2019-01-25 15:07:15 +00:00
|
|
|
self.client, self.ADDRESS, signature, "another message"
|
2018-11-26 16:01:10 +00:00
|
|
|
)
|
|
|
|
assert res is False
|