Skip to content

Implement tropic provisioning #5525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 19, 2025
Merged

Implement tropic provisioning #5525

merged 4 commits into from
Aug 19, 2025

Conversation

onvej-sl
Copy link
Contributor

No description provided.

@onvej-sl onvej-sl requested a review from andrewkozlik August 11, 2025 14:42
@trezor-bot trezor-bot bot added this to Firmware Aug 11, 2025
@github-project-automation github-project-automation bot moved this to 🔎 Needs review in Firmware Aug 11, 2025
Copy link

github-actions bot commented Aug 11, 2025

en main(all)

model device_test click_test persistence_test
T2T1 test(all) main(all) test(all) main(all) test(all) main(all)
T3B1 test(all) main(all) test(all) main(all) test(all) main(all)
T3T1 test(all) main(all) test(all) main(all) test(all) main(all)
T3W1 test(all) main(all) test(all) main(all) test(all) main(all)

Latest CI run: 17072904578

@onvej-sl onvej-sl force-pushed the onvej-sl/prodtest-tropic branch from ad989b9 to e29ef7b Compare August 11, 2025 15:31
@onvej-sl onvej-sl marked this pull request as ready for review August 11, 2025 15:36
@mmilata mmilata removed their request for review August 11, 2025 16:07
Copy link
Contributor

@andrewkozlik andrewkozlik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review. Still need to look at prodtest_tropic.c.

@onvej-sl onvej-sl requested a review from M-pasta August 13, 2025 11:05
Copy link

@M-pasta M-pasta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prodtest_tropic.c checked

Copy link
Contributor

@andrewkozlik andrewkozlik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review.

Comment on lines 1392 to 1480
lt_handle_t* tropic_handle = tropic_get_handle();
lt_ret_t ret = LT_FAIL;

systick_delay_ms(80);
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 =
lt_session_start(tropic_handle, tropic_public, PRIVILEGED_PAIRING_KEYSLOT,
privileged_private, privileged_public);
if (ret != LT_OK) {
cli_error(cli, CLI_ERROR,
"`lt_session_start()` for privileged key failed with error %d",
ret);
goto cleanup;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is duplicated across cert_write(), read_cert() and twice in is_paired(). We can define a function like this:

static bool tropic_handshake(int key_slot) {
  tropic_handshake_state = TROPIC_HANDSHAKE_STATE_0;

  lt_handle_t* tropic_handle = tropic_get_handle();

  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 private = {0};
  if (key_slot == PRIVILEGED_PAIRING_KEY_SLOT) {
    if (secret_key_tropic_pairing_privileged(private) != sectrue) {
      cli_error(cli, CLI_ERROR,
                "`secret_key_tropic_pairing_privileged()` failed.");
      goto cleanup;
    }
  } else if (key_slot == UNPRIVILEGED_PAIRING_KEY_SLOT) {
    if (secret_key_tropic_pairing_unprivileged(private) != sectrue) {
      cli_error(cli, CLI_ERROR,
                "`secret_key_tropic_pairing_unprivileged()` failed.");
      goto cleanup;
    }
  } else {
    cli_error(cli, CLI_ERROR,
              "Unknown key_slot.");
    goto cleanup;
  }

  curve25519_key public = {0};
  curve25519_scalarmult_basepoint(public, private);

  lt_ret_t ret =
      lt_session_start(tropic_handle, tropic_public, key_slot,
                       private, public);
  if (ret != LT_OK) {
    cli_error(cli, CLI_ERROR,
              "`lt_session_start()` for privileged key failed with error %d",
              ret);
    goto cleanup;
  }

cleanup:
  memzero(private, sizeof(private));
  return ret == LT_OK;  // TODO set ret correctly above
}
  • Maybe we can reuse/replace tropic_init() from embed/sec/tropic/tropic.c? I didn't look closely enough. The error handling would probably complicate things.
  • Probably makes sense to add FACTORY_PAIRING_KEY_SLOT to the if-else, so that it can be used in prodtest_tropic_pair(), again I didn't look close enough.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I don't know how long the handshake takes, but we could optimize this, so that if the handshake is already active we don't repeat it. For example replace TROPIC_HANDSHAKE_STATE_1 with different states for each key:
TROPIC_HANDSHAKE_STATE_FACTORY
TROPIC_HANDSHAKE_STATE_PRIVILEGED
TROPIC_HANDSHAKE_STATE_UNPRIVILEGED
TROPIC_HANDSHAKE_STATE_HSM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you, and I wanted to refactor it exactly as you suggested, but I considered it a low priority.

@onvej-sl onvej-sl mentioned this pull request Aug 14, 2025
@onvej-sl onvej-sl force-pushed the onvej-sl/prodtest-tropic branch from 0723387 to 695cd1a Compare August 18, 2025 12:44
@onvej-sl
Copy link
Contributor Author

I squashed all the fix-up commits, reordered the commits, and changed the commit messages. The diff between the old branch and the new branch is empty.

@onvej-sl onvej-sl force-pushed the onvej-sl/prodtest-tropic branch from 15934d0 to 6099c3a Compare August 18, 2025 13:36
@onvej-sl
Copy link
Contributor Author

I squashed 15934d0 and rebased on top of main, that most notably includes #5542 and #5539.

@onvej-sl
Copy link
Contributor Author

@andrewkozlik Could you please review 01675e0?

Copy link
Contributor

@andrewkozlik andrewkozlik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@onvej-sl onvej-sl force-pushed the onvej-sl/prodtest-tropic branch from 04488d9 to f1bff16 Compare August 19, 2025 14:16
@onvej-sl onvej-sl force-pushed the onvej-sl/prodtest-tropic branch from f1bff16 to 3d04afe Compare August 19, 2025 14:34
@onvej-sl onvej-sl merged commit 7494b61 into main Aug 19, 2025
170 of 172 checks passed
@onvej-sl onvej-sl deleted the onvej-sl/prodtest-tropic branch August 19, 2025 15:27
@github-project-automation github-project-automation bot moved this from 🔎 Needs review to 🤝 Needs QA in Firmware Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🤝 Needs QA
Development

Successfully merging this pull request may close these issues.

3 participants