1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

tests: change fw hashing test to work without fw dumping

This commit is contained in:
matejcik 2022-08-02 16:11:55 +02:00 committed by matejcik
parent a6410693b3
commit e37ce2b186
3 changed files with 49 additions and 30 deletions

View File

@ -1,27 +0,0 @@
from hashlib import blake2s
from trezorlib import firmware
from trezorlib.debuglink import TrezorClientDebugLink as Client
FIRMWARE_LENGTHS = {
"1": 7 * 128 * 1024 + 64 * 1024,
"T": 13 * 128 * 1024,
}
def test_firmware_dump_hash(client: Client) -> None:
data = firmware.get_firmware(client)
assert len(data) == FIRMWARE_LENGTHS[client.features.model]
if client.features.fw_vendor != "EMULATOR":
# check that the dumped data is not empty
assert not all(byte == 0xFF for byte in data)
expected_hash = blake2s(data).digest()
hash = firmware.get_hash(client, None)
assert hash == expected_hash
challenge = b"Hello Trezor"
expected_hash = blake2s(data, key=challenge).digest()
hash = firmware.get_hash(client, challenge)
assert hash == expected_hash

View File

@ -0,0 +1,45 @@
from hashlib import blake2s
import pytest
from trezorlib import firmware
from trezorlib.debuglink import TrezorClientDebugLink as Client
FIRMWARE_LENGTHS = {
"1": 7 * 128 * 1024 + 64 * 1024,
"T": 13 * 128 * 1024,
}
def test_firmware_hash_emu(client: Client) -> None:
if client.features.fw_vendor != "EMULATOR":
pytest.skip("Only for emulator")
data = b"\xff" * FIRMWARE_LENGTHS[client.features.model]
expected_hash = blake2s(data).digest()
hash = firmware.get_hash(client, None)
assert hash == expected_hash
challenge = b"Hello Trezor"
expected_hash = blake2s(data, key=challenge).digest()
hash = firmware.get_hash(client, challenge)
assert hash == expected_hash
def test_firmware_hash_hw(client: Client) -> None:
if client.features.fw_vendor == "EMULATOR":
pytest.skip("Only for hardware")
# TODO get firmware image from outside the environment, check for actual result
challenge = b"Hello Trezor"
empty_data = b"\xff" * FIRMWARE_LENGTHS[client.features.model]
empty_hash = blake2s(empty_data).digest()
empty_hash_challenge = blake2s(empty_data, key=challenge).digest()
hash = firmware.get_hash(client, None)
assert hash != empty_hash
hash2 = firmware.get_hash(client, challenge)
assert hash != hash2
assert hash2 != empty_hash_challenge

View File

@ -528,7 +528,8 @@
"T1_test_debuglink.py::test_layout": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "T1_test_debuglink.py::test_layout": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"T1_test_debuglink.py::test_mnemonic": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "T1_test_debuglink.py::test_mnemonic": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"T1_test_debuglink.py::test_pin": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "T1_test_debuglink.py::test_pin": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"T1_test_firmware_dump.py::test_firmware_dump_hash": "cb42c7f21adc31e70ee62c7581245260705dd38f743bbe41161deb5471b9e5f6", "T1_test_firmware_hash.py::test_firmware_hash_emu": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"T1_test_firmware_hash.py::test_firmware_hash_hw": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"T1_test_msg_applysettings.py::test_apply_homescreen": "d85a5591a0a433741fcc897fa6941bf0b8475de957375e3811fe710b3d40a053", "T1_test_msg_applysettings.py::test_apply_homescreen": "d85a5591a0a433741fcc897fa6941bf0b8475de957375e3811fe710b3d40a053",
"T1_test_msg_applysettings.py::test_apply_settings": "fb962820965916d494e44bd5aebd25c4f80095ca3d468d3ed212e04a9e0ef9e0", "T1_test_msg_applysettings.py::test_apply_settings": "fb962820965916d494e44bd5aebd25c4f80095ca3d468d3ed212e04a9e0ef9e0",
"T1_test_msg_applysettings.py::test_apply_settings_passphrase": "1f948e87ea82a0224190d3e552e506d5d4579503905526160c7a527c5a88b729", "T1_test_msg_applysettings.py::test_apply_settings_passphrase": "1f948e87ea82a0224190d3e552e506d5d4579503905526160c7a527c5a88b729",
@ -1538,7 +1539,8 @@
"TT_test_cancel.py::test_cancel_message_via_initialize[message1]": "b014449cbf1a45739d64a370b30af75df2228f48c090a02227bac8ed20c7b2dc", "TT_test_cancel.py::test_cancel_message_via_initialize[message1]": "b014449cbf1a45739d64a370b30af75df2228f48c090a02227bac8ed20c7b2dc",
"TT_test_cancel.py::test_cancel_on_paginated": "6b8a80b8e81a14c0183805fac48a36f9cc61daa290d04d295032ab76ec83300f", "TT_test_cancel.py::test_cancel_on_paginated": "6b8a80b8e81a14c0183805fac48a36f9cc61daa290d04d295032ab76ec83300f",
"TT_test_debuglink.py::test_softlock_instability": "9750df55cb4716f1d497d57de57257a0c5188fb652fcdb66a9d436d9c396c62b", "TT_test_debuglink.py::test_softlock_instability": "9750df55cb4716f1d497d57de57257a0c5188fb652fcdb66a9d436d9c396c62b",
"TT_test_firmware_dump.py::test_firmware_dump_hash": "5bd19a3b684eb5160270266f1900dc1e0e216901a64f6ed1e91dc65f7d88d82f", "TT_test_firmware_hash.py::test_firmware_hash_emu": "6156504fa1a43ed3e9aaae41c53dd6e5e979cc2558333b78846e0d9741e75c47",
"TT_test_firmware_hash.py::test_firmware_hash_hw": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1",
"TT_test_msg_applysettings.py::test_apply_homescreen_toif": "7e7fb6223f2113a592c848cd8e57aa22eb002e6472abb5045814f7fe958b2818", "TT_test_msg_applysettings.py::test_apply_homescreen_toif": "7e7fb6223f2113a592c848cd8e57aa22eb002e6472abb5045814f7fe958b2818",
"TT_test_msg_applysettings.py::test_apply_homescreen_toif_fail[TOIf\\x80\\x00\\x80\\x00~\\x00\\x00\\x0-ba464b0c": "d81ff1a197803cfda9180cad05dad5c1912a064da957d036c1311fa3eeef4b70", "TT_test_msg_applysettings.py::test_apply_homescreen_toif_fail[TOIf\\x80\\x00\\x80\\x00~\\x00\\x00\\x0-ba464b0c": "d81ff1a197803cfda9180cad05dad5c1912a064da957d036c1311fa3eeef4b70",
"TT_test_msg_applysettings.py::test_apply_homescreen_toif_fail[TOIf\\x90\\x00\\x90\\x00~XXXf\\x90\\x0-cb3c88da": "d81ff1a197803cfda9180cad05dad5c1912a064da957d036c1311fa3eeef4b70", "TT_test_msg_applysettings.py::test_apply_homescreen_toif_fail[TOIf\\x90\\x00\\x90\\x00~XXXf\\x90\\x0-cb3c88da": "d81ff1a197803cfda9180cad05dad5c1912a064da957d036c1311fa3eeef4b70",
@ -2554,7 +2556,6 @@
"TTui2_test_cancel.py::test_cancel_message_via_initialize[message1]": "95a40f79fa7ffceb10e89b513c203b4937112b8d764cdba3c1df538355dc129c", "TTui2_test_cancel.py::test_cancel_message_via_initialize[message1]": "95a40f79fa7ffceb10e89b513c203b4937112b8d764cdba3c1df538355dc129c",
"TTui2_test_cancel.py::test_cancel_on_paginated": "676407d1aadec40354589c2358f43d2a06a29eaa3ebb1a9ac43a1a7291615349", "TTui2_test_cancel.py::test_cancel_on_paginated": "676407d1aadec40354589c2358f43d2a06a29eaa3ebb1a9ac43a1a7291615349",
"TTui2_test_debuglink.py::test_softlock_instability": "ce63650e876dcd3c8cadac887e3f6561d2558dd2085d01b6c4f089b91cd4ae45", "TTui2_test_debuglink.py::test_softlock_instability": "ce63650e876dcd3c8cadac887e3f6561d2558dd2085d01b6c4f089b91cd4ae45",
"TTui2_test_firmware_dump.py::test_firmware_dump_hash": "fae9c002f2bd1d55e6efbc423d809088946063d3f87fa1ef40875aecdf793cf6",
"TTui2_test_msg_applysettings.py::test_apply_homescreen_toif": "fb0b7a99c6881ad6bf3a27a09d0e37862a7419c6a10f65139ab3f4562c609d9e", "TTui2_test_msg_applysettings.py::test_apply_homescreen_toif": "fb0b7a99c6881ad6bf3a27a09d0e37862a7419c6a10f65139ab3f4562c609d9e",
"TTui2_test_msg_applysettings.py::test_apply_homescreen_toif_fail[TOIf\\x80\\x00\\x80\\x00~\\x00\\x00\\x0-ba464b0c": "1eda1bb0dac1e0cd285b1face109de60cfd0e7ae4041b82b805cebc3be0db8f5", "TTui2_test_msg_applysettings.py::test_apply_homescreen_toif_fail[TOIf\\x80\\x00\\x80\\x00~\\x00\\x00\\x0-ba464b0c": "1eda1bb0dac1e0cd285b1face109de60cfd0e7ae4041b82b805cebc3be0db8f5",
"TTui2_test_msg_applysettings.py::test_apply_homescreen_toif_fail[TOIf\\x90\\x00\\x90\\x00~XXXf\\x90\\x0-cb3c88da": "1eda1bb0dac1e0cd285b1face109de60cfd0e7ae4041b82b805cebc3be0db8f5", "TTui2_test_msg_applysettings.py::test_apply_homescreen_toif_fail[TOIf\\x90\\x00\\x90\\x00~XXXf\\x90\\x0-cb3c88da": "1eda1bb0dac1e0cd285b1face109de60cfd0e7ae4041b82b805cebc3be0db8f5",