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
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from trezorlib import device, messages
|
|
|
|
|
|
|
|
from .. import buttons
|
|
|
|
from ..common import generate_entropy
|
|
|
|
from . import reset
|
|
|
|
|
2022-10-25 10:46:37 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from ..device_handler import BackgroundDeviceHandler
|
|
|
|
|
|
|
|
|
2019-11-04 14:45:54 +00:00
|
|
|
EXTERNAL_ENTROPY = b"zlutoucky kun upel divoke ody" * 2
|
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
with_mock_urandom = mock.patch("os.urandom", mock.Mock(return_value=EXTERNAL_ENTROPY))
|
|
|
|
|
2019-11-04 14:45:54 +00:00
|
|
|
|
|
|
|
@pytest.mark.skip_t1
|
|
|
|
@pytest.mark.setup_client(uninitialized=True)
|
2019-11-15 14:54:16 +00:00
|
|
|
@with_mock_urandom
|
2022-10-25 10:46:37 +00:00
|
|
|
def test_reset_slip39_advanced_2of2groups_2of2shares(
|
|
|
|
device_handler: "BackgroundDeviceHandler",
|
|
|
|
):
|
2019-11-04 14:45:54 +00:00
|
|
|
features = device_handler.features()
|
|
|
|
debug = device_handler.debuglink()
|
|
|
|
|
|
|
|
assert features.initialized is False
|
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
device_handler.run(
|
|
|
|
device.reset,
|
|
|
|
backup_type=messages.BackupType.Slip39_Advanced,
|
|
|
|
pin_protection=False,
|
|
|
|
)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# confirm new wallet
|
2023-01-13 19:41:58 +00:00
|
|
|
reset.confirm_wait(debug, "Wallet creation")
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# confirm back up
|
2020-05-26 10:55:22 +00:00
|
|
|
reset.confirm_read(debug, "Success")
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# confirm checklist
|
|
|
|
reset.confirm_read(debug, "Checklist")
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# set num of groups
|
|
|
|
reset.set_selection(debug, buttons.RESET_MINUS, 3)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# confirm checklist
|
|
|
|
reset.confirm_read(debug, "Checklist")
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# set group threshold
|
|
|
|
reset.set_selection(debug, buttons.RESET_MINUS, 0)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# confirm checklist
|
|
|
|
reset.confirm_read(debug, "Checklist")
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# set share num and threshold for groups
|
|
|
|
for _ in range(2):
|
|
|
|
# set num of shares
|
|
|
|
reset.set_selection(debug, buttons.RESET_MINUS, 3)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# set share threshold
|
|
|
|
reset.set_selection(debug, buttons.RESET_MINUS, 0)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# confirm backup warning
|
|
|
|
reset.confirm_read(debug, "Caution")
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2022-10-25 10:46:37 +00:00
|
|
|
all_words: list[str] = []
|
2019-11-15 14:54:16 +00:00
|
|
|
for _ in range(2):
|
2019-11-04 14:45:54 +00:00
|
|
|
for _ in range(2):
|
2019-11-15 14:54:16 +00:00
|
|
|
# read words
|
|
|
|
words = reset.read_words(debug, True)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# confirm words
|
|
|
|
reset.confirm_words(debug, words)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# confirm share checked
|
|
|
|
reset.confirm_read(debug, "Success")
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
all_words.append(" ".join(words))
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# confirm backup done
|
|
|
|
reset.confirm_read(debug, "Success")
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# generate secret locally
|
|
|
|
internal_entropy = debug.state().reset_entropy
|
2022-10-25 10:46:37 +00:00
|
|
|
assert internal_entropy is not None
|
2019-11-15 14:54:16 +00:00
|
|
|
secret = generate_entropy(128, internal_entropy, EXTERNAL_ENTROPY)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +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
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
assert device_handler.result() == "Initialized"
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
features = device_handler.features()
|
|
|
|
assert features.initialized is True
|
|
|
|
assert features.needs_backup is False
|
|
|
|
assert features.pin_protection is False
|
|
|
|
assert features.passphrase_protection is False
|
|
|
|
assert features.backup_type is messages.BackupType.Slip39_Advanced
|
2019-11-04 14:45:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_t1
|
|
|
|
@pytest.mark.setup_client(uninitialized=True)
|
2020-03-09 09:31:17 +00:00
|
|
|
@pytest.mark.slow
|
2019-11-15 14:54:16 +00:00
|
|
|
@with_mock_urandom
|
2022-10-25 10:46:37 +00:00
|
|
|
def test_reset_slip39_advanced_16of16groups_16of16shares(
|
|
|
|
device_handler: "BackgroundDeviceHandler",
|
|
|
|
):
|
2019-11-04 14:45:54 +00:00
|
|
|
features = device_handler.features()
|
|
|
|
debug = device_handler.debuglink()
|
|
|
|
|
|
|
|
assert features.initialized is False
|
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
device_handler.run(
|
|
|
|
device.reset,
|
|
|
|
backup_type=messages.BackupType.Slip39_Advanced,
|
|
|
|
pin_protection=False,
|
|
|
|
)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# confirm new wallet
|
2023-01-13 19:41:58 +00:00
|
|
|
reset.confirm_wait(debug, "Wallet creation")
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# confirm back up
|
2020-05-26 10:55:22 +00:00
|
|
|
reset.confirm_read(debug, "Success")
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# confirm checklist
|
|
|
|
reset.confirm_read(debug, "Checklist")
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# set num of groups
|
|
|
|
reset.set_selection(debug, buttons.RESET_PLUS, 11)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# confirm checklist
|
|
|
|
reset.confirm_read(debug, "Checklist")
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# set group threshold
|
|
|
|
reset.set_selection(debug, buttons.RESET_PLUS, 11)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# confirm checklist
|
|
|
|
reset.confirm_read(debug, "Checklist")
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# set share num and threshold for groups
|
|
|
|
for _ in range(16):
|
|
|
|
# set num of shares
|
|
|
|
reset.set_selection(debug, buttons.RESET_PLUS, 11)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# set share threshold
|
|
|
|
reset.set_selection(debug, buttons.RESET_PLUS, 11)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# confirm backup warning
|
|
|
|
reset.confirm_read(debug, "Caution")
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2022-10-25 10:46:37 +00:00
|
|
|
all_words: list[str] = []
|
2019-11-15 14:54:16 +00:00
|
|
|
for _ in range(16):
|
2019-11-04 14:45:54 +00:00
|
|
|
for _ in range(16):
|
2019-11-15 14:54:16 +00:00
|
|
|
# read words
|
|
|
|
words = reset.read_words(debug, True)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# confirm words
|
|
|
|
reset.confirm_words(debug, words)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# confirm share checked
|
|
|
|
reset.confirm_read(debug, "Success")
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
all_words.append(" ".join(words))
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# confirm backup done
|
|
|
|
reset.confirm_read(debug, "Success")
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
# generate secret locally
|
|
|
|
internal_entropy = debug.state().reset_entropy
|
2022-10-25 10:46:37 +00:00
|
|
|
assert internal_entropy is not None
|
2019-11-15 14:54:16 +00:00
|
|
|
secret = generate_entropy(128, internal_entropy, EXTERNAL_ENTROPY)
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +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
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
assert device_handler.result() == "Initialized"
|
2019-11-04 14:45:54 +00:00
|
|
|
|
2019-11-15 14:54:16 +00:00
|
|
|
features = device_handler.features()
|
|
|
|
assert features.initialized is True
|
|
|
|
assert features.needs_backup is False
|
|
|
|
assert features.pin_protection is False
|
|
|
|
assert features.passphrase_protection is False
|
|
|
|
assert features.backup_type is messages.BackupType.Slip39_Advanced
|