2018-06-21 14:28:34 +00:00
|
|
|
# This file is part of the Trezor project.
|
2018-03-22 14:27:43 +00:00
|
|
|
#
|
2019-05-29 16:44:09 +00:00
|
|
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
2018-03-22 14:27:43 +00:00
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
2018-06-21 14:28:34 +00:00
|
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
# as published by the Free Software Foundation.
|
2018-03-22 14:27:43 +00:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2018-06-21 14:28:34 +00:00
|
|
|
# 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>.
|
2018-03-22 14:27:43 +00:00
|
|
|
|
|
|
|
|
2018-05-11 12:53:51 +00:00
|
|
|
import pytest
|
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
from trezorlib import device, messages as proto
|
|
|
|
|
2018-05-11 12:53:51 +00:00
|
|
|
from .common import TrezorTest
|
2018-03-22 14:27:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_t1
|
|
|
|
class TestMsgRecoverydeviceT2(TrezorTest):
|
|
|
|
def test_pin_passphrase(self):
|
2018-08-13 16:21:24 +00:00
|
|
|
mnemonic = self.mnemonic12.split(" ")
|
|
|
|
ret = self.client.call_raw(
|
|
|
|
proto.RecoveryDevice(
|
|
|
|
passphrase_protection=True,
|
|
|
|
pin_protection=True,
|
|
|
|
label="label",
|
|
|
|
enforce_wordlist=True,
|
|
|
|
)
|
|
|
|
)
|
2018-03-22 14:27:43 +00:00
|
|
|
|
2018-10-22 12:44:36 +00:00
|
|
|
# Confirm Recovery
|
|
|
|
assert isinstance(ret, proto.ButtonRequest)
|
|
|
|
self.client.debug.press_yes()
|
|
|
|
ret = self.client.call_raw(proto.ButtonAck())
|
|
|
|
|
2019-07-11 14:52:25 +00:00
|
|
|
# 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
|
|
|
|
assert ret == proto.ButtonRequest(code=proto.ButtonRequestType.Other)
|
|
|
|
self.client.debug.input("654")
|
|
|
|
ret = self.client.call_raw(proto.ButtonAck())
|
|
|
|
|
|
|
|
# Homescreen
|
|
|
|
assert isinstance(ret, proto.ButtonRequest)
|
|
|
|
self.client.debug.press_yes()
|
|
|
|
ret = self.client.call_raw(proto.ButtonAck())
|
|
|
|
|
2018-03-22 14:27:43 +00:00
|
|
|
# Enter word count
|
2018-08-13 16:21:24 +00:00
|
|
|
assert ret == proto.ButtonRequest(
|
|
|
|
code=proto.ButtonRequestType.MnemonicWordCount
|
|
|
|
)
|
2018-03-22 14:27:43 +00:00
|
|
|
self.client.debug.input(str(len(mnemonic)))
|
|
|
|
ret = self.client.call_raw(proto.ButtonAck())
|
|
|
|
|
2019-07-11 14:52:25 +00:00
|
|
|
# Homescreen
|
|
|
|
assert isinstance(ret, proto.ButtonRequest)
|
|
|
|
self.client.debug.press_yes()
|
|
|
|
ret = self.client.call_raw(proto.ButtonAck())
|
|
|
|
|
2018-03-22 14:27:43 +00:00
|
|
|
# Enter mnemonic words
|
|
|
|
assert ret == proto.ButtonRequest(code=proto.ButtonRequestType.MnemonicInput)
|
|
|
|
self.client.transport.write(proto.ButtonAck())
|
|
|
|
for word in mnemonic:
|
|
|
|
self.client.debug.input(word)
|
|
|
|
ret = self.client.transport.read()
|
|
|
|
|
2019-06-26 09:57:59 +00:00
|
|
|
# Confirm success
|
|
|
|
assert isinstance(ret, proto.ButtonRequest)
|
|
|
|
self.client.debug.press_yes()
|
|
|
|
ret = self.client.call_raw(proto.ButtonAck())
|
|
|
|
|
2018-03-22 14:27:43 +00:00
|
|
|
# Workflow succesfully ended
|
2018-08-13 16:21:24 +00:00
|
|
|
assert ret == proto.Success(message="Device recovered")
|
2018-03-22 14:27:43 +00:00
|
|
|
|
|
|
|
# Mnemonic is the same
|
|
|
|
self.client.init_device()
|
2019-03-07 15:28:24 +00:00
|
|
|
assert self.client.debug.read_mnemonic_secret() == self.mnemonic12.encode()
|
2018-03-22 14:27:43 +00:00
|
|
|
|
|
|
|
assert self.client.features.pin_protection is True
|
|
|
|
assert self.client.features.passphrase_protection is True
|
|
|
|
|
|
|
|
def test_nopin_nopassphrase(self):
|
2018-08-13 16:21:24 +00:00
|
|
|
mnemonic = self.mnemonic12.split(" ")
|
|
|
|
ret = self.client.call_raw(
|
|
|
|
proto.RecoveryDevice(
|
|
|
|
passphrase_protection=False,
|
|
|
|
pin_protection=False,
|
|
|
|
label="label",
|
|
|
|
enforce_wordlist=True,
|
|
|
|
)
|
|
|
|
)
|
2018-03-22 14:27:43 +00:00
|
|
|
|
2018-10-22 12:44:36 +00:00
|
|
|
# Confirm Recovery
|
|
|
|
assert isinstance(ret, proto.ButtonRequest)
|
|
|
|
self.client.debug.press_yes()
|
|
|
|
ret = self.client.call_raw(proto.ButtonAck())
|
|
|
|
|
2019-07-11 14:52:25 +00:00
|
|
|
# Homescreen
|
|
|
|
assert isinstance(ret, proto.ButtonRequest)
|
|
|
|
self.client.debug.press_yes()
|
|
|
|
ret = self.client.call_raw(proto.ButtonAck())
|
|
|
|
|
2018-03-22 14:27:43 +00:00
|
|
|
# Enter word count
|
2018-08-13 16:21:24 +00:00
|
|
|
assert ret == proto.ButtonRequest(
|
|
|
|
code=proto.ButtonRequestType.MnemonicWordCount
|
|
|
|
)
|
2018-03-22 14:27:43 +00:00
|
|
|
self.client.debug.input(str(len(mnemonic)))
|
|
|
|
ret = self.client.call_raw(proto.ButtonAck())
|
|
|
|
|
2019-07-11 14:52:25 +00:00
|
|
|
# Homescreen
|
|
|
|
assert isinstance(ret, proto.ButtonRequest)
|
|
|
|
self.client.debug.press_yes()
|
|
|
|
ret = self.client.call_raw(proto.ButtonAck())
|
|
|
|
|
2018-03-22 14:27:43 +00:00
|
|
|
# Enter mnemonic words
|
|
|
|
assert ret == proto.ButtonRequest(code=proto.ButtonRequestType.MnemonicInput)
|
|
|
|
self.client.transport.write(proto.ButtonAck())
|
|
|
|
for word in mnemonic:
|
|
|
|
self.client.debug.input(word)
|
|
|
|
ret = self.client.transport.read()
|
|
|
|
|
2019-06-26 09:57:59 +00:00
|
|
|
# Confirm success
|
|
|
|
assert isinstance(ret, proto.ButtonRequest)
|
|
|
|
self.client.debug.press_yes()
|
|
|
|
ret = self.client.call_raw(proto.ButtonAck())
|
|
|
|
|
2018-03-22 14:27:43 +00:00
|
|
|
# Workflow succesfully ended
|
2018-08-13 16:21:24 +00:00
|
|
|
assert ret == proto.Success(message="Device recovered")
|
2018-03-22 14:27:43 +00:00
|
|
|
|
|
|
|
# Mnemonic is the same
|
|
|
|
self.client.init_device()
|
2019-03-07 15:28:24 +00:00
|
|
|
assert self.client.debug.read_mnemonic_secret() == self.mnemonic12.encode()
|
2018-03-22 14:27:43 +00:00
|
|
|
|
|
|
|
assert self.client.features.pin_protection is False
|
|
|
|
assert self.client.features.passphrase_protection is False
|
|
|
|
|
|
|
|
def test_already_initialized(self):
|
|
|
|
self.setup_mnemonic_nopin_nopassphrase()
|
2018-10-03 12:19:53 +00:00
|
|
|
with pytest.raises(RuntimeError):
|
|
|
|
device.recover(
|
|
|
|
self.client,
|
|
|
|
12,
|
|
|
|
False,
|
|
|
|
False,
|
|
|
|
"label",
|
|
|
|
"english",
|
|
|
|
self.client.mnemonic_callback,
|
|
|
|
)
|