2018-10-04 15:37:49 +00:00
|
|
|
# This file is part of the Trezor project.
|
|
|
|
#
|
2019-05-29 16:44:09 +00:00
|
|
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
2018-10-04 15:37:49 +00:00
|
|
|
#
|
|
|
|
# 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>.
|
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
import pytest
|
|
|
|
|
2018-10-04 15:37:49 +00:00
|
|
|
from trezorlib import messages as proto
|
|
|
|
|
|
|
|
from .common import TrezorTest
|
|
|
|
|
|
|
|
|
|
|
|
class TestMsgResetDeviceNobackup(TrezorTest):
|
|
|
|
|
2018-10-08 13:54:02 +00:00
|
|
|
external_entropy = b"zlutoucky kun upel divoke ody" * 2
|
|
|
|
strength = 128
|
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
@pytest.mark.setup_client(uninitialized=True)
|
|
|
|
def test_reset_device_no_backup(self, client):
|
|
|
|
ret = client.call_raw(
|
2018-10-04 15:37:49 +00:00
|
|
|
proto.ResetDevice(
|
|
|
|
display_random=False,
|
2018-10-08 13:54:02 +00:00
|
|
|
strength=self.strength,
|
2018-10-04 15:37:49 +00:00
|
|
|
passphrase_protection=False,
|
|
|
|
pin_protection=False,
|
|
|
|
language="english",
|
|
|
|
label="test",
|
|
|
|
no_backup=True,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2018-10-22 12:44:36 +00:00
|
|
|
assert isinstance(ret, proto.ButtonRequest)
|
2019-08-27 14:58:59 +00:00
|
|
|
client.debug.press_yes()
|
|
|
|
ret = client.call_raw(proto.ButtonAck())
|
2018-10-22 12:44:36 +00:00
|
|
|
|
2018-10-04 15:37:49 +00:00
|
|
|
# Provide entropy
|
|
|
|
assert isinstance(ret, proto.EntropyRequest)
|
2019-08-27 14:58:59 +00:00
|
|
|
ret = client.call_raw(proto.EntropyAck(entropy=self.external_entropy))
|
2018-10-04 15:37:49 +00:00
|
|
|
assert isinstance(ret, proto.Success)
|
|
|
|
|
|
|
|
# Check if device is properly initialized
|
2019-08-27 14:58:59 +00:00
|
|
|
ret = client.call_raw(proto.Initialize())
|
2018-10-04 15:37:49 +00:00
|
|
|
assert ret.initialized is True
|
|
|
|
assert ret.needs_backup is False
|
|
|
|
assert ret.unfinished_backup is False
|
|
|
|
assert ret.no_backup is True
|
|
|
|
|
|
|
|
# start backup - should fail
|
2019-08-27 14:58:59 +00:00
|
|
|
ret = client.call_raw(proto.BackupDevice())
|
2018-10-04 15:37:49 +00:00
|
|
|
assert isinstance(ret, proto.Failure)
|
2018-10-08 13:54:02 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
@pytest.mark.setup_client(uninitialized=True)
|
|
|
|
def test_reset_device_no_backup_show_entropy_fail(self, client):
|
|
|
|
ret = client.call_raw(
|
2018-10-08 13:54:02 +00:00
|
|
|
proto.ResetDevice(
|
|
|
|
display_random=True,
|
|
|
|
strength=self.strength,
|
|
|
|
passphrase_protection=False,
|
|
|
|
pin_protection=False,
|
|
|
|
language="english",
|
|
|
|
label="test",
|
|
|
|
no_backup=True,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
assert isinstance(ret, proto.Failure)
|