refactor(core/embed): refactor and improve tropic session establishing
What changed, and why it matters
This commit refactors how the Trezor firmware's production-test code establishes secure sessions with the Tropic secure chip. It replaces scattered, manually-managed key-loading and session-start code with a single internal helper, `tropic_custom_session_start()`, and adds a way to invalidate an existing session before starting a new handshake. The change is described by the vendor as a refactor and improvement, not as a security fix. The diff does not show an obvious exploitable vulnerability, but it does remove several direct `memzero()` calls that cleared private key buffers in production-test routines; that cleanup is now handled inside the new helper. Because the commit touches sensitive pairing-key handling and session state, it has defensive-security relevance, but there is no disclosed incident or CVE.
Treat as a hardening/refactor commit rather than an urgent vulnerability patch. Reviewers should verify that `tropic_custom_session_start()` zeroizes the private key on every error path, that `tropic_session_invalidate()` correctly aborts any active session and resets state, and that callers no longer need the removed `memzero()` calls. Because this is provisioning/production-test code, ensure the factory pairing key path remains restricted and that the new public-key auto-fetch behavior does not weaken pairing integrity.
Security signals we found
Refactor of secure-element pairing-key handling and session state
New helper centralizes loading of factory/privileged/unprivileged private keys and session start
New `tropic_session_invalidate()` / `lt_session_abort()` wrapper added and called before raw L2 handshake in `prodtest_tropic_handshake()`
Removal of explicit `memzero()` of private key buffers in multiple callers; zeroization moved into helper
Conditional public-key retrieval path changed: factory slot in prodtest/non-production can fetch chip public key automatically
No changelog entry; commit is tagged [no changelog]
Evidence from the diff
The patch consolidates Tropic session establishment. A new public-ish API tropic_custom_session_start(pkey_index_t) is introduced in sec/tropic.h and implemented in sec/tropic/tropic.c. It loads the appropriate Curve25519 private key (factory, privileged, or unprivileged), derives the public key, optionally fetches the chip’s public key, waits for the chip to be ready, and calls lt_session_start(). It updates driver state (session_started, pairing_key_index) and zeroizes the local private key before returning. A new tropic_session_invalidate() wrapper calls lt_session_abort() and clears session_started. Production-test commands in prodtest_tropic.c and prodtest_secrets.c are updated to call the helper instead of duplicating key retrieval/derivation/session-start logic. The helper also allows fetching the Tropic public key in non-production or prodtest builds when the factory pairing slot is used. Several cleanup: labels and explicit memzero() calls are removed from the callers because the helper now owns key zeroization.
Changed components
core/embed/sec/tropic/tropic.ccore/embed/sec/tropic/inc/sec/tropic.hcore/embed/projects/prodtest/cmd/prodtest_tropic.ccore/embed/projects/prodtest/cmd/prodtest_secrets.ccore/embed/projects/prodtest/cmd/prodtest_tropic.hInspect captured patch +101 / −245
diff --git a/core/embed/projects/prodtest/cmd/prodtest_secrets.c b/core/embed/projects/prodtest/cmd/prodtest_secrets.c
index 033db27ed..0790bc1f0 100644
--- a/core/embed/projects/prodtest/cmd/prodtest_secrets.c
+++ b/core/embed/projects/prodtest/cmd/prodtest_secrets.c
@@ -128,9 +128,8 @@ static void prodtest_secrets_init(cli_t* cli) {
// Ensure that a session with Tropic is established so that we can include
// randomness from the chip when generating the secrets. At this point in
// provisioning the factory pairing key should still be valid.
- if (!prodtest_tropic_factory_session_start(tropic_get_handle())) {
- cli_error(cli, CLI_ERROR,
- "`prodtest_tropic_factory_session_start` failed.");
+ if (tropic_custom_session_start(TROPIC_FACTORY_PAIRING_KEY_SLOT) != LT_OK) {
+ cli_error(cli, CLI_ERROR, "`tropic_custom_session_start()` failed.");
return;
}
#endif
diff --git a/core/embed/projects/prodtest/cmd/prodtest_tropic.c b/core/embed/projects/prodtest/cmd/prodtest_tropic.c
index 8a747adcb..2f48bfcbe 100644
--- a/core/embed/projects/prodtest/cmd/prodtest_tropic.c
+++ b/core/embed/projects/prodtest/cmd/prodtest_tropic.c
@@ -482,12 +482,6 @@ static struct lt_config_t reversible_configuration = {
}};
// clang-format on
-// TODO: Implement a function `lt_handle_t* start_session(const pkey_index_t
-// pkey_index)`. This function will check whether a session with a specified
-// pairing key is active. If a session is not active, it will retrieve the
-// pairing key and initiate a session using it. The function will be used in
-// this file and in `prodtest_secrets.c`. This is only an optimization.
-
static void prodtest_tropic_get_riscv_fw_version(cli_t* cli) {
if (cli_arg_count(cli) > 0) {
cli_error_arg_count(cli);
@@ -627,7 +621,6 @@ static void prodtest_tropic_lock_check(cli_t* cli) {
}
tropic_locked_status get_tropic_locked_status(cli_t* cli) {
- tropic_locked_status locked_status = TROPIC_LOCKED_ERROR;
tropic_handshake_state = TROPIC_HANDSHAKE_STATE_0;
lt_handle_t* tropic_handle = tropic_get_handle();
@@ -636,27 +629,17 @@ tropic_locked_status get_tropic_locked_status(cli_t* cli) {
curve25519_key tropic_public = {0};
if (secret_key_tropic_public(tropic_public) != sectrue) {
// The Tropic pairing process was not initiated.
- locked_status = TROPIC_LOCKED_FALSE;
- goto cleanup;
+ return TROPIC_LOCKED_FALSE;
}
- curve25519_key privileged_private = {0};
- if (secret_key_tropic_pairing_privileged(privileged_private) != sectrue) {
- cli_error(cli, CLI_ERROR,
- "`secret_key_tropic_pairing_privileged()` failed.");
- locked_status = TROPIC_LOCKED_ERROR;
- goto cleanup;
- }
- curve25519_key privileged_public = {0};
- curve25519_scalarmult_basepoint(privileged_public, privileged_private);
-
- ret = tropic_start_custom_session(tropic_public,
- TROPIC_PRIVILEGED_PAIRING_KEY_SLOT,
- privileged_private, privileged_public);
+ ret = tropic_custom_session_start(TROPIC_PRIVILEGED_PAIRING_KEY_SLOT);
if (ret != LT_OK) {
- // The Tropic pairing process was initiated but probably failed midway.
- locked_status = TROPIC_LOCKED_FALSE;
- goto cleanup;
+ if (ret == LT_L2_HSK_ERR) {
+ // The Tropic pairing process was initiated but probably failed midway.
+ return TROPIC_LOCKED_FALSE;
+ } else {
+ return TROPIC_LOCKED_ERROR;
+ }
}
struct lt_config_t configuration_read = {0};
@@ -665,35 +648,27 @@ tropic_locked_status get_tropic_locked_status(cli_t* cli) {
if (ret != LT_OK) {
cli_error(cli, CLI_ERROR, "`lt_read_whole_R_config()` failed with error %d",
ret);
- locked_status = TROPIC_LOCKED_ERROR;
- goto cleanup;
+ return TROPIC_LOCKED_ERROR;
}
if (memcmp(&reversible_configuration, (uint8_t*)&configuration_read,
sizeof(reversible_configuration)) != 0) {
- locked_status = TROPIC_LOCKED_FALSE;
- goto cleanup;
+ return TROPIC_LOCKED_FALSE;
}
ret = lt_read_whole_I_config(tropic_handle, &configuration_read);
if (ret != LT_OK) {
cli_error(cli, CLI_ERROR, "`lt_read_whole_I_config()` failed with error %d",
ret);
- locked_status = TROPIC_LOCKED_ERROR;
- goto cleanup;
+ return TROPIC_LOCKED_ERROR;
}
if (memcmp(&irreversible_configuration, (uint8_t*)&configuration_read,
sizeof(irreversible_configuration)) != 0) {
- locked_status = TROPIC_LOCKED_FALSE;
- goto cleanup;
+ return TROPIC_LOCKED_FALSE;
}
- locked_status = TROPIC_LOCKED_TRUE;
-
-cleanup:
- memzero(privileged_private, sizeof(privileged_private));
- return locked_status;
+ return TROPIC_LOCKED_TRUE;
}
static lt_ret_t pairing_key_write(lt_handle_t* handle, pkey_index_t slot,
@@ -727,64 +702,31 @@ static bool tropic_is_paired(cli_t* cli) {
lt_handle_t* tropic_handle = tropic_get_handle();
lt_ret_t ret = LT_FAIL;
- // Retrieve the tropic public key.
- curve25519_key tropic_public = {0};
- if (secret_key_tropic_public(tropic_public) != sectrue) {
+ // Try to establish a session using the unprivileged key pair.
+ ret = tropic_custom_session_start(TROPIC_UNPRIVILEGED_PAIRING_KEY_SLOT);
+ if (ret != LT_OK) {
if (cli != NULL) {
- cli_error(cli, CLI_ERROR, "`secret_key_tropic_public()` failed.");
+ cli_error(
+ cli, CLI_ERROR,
+ "`tropic_custom_session_start()` for unprivileged key failed with "
+ "error %d",
+ ret);
}
goto cleanup;
}
- // Retrieve the unprivileged key pair and try to establish a session using it.
- curve25519_key unprivileged_private = {0};
- if (secret_key_tropic_pairing_unprivileged(unprivileged_private) != sectrue) {
- if (cli != NULL) {
- cli_error(cli, CLI_ERROR,
- "`secret_key_tropic_pairing_unprivileged()` failed.");
- }
- goto cleanup;
- }
- curve25519_key unprivileged_public = {0};
- curve25519_scalarmult_basepoint(unprivileged_public, unprivileged_private);
- ret = tropic_start_custom_session(tropic_public,
- TROPIC_UNPRIVILEGED_PAIRING_KEY_SLOT,
- unprivileged_private, unprivileged_public);
+ // Try to establish a session using the privileged key pair.
+ ret = tropic_custom_session_start(TROPIC_PRIVILEGED_PAIRING_KEY_SLOT);
if (ret != LT_OK) {
if (cli != NULL) {
cli_error(cli, CLI_ERROR,
- "`tropic_lt_session_start()` for unprivileged key failed with "
- "error %d",
+ "`tropic_custom_session_start()` for privileged key failed "
+ "with error %d",
ret);
}
goto cleanup;
}
- // Retrieve the privileged key pair and try to establish a session using it.
- curve25519_key privileged_private = {0};
- if (secret_key_tropic_pairing_privileged(privileged_private) != sectrue) {
- if (cli != NULL) {
- cli_error(cli, CLI_ERROR,
- "`secret_key_tropic_pairing_privileged()` failed.");
- }
- goto cleanup;
- }
- curve25519_key privileged_public = {0};
- curve25519_scalarmult_basepoint(privileged_public, privileged_private);
-
- ret = tropic_start_custom_session(tropic_public,
- TROPIC_PRIVILEGED_PAIRING_KEY_SLOT,
- privileged_private, privileged_public);
- if (ret != LT_OK) {
- if (cli != NULL) {
- cli_error(
- cli, CLI_ERROR,
- "`tropic_lt_session_start()` for privileged key failed with error %d",
- ret);
- }
- goto cleanup;
- }
-
// Read the factory pairing key to ensure it is invalidated.
curve25519_key public_read = {0};
ret = lt_pairing_key_read(tropic_handle, public_read,
@@ -815,30 +757,9 @@ static bool tropic_is_paired(cli_t* cli) {
is_paired = true;
cleanup:
- memzero(privileged_private, sizeof(privileged_private));
- memzero(unprivileged_private, sizeof(unprivileged_private));
-
return is_paired;
}
-bool prodtest_tropic_factory_session_start(lt_handle_t* tropic_handle) {
- curve25519_key factory_private = {0};
- tropic_get_factory_privkey(factory_private);
-
- curve25519_key factory_public = {0};
- curve25519_scalarmult_basepoint(factory_public, factory_private);
-
- const curve25519_key* tropic_public = prodtest_tropic_get_tropic_public();
- if (tropic_public == NULL) {
- return false;
- }
-
- // Try to establish a session using the factory pairing key.
- return LT_OK == tropic_start_custom_session(*tropic_public,
- TROPIC_FACTORY_PAIRING_KEY_SLOT,
- factory_private, factory_public);
-}
-
static void prodtest_tropic_pair(cli_t* cli) {
// If this functions successfully completes, it is ensured that:
// * The public tropic key is written to MCU's flash.
@@ -918,7 +839,7 @@ static void prodtest_tropic_pair(cli_t* cli) {
curve25519_key privileged_public = {0};
curve25519_scalarmult_basepoint(privileged_public, privileged_private);
- if (prodtest_tropic_factory_session_start(tropic_handle)) {
+ if (tropic_custom_session_start(TROPIC_FACTORY_PAIRING_KEY_SLOT) == LT_OK) {
// Write the privileged pairing key to the tropic's pairing key slot if it
// has not been written yet.
lt_ret_t ret = pairing_key_write(
@@ -1120,6 +1041,13 @@ static void prodtest_tropic_handshake(cli_t* cli) {
memcpy(&l2_state.buff, input, request_length);
+ ret = tropic_session_invalidate();
+ if (ret != LT_OK) {
+ cli_error(cli, CLI_ERROR,
+ "`tropic_session_invalidate()` failed with error %d.", ret);
+ return;
+ }
+
ret = lt_l2_send(&l2_state);
if (ret != LT_OK) {
cli_error(cli, CLI_ERROR, "`lt_l2_send()` failed with error %d.", ret);
@@ -1254,90 +1182,69 @@ static void prodtest_tropic_lock(cli_t* cli) {
}
tropic_handshake_state = TROPIC_HANDSHAKE_STATE_0;
-
- lt_handle_t* tropic_handle = tropic_get_handle();
lt_ret_t ret = LT_FAIL;
- curve25519_key tropic_public = {0};
- if (secret_key_tropic_public(tropic_public) != sectrue) {
- cli_error(cli, CLI_ERROR, "`secret_key_tropic_public()` failed.");
- goto cleanup;
- }
-
- curve25519_key privileged_private = {0};
- if (secret_key_tropic_pairing_privileged(privileged_private) != sectrue) {
- cli_error(cli, CLI_ERROR,
- "`secret_key_tropic_pairing_privileged()` failed.");
- goto cleanup;
- }
- curve25519_key privileged_public = {0};
- curve25519_scalarmult_basepoint(privileged_public, privileged_private);
-
- ret = tropic_start_custom_session(tropic_public,
- TROPIC_PRIVILEGED_PAIRING_KEY_SLOT,
- privileged_private, privileged_public);
+ ret = tropic_custom_session_start(TROPIC_PRIVILEGED_PAIRING_KEY_SLOT);
if (ret != LT_OK) {
- cli_error(
- cli, CLI_ERROR,
- "`tropic_lt_session_start()` for privileged key failed with error %d",
- ret);
- goto cleanup;
+ cli_error(cli, CLI_ERROR,
+ "`tropic_custom_session_start()` for privileged key failed with "
+ "error %d",
+ ret);
+ return;
}
struct lt_config_t configuration_read = {0};
+ lt_handle_t* tropic_handle = tropic_get_handle();
ret = lt_r_config_erase(tropic_handle);
if (ret != LT_OK) {
cli_error(cli, CLI_ERROR, "`lt_r_config_erase()` failed with error %d",
ret);
- goto cleanup;
+ return;
}
ret = lt_write_whole_R_config(tropic_handle, &reversible_configuration);
if (ret != LT_OK) {
cli_error(cli, CLI_ERROR,
"`lt_write_whole_R_config()` failed with error %d", ret);
- goto cleanup;
+ return;
}
ret = lt_read_whole_R_config(tropic_handle, &configuration_read);
if (ret != LT_OK) {
cli_error(cli, CLI_ERROR, "`lt_read_whole_R_config()` failed with error %d",
ret);
- goto cleanup;
+ return;
}
if (memcmp(&reversible_configuration, (uint8_t*)&configuration_read,
sizeof(reversible_configuration)) != 0) {
cli_error(cli, CLI_ERROR, "Reversible configuration mismatch after write.");
- goto cleanup;
+ return;
}
ret = lt_write_whole_I_config(tropic_handle, &irreversible_configuration);
if (ret != LT_OK) {
cli_error(cli, CLI_ERROR,
"`lt_write_whole_I_config()` failed with error %d", ret);
- goto cleanup;
+ return;
}
ret = lt_read_whole_I_config(tropic_handle, &configuration_read);
if (ret != LT_OK) {
cli_error(cli, CLI_ERROR, "`lt_read_whole_I_config()` failed with error %d",
ret);
- goto cleanup;
+ return;
}
if (memcmp(&irreversible_configuration, (uint8_t*)&configuration_read,
sizeof(irreversible_configuration)) != 0) {
cli_error(cli, CLI_ERROR,
"Irreversible configuration mismatch after write.");
- goto cleanup;
+ return;
}
cli_ok(cli, "");
-
-cleanup:
- memzero(privileged_private, sizeof(privileged_private));
}
static lt_ret_t data_write(lt_handle_t* h, uint16_t first_slot,
@@ -1474,65 +1381,44 @@ static void cert_write(cli_t* cli, uint16_t first_slot, uint16_t slots_count) {
tropic_handshake_state = TROPIC_HANDSHAKE_STATE_0;
- uint8_t certificate_read[R_MEM_DATA_SIZE_MAX * slots_count];
-
- lt_handle_t* tropic_handle = tropic_get_handle();
- lt_ret_t ret = LT_FAIL;
-
- curve25519_key tropic_public = {0};
- if (secret_key_tropic_public(tropic_public) != sectrue) {
- cli_error(cli, CLI_ERROR, "`secret_key_tropic_public()` failed.");
- goto cleanup;
- }
-
- curve25519_key privileged_private = {0};
- if (secret_key_tropic_pairing_privileged(privileged_private) != sectrue) {
- cli_error(cli, CLI_ERROR,
- "`secret_key_tropic_pairing_privileged()` failed.");
- goto cleanup;
- }
- curve25519_key privileged_public = {0};
- curve25519_scalarmult_basepoint(privileged_public, privileged_private);
-
- ret = tropic_start_custom_session(tropic_public,
- TROPIC_PRIVILEGED_PAIRING_KEY_SLOT,
- privileged_private, privileged_public);
+ lt_ret_t ret =
+ tropic_custom_session_start(TROPIC_PRIVILEGED_PAIRING_KEY_SLOT);
if (ret != LT_OK) {
- cli_error(
- cli, CLI_ERROR,
- "`tropic_lt_session_start()` for privileged key failed with error %d",
- ret);
- goto cleanup;
+ cli_error(cli, CLI_ERROR,
+ "`tropic_custom_session_start()` for privileged key failed with "
+ "error %d",
+ ret);
+ return;
}
if (first_slot == TROPIC_DEVICE_CERT_FIRST_SLOT &&
!check_device_cert_chain(cli, certificate, certificate_length)) {
// Error returned by check_device_cert_chain().
- goto cleanup;
+ return;
}
+ lt_handle_t* tropic_handle = tropic_get_handle();
+
ret = data_write(tropic_handle, first_slot, slots_count, certificate,
certificate_length);
if (ret != LT_OK) {
cli_error(cli, CLI_ERROR, "Unable to write certificate");
- goto cleanup;
+ return;
}
size_t certificate_read_length = 0;
+ uint8_t certificate_read[R_MEM_DATA_SIZE_MAX * slots_count];
ret = data_read(tropic_handle, first_slot, slots_count, certificate_read,
sizeof(certificate_read), &certificate_read_length);
if (ret != LT_OK || certificate_read_length != certificate_length ||
memcmp(certificate, certificate_read, certificate_length) != 0) {
cli_error(cli, CLI_ERROR, "Unable to read certificate");
- goto cleanup;
+ return;
}
// TODO: call `check_device_cert_chain()` for FIDO certificate
cli_ok(cli, "");
-
-cleanup:
- memzero(privileged_private, sizeof(privileged_private));
}
static void cert_read(cli_t* cli, uint16_t first_slot, uint16_t slots_count) {
@@ -1542,50 +1428,27 @@ static void cert_read(cli_t* cli, uint16_t first_slot, uint16_t slots_count) {
}
tropic_handshake_state = TROPIC_HANDSHAKE_STATE_0;
-
- lt_handle_t* tropic_handle = tropic_get_handle();
-
- uint8_t certificate[R_MEM_DATA_SIZE_MAX * slots_count];
lt_ret_t ret = LT_FAIL;
- curve25519_key tropic_public = {0};
- if (secret_key_tropic_public(tropic_public) != sectrue) {
- cli_error(cli, CLI_ERROR, "`secret_key_tropic_public()` failed.");
- goto cleanup;
- }
-
- curve25519_key privileged_private = {0};
- if (secret_key_tropic_pairing_privileged(privileged_private) != sectrue) {
- cli_error(cli, CLI_ERROR,
- "`secret_key_tropic_pairing_privileged()` failed.");
- goto cleanup;
- }
- curve25519_key privileged_public = {0};
- curve25519_scalarmult_basepoint(privileged_public, privileged_private);
-
- ret = tropic_start_custom_session(tropic_public,
- TROPIC_PRIVILEGED_PAIRING_KEY_SLOT,
- privileged_private, privileged_public);
+ ret = tropic_custom_session_start(TROPIC_PRIVILEGED_PAIRING_KEY_SLOT);
if (ret != LT_OK) {
- cli_error(
- cli, CLI_ERROR,
- "`tropic_lt_session_start()` for privileged key failed with error %d",
- ret);
- goto cleanup;
+ cli_error(cli, CLI_ERROR,
+ "`tropic_custom_session_start()` for privileged key failed with "
+ "error %d",
+ ret);
+ return;
}
+ uint8_t certificate[R_MEM_DATA_SIZE_MAX * slots_count];
size_t certificate_length = 0;
- ret = data_read(tropic_handle, first_slot, slots_count, certificate,
+ 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");
- goto cleanup;
+ return;
}
cli_ok_hexdata(cli, certificate, certificate_length);
-
-cleanup:
- memzero(privileged_private, sizeof(privileged_private));
}
static void prodtest_tropic_certfido_write(cli_t* cli) {
diff --git a/core/embed/projects/prodtest/cmd/prodtest_tropic.h b/core/embed/projects/prodtest/cmd/prodtest_tropic.h
index f465da5fd..d803fe229 100644
--- a/core/embed/projects/prodtest/cmd/prodtest_tropic.h
+++ b/core/embed/projects/prodtest/cmd/prodtest_tropic.h
@@ -30,5 +30,3 @@ typedef enum {
} tropic_locked_status;
tropic_locked_status get_tropic_locked_status(cli_t* cli);
-
-bool prodtest_tropic_factory_session_start(lt_handle_t* tropic_handle);
diff --git a/core/embed/sec/tropic/inc/sec/tropic.h b/core/embed/sec/tropic/inc/sec/tropic.h
index 26da36402..6dcb2ee53 100644
--- a/core/embed/sec/tropic/inc/sec/tropic.h
+++ b/core/embed/sec/tropic/inc/sec/tropic.h
@@ -73,10 +73,9 @@ void tropic_deinit(void);
#include "libtropic.h"
lt_handle_t* tropic_get_handle(void);
-lt_ret_t tropic_start_custom_session(const uint8_t* stpub,
- const pkey_index_t pkey_index,
- const uint8_t* shipriv,
- const uint8_t* shipub);
+lt_ret_t tropic_custom_session_start(pkey_index_t pairing_key_index);
+
+lt_ret_t tropic_session_invalidate(void);
bool tropic_wait_for_ready(void);
#endif
diff --git a/core/embed/sec/tropic/tropic.c b/core/embed/sec/tropic/tropic.c
index f2fdaa9bd..4271307a5 100644
--- a/core/embed/sec/tropic/tropic.c
+++ b/core/embed/sec/tropic/tropic.c
@@ -47,7 +47,8 @@ typedef struct {
bool initialized;
bool session_started;
bool chip_ready;
- pkey_index_t pairing_key_index;
+ pkey_index_t pairing_key_index; // This field is valid only if
+ // session_started is true.
lt_handle_t handle;
#ifdef TREZOR_EMULATOR
lt_dev_unix_tcp_t device;
@@ -85,30 +86,24 @@ bool tropic_wait_for_ready(void) {
return false;
}
-lt_ret_t tropic_start_custom_session(const uint8_t *stpub,
- const pkey_index_t pkey_index,
- const uint8_t *shipriv,
- const uint8_t *shipub) {
+lt_ret_t tropic_session_invalidate(void) {
+ lt_ret_t ret = lt_session_abort(&g_tropic_driver.handle);
+ if (ret != LT_OK) {
+ return ret;
+ }
+ g_tropic_driver.session_started = false;
+ return LT_OK;
+}
+
+lt_ret_t tropic_custom_session_start(pkey_index_t pairing_key_index) {
tropic_driver_t *drv = &g_tropic_driver;
if (!drv->initialized) {
return LT_FAIL;
}
- tropic_wait_for_ready();
-
- lt_ret_t ret =
- lt_session_start(&drv->handle, stpub, pkey_index, shipriv, shipub);
- drv->pairing_key_index = pkey_index;
- drv->session_started = (ret == LT_OK);
-
- return ret;
-}
-
-static bool session_start(tropic_driver_t *drv,
- pkey_index_t pairing_key_index) {
- bool ret = false;
+ lt_ret_t ret = LT_FAIL;
curve25519_key trezor_private = {0};
switch (pairing_key_index) {
@@ -134,20 +129,22 @@ static bool session_start(tropic_driver_t *drv,
curve25519_key tropic_public = {0};
if (secret_key_tropic_public(tropic_public) != sectrue) {
-#if !PRODUCTION
- if (!tropic_get_tropic_pubkey(&drv->handle, tropic_public))
+#if !PRODUCTION || defined(TREZOR_PRODTEST)
+ if (pairing_key_index != TROPIC_FACTORY_PAIRING_KEY_SLOT ||
+ !tropic_get_tropic_pubkey(&drv->handle, tropic_public))
#endif
{
goto cleanup;
}
}
- if (tropic_start_custom_session(tropic_public, pairing_key_index,
- trezor_private, trezor_public) != LT_OK) {
- goto cleanup;
- }
+ tropic_wait_for_ready();
- ret = true;
+ ret = lt_session_start(&drv->handle, tropic_public, pairing_key_index,
+ trezor_private, trezor_public);
+
+ drv->session_started = (ret == LT_OK);
+ drv->pairing_key_index = pairing_key_index;
cleanup:
memzero(trezor_private, sizeof(trezor_private));
@@ -166,18 +163,18 @@ bool tropic_session_start(void) {
return true;
}
- tropic_wait_for_ready();
-
#ifndef TREZOR_EMULATOR
- if (session_start(drv, TROPIC_PRIVILEGED_PAIRING_KEY_SLOT)) {
+ if (tropic_custom_session_start(TROPIC_PRIVILEGED_PAIRING_KEY_SLOT) ==
+ LT_OK) {
return true;
}
- if (session_start(drv, TROPIC_UNPRIVILEGED_PAIRING_KEY_SLOT)) {
+ if (tropic_custom_session_start(TROPIC_UNPRIVILEGED_PAIRING_KEY_SLOT) ==
+ LT_OK) {
return true;
}
#endif
#if !PRODUCTION
- if (session_start(drv, TROPIC_FACTORY_PAIRING_KEY_SLOT)) {
+ if (tropic_custom_session_start(TROPIC_FACTORY_PAIRING_KEY_SLOT) == LT_OK) {
return true;
}
#endif
Why this scored 33/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.