Commit Graph

7 Commits

Author SHA1 Message Date
Kpa-clawbot
bcf7159538 fix: detect garbage text after channel decryption, fixes #197
After decryption produces text, validate it's printable UTF-8.
If it contains more than 2 non-printable characters (excluding
newline/tab), mark as decryption_failed with text: null.

Applied to both Node (decoder.js) and Go (cmd/ingestor/decoder.go)
decoders. Added tests for garbage and valid text in both.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-27 21:48:37 -07:00
Kpa-clawbot
01cce2cb89 fix: cap path hops to buffer size for corrupt packets
decodePath() trusted the pathByte hop count without checking available
buffer space. Corrupt packet cbecda1c7d37d4c0 (route_type=3, pathByte
0xAD) claimed 45 hops × 3 bytes = 135 bytes, but only 65 bytes existed
past the header. Node's Buffer.subarray silently returns empty buffers
for out-of-range slices, producing 23 empty-string hops in the output.

Fix: clamp hashCount to floor(available / hashSize). Add a 'truncated'
flag so consumers know the path was incomplete. No empty hops are ever
returned now.

fixes #183

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-27 18:25:02 -07:00
Kpa-clawbot
1137dd1c08 test: close test gaps for #123 decrypted status and #131 WS handler runtime
Gap 1 (#123): Add 3 decoder tests for GRP_TXT decrypted status path.
Mock ChannelCrypto via require.cache to simulate successful decryption.
Tests cover: sender+message formatting, no-sender fallback, multi-key
iteration with first-match-wins semantics.

Gap 2 (#131): Rewrite 5 src.includes() string-match tests as runtime
vm.createContext tests. New makeNodesWsSandbox() helper with controllable
setTimeout, mock DOM, tracked API/cache calls, and real debouncedOnWS.
Tests verify: ADVERT triggers refresh, non-ADVERT ignored, debounce
collapses multiple ADVERTs, cache reset forces re-fetch, scroll/selection
preserved during WS-triggered refresh.

Decoder: 58 -> 61 tests. Frontend helpers: 87 (5 replaced, not added).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-27 08:47:52 -07:00
Kpa-clawbot
14b7e56403 Show channel hash and decryption status for undecrypted GRP_TXT packets
When a CHANNEL_MSG (GRP_TXT) can't be decrypted, the decoder now includes:
- channelHashHex: zero-padded uppercase hex string of the channel hash byte
- decryptionStatus: 'decrypted', 'no_key', or 'decryption_failed'

Frontend changes:
- Packet list preview shows '🔒 Ch 0xXX (no key)' or '(decryption failed)'
- Detail pane hex breakdown shows channel hash with status label
- Detail pane message area shows channel hash info for undecrypted packets

6 new decoder tests (58 total): channelHashHex formatting, decryptionStatus
for no keys, empty keys, bad keys, and short encrypted data.

Fixes #123

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-27 07:54:27 -07:00
you
efd7d811ca fix: encrypted payload field sizes match firmware source (Mesh.cpp)
Per firmware: PAYLOAD_VER_1 uses dest(1) + src(1) + MAC(2), not 6+6+4.
Confirmed from Mesh.cpp lines 129-130: uint8_t dest_hash = payload[i++]
and MeshCore.h: CIPHER_MAC_SIZE = 2.

Changed: decodeEncryptedPayload (REQ/RESPONSE/TXT_MSG), decodeAck,
decodeAnonReq (dest 1B + pubkey 32B + MAC 2B), decodePath (1+1+2).
Updated test min-length assertions.
2026-03-24 01:32:58 +00:00
you
5b496a8235 feat: add missing payload types from firmware spec
Added GRP_DATA (0x06), MULTIPART (0x0A), CONTROL (0x0B), RAW_CUSTOM (0x0F)
to decoder.js, app.js display names, and packet-filter.js.
Source: firmware/src/Packet.h PAYLOAD_TYPE definitions.
2026-03-24 01:23:12 +00:00
you
3fdad47bfc Add decoder and packet-store unit tests
- test-decoder.js: 52 tests covering all payload types (ADVERT, GRP_TXT, TXT_MSG, ACK, REQ, RESPONSE, ANON_REQ, PATH, TRACE, UNKNOWN), header parsing, path decoding, transport codes, edge cases, validateAdvert, and real packets from the API
- test-packet-store.js: 34 tests covering insert, deduplication, indexing (byHash, byNode, byObserver, advertByObserver), query with filters (type, route, hash, observer, since, until, order), queryGrouped, eviction, findPacketsForNode, getSiblings, countForNode, getTimestamps, getStats

Coverage improvement:
- decoder.js: 73.9% → 85.5% stmts, 41.7% → 89.3% branch, 69.2% → 92.3% funcs
- packet-store.js: 53.9% → 67.5% stmts, 46.6% → 63.9% branch, 50% → 79.2% funcs
- Overall: 37.2% → 40.0% stmts, 43.4% → 56.9% branch, 55.2% → 66.7% funcs
2026-03-24 00:59:41 +00:00