Skip to content
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

Feat/connect: Entropy check workflow in ResetDevice #15887

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

szymonlesisz
Copy link
Contributor

@szymonlesisz szymonlesisz commented Dec 10, 2024

Description

implementation of entropy check workflow

im using @noble/hashes which looks legit and is widely used by our dependencies already.
we should consider to use it in packages which are woriking with crypto and maybe drop crypto-browserify?

i had some doubts should we use slip39-ts lib (see disclaimer) to get decryped slip-39 secret so i ended up porting 3 functions from our python-shamir-mnemonic repo

TODO:

  • update protobuf after firmware PR is merged
  • set capability version after firmware PR is merged, update comment links do workflow docs
  • e2e tests for node and web? or is it covered by suite-web/suite-desktop tests?

Follow up:

  • store xpubs generated during entropy check and validate them occasionally in suite
  • return meaningful/specific error to suite

Copy link

github-actions bot commented Dec 10, 2024

🚀 Expo preview is ready!

  • Project → trezor-suite-preview
  • Platforms → android, ios
  • Scheme → trezorsuitelite
  • Runtime Version → 21
  • More info

Learn more about 𝝠 Expo Github Action

@szymonlesisz szymonlesisz force-pushed the feat/connect-display_random branch 5 times, most recently from cfdd832 to 89b3054 Compare December 11, 2024 15:16
this.params.entropy_check = false;
}
// Entropy check workflow:
// https://github.com/trezor/trezor-firmware/blob/andrewkozlik/display_random/docs/common/message-workflows.md#entropy-check-workflow
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: update link

@szymonlesisz szymonlesisz force-pushed the feat/connect-display_random branch from 89b3054 to c4ee1cc Compare December 12, 2024 10:54
@szymonlesisz szymonlesisz marked this pull request as ready for review December 12, 2024 10:59
@szymonlesisz szymonlesisz requested review from mroz22 and removed request for mroz22 December 12, 2024 11:00
@szymonlesisz
Copy link
Contributor Author

i guess it was premature excitement regarding @noble/hashes.

it takes ~8sec. to perform @noble/hashes/pbkdf2 in the web build :(

i'm fallbacking to WebCrypto available in node.js and web (takes ~300ms to calculate)

xpubs,
});
if (res.error) {
throw new Error(res.error);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: return specific error to suite

return response.message;
if (this.params.entropy_check && this.device.unavailableCapabilities['entropyCheck']) {
// entropy check requested but not supported by the firmware
this.params.entropy_check = false;
Copy link
Contributor

@onvej-sl onvej-sl Dec 13, 2024

Choose a reason for hiding this comment

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

From a security perspective, if the firmware does not support the entropy check, we should display the same error message as we would if the entropy check failed.

The reason is that a counterfeit trezor could bypass the entropy check by pretending not to support it, that is the trezor can present itself as having a lower firmware version than it actually does. However, we can instruct the user to update the firmware before generating their seed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this feature needs to be backward compatible with firmwares which does not support it for example afaik T1 will not be supported.
i need to rely on something to make the decision whether ResetDeviceContinue will be sent or not.
following your example counterfeit trezor could bypass this check by pretending that its T1 model.

I think suite in the first onboarding step does FW version check (and asks you to update) then in the next step you create a seed.

We were discussing this version check with @andrewkozlik

Comment on lines +104 to +105
BackupType.Slip39_Basic,
BackupType.Slip39_Advanced,
Copy link
Contributor

Choose a reason for hiding this comment

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

The implementation of slip39 in this file assumes that the backup is extendable, meaning that using a non-extendable backup will likely result in the "verifyEntropy xpub mismatch" error.

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 did it 1:1 with python-trezor implementation, which assumes that as well:
https://github.com/trezor/trezor-firmware/blob/ce803a5452c5d12eb7b026fa2c20b521957fb8c8/python/src/trezorlib/device.py#L268

seed = shamir_mnemonic.cipher.decrypt(
            secret, b"", iteration_exponent=1, identifier=0, extendable=True
        )

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough.

However, I think both implementations should raise an exception in this case. Nonetheless, this is not a security issue.


return currentData;
}

async run() {
Copy link
Contributor

Choose a reason for hiding this comment

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

If the entropy check fails, a small error message is displayed to the user and the user can continue with the onboarding process. We should warn the user similarly to how they are warned when the authenticity check fails.

I think this has already been discussed in person so I'm adding this comment merely as a reminder.

Copy link
Contributor Author

@szymonlesisz szymonlesisz Dec 13, 2024

Choose a reason for hiding this comment

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

yes, i've left a TODO above: return specific error to suite

btw. when this happens user cannot continue with onboarding as the seed was not created (ResetDeviceFinish was not called)

private async entropyCheck(prevData: EntropyRequestData): Promise<EntropyRequestData> {
const cmd = this.device.getCommands();
const paths = ["m/84'/0'/0'", "m/44'/60'/0'"];
const xpubs: Record<string, string> = {}; // <path, xpub>
Copy link
Contributor

Choose a reason for hiding this comment

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

We should verify that these XPUBs match the XPUBs later used by the suite to derive change and receive addresses.

I think this has already been discussed in person so I'm adding this comment merely as a reminder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, marked as "followup" above

@szymonlesisz szymonlesisz force-pushed the feat/connect-display_random branch from 75c85bd to 407ff07 Compare December 28, 2024 14:52
@szymonlesisz
Copy link
Contributor Author

rebased, resolved conflicts (dependencies, yarn.lock) and implemented recent changes - renamed protobuf fields

@szymonlesisz szymonlesisz force-pushed the feat/connect-display_random branch from 407ff07 to dc41db0 Compare December 28, 2024 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🔎 Needs review
Development

Successfully merging this pull request may close these issues.

2 participants