What changed, and why it matters
This is a small internal code cleanup in the Trezor firmware test tooling. It replaces a manual socket creation and connection check with Python's built-in `socket.create_connection` helper. There is no security-relevant change: the code still only connects to the local emulator on a fixed loopback address (127.0.0.1), and the behavior is functionally equivalent.
No action required. This is a non-security refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff refactors TropicModel._wait_until_ready() in python/src/trezorlib/_internal/emulator.py. Previously it created a TCP socket manually, set a 1-second timeout, and used connect_ex() to poll whether the local emulator port was open. The patch switches to socket.create_connection(("127.0.0.1", self.port), timeout=1) inside a try/except OSError block. This is a purely syntactic simplification; the network target remains localhost, the timeout is unchanged, and the polling loop semantics are preserved.
Changed components
python/src/trezorlib/_internal/emulator.pyInspect captured patch +6 / −7
diff --git a/python/src/trezorlib/_internal/emulator.py b/python/src/trezorlib/_internal/emulator.py
index fc812639e..1c772e4e2 100644
--- a/python/src/trezorlib/_internal/emulator.py
+++ b/python/src/trezorlib/_internal/emulator.py
@@ -121,13 +121,12 @@ class TropicModel:
LOG.info("Waiting for Tropic model to come up...")
start = time.monotonic()
while True:
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
- s.settimeout(1.0)
- # simply check whether we can connect to the TCP port
- # where we told the model to listen
- result = s.connect_ex(("127.0.0.1", self.port))
- if result == 0:
- break
+ try:
+ with socket.create_connection(("127.0.0.1", self.port), timeout=1):
+ break # if we can connect to the model, it means it is ready
+ except OSError:
+ pass
+
if self.process.poll() is not None:
raise RuntimeError("Tropic model process died")
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.