mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-16 10:20:57 +00:00
fixup! feat(core): Implement entropy check workflow in ResetDevice.
This commit is contained in:
parent
dfb6210e7d
commit
0ca958c6f1
@ -105,7 +105,7 @@ async def reset_device(msg: ResetDevice) -> Success:
|
||||
# in BIP-39 we store mnemonic string instead of the secret
|
||||
secret = bip39.from_data(secret).encode()
|
||||
|
||||
if not msg.entropy_check or not await _entropy_check(secret):
|
||||
if not msg.entropy_check or await _entropy_check(secret):
|
||||
break
|
||||
|
||||
prev_int_entropy = int_entropy
|
||||
@ -143,8 +143,8 @@ async def reset_device(msg: ResetDevice) -> Success:
|
||||
|
||||
|
||||
async def _entropy_check(secret: bytes) -> bool:
|
||||
"""Returns True to indicate that entropy check loop should continue."""
|
||||
from trezor.messages import GetPublicKey, Success
|
||||
"""Returns True to indicate that entropy check loop should end."""
|
||||
from trezor.messages import EntropyCheckContinue, EntropyCheckReady, GetPublicKey
|
||||
from trezor.wire.context import call_any
|
||||
|
||||
from apps.bitcoin.get_public_key import get_public_key
|
||||
@ -154,21 +154,17 @@ async def _entropy_check(secret: bytes) -> bool:
|
||||
|
||||
seed = get_seed(mnemonic_secret=secret)
|
||||
|
||||
msg = Success()
|
||||
msg = EntropyCheckReady()
|
||||
while True:
|
||||
req = await call_any(
|
||||
msg,
|
||||
MessageType.EntropyCheckContinue,
|
||||
MessageType.GetPublicKey,
|
||||
MessageType.ResetDeviceContinue,
|
||||
MessageType.ResetDeviceFinish,
|
||||
)
|
||||
assert req.MESSAGE_WIRE_TYPE is not None
|
||||
|
||||
if req.MESSAGE_WIRE_TYPE == MessageType.ResetDeviceContinue:
|
||||
return True
|
||||
|
||||
if req.MESSAGE_WIRE_TYPE == MessageType.ResetDeviceFinish:
|
||||
return False
|
||||
if EntropyCheckContinue.is_type_of(req):
|
||||
return req.finish
|
||||
|
||||
assert GetPublicKey.is_type_of(req)
|
||||
req.show_display = False
|
||||
|
@ -289,18 +289,18 @@ The host chooses a small random number *n*, e.g. from 1 to 5, and proceeds as fo
|
||||
1. H -> T `ResetDevice` (Host specifies strength, backup type, etc.)
|
||||
2. H <- T `EntropyRequest` (Trezor commits to an internal entropy value.)
|
||||
3. H -> T `EntropyAck` (Host provides external entropy.)
|
||||
4. H <- T `Success` (Trezor stores the seed in storage cache.)
|
||||
4. H <- T `EntropyCheckReady` (Trezor stores the seed in storage cache.)
|
||||
5. Host obtains the XPUBs for several accounts that the user intends to use:
|
||||
1. H -> T `GetPublicKey`
|
||||
2. H <- T `PublicKey`
|
||||
6. If this step was executed less than *n* times, then:
|
||||
1. H -> T `ResetDeviceContinue` (Host instructs Trezor to prove seed correctness.)
|
||||
1. H -> T `EntropyCheckContinue(finish=False)` (Host instructs Trezor to prove seed correctness.)
|
||||
2. H <- T `EntropyRequest` (Trezor reveals previous internal entropy and commits to a new internal entropy value.)
|
||||
3. The host verifies that the entropy commitment is valid, derives the seed and checks that it produces the same XPUBs as Trezor provided in step 5.
|
||||
4. Go to step 3.
|
||||
7. Host instructs trezor to store the current seed in flash memory.
|
||||
1. H <- T `ResetDeviceFinish`
|
||||
2. H -> T `Success`
|
||||
1. H -> T `EntropyCheckContinue(finish=True)`
|
||||
2. H <- T `Success`
|
||||
|
||||
The host should record the XPUBs that it received in the last repetition of
|
||||
step 5. Every time the user connects the Trezor to the host, it should verify
|
||||
|
Loading…
Reference in New Issue
Block a user