parent
c307d9f14b
commit
81f5cbef93
@ -0,0 +1,127 @@
|
|||||||
|
# This file is part of the Trezor project.
|
||||||
|
#
|
||||||
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
||||||
|
#
|
||||||
|
# This library is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Lesser General Public License version 3
|
||||||
|
# as published by the Free Software Foundation.
|
||||||
|
#
|
||||||
|
# This library is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the License along with this library.
|
||||||
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
||||||
|
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from trezorlib import device, exceptions, messages
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.skip_t1
|
||||||
|
|
||||||
|
SHARES_20_2of3_2of3_GROUPS = [
|
||||||
|
"gesture negative ceramic leaf device fantasy style ceramic safari keyboard thumb total smug cage plunge aunt favorite lizard intend peanut",
|
||||||
|
"gesture negative acrobat leaf craft sidewalk adorn spider submit bumpy alcohol cards salon making prune decorate smoking image corner method",
|
||||||
|
"gesture negative acrobat lily bishop voting humidity rhyme parcel crunch elephant victim dish mailman triumph agree episode wealthy mayor beam",
|
||||||
|
"gesture negative beard leaf deadline stadium vegan employer armed marathon alien lunar broken edge justice military endorse diet sweater either",
|
||||||
|
"gesture negative beard lily desert belong speak realize explain bolt diet believe response counter medal luck wits glance remove ending",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def enter_all_shares(debug, shares):
|
||||||
|
word_count = len(shares[0].split(" "))
|
||||||
|
|
||||||
|
# Homescreen - proceed to word number selection
|
||||||
|
yield
|
||||||
|
debug.press_yes()
|
||||||
|
# Input word number
|
||||||
|
code = yield
|
||||||
|
assert code == messages.ButtonRequestType.MnemonicWordCount
|
||||||
|
debug.input(str(word_count))
|
||||||
|
# Homescreen - proceed to share entry
|
||||||
|
yield
|
||||||
|
debug.press_yes()
|
||||||
|
# Enter shares
|
||||||
|
for index, share in enumerate(shares):
|
||||||
|
if index >= 1:
|
||||||
|
# confirm remaining shares
|
||||||
|
debug.swipe_down()
|
||||||
|
code = yield
|
||||||
|
assert code == messages.ButtonRequestType.Other
|
||||||
|
debug.press_yes()
|
||||||
|
code = yield
|
||||||
|
assert code == messages.ButtonRequestType.MnemonicInput
|
||||||
|
# Enter mnemonic words
|
||||||
|
for word in share.split(" "):
|
||||||
|
debug.input(word)
|
||||||
|
|
||||||
|
# Confirm share entered
|
||||||
|
yield
|
||||||
|
debug.press_yes()
|
||||||
|
|
||||||
|
# Homescreen - continue
|
||||||
|
# or Homescreen - confirm success
|
||||||
|
yield
|
||||||
|
debug.press_yes()
|
||||||
|
|
||||||
|
|
||||||
|
def test_recover_no_pin_no_passphrase(client):
|
||||||
|
debug = client.debug
|
||||||
|
|
||||||
|
def input_flow():
|
||||||
|
yield # Confirm Recovery
|
||||||
|
debug.press_yes()
|
||||||
|
# Proceed with recovery
|
||||||
|
yield from enter_all_shares(debug, SHARES_20_2of3_2of3_GROUPS)
|
||||||
|
|
||||||
|
with client:
|
||||||
|
client.set_input_flow(input_flow)
|
||||||
|
ret = device.recover(
|
||||||
|
client, pin_protection=False, passphrase_protection=False, label="label"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Workflow succesfully ended
|
||||||
|
assert ret == messages.Success(message="Device recovered")
|
||||||
|
assert client.features.initialized is True
|
||||||
|
assert client.features.pin_protection is False
|
||||||
|
assert client.features.passphrase_protection is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_abort(client):
|
||||||
|
debug = client.debug
|
||||||
|
|
||||||
|
def input_flow():
|
||||||
|
yield # Confirm Recovery
|
||||||
|
debug.press_yes()
|
||||||
|
yield # Homescreen - abort process
|
||||||
|
debug.press_no()
|
||||||
|
yield # Homescreen - confirm abort
|
||||||
|
debug.press_yes()
|
||||||
|
|
||||||
|
with client:
|
||||||
|
client.set_input_flow(input_flow)
|
||||||
|
with pytest.raises(exceptions.Cancelled):
|
||||||
|
device.recover(client, pin_protection=False, label="label")
|
||||||
|
client.init_device()
|
||||||
|
assert client.features.initialized is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_noabort(client):
|
||||||
|
debug = client.debug
|
||||||
|
|
||||||
|
def input_flow():
|
||||||
|
yield # Confirm Recovery
|
||||||
|
debug.press_yes()
|
||||||
|
yield # Homescreen - abort process
|
||||||
|
debug.press_no()
|
||||||
|
yield # Homescreen - go back to process
|
||||||
|
debug.press_no()
|
||||||
|
yield from enter_all_shares(debug, SHARES_20_2of3_2of3_GROUPS)
|
||||||
|
|
||||||
|
with client:
|
||||||
|
client.set_input_flow(input_flow)
|
||||||
|
device.recover(client, pin_protection=False, label="label")
|
||||||
|
client.init_device()
|
||||||
|
assert client.features.initialized is True
|
@ -0,0 +1,112 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
from trezorlib import device, messages
|
||||||
|
from trezorlib.exceptions import TrezorFailure
|
||||||
|
|
||||||
|
from .conftest import setup_client
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.skip_t1
|
||||||
|
|
||||||
|
SHARES_20_2of3_2of3_GROUPS = [
|
||||||
|
"gesture negative ceramic leaf device fantasy style ceramic safari keyboard thumb total smug cage plunge aunt favorite lizard intend peanut",
|
||||||
|
"gesture negative acrobat leaf craft sidewalk adorn spider submit bumpy alcohol cards salon making prune decorate smoking image corner method",
|
||||||
|
"gesture negative acrobat lily bishop voting humidity rhyme parcel crunch elephant victim dish mailman triumph agree episode wealthy mayor beam",
|
||||||
|
"gesture negative beard leaf deadline stadium vegan employer armed marathon alien lunar broken edge justice military endorse diet sweater either",
|
||||||
|
"gesture negative beard lily desert belong speak realize explain bolt diet believe response counter medal luck wits glance remove ending",
|
||||||
|
]
|
||||||
|
|
||||||
|
INVALID_SHARES_20_2of3_2of3_GROUPS = [
|
||||||
|
"chest garlic acrobat leaf diploma thank soul predator grant laundry camera license language likely slim twice amount rich total carve",
|
||||||
|
"chest garlic acrobat lily adequate dwarf genius wolf faint nylon scroll national necklace leader pants literary lift axle watch midst",
|
||||||
|
"chest garlic beard leaf coastal album dramatic learn identify angry dismiss goat plan describe round writing primary surprise sprinkle orbit",
|
||||||
|
"chest garlic beard lily burden pistol retreat pickup emphasis large gesture hand eyebrow season pleasure genuine election skunk champion income",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@setup_client(mnemonic=SHARES_20_2of3_2of3_GROUPS[1:5], passphrase=False)
|
||||||
|
def test_2of3_dryrun(client):
|
||||||
|
debug = client.debug
|
||||||
|
|
||||||
|
def input_flow():
|
||||||
|
yield # Confirm Dryrun
|
||||||
|
debug.press_yes()
|
||||||
|
# run recovery flow
|
||||||
|
yield from enter_all_shares(debug, SHARES_20_2of3_2of3_GROUPS)
|
||||||
|
|
||||||
|
with client:
|
||||||
|
client.set_input_flow(input_flow)
|
||||||
|
ret = device.recover(
|
||||||
|
client,
|
||||||
|
passphrase_protection=False,
|
||||||
|
pin_protection=False,
|
||||||
|
label="label",
|
||||||
|
language="english",
|
||||||
|
dry_run=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Dry run was successful
|
||||||
|
assert ret == messages.Success(
|
||||||
|
message="The seed is valid and matches the one in the device"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@setup_client(mnemonic=SHARES_20_2of3_2of3_GROUPS[1:5], passphrase=True)
|
||||||
|
def test_2of3_invalid_seed_dryrun(client):
|
||||||
|
debug = client.debug
|
||||||
|
|
||||||
|
def input_flow():
|
||||||
|
yield # Confirm Dryrun
|
||||||
|
debug.press_yes()
|
||||||
|
# run recovery flow
|
||||||
|
yield from enter_all_shares(debug, INVALID_SHARES_20_2of3_2of3_GROUPS)
|
||||||
|
|
||||||
|
# test fails because of different seed on device
|
||||||
|
with client, pytest.raises(
|
||||||
|
TrezorFailure, match=r"The seed does not match the one in the device"
|
||||||
|
):
|
||||||
|
client.set_input_flow(input_flow)
|
||||||
|
device.recover(
|
||||||
|
client,
|
||||||
|
passphrase_protection=False,
|
||||||
|
pin_protection=False,
|
||||||
|
label="label",
|
||||||
|
language="english",
|
||||||
|
dry_run=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def enter_all_shares(debug, shares):
|
||||||
|
word_count = len(shares[0].split(" "))
|
||||||
|
|
||||||
|
# Homescreen - proceed to word number selection
|
||||||
|
yield
|
||||||
|
debug.press_yes()
|
||||||
|
# Input word number
|
||||||
|
code = yield
|
||||||
|
assert code == messages.ButtonRequestType.MnemonicWordCount
|
||||||
|
debug.input(str(word_count))
|
||||||
|
# Homescreen - proceed to share entry
|
||||||
|
yield
|
||||||
|
debug.press_yes()
|
||||||
|
# Enter shares
|
||||||
|
for index, share in enumerate(shares):
|
||||||
|
if index >= 1:
|
||||||
|
# confirm remaining shares
|
||||||
|
debug.swipe_down()
|
||||||
|
code = yield
|
||||||
|
assert code == messages.ButtonRequestType.Other
|
||||||
|
debug.press_yes()
|
||||||
|
code = yield
|
||||||
|
assert code == messages.ButtonRequestType.MnemonicInput
|
||||||
|
# Enter mnemonic words
|
||||||
|
for word in share.split(" "):
|
||||||
|
debug.input(word)
|
||||||
|
|
||||||
|
# Confirm share entered
|
||||||
|
yield
|
||||||
|
debug.press_yes()
|
||||||
|
|
||||||
|
# Homescreen - continue
|
||||||
|
# or Homescreen - confirm success
|
||||||
|
yield
|
||||||
|
debug.press_yes()
|
@ -0,0 +1,231 @@
|
|||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import shamir_mnemonic as shamir
|
||||||
|
|
||||||
|
from trezorlib import device, messages as proto
|
||||||
|
from trezorlib.messages import ButtonRequestType as B, ResetDeviceBackupType
|
||||||
|
|
||||||
|
from .common import TrezorTest, generate_entropy
|
||||||
|
|
||||||
|
EXTERNAL_ENTROPY = b"zlutoucky kun upel divoke ody" * 2
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skip_t1
|
||||||
|
class TestMsgResetDeviceT2(TrezorTest):
|
||||||
|
# TODO: test with different options
|
||||||
|
def test_reset_device_supershamir(self):
|
||||||
|
strength = 128
|
||||||
|
member_threshold = 3
|
||||||
|
all_mnemonics = []
|
||||||
|
|
||||||
|
def input_flow():
|
||||||
|
# Confirm Reset
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
self.client.debug.press_yes()
|
||||||
|
|
||||||
|
# Backup your seed
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
self.client.debug.press_yes()
|
||||||
|
|
||||||
|
# Confirm warning
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
self.client.debug.press_yes()
|
||||||
|
|
||||||
|
# shares info
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
self.client.debug.press_yes()
|
||||||
|
|
||||||
|
# Set & Confirm number of groups
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
self.client.debug.press_yes()
|
||||||
|
|
||||||
|
# threshold info
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
self.client.debug.press_yes()
|
||||||
|
|
||||||
|
# Set & confirm group threshold value
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
self.client.debug.press_yes()
|
||||||
|
|
||||||
|
for _ in range(5):
|
||||||
|
# Set & Confirm number of share
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
self.client.debug.press_yes()
|
||||||
|
|
||||||
|
# Set & confirm share threshold value
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
self.client.debug.press_yes()
|
||||||
|
|
||||||
|
# Confirm show seeds
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
self.client.debug.press_yes()
|
||||||
|
|
||||||
|
# show & confirm shares for all groups
|
||||||
|
for g in range(5):
|
||||||
|
for h in range(5):
|
||||||
|
words = []
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.Other
|
||||||
|
|
||||||
|
# mnemonic phrases
|
||||||
|
# 20 word over 6 pages for strength 128, 33 words over 9 pages for strength 256
|
||||||
|
for i in range(6):
|
||||||
|
words.extend(self.client.debug.read_reset_word().split())
|
||||||
|
if i < 5:
|
||||||
|
self.client.debug.swipe_down()
|
||||||
|
else:
|
||||||
|
# last page is confirmation
|
||||||
|
self.client.debug.press_yes()
|
||||||
|
|
||||||
|
# check share
|
||||||
|
for _ in range(3):
|
||||||
|
index = self.client.debug.read_reset_word_pos()
|
||||||
|
self.client.debug.input(words[index])
|
||||||
|
|
||||||
|
all_mnemonics.extend([" ".join(words)])
|
||||||
|
|
||||||
|
# Confirm continue to next share
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.Success
|
||||||
|
self.client.debug.press_yes()
|
||||||
|
|
||||||
|
# safety warning
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.Success
|
||||||
|
self.client.debug.press_yes()
|
||||||
|
|
||||||
|
os_urandom = mock.Mock(return_value=EXTERNAL_ENTROPY)
|
||||||
|
with mock.patch("os.urandom", os_urandom), self.client:
|
||||||
|
self.client.set_expected_responses(
|
||||||
|
[
|
||||||
|
proto.ButtonRequest(code=B.ResetDevice),
|
||||||
|
proto.EntropyRequest(),
|
||||||
|
proto.ButtonRequest(code=B.ResetDevice),
|
||||||
|
proto.ButtonRequest(code=B.ResetDevice),
|
||||||
|
proto.ButtonRequest(code=B.ResetDevice),
|
||||||
|
proto.ButtonRequest(code=B.ResetDevice),
|
||||||
|
proto.ButtonRequest(code=B.ResetDevice),
|
||||||
|
proto.ButtonRequest(code=B.ResetDevice),
|
||||||
|
proto.ButtonRequest(code=B.ResetDevice),
|
||||||
|
proto.ButtonRequest(
|
||||||
|
code=B.ResetDevice
|
||||||
|
), # group #1 shares& thresholds
|
||||||
|
proto.ButtonRequest(code=B.ResetDevice),
|
||||||
|
proto.ButtonRequest(
|
||||||
|
code=B.ResetDevice
|
||||||
|
), # group #2 shares& thresholds
|
||||||
|
proto.ButtonRequest(code=B.ResetDevice),
|
||||||
|
proto.ButtonRequest(
|
||||||
|
code=B.ResetDevice
|
||||||
|
), # group #3 shares& thresholds
|
||||||
|
proto.ButtonRequest(code=B.ResetDevice),
|
||||||
|
proto.ButtonRequest(
|
||||||
|
code=B.ResetDevice
|
||||||
|
), # group #4 shares& thresholds
|
||||||
|
proto.ButtonRequest(code=B.ResetDevice),
|
||||||
|
proto.ButtonRequest(
|
||||||
|
code=B.ResetDevice
|
||||||
|
), # group #5 shares& thresholds
|
||||||
|
proto.ButtonRequest(code=B.ResetDevice),
|
||||||
|
proto.ButtonRequest(code=B.Other), # show seeds
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.ButtonRequest(code=B.Other),
|
||||||
|
proto.ButtonRequest(code=B.Success), # show seeds ends here
|
||||||
|
proto.ButtonRequest(code=B.Success),
|
||||||
|
proto.Success(),
|
||||||
|
proto.Features(),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
self.client.set_input_flow(input_flow)
|
||||||
|
|
||||||
|
# No PIN, no passphrase, don't display random
|
||||||
|
device.reset(
|
||||||
|
self.client,
|
||||||
|
display_random=False,
|
||||||
|
strength=strength,
|
||||||
|
passphrase_protection=False,
|
||||||
|
pin_protection=False,
|
||||||
|
label="test",
|
||||||
|
language="english",
|
||||||
|
backup_type=ResetDeviceBackupType.Slip39_Multiple_Groups,
|
||||||
|
)
|
||||||
|
|
||||||
|
# generate secret locally
|
||||||
|
internal_entropy = self.client.debug.state().reset_entropy
|
||||||
|
secret = generate_entropy(strength, internal_entropy, EXTERNAL_ENTROPY)
|
||||||
|
|
||||||
|
# validate that all combinations will result in the correct master secret
|
||||||
|
validate_mnemonics(all_mnemonics, member_threshold, secret)
|
||||||
|
|
||||||
|
# Check if device is properly initialized
|
||||||
|
assert self.client.features.initialized is True
|
||||||
|
assert self.client.features.needs_backup is False
|
||||||
|
assert self.client.features.pin_protection is False
|
||||||
|
assert self.client.features.passphrase_protection is False
|
||||||
|
|
||||||
|
|
||||||
|
def validate_mnemonics(mnemonics, threshold, expected_ems):
|
||||||
|
# 3of5 shares 3of5 groups
|
||||||
|
# TODO: test all possible group+share combinations?
|
||||||
|
test_combination = mnemonics[0:3] + mnemonics[5:8] + mnemonics[10:13]
|
||||||
|
ms = shamir.combine_mnemonics(test_combination)
|
||||||
|
identifier, iteration_exponent, _, _, _ = shamir._decode_mnemonics(test_combination)
|
||||||
|
ems = shamir._encrypt(ms, b"", iteration_exponent, identifier)
|
||||||
|
assert ems == expected_ems
|
@ -0,0 +1,286 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
from trezorlib import btc, device, messages
|
||||||
|
from trezorlib.messages import ButtonRequestType as B, ResetDeviceBackupType
|
||||||
|
from trezorlib.tools import parse_path
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skip_t1
|
||||||
|
def test_reset_recovery(client):
|
||||||
|
mnemonics = reset(client)
|
||||||
|
address_before = btc.get_address(client, "Bitcoin", parse_path("44'/0'/0'/0/0"))
|
||||||
|
# TODO: more combinations
|
||||||
|
selected_mnemonics = [
|
||||||
|
mnemonics[0],
|
||||||
|
mnemonics[1],
|
||||||
|
mnemonics[2],
|
||||||
|
mnemonics[5],
|
||||||
|
mnemonics[6],
|
||||||
|
mnemonics[7],
|
||||||
|
mnemonics[10],
|
||||||
|
mnemonics[11],
|
||||||
|
mnemonics[12],
|
||||||
|
]
|
||||||
|
device.wipe(client)
|
||||||
|
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 = []
|
||||||
|
|
||||||
|
def input_flow():
|
||||||
|
# Confirm Reset
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
client.debug.press_yes()
|
||||||
|
|
||||||
|
# Backup your seed
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
client.debug.press_yes()
|
||||||
|
|
||||||
|
# Confirm warning
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
client.debug.press_yes()
|
||||||
|
|
||||||
|
# shares info
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
client.debug.press_yes()
|
||||||
|
|
||||||
|
# Set & Confirm number of groups
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
client.debug.press_yes()
|
||||||
|
|
||||||
|
# threshold info
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
client.debug.press_yes()
|
||||||
|
|
||||||
|
# Set & confirm group threshold value
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
client.debug.press_yes()
|
||||||
|
|
||||||
|
for _ in range(5):
|
||||||
|
# Set & Confirm number of share
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
client.debug.press_yes()
|
||||||
|
|
||||||
|
# Set & confirm share threshold value
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
client.debug.press_yes()
|
||||||
|
|
||||||
|
# Confirm show seeds
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.ResetDevice
|
||||||
|
client.debug.press_yes()
|
||||||
|
|
||||||
|
# show & confirm shares for all groups
|
||||||
|
for g in range(5):
|
||||||
|
for h in range(5):
|
||||||
|
words = []
|
||||||
|
btn_code = yield
|
||||||
|
assert btn_code == B.Other
|
||||||
|
|
||||||
|
# mnemonic phrases
|
||||||
|
# 20 word over 6 pages for strength 128, 33 words over 9 pages for strength 256
|
||||||
|
for i in range(6):
|
||||||
|
words.extend(client.debug.read_reset_word().split())
|
||||||
|
if i < 5:
|
||||||
|
client.debug.swipe_down()
|
||||||
|
else:
|
||||||
|
# last page is confirmation
|
||||||
|
client.debug.press_yes()
|
||||||
|
|
||||||
|
# check share
|
||||||
|
for _ in range(3):
|
||||||
|
index = client.debug.read_reset_word_pos()
|
||||||
|
client.debug.input(words[index])
|
||||||
|
|
||||||
|
all_mnemonics.extend([" ".join(words)])
|
||||||
|
|
||||||
|
# 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.ResetDevice
|
||||||
|
), # group #1 shares& thresholds
|
||||||
|
messages.ButtonRequest(code=B.ResetDevice),
|
||||||
|
messages.ButtonRequest(
|
||||||
|
code=B.ResetDevice
|
||||||
|
), # group #2 shares& thresholds
|
||||||
|
messages.ButtonRequest(code=B.ResetDevice),
|
||||||
|
messages.ButtonRequest(
|
||||||
|
code=B.ResetDevice
|
||||||
|
), # group #3 shares& thresholds
|
||||||
|
messages.ButtonRequest(code=B.ResetDevice),
|
||||||
|
messages.ButtonRequest(
|
||||||
|
code=B.ResetDevice
|
||||||
|
), # group #4 shares& thresholds
|
||||||
|
messages.ButtonRequest(code=B.ResetDevice),
|
||||||
|
messages.ButtonRequest(
|
||||||
|
code=B.ResetDevice
|
||||||
|
), # group #5 shares& thresholds
|
||||||
|
messages.ButtonRequest(code=B.ResetDevice),
|
||||||
|
messages.ButtonRequest(code=B.Other), # show seeds
|
||||||
|
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.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.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.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.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), # show seeds ends here
|
||||||
|
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_Multiple_Groups,
|
||||||
|
)
|
||||||
|
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
|
||||||
|
yield from enter_all_shares(debug, shares)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: let's merge this with test_msg_recoverydevice_supershamir.py
|
||||||
|
def enter_all_shares(debug, shares):
|
||||||
|
word_count = len(shares[0].split(" "))
|
||||||
|
|
||||||
|
# Homescreen - proceed to word number selection
|
||||||
|
yield
|
||||||
|
debug.press_yes()
|
||||||
|
# Input word number
|
||||||
|
code = yield
|
||||||
|
assert code == messages.ButtonRequestType.MnemonicWordCount
|
||||||
|
debug.input(str(word_count))
|
||||||
|
# Homescreen - proceed to share entry
|
||||||
|
yield
|
||||||
|
debug.press_yes()
|
||||||
|
# Enter shares
|
||||||
|
for index, share in enumerate(shares):
|
||||||
|
if index >= 1:
|
||||||
|
# confirm remaining shares
|
||||||
|
debug.swipe_down()
|
||||||
|
code = yield
|
||||||
|
assert code == messages.ButtonRequestType.Other
|
||||||
|
debug.press_yes()
|
||||||
|
code = yield
|
||||||
|
assert code == messages.ButtonRequestType.MnemonicInput
|
||||||
|
# Enter mnemonic words
|
||||||
|
for word in share.split(" "):
|
||||||
|
debug.input(word)
|
||||||
|
|
||||||
|
# Confirm share entered
|
||||||
|
yield
|
||||||
|
debug.press_yes()
|
||||||
|
|
||||||
|
# Homescreen - continue
|
||||||
|
# or Homescreen - confirm success
|
||||||
|
yield
|
||||||
|
debug.press_yes()
|
Loading…
Reference in new issue