Skip to content

Commit d4b0ca0

Browse files
committed
fix(core/thp): correct Failure_InvalidProtocol constant message
[no changelog]
1 parent 979baa5 commit d4b0ca0

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

core/src/trezor/wire/thp/interface_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ async def _handle_codec_v1(self, packet: AnyBytes) -> None:
172172
response = bytearray(self._iface.TX_PACKET_LEN)
173173
# Codec_v1 magic constant:
174174
# "?##" + Failure message type + msg_size + msg_data (code = "Failure_InvalidProtocol")
175-
utils.memcpy(response, 0, b"?##\x00\x03\x00\x00\x00\x14\x08\x11", 0)
175+
utils.memcpy(response, 0, b"?##\x00\x03\x00\x00\x00\x02\x08\x11", 0)
176176
await self._write_packets([response])
177177

178178
async def _handle_broadcast(self, packet: AnyBytes) -> None:

tests/device_tests/thp/test_basic.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ def test_v1(client: Client):
2424
# There should be a failure response to received init packet (starts with "?##")
2525
write_padded(client.transport, b"?## Init packet")
2626
res_id, res_data = protocol_v1.read(client.transport)
27+
expected = messages.Failure(code=messages.FailureType.InvalidProtocol)
2728
res = DEFAULT_MAPPING.decode(res_id, res_data)
28-
assert res == messages.Failure(code=messages.FailureType.InvalidProtocol)
29+
assert res == expected
30+
# make sure the constant "InvalidProtocol" response doesn't have trailing bytes (#6549)
31+
assert (res_id, res_data) == DEFAULT_MAPPING.encode(expected)
2932

3033
# There should be no response for continuation packet (starts with "?" only)
3134
write_padded(client.transport, b"? Cont packet")

0 commit comments

Comments
 (0)