From 44832ada5e62a147c203cc4eaa0911a35020f508 Mon Sep 17 00:00:00 2001 From: MarekWo Date: Mon, 2 Mar 2026 15:53:59 +0100 Subject: [PATCH] fix(analyzer): fix pkt_payload computation for block-aligned text + trailing whitespace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two bugs in Analyzer URL generation: 1. Firmware omits null+padding when header+text exactly fills AES block boundary (len % 16 == 0), but our code always added \0+padding → wrong MAC → wrong hash 2. content.strip() in event handler removed trailing whitespace that was part of the original packet. Now uses raw_text from raw_json (preserves original text) Co-Authored-By: Claude Opus 4.6 --- app/routes/api.py | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/app/routes/api.py b/app/routes/api.py index da0c39e..1d75dc8 100644 --- a/app/routes/api.py +++ b/app/routes/api.py @@ -67,14 +67,20 @@ def compute_pkt_payload(channel_secret_hex, sender_timestamp, txt_type, text, at Reconstructs the encrypted GRP_TXT payload: channel_hash(1) + HMAC-MAC(2) + AES-128-ECB(plaintext) - where plaintext = timestamp(4 LE) + flags(1) + text(UTF-8) + null + zero-pad. + where plaintext = timestamp(4 LE) + flags(1) + text(UTF-8) [+ null + zero-pad]. + Firmware omits null+padding when header+text exactly fills an AES block boundary. """ secret = bytes.fromhex(channel_secret_hex) flags = ((txt_type & 0x3F) << 2) | (attempt & 0x03) - plaintext = struct.pack('