2024-04-11 14:21:17 +00:00
|
|
|
# This file is part of the Trezor project.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2012-2024 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>.
|
|
|
|
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2024-09-02 11:01:16 +00:00
|
|
|
from trezorlib import device, messages
|
|
|
|
from trezorlib.debuglink import LayoutType
|
2024-04-11 14:21:17 +00:00
|
|
|
|
2023-11-21 15:55:46 +00:00
|
|
|
from .. import translations as TR
|
2024-09-04 09:03:20 +00:00
|
|
|
from ..common import EXTERNAL_ENTROPY, WITH_MOCK_URANDOM, generate_entropy
|
2024-04-11 14:21:17 +00:00
|
|
|
from . import reset
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from ..device_handler import BackgroundDeviceHandler
|
|
|
|
|
|
|
|
|
2024-09-02 11:01:16 +00:00
|
|
|
pytestmark = pytest.mark.models("core")
|
2024-04-11 14:21:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"group_threshold, share_threshold, share_count",
|
|
|
|
[
|
|
|
|
pytest.param(1, 1, 1, id="1of1"),
|
|
|
|
pytest.param(1, 2, 3, id="2of3"),
|
|
|
|
pytest.param(1, 5, 5, id="5of5"),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
@pytest.mark.setup_client(uninitialized=True)
|
|
|
|
@WITH_MOCK_URANDOM
|
|
|
|
def test_backup_slip39_custom(
|
|
|
|
device_handler: "BackgroundDeviceHandler",
|
|
|
|
group_threshold: int,
|
|
|
|
share_threshold: int,
|
|
|
|
share_count: int,
|
|
|
|
):
|
|
|
|
features = device_handler.features()
|
|
|
|
debug = device_handler.debuglink()
|
|
|
|
|
|
|
|
assert features.initialized is False
|
|
|
|
|
|
|
|
device_handler.run(
|
|
|
|
device.reset,
|
|
|
|
strength=128,
|
|
|
|
backup_type=messages.BackupType.Slip39_Basic,
|
|
|
|
pin_protection=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
# confirm new wallet
|
|
|
|
reset.confirm_new_wallet(debug)
|
|
|
|
|
|
|
|
# cancel back up
|
2024-06-04 10:47:09 +00:00
|
|
|
reset.cancel_backup(debug, confirm=True)
|
2024-04-11 14:21:17 +00:00
|
|
|
|
|
|
|
assert device_handler.result() == "Initialized"
|
|
|
|
|
|
|
|
device_handler.run(
|
|
|
|
device.backup,
|
|
|
|
group_threshold=group_threshold,
|
|
|
|
groups=[(share_threshold, share_count)],
|
|
|
|
)
|
|
|
|
|
2023-11-21 15:55:46 +00:00
|
|
|
# confirm backup configuration
|
2024-04-11 14:21:17 +00:00
|
|
|
if share_count > 1:
|
2024-11-14 14:11:03 +00:00
|
|
|
assert TR.regexp("reset__create_x_of_y_multi_share_backup_template").match(
|
|
|
|
debug.read_layout().text_content()
|
2024-09-04 09:03:20 +00:00
|
|
|
)
|
2024-06-04 13:40:42 +00:00
|
|
|
else:
|
2024-11-14 14:11:03 +00:00
|
|
|
assert TR.regexp("backup__info_single_share_backup").match(
|
|
|
|
debug.read_layout().text_content()
|
2024-09-04 09:03:20 +00:00
|
|
|
)
|
2023-11-21 15:55:46 +00:00
|
|
|
reset.confirm_read(debug)
|
|
|
|
|
|
|
|
# confirm backup intro
|
2024-11-14 14:11:03 +00:00
|
|
|
assert TR.reset__never_make_digital_copy in debug.read_layout().text_content()
|
2023-11-21 15:55:46 +00:00
|
|
|
reset.confirm_read(debug, middle_r=True)
|
2024-04-11 14:21:17 +00:00
|
|
|
|
|
|
|
all_words: list[str] = []
|
|
|
|
for _ in range(share_count):
|
|
|
|
# read words
|
2024-04-23 10:26:46 +00:00
|
|
|
words = reset.read_words(debug)
|
2024-04-11 14:21:17 +00:00
|
|
|
|
|
|
|
# confirm words
|
|
|
|
reset.confirm_words(debug, words)
|
|
|
|
|
|
|
|
# confirm share checked
|
|
|
|
reset.confirm_read(debug)
|
|
|
|
|
|
|
|
all_words.append(" ".join(words))
|
|
|
|
|
|
|
|
# confirm backup done
|
2024-09-02 11:01:16 +00:00
|
|
|
if debug.layout_type is LayoutType.Mercury and share_count > 1:
|
2024-06-04 13:40:42 +00:00
|
|
|
reset.confirm_read(debug)
|
2024-09-02 11:01:16 +00:00
|
|
|
elif debug.layout_type is not LayoutType.Mercury:
|
2024-06-04 13:40:42 +00:00
|
|
|
reset.confirm_read(debug)
|
2024-04-11 14:21:17 +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)
|
|
|
|
|
|
|
|
# validate that all combinations will result in the correct master secret
|
|
|
|
reset.validate_mnemonics(all_words[:share_threshold], secret)
|
|
|
|
|
|
|
|
assert device_handler.result() == "Seed successfully backed up"
|
|
|
|
features = device_handler.features()
|
|
|
|
assert features.initialized is True
|
2024-05-23 14:09:16 +00:00
|
|
|
assert features.backup_availability == messages.BackupAvailability.NotAvailable
|
2024-04-11 14:21:17 +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
|