mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 23:08:14 +00:00
tests: added device tests for dry run and warnings
This commit is contained in:
parent
5eb0cdf020
commit
db35a11fc1
@ -18,206 +18,219 @@ import time
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from trezorlib import btc, messages as proto
|
from trezorlib import device, exceptions, messages
|
||||||
|
|
||||||
from .common import TrezorTest
|
pytestmark = pytest.mark.skip_t1
|
||||||
|
|
||||||
|
SHARES_20_3of6 = [
|
||||||
|
"extra extend academic bishop cricket bundle tofu goat apart victim enlarge program behavior permit course armed jerky faint language modern",
|
||||||
|
"extra extend academic acne away best indicate impact square oasis prospect painting voting guest either argue username racism enemy eclipse",
|
||||||
|
"extra extend academic arcade born dive legal hush gross briefing talent drug much home firefly toxic analysis idea umbrella slice",
|
||||||
|
]
|
||||||
|
|
||||||
|
SHARES_33_2of5 = [
|
||||||
|
"hobo romp academic axis august founder knife legal recover alien expect emphasis loan kitchen involve teacher capture rebuild trial numb spider forward ladle lying voter typical security quantity hawk legs idle leaves gasoline",
|
||||||
|
"hobo romp academic agency ancestor industry argue sister scene midst graduate profile numb paid headset airport daisy flame express scene usual welcome quick silent downtown oral critical step remove says rhythm venture aunt",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip_t1
|
VECTORS = (
|
||||||
class TestMsgRecoveryDeviceShamir(TrezorTest):
|
(SHARES_20_3of6, "491b795b80fc21ccdf466c0fbc98c8fc"),
|
||||||
def test_3of6_nopin_nopassphrase(self):
|
(
|
||||||
# 128 bits security, 3 of 6
|
SHARES_33_2of5,
|
||||||
mnemonics = [
|
"b770e0da1363247652de97a39bdbf2463be087848d709ecbf28e84508e31202a",
|
||||||
"extra extend academic bishop cricket bundle tofu goat apart victim enlarge program behavior permit course armed jerky faint language modern",
|
),
|
||||||
"extra extend academic acne away best indicate impact square oasis prospect painting voting guest either argue username racism enemy eclipse",
|
)
|
||||||
"extra extend academic arcade born dive legal hush gross briefing talent drug much home firefly toxic analysis idea umbrella slice",
|
|
||||||
]
|
|
||||||
word_count = len(mnemonics[0].split(" "))
|
|
||||||
|
|
||||||
ret = self.client.call_raw(
|
|
||||||
proto.RecoveryDevice(
|
def enter_all_shares(debug, shares):
|
||||||
passphrase_protection=False, pin_protection=False, label="label"
|
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 share in shares:
|
||||||
|
code = yield
|
||||||
|
assert code == messages.ButtonRequestType.MnemonicInput
|
||||||
|
# Enter mnemonic words
|
||||||
|
for word in share.split(" "):
|
||||||
|
time.sleep(1)
|
||||||
|
debug.input(word)
|
||||||
|
|
||||||
|
# Homescreen - continue
|
||||||
|
# or Homescreen - confirm success
|
||||||
|
yield
|
||||||
|
debug.press_yes()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("shares, secret", VECTORS)
|
||||||
|
def test_secret(client, shares, secret):
|
||||||
|
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")
|
||||||
|
|
||||||
|
# Workflow succesfully ended
|
||||||
|
assert ret == messages.Success(message="Device recovered")
|
||||||
|
assert client.features.pin_protection is False
|
||||||
|
assert client.features.passphrase_protection is False
|
||||||
|
|
||||||
|
# Check mnemonic
|
||||||
|
assert debug.read_mnemonic_secret().hex() == secret
|
||||||
|
|
||||||
|
|
||||||
|
def test_recover_with_pin_passphrase(client):
|
||||||
|
debug = client.debug
|
||||||
|
|
||||||
|
def input_flow():
|
||||||
|
yield # Confirm Recovery
|
||||||
|
debug.press_yes()
|
||||||
|
yield # Enter PIN
|
||||||
|
debug.input("654")
|
||||||
|
yield # Enter PIN again
|
||||||
|
debug.input("654")
|
||||||
|
# Proceed with recovery
|
||||||
|
yield from enter_all_shares(debug, SHARES_20_3of6)
|
||||||
|
|
||||||
|
with client:
|
||||||
|
client.set_input_flow(input_flow)
|
||||||
|
ret = device.recover(
|
||||||
|
client, pin_protection=True, passphrase_protection=True, label="label"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Confirm Recovery
|
# Workflow succesfully ended
|
||||||
assert isinstance(ret, proto.ButtonRequest)
|
assert ret == messages.Success(message="Device recovered")
|
||||||
self.client.debug.press_yes()
|
assert client.features.pin_protection is True
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
assert client.features.passphrase_protection is True
|
||||||
|
|
||||||
# Homescreen - consider aborting process
|
|
||||||
assert isinstance(ret, proto.ButtonRequest)
|
|
||||||
self.client.debug.press_no()
|
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
|
||||||
|
|
||||||
# Homescreen - but then bail out in the warning
|
def test_abort(client):
|
||||||
assert isinstance(ret, proto.ButtonRequest)
|
debug = client.debug
|
||||||
self.client.debug.press_no()
|
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
|
||||||
|
|
||||||
# Homescreen - click Enter
|
def input_flow():
|
||||||
assert isinstance(ret, proto.ButtonRequest)
|
yield # Confirm Recovery
|
||||||
self.client.debug.press_yes()
|
debug.press_yes()
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
yield # Homescreen - abort process
|
||||||
|
debug.press_no()
|
||||||
|
yield # Homescreen - confirm abort
|
||||||
|
debug.press_yes()
|
||||||
|
|
||||||
# Enter word count
|
with client:
|
||||||
assert ret == proto.ButtonRequest(
|
client.set_input_flow(input_flow)
|
||||||
code=proto.ButtonRequestType.MnemonicWordCount
|
with pytest.raises(exceptions.Cancelled):
|
||||||
)
|
device.recover(client, pin_protection=False, label="label")
|
||||||
self.client.debug.input(str(word_count))
|
client.init_device()
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
assert client.features.initialized is False
|
||||||
|
|
||||||
# Homescreen
|
|
||||||
assert isinstance(ret, proto.ButtonRequest)
|
|
||||||
self.client.debug.press_yes()
|
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
|
||||||
|
|
||||||
# Enter shares
|
def test_noabort(client):
|
||||||
for mnemonic in mnemonics:
|
debug = client.debug
|
||||||
# Enter mnemonic words
|
|
||||||
assert ret == proto.ButtonRequest(
|
|
||||||
code=proto.ButtonRequestType.MnemonicInput
|
|
||||||
)
|
|
||||||
self.client.transport.write(proto.ButtonAck())
|
|
||||||
for word in mnemonic.split(" "):
|
|
||||||
time.sleep(1)
|
|
||||||
self.client.debug.input(word)
|
|
||||||
ret = self.client.transport.read()
|
|
||||||
|
|
||||||
if mnemonic != mnemonics[-1]:
|
def input_flow():
|
||||||
# Homescreen
|
yield # Confirm Recovery
|
||||||
assert isinstance(ret, proto.ButtonRequest)
|
debug.press_yes()
|
||||||
self.client.debug.press_yes()
|
yield # Homescreen - abort process
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
debug.press_no()
|
||||||
|
yield # Homescreen - go back to process
|
||||||
|
debug.press_no()
|
||||||
|
yield from enter_all_shares(debug, SHARES_20_3of6)
|
||||||
|
|
||||||
# Confirm success
|
with client:
|
||||||
assert isinstance(ret, proto.ButtonRequest)
|
client.set_input_flow(input_flow)
|
||||||
self.client.debug.press_yes()
|
device.recover(client, pin_protection=False, label="label")
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
client.init_device()
|
||||||
|
assert client.features.initialized is True
|
||||||
|
|
||||||
# Workflow succesfully ended
|
|
||||||
assert ret == proto.Success(message="Device recovered")
|
|
||||||
|
|
||||||
assert self.client.features.pin_protection is False
|
@pytest.mark.parametrize("nth_word", range(3))
|
||||||
assert self.client.features.passphrase_protection is False
|
def test_wrong_nth_word(client, nth_word):
|
||||||
|
debug = client.debug
|
||||||
|
share = SHARES_20_3of6[0].split(" ")
|
||||||
|
|
||||||
# Check mnemonic
|
def input_flow():
|
||||||
assert (
|
yield # Confirm Recovery
|
||||||
self.client.debug.read_mnemonic_secret().hex()
|
debug.press_yes()
|
||||||
== "491b795b80fc21ccdf466c0fbc98c8fc"
|
yield # Homescreen - start process
|
||||||
)
|
debug.press_yes()
|
||||||
|
yield # Enter number of words
|
||||||
|
debug.input(str(len(share)))
|
||||||
|
yield # Homescreen - proceed to share entry
|
||||||
|
debug.press_yes()
|
||||||
|
yield # Enter first share
|
||||||
|
for word in share:
|
||||||
|
time.sleep(1)
|
||||||
|
debug.input(word)
|
||||||
|
|
||||||
# BIP32 Root Key for empty passphrase
|
yield # Continue to next share
|
||||||
# provided by Andrew, address calculated using T1
|
debug.press_yes()
|
||||||
# xprv9s21ZrQH143K3reExTJbGTHPu6mGuUx6yN1H1KkqoiAcw6j1t6hBiwwnXYxNQXxU8T7pANSv1rJYQPXn1LMQk1gbWes5BjSz3rJ5ZfH1cc3
|
yield # Enter next share
|
||||||
address = btc.get_address(self.client, "Bitcoin", [])
|
for i, word in enumerate(share):
|
||||||
assert address == "1G1MwH5sLVxKQ7yKYasfE5pxWaABLo7VK7"
|
time.sleep(1)
|
||||||
|
if i < nth_word:
|
||||||
|
debug.input(word)
|
||||||
|
else:
|
||||||
|
debug.input(share[-1])
|
||||||
|
break
|
||||||
|
|
||||||
def test_2of5_pin_passphrase(self):
|
code = yield
|
||||||
# 256 bits security, 2 of 5
|
assert code == messages.ButtonRequestType.Warning
|
||||||
mnemonics = [
|
|
||||||
"hobo romp academic axis august founder knife legal recover alien expect emphasis loan kitchen involve teacher capture rebuild trial numb spider forward ladle lying voter typical security quantity hawk legs idle leaves gasoline",
|
|
||||||
"hobo romp academic agency ancestor industry argue sister scene midst graduate profile numb paid headset airport daisy flame express scene usual welcome quick silent downtown oral critical step remove says rhythm venture aunt",
|
|
||||||
]
|
|
||||||
# TODO: add incorrect mnemonic to test
|
|
||||||
word_count = len(mnemonics[0].split(" "))
|
|
||||||
|
|
||||||
ret = self.client.call_raw(
|
client.cancel()
|
||||||
proto.RecoveryDevice(
|
|
||||||
passphrase_protection=True, pin_protection=True, label="label"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Confirm Recovery
|
with client:
|
||||||
assert isinstance(ret, proto.ButtonRequest)
|
client.set_input_flow(input_flow)
|
||||||
self.client.debug.press_yes()
|
with pytest.raises(exceptions.Cancelled):
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
device.recover(client, pin_protection=False, label="label")
|
||||||
|
|
||||||
# Enter PIN for first time
|
|
||||||
assert ret == proto.ButtonRequest(code=proto.ButtonRequestType.Other)
|
|
||||||
self.client.debug.input("654")
|
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
|
||||||
|
|
||||||
# Enter PIN for second time
|
def test_same_share(client):
|
||||||
assert ret == proto.ButtonRequest(code=proto.ButtonRequestType.Other)
|
debug = client.debug
|
||||||
self.client.debug.input("654")
|
first_share = SHARES_20_3of6[0].split(" ")
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
# second share is first 4 words of first
|
||||||
|
second_share = SHARES_20_3of6[0].split(" ")[:4]
|
||||||
|
|
||||||
# Homescreen
|
def input_flow():
|
||||||
assert isinstance(ret, proto.ButtonRequest)
|
yield # Confirm Recovery
|
||||||
self.client.debug.press_yes()
|
debug.press_yes()
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
yield # Homescreen - start process
|
||||||
|
debug.press_yes()
|
||||||
|
yield # Enter number of words
|
||||||
|
debug.input(str(len(first_share)))
|
||||||
|
yield # Homescreen - proceed to share entry
|
||||||
|
debug.press_yes()
|
||||||
|
yield # Enter first share
|
||||||
|
for word in first_share:
|
||||||
|
time.sleep(1)
|
||||||
|
debug.input(word)
|
||||||
|
|
||||||
# Enter word count
|
yield # Continue to next share
|
||||||
assert ret == proto.ButtonRequest(
|
debug.press_yes()
|
||||||
code=proto.ButtonRequestType.MnemonicWordCount
|
yield # Enter next share
|
||||||
)
|
for word in second_share:
|
||||||
self.client.debug.input(str(word_count))
|
time.sleep(1)
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
debug.input(word)
|
||||||
|
|
||||||
# Homescreen
|
code = yield
|
||||||
assert isinstance(ret, proto.ButtonRequest)
|
assert code == messages.ButtonRequestType.Warning
|
||||||
self.client.debug.press_yes()
|
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
|
||||||
|
|
||||||
# Enter shares
|
client.cancel()
|
||||||
for mnemonic in mnemonics:
|
|
||||||
# Enter mnemonic words
|
|
||||||
assert ret == proto.ButtonRequest(
|
|
||||||
code=proto.ButtonRequestType.MnemonicInput
|
|
||||||
)
|
|
||||||
self.client.transport.write(proto.ButtonAck())
|
|
||||||
for word in mnemonic.split(" "):
|
|
||||||
time.sleep(1)
|
|
||||||
self.client.debug.input(word)
|
|
||||||
ret = self.client.transport.read()
|
|
||||||
|
|
||||||
if mnemonic != mnemonics[-1]:
|
with client:
|
||||||
# Homescreen
|
client.set_input_flow(input_flow)
|
||||||
assert isinstance(ret, proto.ButtonRequest)
|
with pytest.raises(exceptions.Cancelled):
|
||||||
self.client.debug.press_yes()
|
device.recover(client, pin_protection=False, label="label")
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
|
||||||
|
|
||||||
# Confirm success
|
|
||||||
assert isinstance(ret, proto.ButtonRequest)
|
|
||||||
self.client.debug.press_yes()
|
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
|
||||||
|
|
||||||
# Workflow succesfully ended
|
|
||||||
assert ret == proto.Success(message="Device recovered")
|
|
||||||
|
|
||||||
# Check mnemonic
|
|
||||||
self.client.init_device()
|
|
||||||
assert (
|
|
||||||
self.client.debug.read_mnemonic_secret().hex()
|
|
||||||
== "b770e0da1363247652de97a39bdbf2463be087848d709ecbf28e84508e31202a"
|
|
||||||
)
|
|
||||||
|
|
||||||
assert self.client.features.pin_protection is True
|
|
||||||
assert self.client.features.passphrase_protection is True
|
|
||||||
|
|
||||||
def test_abort(self):
|
|
||||||
ret = self.client.call_raw(
|
|
||||||
proto.RecoveryDevice(
|
|
||||||
passphrase_protection=False, pin_protection=False, label="label"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Confirm Recovery
|
|
||||||
assert isinstance(ret, proto.ButtonRequest)
|
|
||||||
self.client.debug.press_yes()
|
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
|
||||||
|
|
||||||
# Homescreen - abort process
|
|
||||||
assert isinstance(ret, proto.ButtonRequest)
|
|
||||||
self.client.debug.press_no()
|
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
|
||||||
|
|
||||||
# Homescreen - yup, really
|
|
||||||
assert isinstance(ret, proto.ButtonRequest)
|
|
||||||
self.client.debug.press_yes()
|
|
||||||
ret = self.client.call_raw(proto.ButtonAck())
|
|
||||||
|
|
||||||
# check that the device is wiped
|
|
||||||
features = self.client.call_raw(proto.Initialize())
|
|
||||||
assert features.initialized is False
|
|
||||||
|
@ -0,0 +1,78 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from trezorlib import debuglink, device, messages
|
||||||
|
|
||||||
|
pytestmark = pytest.mark.skip_t1
|
||||||
|
|
||||||
|
SHARES_20_2of3 = [
|
||||||
|
"crush merchant academic acid dream decision orbit smug trend trust painting slice glad crunch veteran lunch friar satoshi engage aquatic",
|
||||||
|
"crush merchant academic agency devote eyebrow disaster island deploy flip toxic budget numerous airport loyalty fitness resident learn sympathy daughter",
|
||||||
|
"crush merchant academic always course verdict rescue paces fridge museum energy solution space ladybug junction national biology game fawn coal",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_2of3_dryrun(client):
|
||||||
|
debug = client.debug
|
||||||
|
|
||||||
|
debuglink.load_device_by_mnemonic(
|
||||||
|
client,
|
||||||
|
mnemonic=SHARES_20_2of3[0:2],
|
||||||
|
pin="",
|
||||||
|
passphrase_protection=True,
|
||||||
|
label="test",
|
||||||
|
language="english",
|
||||||
|
skip_checksum=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
def input_flow():
|
||||||
|
yield # Confirm Dryrun
|
||||||
|
debug.press_yes()
|
||||||
|
# run recovery flow
|
||||||
|
yield from enter_all_shares(debug, SHARES_20_2of3[1:3])
|
||||||
|
|
||||||
|
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,
|
||||||
|
type=messages.ResetDeviceBackupType.Slip39_Single_Group,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Dry run was successful
|
||||||
|
assert ret == messages.Success(
|
||||||
|
message="The seed is valid and matches the one in the device"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
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 share in shares:
|
||||||
|
code = yield
|
||||||
|
assert code == messages.ButtonRequestType.MnemonicInput
|
||||||
|
# Enter mnemonic words
|
||||||
|
for word in share.split(" "):
|
||||||
|
time.sleep(1)
|
||||||
|
debug.input(word)
|
||||||
|
|
||||||
|
# Homescreen - continue
|
||||||
|
# or Homescreen - confirm success
|
||||||
|
yield
|
||||||
|
debug.press_yes()
|
Loading…
Reference in New Issue
Block a user