From c9b521a8b03606c5363854607a0f4d0e6a38499d Mon Sep 17 00:00:00 2001 From: matejcik Date: Tue, 3 May 2022 13:59:16 +0200 Subject: [PATCH] tests: add test for firmware dumping and hashing --- tests/device_tests/test_firmware_dump.py | 27 ++++++++++++++++++++++++ tests/ui_tests/fixtures.json | 2 ++ 2 files changed, 29 insertions(+) create mode 100644 tests/device_tests/test_firmware_dump.py diff --git a/tests/device_tests/test_firmware_dump.py b/tests/device_tests/test_firmware_dump.py new file mode 100644 index 000000000..990bb7b87 --- /dev/null +++ b/tests/device_tests/test_firmware_dump.py @@ -0,0 +1,27 @@ +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 diff --git a/tests/ui_tests/fixtures.json b/tests/ui_tests/fixtures.json index 8521b6e3c..8fecf0cec 100644 --- a/tests/ui_tests/fixtures.json +++ b/tests/ui_tests/fixtures.json @@ -527,6 +527,7 @@ "T1_test_debuglink.py::test_layout": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "T1_test_debuglink.py::test_mnemonic": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "T1_test_debuglink.py::test_pin": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", +"T1_test_firmware_dump.py::test_firmware_dump_hash": "cb42c7f21adc31e70ee62c7581245260705dd38f743bbe41161deb5471b9e5f6", "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_passphrase": "1f948e87ea82a0224190d3e552e506d5d4579503905526160c7a527c5a88b729", @@ -1507,6 +1508,7 @@ "TT_test_cancel.py::test_cancel_message_via_initialize[message1]": "b014449cbf1a45739d64a370b30af75df2228f48c090a02227bac8ed20c7b2dc", "TT_test_cancel.py::test_cancel_on_paginated": "6b8a80b8e81a14c0183805fac48a36f9cc61daa290d04d295032ab76ec83300f", "TT_test_debuglink.py::test_softlock_instability": "9750df55cb4716f1d497d57de57257a0c5188fb652fcdb66a9d436d9c396c62b", +"TT_test_firmware_dump.py::test_firmware_dump_hash": "5bd19a3b684eb5160270266f1900dc1e0e216901a64f6ed1e91dc65f7d88d82f", "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\\x90\\x00\\x90\\x00~XXXf\\x90\\x0-cb3c88da": "d81ff1a197803cfda9180cad05dad5c1912a064da957d036c1311fa3eeef4b70",