mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-06 16:18:45 +00:00
remove ping.passphrase/pin
This commit is contained in:
parent
48fe192103
commit
a3f3d4fcdb
@ -173,8 +173,6 @@ message SdProtect {
|
|||||||
message Ping {
|
message Ping {
|
||||||
optional string message = 1; // message to send back in Success message
|
optional string message = 1; // message to send back in Success message
|
||||||
optional bool button_protection = 2; // ask for button press
|
optional bool button_protection = 2; // ask for button press
|
||||||
optional bool pin_protection = 3; // ask for PIN if set in device
|
|
||||||
optional bool passphrase_protection = 4; // ask for passphrase if set in device
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,10 +104,6 @@ async def handle_Ping(ctx: wire.Context, msg: Ping) -> Success:
|
|||||||
from trezor.ui.text import Text
|
from trezor.ui.text import Text
|
||||||
|
|
||||||
await require_confirm(ctx, Text("Confirm"), ProtectCall)
|
await require_confirm(ctx, Text("Confirm"), ProtectCall)
|
||||||
if msg.passphrase_protection: # TODO
|
|
||||||
from apps.common import passphrase
|
|
||||||
|
|
||||||
await passphrase.get(ctx)
|
|
||||||
return Success(message=msg.message)
|
return Success(message=msg.message)
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,19 +17,13 @@ class Ping(p.MessageType):
|
|||||||
self,
|
self,
|
||||||
message: str = None,
|
message: str = None,
|
||||||
button_protection: bool = None,
|
button_protection: bool = None,
|
||||||
pin_protection: bool = None,
|
|
||||||
passphrase_protection: bool = None,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
self.message = message
|
self.message = message
|
||||||
self.button_protection = button_protection
|
self.button_protection = button_protection
|
||||||
self.pin_protection = pin_protection
|
|
||||||
self.passphrase_protection = passphrase_protection
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_fields(cls) -> Dict:
|
def get_fields(cls) -> Dict:
|
||||||
return {
|
return {
|
||||||
1: ('message', p.UnicodeType, 0),
|
1: ('message', p.UnicodeType, 0),
|
||||||
2: ('button_protection', p.BoolType, 0),
|
2: ('button_protection', p.BoolType, 0),
|
||||||
3: ('pin_protection', p.BoolType, 0),
|
|
||||||
4: ('passphrase_protection', p.BoolType, 0),
|
|
||||||
}
|
}
|
||||||
|
@ -122,19 +122,6 @@ void fsm_msgPing(const Ping *msg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg->has_pin_protection && msg->pin_protection) {
|
|
||||||
CHECK_PIN
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg->has_passphrase_protection && msg->passphrase_protection) {
|
|
||||||
char dummy[51];
|
|
||||||
if (!protectPassphrase(dummy)) {
|
|
||||||
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
memzero(&dummy, sizeof(dummy));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg->has_message) {
|
if (msg->has_message) {
|
||||||
resp->has_message = true;
|
resp->has_message = true;
|
||||||
memcpy(&(resp->message), &(msg->message), sizeof(resp->message));
|
memcpy(&(resp->message), &(msg->message), sizeof(resp->message));
|
||||||
|
@ -221,17 +221,10 @@ def version():
|
|||||||
@cli.command()
|
@cli.command()
|
||||||
@click.argument("message")
|
@click.argument("message")
|
||||||
@click.option("-b", "--button-protection", is_flag=True)
|
@click.option("-b", "--button-protection", is_flag=True)
|
||||||
@click.option("-p", "--pin-protection", is_flag=True)
|
|
||||||
@click.option("-r", "--passphrase-protection", is_flag=True)
|
|
||||||
@click.pass_obj
|
@click.pass_obj
|
||||||
def ping(connect, message, button_protection, pin_protection, passphrase_protection):
|
def ping(connect, message, button_protection):
|
||||||
"""Send ping message."""
|
"""Send ping message."""
|
||||||
return connect().ping(
|
return connect().ping(message, button_protection=button_protection,)
|
||||||
message,
|
|
||||||
button_protection=button_protection,
|
|
||||||
pin_protection=pin_protection,
|
|
||||||
passphrase_protection=passphrase_protection,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
@ -266,17 +266,13 @@ class TrezorClient:
|
|||||||
|
|
||||||
@tools.expect(messages.Success, field="message")
|
@tools.expect(messages.Success, field="message")
|
||||||
def ping(
|
def ping(
|
||||||
self,
|
self, msg, button_protection=False,
|
||||||
msg,
|
|
||||||
button_protection=False,
|
|
||||||
pin_protection=False,
|
|
||||||
passphrase_protection=False,
|
|
||||||
):
|
):
|
||||||
# We would like ping to work on any valid TrezorClient instance, but
|
# We would like ping to work on any valid TrezorClient instance, but
|
||||||
# due to the protection modes, we need to go through self.call, and that will
|
# due to the protection modes, we need to go through self.call, and that will
|
||||||
# raise an exception if the firmware is too old.
|
# raise an exception if the firmware is too old.
|
||||||
# So we short-circuit the simplest variant of ping with call_raw.
|
# So we short-circuit the simplest variant of ping with call_raw.
|
||||||
if not button_protection and not pin_protection and not passphrase_protection:
|
if not button_protection:
|
||||||
# XXX this should be: `with self:`
|
# XXX this should be: `with self:`
|
||||||
try:
|
try:
|
||||||
self.open()
|
self.open()
|
||||||
@ -284,12 +280,7 @@ class TrezorClient:
|
|||||||
finally:
|
finally:
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
msg = messages.Ping(
|
msg = messages.Ping(message=msg, button_protection=button_protection,)
|
||||||
message=msg,
|
|
||||||
button_protection=button_protection,
|
|
||||||
pin_protection=pin_protection,
|
|
||||||
passphrase_protection=passphrase_protection,
|
|
||||||
)
|
|
||||||
return self.call(msg)
|
return self.call(msg)
|
||||||
|
|
||||||
def get_device_id(self):
|
def get_device_id(self):
|
||||||
|
@ -17,19 +17,13 @@ class Ping(p.MessageType):
|
|||||||
self,
|
self,
|
||||||
message: str = None,
|
message: str = None,
|
||||||
button_protection: bool = None,
|
button_protection: bool = None,
|
||||||
pin_protection: bool = None,
|
|
||||||
passphrase_protection: bool = None,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
self.message = message
|
self.message = message
|
||||||
self.button_protection = button_protection
|
self.button_protection = button_protection
|
||||||
self.pin_protection = pin_protection
|
|
||||||
self.passphrase_protection = passphrase_protection
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_fields(cls) -> Dict:
|
def get_fields(cls) -> Dict:
|
||||||
return {
|
return {
|
||||||
1: ('message', p.UnicodeType, 0),
|
1: ('message', p.UnicodeType, 0),
|
||||||
2: ('button_protection', p.BoolType, 0),
|
2: ('button_protection', p.BoolType, 0),
|
||||||
3: ('pin_protection', p.BoolType, 0),
|
|
||||||
4: ('passphrase_protection', p.BoolType, 0),
|
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class TestDebuglink:
|
|||||||
|
|
||||||
@pytest.mark.setup_client(mnemonic=MNEMONIC12, pin="1234", passphrase=True)
|
@pytest.mark.setup_client(mnemonic=MNEMONIC12, pin="1234", passphrase=True)
|
||||||
def test_pin(self, client):
|
def test_pin(self, client):
|
||||||
resp = client.call_raw(messages.Ping(message="test", pin_protection=True))
|
resp = client.call_raw(messages.GetAddress(address_n=[], coin_name="Testnet"))
|
||||||
assert isinstance(resp, messages.PinMatrixRequest)
|
assert isinstance(resp, messages.PinMatrixRequest)
|
||||||
|
|
||||||
pin, matrix = client.debug.read_pin()
|
pin, matrix = client.debug.read_pin()
|
||||||
@ -43,4 +43,7 @@ class TestDebuglink:
|
|||||||
|
|
||||||
pin_encoded = client.debug.read_pin_encoded()
|
pin_encoded = client.debug.read_pin_encoded()
|
||||||
resp = client.call_raw(messages.PinMatrixAck(pin=pin_encoded))
|
resp = client.call_raw(messages.PinMatrixAck(pin=pin_encoded))
|
||||||
assert isinstance(resp, messages.Success)
|
assert isinstance(resp, messages.PassphraseRequest)
|
||||||
|
|
||||||
|
resp = client.call_raw(messages.PassphraseAck(passphrase=""))
|
||||||
|
assert isinstance(resp, messages.Address)
|
||||||
|
@ -18,7 +18,7 @@ import time
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from trezorlib import device, messages as proto
|
from trezorlib import btc, device, messages as proto
|
||||||
|
|
||||||
EXPECTED_RESPONSES_NOPIN = [proto.ButtonRequest(), proto.Success(), proto.Features()]
|
EXPECTED_RESPONSES_NOPIN = [proto.ButtonRequest(), proto.Success(), proto.Features()]
|
||||||
EXPECTED_RESPONSES_PIN = [proto.PinMatrixRequest()] + EXPECTED_RESPONSES_NOPIN
|
EXPECTED_RESPONSES_PIN = [proto.PinMatrixRequest()] + EXPECTED_RESPONSES_NOPIN
|
||||||
@ -91,13 +91,13 @@ class TestMsgApplysettings:
|
|||||||
time.sleep(0.1) # sleep less than auto-lock delay
|
time.sleep(0.1) # sleep less than auto-lock delay
|
||||||
with client:
|
with client:
|
||||||
# No PIN protection is required.
|
# No PIN protection is required.
|
||||||
client.set_expected_responses([proto.Success()])
|
client.set_expected_responses([proto.Address()])
|
||||||
client.ping(msg="", pin_protection=True)
|
btc.get_address(client, "Testnet", [0])
|
||||||
|
|
||||||
time.sleep(10.1) # sleep more than auto-lock delay
|
time.sleep(10.1) # sleep more than auto-lock delay
|
||||||
with client:
|
with client:
|
||||||
client.set_expected_responses([proto.PinMatrixRequest(), proto.Success()])
|
client.set_expected_responses([proto.PinMatrixRequest(), proto.Address()])
|
||||||
client.ping(msg="", pin_protection=True)
|
btc.get_address(client, "Testnet", [0])
|
||||||
|
|
||||||
@pytest.mark.skip_t2
|
@pytest.mark.skip_t2
|
||||||
def test_apply_minimal_auto_lock_delay(self, client):
|
def test_apply_minimal_auto_lock_delay(self, client):
|
||||||
@ -114,16 +114,16 @@ class TestMsgApplysettings:
|
|||||||
time.sleep(0.1) # sleep less than auto-lock delay
|
time.sleep(0.1) # sleep less than auto-lock delay
|
||||||
with client:
|
with client:
|
||||||
# No PIN protection is required.
|
# No PIN protection is required.
|
||||||
client.set_expected_responses([proto.Success()])
|
client.set_expected_responses([proto.Address()])
|
||||||
client.ping(msg="", pin_protection=True)
|
btc.get_address(client, "Testnet", [0])
|
||||||
|
|
||||||
time.sleep(2) # sleep less than the minimal auto-lock delay
|
time.sleep(2) # sleep less than the minimal auto-lock delay
|
||||||
with client:
|
with client:
|
||||||
# No PIN protection is required.
|
# No PIN protection is required.
|
||||||
client.set_expected_responses([proto.Success()])
|
client.set_expected_responses([proto.Address()])
|
||||||
client.ping(msg="", pin_protection=True)
|
btc.get_address(client, "Testnet", [0])
|
||||||
|
|
||||||
time.sleep(10.1) # sleep more than the minimal auto-lock delay
|
time.sleep(10.1) # sleep more than the minimal auto-lock delay
|
||||||
with client:
|
with client:
|
||||||
client.set_expected_responses([proto.PinMatrixRequest(), proto.Success()])
|
client.set_expected_responses([proto.PinMatrixRequest(), proto.Address()])
|
||||||
client.ping(msg="", pin_protection=True)
|
btc.get_address(client, "Testnet", [0])
|
||||||
|
@ -225,5 +225,5 @@ def test_set_pin_to_wipe_code(client):
|
|||||||
# Check that there is no PIN protection.
|
# Check that there is no PIN protection.
|
||||||
client.init_device()
|
client.init_device()
|
||||||
assert client.features.pin_protection is False
|
assert client.features.pin_protection is False
|
||||||
ret = client.call_raw(messages.Ping(pin_protection=True))
|
resp = client.call_raw(messages.GetAddress())
|
||||||
assert isinstance(ret, messages.Success)
|
assert isinstance(resp, messages.Address)
|
||||||
|
@ -29,8 +29,8 @@ class TestMsgChangepin:
|
|||||||
assert features.pin_protection is False
|
assert features.pin_protection is False
|
||||||
|
|
||||||
# Check that there's no PIN protection
|
# Check that there's no PIN protection
|
||||||
ret = client.call_raw(proto.Ping(pin_protection=True))
|
ret = client.call_raw(proto.GetAddress())
|
||||||
assert isinstance(ret, proto.Success)
|
assert isinstance(ret, proto.Address)
|
||||||
|
|
||||||
# Let's set new PIN
|
# Let's set new PIN
|
||||||
ret = client.call_raw(proto.ChangePin())
|
ret = client.call_raw(proto.ChangePin())
|
||||||
@ -66,7 +66,7 @@ class TestMsgChangepin:
|
|||||||
assert features.pin_protection is True
|
assert features.pin_protection is True
|
||||||
|
|
||||||
# Check that there's PIN protection
|
# Check that there's PIN protection
|
||||||
ret = client.call_raw(proto.Ping(pin_protection=True))
|
ret = client.call_raw(proto.GetAddress())
|
||||||
assert isinstance(ret, proto.PinMatrixRequest)
|
assert isinstance(ret, proto.PinMatrixRequest)
|
||||||
client.call_raw(proto.Cancel())
|
client.call_raw(proto.Cancel())
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ class TestMsgChangepin:
|
|||||||
assert features.pin_protection is True
|
assert features.pin_protection is True
|
||||||
|
|
||||||
# Check that there's PIN protection
|
# Check that there's PIN protection
|
||||||
ret = client.call_raw(proto.Ping(pin_protection=True))
|
ret = client.call_raw(proto.GetAddress())
|
||||||
assert isinstance(ret, proto.PinMatrixRequest)
|
assert isinstance(ret, proto.PinMatrixRequest)
|
||||||
client.call_raw(proto.Cancel())
|
client.call_raw(proto.Cancel())
|
||||||
|
|
||||||
@ -135,16 +135,16 @@ class TestMsgChangepin:
|
|||||||
# Check that there's no PIN protection now
|
# Check that there's no PIN protection now
|
||||||
features = client.call_raw(proto.Initialize())
|
features = client.call_raw(proto.Initialize())
|
||||||
assert features.pin_protection is False
|
assert features.pin_protection is False
|
||||||
ret = client.call_raw(proto.Ping(pin_protection=True))
|
ret = client.call_raw(proto.GetAddress())
|
||||||
assert isinstance(ret, proto.Success)
|
assert isinstance(ret, proto.Address)
|
||||||
|
|
||||||
def test_set_failed(self, client):
|
def test_set_failed(self, client):
|
||||||
features = client.call_raw(proto.Initialize())
|
features = client.call_raw(proto.Initialize())
|
||||||
assert features.pin_protection is False
|
assert features.pin_protection is False
|
||||||
|
|
||||||
# Check that there's no PIN protection
|
# Check that there's no PIN protection
|
||||||
ret = client.call_raw(proto.Ping(pin_protection=True))
|
ret = client.call_raw(proto.GetAddress())
|
||||||
assert isinstance(ret, proto.Success)
|
assert isinstance(ret, proto.Address)
|
||||||
|
|
||||||
# Let's set new PIN
|
# Let's set new PIN
|
||||||
ret = client.call_raw(proto.ChangePin())
|
ret = client.call_raw(proto.ChangePin())
|
||||||
@ -170,8 +170,8 @@ class TestMsgChangepin:
|
|||||||
# Check that there's still no PIN protection now
|
# Check that there's still no PIN protection now
|
||||||
features = client.call_raw(proto.Initialize())
|
features = client.call_raw(proto.Initialize())
|
||||||
assert features.pin_protection is False
|
assert features.pin_protection is False
|
||||||
ret = client.call_raw(proto.Ping(pin_protection=True))
|
ret = client.call_raw(proto.GetAddress())
|
||||||
assert isinstance(ret, proto.Success)
|
assert isinstance(ret, proto.Address)
|
||||||
|
|
||||||
@pytest.mark.setup_client(pin=True)
|
@pytest.mark.setup_client(pin=True)
|
||||||
def test_set_failed_2(self, client):
|
def test_set_failed_2(self, client):
|
||||||
@ -211,8 +211,8 @@ class TestMsgChangepin:
|
|||||||
|
|
||||||
def check_pin(self, client, pin):
|
def check_pin(self, client, pin):
|
||||||
client.clear_session()
|
client.clear_session()
|
||||||
ret = client.call_raw(proto.Ping(pin_protection=True))
|
ret = client.call_raw(proto.GetAddress())
|
||||||
assert isinstance(ret, proto.PinMatrixRequest)
|
assert isinstance(ret, proto.PinMatrixRequest)
|
||||||
pin_encoded = client.debug.encode_pin(pin)
|
pin_encoded = client.debug.encode_pin(pin)
|
||||||
ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
|
ret = client.call_raw(proto.PinMatrixAck(pin=pin_encoded))
|
||||||
assert isinstance(ret, proto.Success)
|
assert isinstance(ret, proto.Address)
|
||||||
|
@ -17,77 +17,64 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from trezorlib import messages as proto
|
from trezorlib import messages as proto
|
||||||
|
from trezorlib.btc import get_public_node
|
||||||
|
from trezorlib.tools import parse_path
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip_t2
|
@pytest.mark.skip_ui
|
||||||
class TestMsgClearsession:
|
@pytest.mark.setup_client(pin=True, passphrase=True)
|
||||||
@pytest.mark.setup_client(pin=True, passphrase=True)
|
def test_clear_session(client):
|
||||||
def test_clearsession(self, client):
|
if client.features.model == "1":
|
||||||
with client:
|
init_responses = [
|
||||||
client.set_expected_responses(
|
|
||||||
[
|
|
||||||
proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall),
|
|
||||||
proto.PinMatrixRequest(),
|
proto.PinMatrixRequest(),
|
||||||
proto.PassphraseRequest(),
|
proto.PassphraseRequest(),
|
||||||
proto.Success(),
|
|
||||||
]
|
]
|
||||||
|
else:
|
||||||
|
init_responses = [
|
||||||
|
proto.PassphraseRequest(),
|
||||||
|
]
|
||||||
|
cached_responses = [
|
||||||
|
proto.ButtonRequest(code=proto.ButtonRequestType.PublicKey),
|
||||||
|
proto.PublicKey(),
|
||||||
|
]
|
||||||
|
|
||||||
|
with client:
|
||||||
|
client.set_expected_responses(init_responses + cached_responses)
|
||||||
|
assert (
|
||||||
|
get_public_node(
|
||||||
|
client, parse_path("44'/0'/0'"), show_display=True
|
||||||
|
).node.public_key.hex()
|
||||||
|
== "03c8166eb40ac84088b618ec07c7cebadacee31c5f5b04a1e8c2a2f3e748eb2cdd"
|
||||||
)
|
)
|
||||||
res = client.ping(
|
|
||||||
"random data",
|
|
||||||
button_protection=True,
|
|
||||||
pin_protection=True,
|
|
||||||
passphrase_protection=True,
|
|
||||||
)
|
|
||||||
assert res == "random data"
|
|
||||||
|
|
||||||
with client:
|
with client:
|
||||||
# pin and passphrase are cached
|
# pin and passphrase are cached
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(cached_responses)
|
||||||
[
|
assert (
|
||||||
proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall),
|
get_public_node(
|
||||||
proto.Success(),
|
client, parse_path("44'/0'/0'"), show_display=True
|
||||||
]
|
).node.public_key.hex()
|
||||||
|
== "03c8166eb40ac84088b618ec07c7cebadacee31c5f5b04a1e8c2a2f3e748eb2cdd"
|
||||||
)
|
)
|
||||||
res = client.ping(
|
|
||||||
"random data",
|
|
||||||
button_protection=True,
|
|
||||||
pin_protection=True,
|
|
||||||
passphrase_protection=True,
|
|
||||||
)
|
|
||||||
assert res == "random data"
|
|
||||||
|
|
||||||
client.clear_session()
|
client.clear_session()
|
||||||
|
|
||||||
# session cache is cleared
|
# session cache is cleared
|
||||||
with client:
|
with client:
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(init_responses + cached_responses)
|
||||||
[
|
assert (
|
||||||
proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall),
|
get_public_node(
|
||||||
proto.PinMatrixRequest(),
|
client, parse_path("44'/0'/0'"), show_display=True
|
||||||
proto.PassphraseRequest(),
|
).node.public_key.hex()
|
||||||
proto.Success(),
|
== "03c8166eb40ac84088b618ec07c7cebadacee31c5f5b04a1e8c2a2f3e748eb2cdd"
|
||||||
]
|
|
||||||
)
|
)
|
||||||
res = client.ping(
|
|
||||||
"random data",
|
|
||||||
button_protection=True,
|
|
||||||
pin_protection=True,
|
|
||||||
passphrase_protection=True,
|
|
||||||
)
|
|
||||||
assert res == "random data"
|
|
||||||
|
|
||||||
with client:
|
with client:
|
||||||
# pin and passphrase are cached
|
# pin and passphrase are cached
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(cached_responses)
|
||||||
[
|
assert (
|
||||||
proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall),
|
get_public_node(
|
||||||
proto.Success(),
|
client, parse_path("44'/0'/0'"), show_display=True
|
||||||
]
|
).node.public_key.hex()
|
||||||
|
== "03c8166eb40ac84088b618ec07c7cebadacee31c5f5b04a1e8c2a2f3e748eb2cdd"
|
||||||
)
|
)
|
||||||
res = client.ping(
|
|
||||||
"random data",
|
|
||||||
button_protection=True,
|
|
||||||
pin_protection=True,
|
|
||||||
passphrase_protection=True,
|
|
||||||
)
|
|
||||||
assert res == "random data"
|
|
||||||
|
@ -19,8 +19,8 @@ import pytest
|
|||||||
from trezorlib import messages as proto
|
from trezorlib import messages as proto
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip_t2
|
|
||||||
class TestMsgPing:
|
class TestMsgPing:
|
||||||
|
@pytest.mark.skip_ui
|
||||||
@pytest.mark.setup_client(pin=True, passphrase=True)
|
@pytest.mark.setup_client(pin=True, passphrase=True)
|
||||||
def test_ping(self, client):
|
def test_ping(self, client):
|
||||||
with client:
|
with client:
|
||||||
@ -37,48 +37,3 @@ class TestMsgPing:
|
|||||||
)
|
)
|
||||||
res = client.ping("random data", button_protection=True)
|
res = client.ping("random data", button_protection=True)
|
||||||
assert res == "random data"
|
assert res == "random data"
|
||||||
|
|
||||||
with client:
|
|
||||||
client.set_expected_responses([proto.PinMatrixRequest(), proto.Success()])
|
|
||||||
res = client.ping("random data", pin_protection=True)
|
|
||||||
assert res == "random data"
|
|
||||||
|
|
||||||
with client:
|
|
||||||
client.set_expected_responses([proto.PassphraseRequest(), proto.Success()])
|
|
||||||
res = client.ping("random data", passphrase_protection=True)
|
|
||||||
assert res == "random data"
|
|
||||||
|
|
||||||
@pytest.mark.setup_client(pin=True, passphrase=True)
|
|
||||||
def test_ping_caching(self, client):
|
|
||||||
with client:
|
|
||||||
client.set_expected_responses(
|
|
||||||
[
|
|
||||||
proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall),
|
|
||||||
proto.PinMatrixRequest(),
|
|
||||||
proto.PassphraseRequest(),
|
|
||||||
proto.Success(),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
res = client.ping(
|
|
||||||
"random data",
|
|
||||||
button_protection=True,
|
|
||||||
pin_protection=True,
|
|
||||||
passphrase_protection=True,
|
|
||||||
)
|
|
||||||
assert res == "random data"
|
|
||||||
|
|
||||||
with client:
|
|
||||||
# pin and passphrase are cached
|
|
||||||
client.set_expected_responses(
|
|
||||||
[
|
|
||||||
proto.ButtonRequest(code=proto.ButtonRequestType.ProtectCall),
|
|
||||||
proto.Success(),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
res = client.ping(
|
|
||||||
"random data",
|
|
||||||
button_protection=True,
|
|
||||||
pin_protection=True,
|
|
||||||
passphrase_protection=True,
|
|
||||||
)
|
|
||||||
assert res == "random data"
|
|
||||||
|
@ -85,7 +85,7 @@ class TestMsgRecoverydevice:
|
|||||||
assert client.features.passphrase_protection is True
|
assert client.features.passphrase_protection is True
|
||||||
|
|
||||||
# Do passphrase-protected action, PassphraseRequest should be raised
|
# Do passphrase-protected action, PassphraseRequest should be raised
|
||||||
resp = client.call_raw(proto.Ping(passphrase_protection=True))
|
resp = client.call_raw(proto.GetAddress(address_n=[], coin_name="Testnet"))
|
||||||
assert isinstance(resp, proto.PassphraseRequest)
|
assert isinstance(resp, proto.PassphraseRequest)
|
||||||
client.call_raw(proto.Cancel())
|
client.call_raw(proto.Cancel())
|
||||||
|
|
||||||
@ -136,13 +136,9 @@ class TestMsgRecoverydevice:
|
|||||||
assert client.features.pin_protection is False
|
assert client.features.pin_protection is False
|
||||||
assert client.features.passphrase_protection is False
|
assert client.features.passphrase_protection is False
|
||||||
|
|
||||||
# Do passphrase-protected action, PassphraseRequest should NOT be raised
|
# Do pin & passphrase-protected action, PassphraseRequest should NOT be raised
|
||||||
resp = client.call_raw(proto.Ping(passphrase_protection=True))
|
resp = client.call_raw(proto.GetAddress(address_n=[], coin_name="Testnet"))
|
||||||
assert isinstance(resp, proto.Success)
|
assert isinstance(resp, proto.Address)
|
||||||
|
|
||||||
# Do PIN-protected action, PinRequest should NOT be raised
|
|
||||||
resp = client.call_raw(proto.Ping(pin_protection=True))
|
|
||||||
assert isinstance(resp, proto.Success)
|
|
||||||
|
|
||||||
@pytest.mark.setup_client(uninitialized=True)
|
@pytest.mark.setup_client(uninitialized=True)
|
||||||
def test_word_fail(self, client):
|
def test_word_fail(self, client):
|
||||||
|
@ -87,13 +87,9 @@ class TestMsgResetDevice:
|
|||||||
assert resp.pin_protection is False
|
assert resp.pin_protection is False
|
||||||
assert resp.passphrase_protection is False
|
assert resp.passphrase_protection is False
|
||||||
|
|
||||||
# Do passphrase-protected action, PassphraseRequest should NOT be raised
|
# Do pin & passphrase-protected action, PassphraseRequest should NOT be raised
|
||||||
resp = client.call_raw(proto.Ping(passphrase_protection=True))
|
resp = client.call_raw(proto.GetAddress(address_n=[], coin_name="Testnet"))
|
||||||
assert isinstance(resp, proto.Success)
|
assert isinstance(resp, proto.Address)
|
||||||
|
|
||||||
# Do PIN-protected action, PinRequest should NOT be raised
|
|
||||||
resp = client.call_raw(proto.Ping(pin_protection=True))
|
|
||||||
assert isinstance(resp, proto.Success)
|
|
||||||
|
|
||||||
@pytest.mark.setup_client(uninitialized=True)
|
@pytest.mark.setup_client(uninitialized=True)
|
||||||
def test_reset_device_pin(self, client):
|
def test_reset_device_pin(self, client):
|
||||||
@ -180,7 +176,7 @@ class TestMsgResetDevice:
|
|||||||
assert resp.passphrase_protection is True
|
assert resp.passphrase_protection is True
|
||||||
|
|
||||||
# Do passphrase-protected action, PassphraseRequest should be raised
|
# Do passphrase-protected action, PassphraseRequest should be raised
|
||||||
resp = client.call_raw(proto.Ping(passphrase_protection=True))
|
resp = client.call_raw(proto.GetAddress(address_n=[], coin_name="Testnet"))
|
||||||
assert isinstance(resp, proto.PassphraseRequest)
|
assert isinstance(resp, proto.PassphraseRequest)
|
||||||
client.call_raw(proto.Cancel())
|
client.call_raw(proto.Cancel())
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import time
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from trezorlib import messages as proto
|
from trezorlib import btc, messages as proto
|
||||||
from trezorlib.exceptions import PinException
|
from trezorlib.exceptions import PinException
|
||||||
|
|
||||||
# FIXME TODO Add passphrase tests
|
# FIXME TODO Add passphrase tests
|
||||||
@ -26,84 +26,45 @@ from trezorlib.exceptions import PinException
|
|||||||
|
|
||||||
@pytest.mark.skip_t2
|
@pytest.mark.skip_t2
|
||||||
class TestProtectCall:
|
class TestProtectCall:
|
||||||
def _some_protected_call(self, client, button, pin, passphrase):
|
def _some_protected_call(self, client):
|
||||||
# This method perform any call which have protection in the device
|
# This method perform any call which have protection in the device
|
||||||
res = client.ping(
|
res = btc.get_address(client, "Testnet", [0])
|
||||||
"random data",
|
assert res == "mndoQDWatQhfeQbprzZxD43mZ75Z94D6vz"
|
||||||
button_protection=button,
|
|
||||||
pin_protection=pin,
|
|
||||||
passphrase_protection=passphrase,
|
|
||||||
)
|
|
||||||
assert res == "random data"
|
|
||||||
|
|
||||||
@pytest.mark.setup_client(pin="1234", passphrase=True)
|
@pytest.mark.setup_client(pin="1234", passphrase=True)
|
||||||
def test_expected_responses(self, client):
|
def test_expected_responses(self, client):
|
||||||
# This is low-level test of set_expected_responses()
|
with client:
|
||||||
# feature of debugging client
|
|
||||||
|
|
||||||
with pytest.raises(AssertionError), client:
|
|
||||||
# Scenario 1 - Received unexpected message
|
|
||||||
client.set_expected_responses([])
|
|
||||||
self._some_protected_call(client, True, True, True)
|
|
||||||
|
|
||||||
with pytest.raises(AssertionError), client:
|
|
||||||
# Scenario 2 - Received other than expected message
|
|
||||||
client.set_expected_responses([proto.Success()])
|
|
||||||
self._some_protected_call(client, True, True, True)
|
|
||||||
|
|
||||||
with pytest.raises(AssertionError), client:
|
|
||||||
# Scenario 3 - Not received expected message
|
|
||||||
client.set_expected_responses(
|
|
||||||
[proto.ButtonRequest(), proto.Success(), proto.Success()]
|
|
||||||
) # This is expected, but not received
|
|
||||||
self._some_protected_call(client, True, False, False)
|
|
||||||
|
|
||||||
with pytest.raises(AssertionError), client:
|
|
||||||
# Scenario 4 - Received what expected
|
# Scenario 4 - Received what expected
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[
|
[proto.PinMatrixRequest(), proto.PassphraseRequest(), proto.Address()]
|
||||||
proto.ButtonRequest(),
|
|
||||||
proto.PinMatrixRequest(),
|
|
||||||
proto.PassphraseRequest(),
|
|
||||||
proto.Success(message="random data"),
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
self._some_protected_call(client, True, True, True)
|
self._some_protected_call(client)
|
||||||
|
|
||||||
with pytest.raises(AssertionError), client:
|
|
||||||
# Scenario 5 - Failed message by field filter
|
|
||||||
client.set_expected_responses(
|
|
||||||
[proto.ButtonRequest(), proto.Success(message="wrong data")]
|
|
||||||
)
|
|
||||||
self._some_protected_call(client, True, True, True)
|
|
||||||
|
|
||||||
def test_no_protection(self, client):
|
def test_no_protection(self, client):
|
||||||
with client:
|
with client:
|
||||||
assert client.debug.read_pin()[0] is None
|
assert client.debug.read_pin()[0] is None
|
||||||
client.set_expected_responses([proto.Success()])
|
client.set_expected_responses([proto.Address()])
|
||||||
self._some_protected_call(client, False, True, True)
|
self._some_protected_call(client)
|
||||||
|
|
||||||
@pytest.mark.setup_client(pin="1234", passphrase=True)
|
@pytest.mark.setup_client(pin="1234")
|
||||||
def test_pin(self, client):
|
def test_pin(self, client):
|
||||||
with client:
|
with client:
|
||||||
assert client.debug.read_pin()[0] == "1234"
|
assert client.debug.read_pin()[0] == "1234"
|
||||||
client.setup_debuglink(button=True, pin_correct=True)
|
client.setup_debuglink(button=True, pin_correct=True)
|
||||||
client.set_expected_responses(
|
client.set_expected_responses([proto.PinMatrixRequest(), proto.Address()])
|
||||||
[proto.ButtonRequest(), proto.PinMatrixRequest(), proto.Success()]
|
self._some_protected_call(client)
|
||||||
)
|
|
||||||
self._some_protected_call(client, True, True, False)
|
|
||||||
|
|
||||||
@pytest.mark.setup_client(pin="1234", passphrase=True)
|
@pytest.mark.setup_client(pin="1234")
|
||||||
def test_incorrect_pin(self, client):
|
def test_incorrect_pin(self, client):
|
||||||
client.setup_debuglink(button=True, pin_correct=False)
|
client.setup_debuglink(button=True, pin_correct=False)
|
||||||
with pytest.raises(PinException):
|
with pytest.raises(PinException):
|
||||||
self._some_protected_call(client, False, True, False)
|
self._some_protected_call(client)
|
||||||
|
|
||||||
@pytest.mark.setup_client(pin="1234", passphrase=True)
|
@pytest.mark.setup_client(pin="1234")
|
||||||
def test_cancelled_pin(self, client):
|
def test_cancelled_pin(self, client):
|
||||||
client.setup_debuglink(button=True, pin_correct=False) # PIN cancel
|
client.setup_debuglink(button=True, pin_correct=False) # PIN cancel
|
||||||
with pytest.raises(PinException):
|
with pytest.raises(PinException):
|
||||||
self._some_protected_call(client, False, True, False)
|
self._some_protected_call(client)
|
||||||
|
|
||||||
@pytest.mark.setup_client(pin="1234", passphrase=True)
|
@pytest.mark.setup_client(pin="1234", passphrase=True)
|
||||||
def test_exponential_backoff_with_reboot(self, client):
|
def test_exponential_backoff_with_reboot(self, client):
|
||||||
@ -126,5 +87,5 @@ class TestProtectCall:
|
|||||||
for attempt in range(1, 4):
|
for attempt in range(1, 4):
|
||||||
start = time.time()
|
start = time.time()
|
||||||
with pytest.raises(PinException):
|
with pytest.raises(PinException):
|
||||||
self._some_protected_call(client, False, True, False)
|
self._some_protected_call(client)
|
||||||
test_backoff(attempt, start)
|
test_backoff(attempt, start)
|
||||||
|
@ -63,18 +63,11 @@ class TestProtectionLevels:
|
|||||||
)
|
)
|
||||||
device.change_pin(client)
|
device.change_pin(client)
|
||||||
|
|
||||||
@pytest.mark.setup_client(pin=True, passphrase=True)
|
@pytest.mark.setup_client()
|
||||||
def test_ping(self, client):
|
def test_ping(self, client):
|
||||||
with client:
|
with client:
|
||||||
client.set_expected_responses(
|
client.set_expected_responses([proto.ButtonRequest(), proto.Success()])
|
||||||
[
|
client.ping("msg", True)
|
||||||
proto.ButtonRequest(),
|
|
||||||
proto.PinMatrixRequest(),
|
|
||||||
proto.PassphraseRequest(),
|
|
||||||
proto.Success(),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
client.ping("msg", True, True, True)
|
|
||||||
|
|
||||||
@pytest.mark.setup_client(pin=True, passphrase=True)
|
@pytest.mark.setup_client(pin=True, passphrase=True)
|
||||||
def test_get_entropy(self, client):
|
def test_get_entropy(self, client):
|
||||||
@ -270,28 +263,22 @@ class TestProtectionLevels:
|
|||||||
|
|
||||||
with client:
|
with client:
|
||||||
client.set_expected_responses(
|
client.set_expected_responses(
|
||||||
[proto.ButtonRequest(), proto.PinMatrixRequest(), proto.Success()]
|
[proto.PinMatrixRequest(), proto.ButtonRequest(), proto.Address()]
|
||||||
)
|
)
|
||||||
client.ping("msg", True, True, True)
|
btc.get_address(client, "Bitcoin", [], show_display=True)
|
||||||
|
|
||||||
client.init_device()
|
client.init_device()
|
||||||
assert client.features.pin_cached is True
|
assert client.features.pin_cached is True
|
||||||
with client:
|
with client:
|
||||||
client.set_expected_responses([proto.ButtonRequest(), proto.Success()])
|
client.set_expected_responses([proto.ButtonRequest(), proto.Address()])
|
||||||
client.ping("msg", True, True, True)
|
btc.get_address(client, "Bitcoin", [], show_display=True)
|
||||||
|
|
||||||
@pytest.mark.setup_client(passphrase=True)
|
@pytest.mark.setup_client(passphrase=True)
|
||||||
def test_passphrase_cached(self, client):
|
def test_passphrase_cached(self, client):
|
||||||
assert client.features.passphrase_cached is False
|
with client:
|
||||||
|
client.set_expected_responses([proto.PassphraseRequest(), proto.Address()])
|
||||||
|
btc.get_address(client, "Bitcoin", [])
|
||||||
|
|
||||||
with client:
|
with client:
|
||||||
client.set_expected_responses(
|
client.set_expected_responses([proto.Address()])
|
||||||
[proto.ButtonRequest(), proto.PassphraseRequest(), proto.Success()]
|
btc.get_address(client, "Bitcoin", [])
|
||||||
)
|
|
||||||
client.ping("msg", True, True, True)
|
|
||||||
|
|
||||||
features = client.call(proto.GetFeatures())
|
|
||||||
assert features.passphrase_cached is True
|
|
||||||
with client:
|
|
||||||
client.set_expected_responses([proto.ButtonRequest(), proto.Success()])
|
|
||||||
client.ping("msg", True, True, True)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user