Receive signed ITS messages and forward each at its declared length

Signed packets. A GeoNetworking Basic Header NextHeader of 2 means a
TS 103 097 (IEEE 1609.2) envelope follows, with the Common Header
inside it. gn_unwrap_its rejected all of these, and most real traffic is
signed: the 2026-08-17 capture holds 157 signed frames from 15 source
MACs against 2 unsecured stations. It now opens a COER-encoded
signedData, or a bare unsecuredData, and parses the inner packet as
before. The inner packet comes first inside tbsData, so the certificate
and signature are never parsed, and the signature is not verified - the
firmware has no trust store. Such messages reach the phone with the new
V2X_RX flags bit1, signed but not verified. The app reads only bit0 and
is unaffected until it learns the flag. Encrypted payloads, nested
signing and the legacy v1.2.1 envelope are still rejected. All 157
recorded signed frames have the layout this reads, in all three COER
length forms, and asn1tools decodes every envelope to the same inner
packet.

Payload bounds. Every frame recorded through the ESP32-C5's promiscuous
RX, about 15 000 of them, ends in 8 bytes that are not part of the
802.11 frame and not a valid FCS. obu-firmware reads frames through the
same API and took the rest of the frame as the message, so it forwarded
those 8 bytes to the phone after every message. UPER decoders stop where
the message ends, so nothing visibly broke, but the bytes cost serial
bandwidth and 8 bytes of the DENM's headroom, and they stayed attached
wherever raw payloads were stored or passed on. The payload is now
exactly what the Common Header's payload-length field declares, which is
also what separates a signed message from its signature.

A frame longer than main.c's 800-byte capture buffer is now reported as
truncated instead of being forwarded cut off, and counted as an oversize
drop through the new serial_link_note_oversize_drop, as it was when the
cut-off frame failed serial_link's size check.

Host tests in obu-firmware/test/host build the firmware sources
unmodified with MSYS2 gcc; `make` runs all three.
- test_chain: frames from the firmware's TX code checked byte by byte
  against EN 302 636-4-1 and parsed back, including hand-built signed
  frames, the payload-length rule, the RX trailer, and every truncation
  length against a no-access guard page. 1731 checks, 0 failures.
- test_replay and check_replay.py: all 15 145 recorded frames through
  gn_unwrap_its, cut to 800 bytes as on the board, and re-derived
  independently in Python with the envelope decoded by asn1tools. They
  agree on every record; 15 131 accepted, 157 of them signed. 11 043 of
  the 11 106 distinct messages re-encode byte-identically. The other 63
  fail the same way with the old 8 bytes put back, so the boundary is
  not the cause: 5 are our own CAMs from before the 2026-08-20
  yawRateConfidence fix, and the rest, from other stations, are a
  follow-up in TODO.md.
- fuzz_gn_unwrap: random edits of every recorded frame, each run against
  the guard page. 50 000 000 iterations, no crash.

obu-firmware/test/pcap_gn_tally.py tallies GeoNetworking header fields
per station over captures; it is how the other stations' lifetimes were
measured. TODO.md collects what is still open, including the on-air
check for this change: it builds on IDF 6.1 but has not been flashed.
This commit is contained in:
Ashin Walpola
2026-09-11 20:19:40 +02:00
parent 1baae2c5f6
commit 75d6d3b85c
15 changed files with 2196 additions and 34 deletions
+36
View File
@@ -0,0 +1,36 @@
#ifndef TEST_UTIL_H
#define TEST_UTIL_H
// Shared by the host tests: crash reporting, the guard page, and pcap reading and writing.
#include <stdbool.h>
#include <stdint.h>
// What the test is doing right now, printed if it crashes. printf-style.
void tu_set_context(const char *fmt, ...);
const char *tu_context(void);
// Also print these bytes as hex if it crashes (the fuzzer's current input). NULL to clear.
void tu_set_crash_input(const uint8_t *bytes, const int *len);
void tu_install_crash_handler(void);
// One read-write page followed by one no-access page.
void tu_guard_init(void);
// A buffer of exactly `len` bytes (at most one page) whose end touches the no-access page.
uint8_t *tu_guard_buf(int len);
// Copy of `frame` whose last byte is the last readable one: reading past it crashes.
const uint8_t *tu_guarded(const uint8_t *frame, int len);
// Calls `fn` for every record of a pcap file, with its 802.11 frame. Linktype 127 (radiotap,
// what its-g5-receiver-firmware records) has the radiotap header removed; linktype 105 is passed
// as is. The frame is otherwise exactly as captured, including the 8 bytes the ESP32-C5's
// promiscuous RX appends - which is what obu-firmware's callback receives through the same API.
// `index` counts every record, including ones skipped for a malformed radiotap header. Returns
// the number of records (0 for an empty file), or -1 if the file can't be read or isn't a pcap
// of those linktypes.
typedef void (*tu_frame_fn)(const uint8_t *frame, int len, int index, void *ctx);
int tu_pcap_foreach(const char *path, tu_frame_fn fn, void *ctx);
// Writes frames to a pcap, linktype 105 (bare 802.11).
bool tu_pcap_open(const char *path);
void tu_pcap_add(const uint8_t *frame, int len);
void tu_pcap_close(void);
#endif