2020-02-17 16:35:46 +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>.
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from trezorlib import device, messages
|
2024-11-15 16:31:22 +00:00
|
|
|
from trezorlib.debuglink import SessionDebugWrapper as Session
|
2020-02-17 16:35:46 +00:00
|
|
|
from trezorlib.exceptions import TrezorFailure
|
|
|
|
from trezorlib.messages import SdProtectOperationType as Op
|
|
|
|
|
2023-08-11 15:57:32 +00:00
|
|
|
from .. import translations as TR
|
|
|
|
|
2024-09-02 11:01:16 +00:00
|
|
|
pytestmark = pytest.mark.models("core", skip="safe3")
|
2020-02-17 16:35:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sd_card(formatted=False)
|
2024-11-15 16:31:22 +00:00
|
|
|
def test_sd_format(session: Session):
|
|
|
|
device.sd_protect(session, Op.ENABLE)
|
|
|
|
assert session.features.sd_protection is True
|
2020-02-17 16:35:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sd_card(formatted=False)
|
2024-11-15 16:31:22 +00:00
|
|
|
def test_sd_no_format(session: Session):
|
|
|
|
debug = session.client.debug
|
|
|
|
|
2020-02-17 16:35:46 +00:00
|
|
|
def input_flow():
|
|
|
|
yield # enable SD protection?
|
2024-11-15 16:31:22 +00:00
|
|
|
debug.press_yes()
|
2020-02-17 16:35:46 +00:00
|
|
|
|
|
|
|
yield # format SD card
|
2024-11-15 16:31:22 +00:00
|
|
|
debug.press_no()
|
2020-02-17 16:35:46 +00:00
|
|
|
|
2024-11-15 16:31:22 +00:00
|
|
|
with session, session.client as client, pytest.raises(TrezorFailure) as e:
|
2020-02-17 16:35:46 +00:00
|
|
|
client.set_input_flow(input_flow)
|
2024-11-15 16:31:22 +00:00
|
|
|
device.sd_protect(session, Op.ENABLE)
|
2020-02-17 16:35:46 +00:00
|
|
|
|
2020-03-24 15:24:53 +00:00
|
|
|
assert e.value.code == messages.FailureType.ProcessError
|
2020-02-21 14:53:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sd_card
|
|
|
|
@pytest.mark.setup_client(pin="1234")
|
2024-11-15 16:31:22 +00:00
|
|
|
def test_sd_protect_unlock(session: Session):
|
|
|
|
debug = session.client.debug
|
|
|
|
layout = debug.read_layout
|
|
|
|
session.lock()
|
2022-10-25 13:08:19 +00:00
|
|
|
|
2020-02-21 14:53:53 +00:00
|
|
|
def input_flow_enable_sd_protect():
|
2024-11-15 16:31:22 +00:00
|
|
|
# debug.press_yes()
|
2020-04-27 11:15:25 +00:00
|
|
|
yield # Enter PIN to unlock device
|
2023-06-20 07:25:02 +00:00
|
|
|
assert "PinKeyboard" in layout().all_components()
|
2024-11-15 16:31:22 +00:00
|
|
|
debug.input("1234")
|
2020-04-27 11:15:25 +00:00
|
|
|
|
2020-02-21 14:53:53 +00:00
|
|
|
yield # do you really want to enable SD protection
|
2024-11-14 14:11:03 +00:00
|
|
|
assert TR.sd_card__enable in layout().text_content()
|
2024-11-15 16:31:22 +00:00
|
|
|
debug.press_yes()
|
2020-02-21 14:53:53 +00:00
|
|
|
|
|
|
|
yield # enter current PIN
|
2023-06-20 07:25:02 +00:00
|
|
|
assert "PinKeyboard" in layout().all_components()
|
2024-11-15 16:31:22 +00:00
|
|
|
debug.input("1234")
|
2020-02-21 14:53:53 +00:00
|
|
|
|
|
|
|
yield # you have successfully enabled SD protection
|
2024-11-14 14:11:03 +00:00
|
|
|
assert TR.sd_card__enabled in layout().text_content()
|
2024-11-15 16:31:22 +00:00
|
|
|
debug.press_yes()
|
2020-02-21 14:53:53 +00:00
|
|
|
|
2024-11-15 16:31:22 +00:00
|
|
|
with session, session.client as client:
|
2020-07-28 12:40:54 +00:00
|
|
|
client.watch_layout()
|
2020-02-21 14:53:53 +00:00
|
|
|
client.set_input_flow(input_flow_enable_sd_protect)
|
2024-11-15 16:31:22 +00:00
|
|
|
device.sd_protect(session, Op.ENABLE)
|
2020-02-21 14:53:53 +00:00
|
|
|
|
|
|
|
def input_flow_change_pin():
|
|
|
|
yield # do you really want to change PIN?
|
2024-11-14 14:11:03 +00:00
|
|
|
assert layout().title() == TR.pin__title_settings
|
2024-11-15 16:31:22 +00:00
|
|
|
debug.press_yes()
|
2020-02-21 14:53:53 +00:00
|
|
|
|
|
|
|
yield # enter current PIN
|
2023-06-20 07:25:02 +00:00
|
|
|
assert "PinKeyboard" in layout().all_components()
|
2024-11-15 16:31:22 +00:00
|
|
|
debug.input("1234")
|
2020-02-21 14:53:53 +00:00
|
|
|
|
|
|
|
yield # enter new PIN
|
2023-06-20 07:25:02 +00:00
|
|
|
assert "PinKeyboard" in layout().all_components()
|
2024-11-15 16:31:22 +00:00
|
|
|
debug.input("1234")
|
2020-02-21 14:53:53 +00:00
|
|
|
|
|
|
|
yield # enter new PIN again
|
2023-06-20 07:25:02 +00:00
|
|
|
assert "PinKeyboard" in layout().all_components()
|
2024-11-15 16:31:22 +00:00
|
|
|
debug.input("1234")
|
2020-02-21 14:53:53 +00:00
|
|
|
|
|
|
|
yield # Pin change successful
|
2024-11-14 14:11:03 +00:00
|
|
|
assert TR.pin__changed in layout().text_content()
|
2024-11-15 16:31:22 +00:00
|
|
|
debug.press_yes()
|
2020-02-21 14:53:53 +00:00
|
|
|
|
2024-11-15 16:31:22 +00:00
|
|
|
with session, session.client as client:
|
2020-07-28 12:40:54 +00:00
|
|
|
client.watch_layout()
|
2020-02-21 14:53:53 +00:00
|
|
|
client.set_input_flow(input_flow_change_pin)
|
2024-11-15 16:31:22 +00:00
|
|
|
device.change_pin(session)
|
2020-02-21 14:53:53 +00:00
|
|
|
|
2024-11-15 16:31:22 +00:00
|
|
|
debug.erase_sd_card(format=False)
|
2020-02-21 14:53:53 +00:00
|
|
|
|
|
|
|
def input_flow_change_pin_format():
|
|
|
|
yield # do you really want to change PIN?
|
2024-11-14 14:11:03 +00:00
|
|
|
assert layout().title() == TR.pin__title_settings
|
2024-11-15 16:31:22 +00:00
|
|
|
debug.press_yes()
|
2020-02-21 14:53:53 +00:00
|
|
|
|
2020-03-16 22:40:39 +00:00
|
|
|
yield # enter current PIN
|
2023-06-20 07:25:02 +00:00
|
|
|
assert "PinKeyboard" in layout().all_components()
|
2024-11-15 16:31:22 +00:00
|
|
|
debug.input("1234")
|
2020-03-16 22:40:39 +00:00
|
|
|
|
2020-02-21 14:53:53 +00:00
|
|
|
yield # SD card problem
|
2024-11-14 14:11:03 +00:00
|
|
|
assert (
|
|
|
|
TR.sd_card__unplug_and_insert_correct in layout().text_content()
|
|
|
|
or TR.sd_card__insert_correct_card in layout().text_content()
|
2024-03-09 21:05:05 +00:00
|
|
|
)
|
2024-11-15 16:31:22 +00:00
|
|
|
debug.press_no() # close
|
2020-02-21 14:53:53 +00:00
|
|
|
|
2024-11-15 16:31:22 +00:00
|
|
|
with session, session.client as client, pytest.raises(TrezorFailure) as e:
|
2020-07-28 12:40:54 +00:00
|
|
|
client.watch_layout()
|
2020-02-21 14:53:53 +00:00
|
|
|
client.set_input_flow(input_flow_change_pin_format)
|
2024-11-15 16:31:22 +00:00
|
|
|
device.change_pin(session)
|
2020-02-21 14:53:53 +00:00
|
|
|
|
2020-03-24 15:24:53 +00:00
|
|
|
assert e.value.code == messages.FailureType.ProcessError
|