fix(core): Error handling in prodtest_tropic.c
What changed, and why it matters
This commit improves error messages and logging in a Trezor production-test command file for the Tropic chip. It does not change program logic, access controls, or cryptographic checks; it only makes failures easier to diagnose by printing the actual numeric error code and correcting a misleading function name in one message. The change is in a prodtest (factory testing) tool, not in the wallet firmware that end users rely on for securing funds.
No security action required; treat as a normal code-quality/diagnostics fix. Reviewers may verify that the new format strings cannot be exploited for format-string injection, which is straightforward because `ret` is an integer passed as a variadic argument to `cli_error`.
Security signals we found
Improved diagnostic logging of low-level secure-element error codes
Correction of a misleading error message for a privileged pairing key function
No change to control flow, authentication, or authorization logic
Evidence from the diff
The patch updates core/embed/projects/prodtest/cmd/prodtest_tropic.c to capture the lt_ret_t return value from several Tropic lt_get_info_* calls and from tropic_custom_session_start(), then report that value in the CLI error string. It also fixes a copy/paste error where the wrong function name (secret_key_tropic_pairing_unprivileged) was printed on failure of secret_key_tropic_pairing_privileged(). No error-handling branches, return paths, or security decisions were altered.
Changed components
core/embed/projects/prodtest/cmd/prodtest_tropic.cTropic secure-element production-test CLI commandsInspect captured patch +16 / −8
diff --git a/core/embed/projects/prodtest/cmd/prodtest_tropic.c b/core/embed/projects/prodtest/cmd/prodtest_tropic.c
index 77bcb75c6..52084b14a 100644
--- a/core/embed/projects/prodtest/cmd/prodtest_tropic.c
+++ b/core/embed/projects/prodtest/cmd/prodtest_tropic.c
@@ -486,8 +486,10 @@ static void prodtest_tropic_get_riscv_fw_version(cli_t* cli) {
lt_handle_t* tropic_handle = tropic_get_handle();
uint8_t version[TR01_L2_GET_INFO_RISCV_FW_SIZE] = {0};
- if (lt_get_info_riscv_fw_ver(tropic_handle, version) != LT_OK) {
- cli_error(cli, CLI_ERROR, "Unable to get RISCV FW version");
+ lt_ret_t ret = lt_get_info_riscv_fw_ver(tropic_handle, version);
+ if (ret != LT_OK) {
+ cli_error(cli, CLI_ERROR, "lt_get_info_riscv_fw_ver() failed with error %d",
+ ret);
return;
}
@@ -504,8 +506,10 @@ static void prodtest_tropic_get_spect_fw_version(cli_t* cli) {
lt_handle_t* tropic_handle = tropic_get_handle();
uint8_t version[TR01_L2_GET_INFO_SPECT_FW_SIZE];
- if (lt_get_info_spect_fw_ver(tropic_handle, version) != LT_OK) {
- cli_error(cli, CLI_ERROR, "Unable to get SPECT FW version");
+ lt_ret_t ret = lt_get_info_spect_fw_ver(tropic_handle, version);
+ if (ret != LT_OK) {
+ cli_error(cli, CLI_ERROR, "lt_get_info_spect_fw_ver() failed with error %d",
+ ret);
return;
}
@@ -522,8 +526,10 @@ static void prodtest_tropic_get_chip_id(cli_t* cli) {
lt_handle_t* tropic_handle = tropic_get_handle();
struct lt_chip_id_t chip_id;
- if (lt_get_info_chip_id(tropic_handle, &chip_id) != LT_OK) {
- cli_error(cli, CLI_ERROR, "Unable to get CHIP ID");
+ lt_ret_t ret = lt_get_info_chip_id(tropic_handle, &chip_id);
+ if (ret != LT_OK) {
+ cli_error(cli, CLI_ERROR, "lt_get_info_chip_id() failed with error %d",
+ ret);
return;
}
@@ -590,6 +596,8 @@ tropic_locked_status get_tropic_locked_status(cli_t* cli) {
// The Tropic pairing process was initiated but probably failed midway.
return TROPIC_LOCKED_FALSE;
} else {
+ cli_error(cli, CLI_ERROR,
+ "`tropic_custom_session_start()` failed with error %d", ret);
return TROPIC_LOCKED_ERROR;
}
}
@@ -783,7 +791,7 @@ static void prodtest_tropic_pair(cli_t* cli) {
curve25519_key privileged_private = {0};
if (secret_key_tropic_pairing_privileged(privileged_private) != sectrue) {
cli_error(cli, CLI_ERROR,
- "`secret_key_tropic_pairing_unprivileged()` failed.");
+ "`secret_key_tropic_pairing_privileged()` failed.");
goto cleanup;
}
curve25519_key privileged_public = {0};
@@ -1391,7 +1399,7 @@ static void cert_read(cli_t* cli, uint16_t first_slot, uint16_t slots_count) {
ret = data_read(tropic_get_handle(), first_slot, slots_count, certificate,
sizeof(certificate), &certificate_length);
if (ret != LT_OK) {
- cli_error(cli, CLI_ERROR, "Unable to read certificate");
+ cli_error(cli, CLI_ERROR, "Reading certificate failed with error %d", ret);
return;
}
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.