mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 07:28:10 +00:00
python/debuglink: make pin sequences configurable
This commit is contained in:
parent
f947fe97cc
commit
94b85efba1
@ -221,8 +221,12 @@ class DebugUI:
|
||||
self.input_flow = self.INPUT_FLOW_DONE
|
||||
|
||||
def get_pin(self, code=None):
|
||||
if self.pin:
|
||||
return self.pin
|
||||
if isinstance(self.pin, str):
|
||||
return self.debuglink.encode_pin(self.pin)
|
||||
elif self.pin == []:
|
||||
raise AssertionError("PIN sequence ended prematurely")
|
||||
elif self.pin:
|
||||
return self.debuglink.encode_pin(self.pin.pop(0))
|
||||
else:
|
||||
return self.debuglink.read_pin_encoded()
|
||||
|
||||
@ -261,9 +265,6 @@ class TrezorClientDebugLink(TrezorClient):
|
||||
|
||||
self.filters = {}
|
||||
|
||||
# Always press Yes and provide correct pin
|
||||
self.setup_debuglink(True, True)
|
||||
|
||||
# Do not expect any specific response from device
|
||||
self.expected_responses = None
|
||||
self.current_response = None
|
||||
@ -342,12 +343,11 @@ class TrezorClientDebugLink(TrezorClient):
|
||||
self.expected_responses = expected
|
||||
self.current_response = 0
|
||||
|
||||
def setup_debuglink(self, button, pin_correct):
|
||||
# self.button = button # True -> YES button, False -> NO button
|
||||
if pin_correct:
|
||||
self.ui.pin = None
|
||||
def set_pin(self, pin):
|
||||
if isinstance(pin, str):
|
||||
self.ui.pin = pin
|
||||
else:
|
||||
self.ui.pin = "444222"
|
||||
self.ui.pin = list(pin)
|
||||
|
||||
def set_passphrase(self, passphrase):
|
||||
self.ui.passphrase = Mnemonic.normalize_string(passphrase)
|
||||
|
@ -41,25 +41,18 @@ class TestProtectCall:
|
||||
def test_pin(self, client):
|
||||
with client:
|
||||
assert client.debug.read_pin()[0] == "1234"
|
||||
client.setup_debuglink(button=True, pin_correct=True)
|
||||
client.set_expected_responses([proto.PinMatrixRequest(), proto.Address()])
|
||||
self._some_protected_call(client)
|
||||
|
||||
@pytest.mark.setup_client(pin="1234")
|
||||
def test_incorrect_pin(self, client):
|
||||
client.setup_debuglink(button=True, pin_correct=False)
|
||||
with pytest.raises(PinException):
|
||||
self._some_protected_call(client)
|
||||
|
||||
@pytest.mark.setup_client(pin="1234")
|
||||
def test_cancelled_pin(self, client):
|
||||
client.setup_debuglink(button=True, pin_correct=False) # PIN cancel
|
||||
client.set_pin("5678")
|
||||
with pytest.raises(PinException):
|
||||
self._some_protected_call(client)
|
||||
|
||||
@pytest.mark.setup_client(pin="1234", passphrase=True)
|
||||
def test_exponential_backoff_with_reboot(self, client):
|
||||
client.setup_debuglink(button=True, pin_correct=False)
|
||||
client.set_pin("5678")
|
||||
|
||||
def test_backoff(attempts, start):
|
||||
if attempts <= 1:
|
||||
|
Loading…
Reference in New Issue
Block a user