Files
bitchat/bitchatTests/EndToEnd
Jozef Koval 2fac395c40 Keep parked Noise payloads when the proof watchdog fires with no session (#1744)
The capability-proof watchdog drains the peer's parked Noise payloads
whenever the timeout-restore deferral is off, whether or not a session
exists. The drain encrypts under the current session and never
re-queues, so with the handshake still in flight past the 5 s deadline
every encryption fails: media with a transfer ID gets a visible
rejection, and a delivery ack, read receipt, verify, vouch or group
payload is dropped with a log line.

No attacker is needed. Sending a photo to a private-media peer with no
session arms the watchdog and starts a handshake; anything parked
behind that handshake is lost if it outlives 5 s, which is ordinary
over a multi-hop mesh. noteNoiseSessionCleared re-arms the watchdog as
a session goes away, so a slow reconnect with a pending media decision
takes the same path.

Of the drain's four production callers the watchdog was the only one
without a session precondition; the timeout-restore case was already
held back by deferredOutbound. It now drains only under an established
session and otherwise leaves the payloads for the drain that runs when
the session authenticates. The policy resolution is unchanged.

proofTimeoutBeforeHandshakeLeavesParkedAckForTheSession drives it
through the public path -- resolvePrivateMediaSendPolicy, then
sendDeliveryAck -- and forces the watchdog as the neighbouring
proof-timeout tests do. Without the guard it fails on its last
expectation: the parked count goes from 1 to 0. It needs one DEBUG-only
count hook, because _test_privateMediaTransferState only sees payloads
that carry a transfer ID.

Encryption fails closed throughout; nothing is sent unencrypted. The
drain's error path still drops what it cannot encrypt; whether it
should re-queue payloads without a transfer ID is left for review
rather than changed here.

Full SwiftPM suite green: 2068 tests in 222 suites.
2026-11-28 14:02:48 -10:00
..