From de5931210fa27035e5a6075209c4e0f70064e605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Martin?= Date: Sat, 3 Oct 2026 21:43:03 +0200 Subject: [PATCH] OTA: clean refusal report in ota_push.py; shorter signature error The device refuses at the header and hangs up mid-transfer; the push client now says so instead of crashing on the reset. The error fits a Toast (47 characters). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT --- lib/ota/src/update_parser.cpp | 2 +- scripts/ota_push.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/ota/src/update_parser.cpp b/lib/ota/src/update_parser.cpp index 0cae285..83903e3 100644 --- a/lib/ota/src/update_parser.cpp +++ b/lib/ota/src/update_parser.cpp @@ -30,7 +30,7 @@ void UpdateParser::parseHeader() { if (sigLen == 0 || sigLen > update::kMaxSignature) return fail("missing signature"); uint8_t digest[32]; Sha256::hash(h, update::kSignedBytes, digest); - if (!verifier_.verify(digest, h + 82, sigLen)) return fail("bad signature: not signed with this device's key"); + if (!verifier_.verify(digest, h + 82, sigLen)) return fail("bad signature (wrong key)"); downgrade_ = versionOlder(version_, installed_); if (!sink_.begin(imageSize_)) return fail("could not prepare the update slot"); diff --git a/scripts/ota_push.py b/scripts/ota_push.py index b035e8b..8ebc7f2 100755 --- a/scripts/ota_push.py +++ b/scripts/ota_push.py @@ -15,6 +15,18 @@ def main(): sys.exit(__doc__) path, host = sys.argv[1:3] data = open(path, "rb").read() + try: + reply = push(data, host) + except (ConnectionResetError, BrokenPipeError): + # The device checks the header first and hangs up on a refused update mid-transfer. + print() + print("device: refused the update and closed the connection (the reason is on its screen)") + sys.exit(1) + print(f"device: {reply or '(no answer)'}") + sys.exit(0 if reply.startswith("OK") else 1) + + +def push(data, host): with socket.create_connection((host, PORT), timeout=15) as s: s.settimeout(60) sent, last = 0, -1 @@ -44,9 +56,7 @@ def main(): break reply += part print() - reply = reply.decode(errors="replace").strip() - print(f"device: {reply or '(no answer)'}") - sys.exit(0 if reply.startswith("OK") else 1) + return reply.decode(errors="replace").strip() if __name__ == "__main__":