2019-11-04 14:45:54 +00:00
|
|
|
# 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>.
|
|
|
|
|
2022-10-25 10:46:37 +00:00
|
|
|
from typing import TYPE_CHECKING
|
2019-11-04 14:45:54 +00:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from trezorlib import device, messages
|
|
|
|
|
|
|
|
from .. import buttons
|
2023-05-04 12:16:40 +00:00
|
|
|
from ..common import EXTERNAL_ENTROPY, WITH_MOCK_URANDOM, generate_entropy
|
2019-11-04 14:45:54 +00:00
|
|
|
from . import reset
|
|
|
|
|
2022-10-25 10:46:37 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from ..device_handler import BackgroundDeviceHandler
|
|
|
|
|
|
|
|
|
2024-03-11 15:20:08 +00:00
|
|
|
pytestmark = [pytest.mark.skip_t1b1]
|
2019-11-04 14:45:54 +00:00
|
|
|
|
|
|
|
|
2023-05-04 12:16:40 +00:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"num_of_shares, threshold",
|
|
|
|
[
|
|
|
|
pytest.param(1, 1, id="1of1"),
|
|
|
|
pytest.param(16, 16, id="16of16"),
|
|
|
|
],
|
|
|
|
)
|
2019-11-04 14:45:54 +00:00
|
|
|
@pytest.mark.setup_client(uninitialized=True)
|
2023-05-04 12:16:40 +00:00
|
|
|
@WITH_MOCK_URANDOM
|
|
|
|
def test_reset_slip39_basic(
|
|
|
|
device_handler: "BackgroundDeviceHandler", num_of_shares: int, threshold: int
|
|
|
|
):
|
2019-11-04 14:45:54 +00:00
|
|
|
features = device_handler.features()
|
|
|
|
debug = device_handler.debuglink()
|
|
|
|
|
|
|
|
assert features.initialized is False
|
|
|
|
|
2023-05-04 12:16:40 +00:00
|
|
|
device_handler.run(
|
|
|
|
device.reset,
|
|
|
|
strength=128,
|
|
|
|
backup_type=messages.BackupType.Slip39_Basic,
|
|
|
|
pin_protection=False,
|
|
|
|
)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2023-05-04 12:16:40 +00:00
|
|
|
# confirm new wallet
|
|
|
|
reset.confirm_new_wallet(debug)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2023-05-04 12:16:40 +00:00
|
|
|
# confirm back up
|
2023-08-11 15:57:32 +00:00
|
|
|
reset.confirm_read(debug)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2023-05-04 12:16:40 +00:00
|
|
|
# confirm checklist
|
2023-08-11 15:57:32 +00:00
|
|
|
reset.confirm_read(debug)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2023-05-04 12:16:40 +00:00
|
|
|
# set num of shares - default is 5
|
2024-05-27 22:19:01 +00:00
|
|
|
assert debug.model is not None
|
|
|
|
model_name: str = debug.model.internal_name
|
2023-05-04 12:16:40 +00:00
|
|
|
if num_of_shares < 5:
|
2024-05-27 22:19:01 +00:00
|
|
|
reset.set_selection(debug, buttons.reset_minus(model_name), 5 - num_of_shares)
|
2023-05-04 12:16:40 +00:00
|
|
|
else:
|
2024-05-27 22:19:01 +00:00
|
|
|
reset.set_selection(debug, buttons.reset_plus(model_name), num_of_shares - 5)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2023-05-04 12:16:40 +00:00
|
|
|
# confirm checklist
|
2023-08-11 15:57:32 +00:00
|
|
|
reset.confirm_read(debug)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2023-05-04 12:16:40 +00:00
|
|
|
# set threshold
|
|
|
|
# TODO: could make it general as well
|
|
|
|
if num_of_shares == 1 and threshold == 1:
|
2024-05-27 22:19:01 +00:00
|
|
|
reset.set_selection(debug, buttons.reset_plus(model_name), 0)
|
2023-05-04 12:16:40 +00:00
|
|
|
elif num_of_shares == 16 and threshold == 16:
|
2024-05-27 22:19:01 +00:00
|
|
|
reset.set_selection(debug, buttons.reset_plus(model_name), 11)
|
2023-05-04 12:16:40 +00:00
|
|
|
else:
|
|
|
|
raise RuntimeError("not a supported combination")
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2023-05-04 12:16:40 +00:00
|
|
|
# confirm checklist
|
2023-08-11 15:57:32 +00:00
|
|
|
reset.confirm_read(debug)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2023-06-26 08:50:28 +00:00
|
|
|
# confirm backup warning
|
2023-08-11 15:57:32 +00:00
|
|
|
reset.confirm_read(debug, middle_r=True)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2023-05-04 12:16:40 +00:00
|
|
|
all_words: list[str] = []
|
|
|
|
for _ in range(num_of_shares):
|
2019-11-04 14:45:54 +00:00
|
|
|
# read words
|
2024-04-23 10:26:46 +00:00
|
|
|
words = reset.read_words(debug)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
|
|
|
# confirm words
|
|
|
|
reset.confirm_words(debug, words)
|
|
|
|
|
|
|
|
# confirm share checked
|
2023-08-11 15:57:32 +00:00
|
|
|
reset.confirm_read(debug)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2023-05-04 12:16:40 +00:00
|
|
|
all_words.append(" ".join(words))
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2023-05-04 12:16:40 +00:00
|
|
|
# confirm backup done
|
2023-08-11 15:57:32 +00:00
|
|
|
reset.confirm_read(debug)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2023-05-04 12:16:40 +00:00
|
|
|
# generate secret locally
|
|
|
|
internal_entropy = debug.state().reset_entropy
|
|
|
|
assert internal_entropy is not None
|
|
|
|
secret = generate_entropy(128, internal_entropy, EXTERNAL_ENTROPY)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2023-05-04 12:16:40 +00:00
|
|
|
# validate that all combinations will result in the correct master secret
|
|
|
|
reset.validate_mnemonics(all_words, secret)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2023-05-04 12:16:40 +00:00
|
|
|
assert device_handler.result() == "Initialized"
|
2019-11-04 14:45:54 +00:00
|
|
|
features = device_handler.features()
|
2023-05-04 12:16:40 +00:00
|
|
|
assert features.initialized is True
|
2024-05-23 14:09:16 +00:00
|
|
|
assert features.backup_availability == messages.BackupAvailability.NotAvailable
|
2023-05-04 12:16:40 +00:00
|
|
|
assert features.pin_protection is False
|
|
|
|
assert features.passphrase_protection is False
|
2024-05-17 21:08:23 +00:00
|
|
|
assert features.backup_type is messages.BackupType.Slip39_Basic_Extendable
|