2019-09-10 09:52:59 +00:00
|
|
|
import itertools
|
|
|
|
|
2019-08-12 10:27:02 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from trezorlib import btc, device, messages
|
|
|
|
from trezorlib.messages import ButtonRequestType as B, ResetDeviceBackupType
|
|
|
|
from trezorlib.tools import parse_path
|
|
|
|
|
2019-09-10 09:24:57 +00:00
|
|
|
from .common import click_through, read_and_confirm_mnemonic, recovery_enter_shares
|
2019-09-02 08:20:51 +00:00
|
|
|
|
2019-08-12 10:27:02 +00:00
|
|
|
|
|
|
|
@pytest.mark.skip_t1
|
2019-08-26 16:26:57 +00:00
|
|
|
@pytest.mark.setup_client(uninitialized=True)
|
2019-08-12 10:27:02 +00:00
|
|
|
def test_reset_recovery(client):
|
|
|
|
mnemonics = reset(client)
|
|
|
|
address_before = btc.get_address(client, "Bitcoin", parse_path("44'/0'/0'/0/0"))
|
|
|
|
|
2019-09-10 09:52:59 +00:00
|
|
|
for share_subset in itertools.combinations(mnemonics, 3):
|
2019-08-12 10:27:02 +00:00
|
|
|
device.wipe(client)
|
2019-09-10 09:52:59 +00:00
|
|
|
selected_mnemonics = share_subset
|
2019-08-12 10:27:02 +00:00
|
|
|
recover(client, selected_mnemonics)
|
|
|
|
address_after = btc.get_address(client, "Bitcoin", parse_path("44'/0'/0'/0/0"))
|
|
|
|
assert address_before == address_after
|
|
|
|
|
|
|
|
|
|
|
|
def reset(client, strength=128):
|
|
|
|
all_mnemonics = []
|
2019-09-10 09:24:57 +00:00
|
|
|
# per SLIP-39: strength in bits, rounded up to nearest multiple of 10, plus 70 bits
|
|
|
|
# of metadata, split into 10-bit words
|
|
|
|
word_count = ((strength + 9) // 10) + 7
|
2019-08-12 10:27:02 +00:00
|
|
|
|
|
|
|
def input_flow():
|
2019-09-10 09:24:57 +00:00
|
|
|
# 1. Confirm Reset
|
|
|
|
# 2. Backup your seed
|
|
|
|
# 3. Confirm warning
|
|
|
|
# 4. shares info
|
|
|
|
# 5. Set & Confirm number of shares
|
|
|
|
# 6. threshold info
|
|
|
|
# 7. Set & confirm threshold value
|
|
|
|
# 8. Confirm show seeds
|
|
|
|
yield from click_through(client.debug, screens=8, code=B.ResetDevice)
|
2019-08-12 10:27:02 +00:00
|
|
|
|
|
|
|
# show & confirm shares
|
|
|
|
for h in range(5):
|
2019-09-10 09:24:57 +00:00
|
|
|
# mnemonic phrases
|
2019-08-12 10:27:02 +00:00
|
|
|
btn_code = yield
|
|
|
|
assert btn_code == B.Other
|
2019-09-10 09:24:57 +00:00
|
|
|
mnemonic = read_and_confirm_mnemonic(client.debug, words=word_count)
|
|
|
|
all_mnemonics.append(mnemonic)
|
2019-08-12 10:27:02 +00:00
|
|
|
|
|
|
|
# Confirm continue to next share
|
|
|
|
btn_code = yield
|
|
|
|
assert btn_code == B.Success
|
|
|
|
client.debug.press_yes()
|
|
|
|
|
|
|
|
# safety warning
|
|
|
|
btn_code = yield
|
|
|
|
assert btn_code == B.Success
|
|
|
|
client.debug.press_yes()
|
|
|
|
|
|
|
|
with client:
|
|
|
|
client.set_expected_responses(
|
|
|
|
[
|
|
|
|
messages.ButtonRequest(code=B.ResetDevice),
|
|
|
|
messages.EntropyRequest(),
|
|
|
|
messages.ButtonRequest(code=B.ResetDevice),
|
|
|
|
messages.ButtonRequest(code=B.ResetDevice),
|
|
|
|
messages.ButtonRequest(code=B.ResetDevice),
|
|
|
|
messages.ButtonRequest(code=B.ResetDevice),
|
|
|
|
messages.ButtonRequest(code=B.ResetDevice),
|
|
|
|
messages.ButtonRequest(code=B.ResetDevice),
|
|
|
|
messages.ButtonRequest(code=B.ResetDevice),
|
|
|
|
messages.ButtonRequest(code=B.Other),
|
|
|
|
messages.ButtonRequest(code=B.Success),
|
|
|
|
messages.ButtonRequest(code=B.Other),
|
|
|
|
messages.ButtonRequest(code=B.Success),
|
|
|
|
messages.ButtonRequest(code=B.Other),
|
|
|
|
messages.ButtonRequest(code=B.Success),
|
|
|
|
messages.ButtonRequest(code=B.Other),
|
|
|
|
messages.ButtonRequest(code=B.Success),
|
|
|
|
messages.ButtonRequest(code=B.Other),
|
|
|
|
messages.ButtonRequest(code=B.Success),
|
|
|
|
messages.ButtonRequest(code=B.Success),
|
|
|
|
messages.Success(),
|
|
|
|
messages.Features(),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
client.set_input_flow(input_flow)
|
|
|
|
|
|
|
|
# No PIN, no passphrase, don't display random
|
|
|
|
device.reset(
|
|
|
|
client,
|
|
|
|
display_random=False,
|
|
|
|
strength=strength,
|
|
|
|
passphrase_protection=False,
|
|
|
|
pin_protection=False,
|
|
|
|
label="test",
|
|
|
|
language="english",
|
|
|
|
backup_type=ResetDeviceBackupType.Slip39_Single_Group,
|
|
|
|
)
|
2019-09-10 09:24:57 +00:00
|
|
|
|
2019-08-12 10:27:02 +00:00
|
|
|
client.set_input_flow(None)
|
|
|
|
|
|
|
|
# Check if device is properly initialized
|
|
|
|
assert client.features.initialized is True
|
|
|
|
assert client.features.needs_backup is False
|
|
|
|
assert client.features.pin_protection is False
|
|
|
|
assert client.features.passphrase_protection is False
|
|
|
|
|
|
|
|
return all_mnemonics
|
|
|
|
|
|
|
|
|
|
|
|
def recover(client, shares):
|
|
|
|
debug = client.debug
|
|
|
|
|
|
|
|
def input_flow():
|
|
|
|
yield # Confirm Recovery
|
|
|
|
debug.press_yes()
|
|
|
|
# run recovery flow
|
2019-09-02 08:20:51 +00:00
|
|
|
yield from recovery_enter_shares(debug, shares)
|
2019-08-12 10:27:02 +00:00
|
|
|
|
|
|
|
with client:
|
|
|
|
client.set_input_flow(input_flow)
|
|
|
|
ret = device.recover(client, pin_protection=False, label="label")
|
|
|
|
|
|
|
|
client.set_input_flow(None)
|
|
|
|
|
|
|
|
# Workflow successfully ended
|
|
|
|
assert ret == messages.Success(message="Device recovered")
|
|
|
|
assert client.features.pin_protection is False
|
|
|
|
assert client.features.passphrase_protection is False
|