Skip to content
Prev Previous commit
Next Next commit
docs(net): keep revision 1.11 append-only
Restore the main text that cites de6f272. Revision 1.12 records that aa30a82 is the reachable equivalent, dated 2026-10-28.

Co-authored-by: Andrew Brown <lazyxeon@users.noreply.github.com>
  • Loading branch information
cursoragent and lazyxeon committed Oct 29, 2026
commit aef7d043b7872ff30e0d6e970787c3010670f05d
2 changes: 1 addition & 1 deletion docs/architecture/net_ecs.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ last_verified_commit: aa30a82f
| **Last verified against commit** | `aa30a82f` |
| **Last verified date** | 2026-10-28 |
| **Status** | Active (mixed: production-grade standalone binary; dormant ECS Plugin layer). **Standalone-trio input signing is real and enforced:** client and server both compute HMAC-SHA256 over the canonical `aw-net-proto` signing surface; the server verifies FIRST (before any per-player state mutation) and kicks by default on failure. The historical `sign16`/XOR-vs-HMAC mismatch is RESOLVED (Net-Trio-Remediation, see revision 1.3). |
| **Revision history** | 1.12 (2026-10-29): Re-read at `aa30a82f`. Family 5 is 4 tests. Families 1-5 + w2b_fix1 are 41. #523 adds `failed_join_send_removes_the_player` and `failed_join_send_removes_the_player_on_the_tls_entry`, so the server is 46 and the standalone trio is 112. The test grep matches `#[tokio::test(flavor...)]`. Under Warn a bad tag still assigns `tokens` and `last_refill`; `last_input_seq` and `last_seen` stay bucket-gated. There is no dedicated workflow; client binaries run in `ci.yml` and proto fuzz is in `fuzz-nightly.yml`. <br><br>1.11 (2026-10-28): Verified at `aa30a82f`. Plain and TLS sessions share `handle_socket`. `handle_socket_tls` delegates to it. `PlayerMembership` removes the player, and an empty room, on every exit from that handler, including a failed `MatchResult` or `JoinAccepted` send. The trailing cleanup block, `send_tls`, `recv_tls`, and `on_client_msg_tls` are gone. Line cites in 1.10 describe the duplicated handlers at `28ef548c`. <br><br>1.10 (2026-10-28): Line cites were read against main 28ef548c. HelloAck and JoinAccepted are not the same lines. The player insert happens before either send. Warn writes last_input_seq and last_seen only while the token bucket stays non-negative. The client TLS feature is rustls-tls-native-roots. spawn_server refuses the published key outside debug and test builds. --sig-failure-policy parses on every build. <br><br>1.9 (2026-10-28): A release server does not see the client's key. A published-key client joins; the first InputFrame is Close 1008 under Kick, and under --sig-failure-policy warn the connection can stay up after a bad tag (see 1.10 for bucket-gated last_input_seq/last_seen). A debug server keeps dev_default() when --shared-key-hex is absent. The client TLS feature is rustls-tls-native-roots. Checked against main b6f6c654. <br><br>1.8 (2026-10-27): `decode_msg` for `Codec::Bincode` uses `standard().with_limit::<MAX_LZ4_DECLARED_OUTPUT>()` (4 MiB). The parent `99382af7` uses `standard()` with no limit, so a length prefix allocates before the payload bytes exist. The LZ4 declared-size cap is unchanged. 1.7 (2026-10-16): `astraweave-net-ecs` opts into `tokio` feature `net`. The workspace dependency does not enable it.<br><br>1.6 (2026-10-15): `aw-net-server` uses rustls 0.23 with the ring provider. Certificate PEM is parsed with `rustls-pki-types`.<br><br>1.5 (2026-10-15): `/healthz` and `/regions` require `ServerConfig.admin_token` as a bearer token. `None` rejects every admin request. The listener still binds so `RunningServer.http_addr` stays valid. CLI flag `--admin-token`. 1.4 (2026-10-15): `ServerConfig::default` binds `127.0.0.1`. `spawn_server` refuses the published dev signing key outside debug and test builds. `decode_msg` rejects an LZ4 declared output above 4 MiB. 1.3 (2026-06-10): **Net-Trio-Remediation closeout.** The standalone trio's signature defect — client signed with the XOR `sign16` (16-byte tag) while the server verified HMAC-SHA256 (32-byte tag), so every verification failed and the server only `warn!`ed — is FIXED and ENFORCED. `aw-net-proto` now exposes a canonical signing surface (`SigningKey` with a private 32-byte field + redacted `Debug`; `sign`/`verify` (constant-time via `Mac::verify_slice`); `hmac_sha256`; `input_frame_sig_payload(seq, tick_ms, blob)`; `SIG_LEN = 32`). The `sign16` XOR stub, the `SessionKey` type, and the `session_key_hint` fields on `MatchResult`/`JoinAccepted` are DELETED; `InputFrame.sig` is now `[u8; 32]`. Both client (sign) and server (verify) build the MAC'd bytes via the single shared `input_frame_sig_payload`. The server is now lib+bin (`aw-net-server/src/lib.rs` ~1080 lines holds all logic; `src/main.rs` is a thin arg-parse → `run_server`). Verification runs FIRST in both plain and TLS handlers and applies `SignatureFailurePolicy { Kick (DEFAULT), Warn }`: Kick sends a WebSocket Close (code 1008) and routes the disconnect through the existing cleanup path; Warn retains legacy log-and-continue. Regression net: 104 tests (proto 59, server 41 across families 1-5 + w2b_fix1, client 4); a §5 adversarial refute pass ran and CONVERGED. Commit ledger: `561b20957` (W.1 canonical HMAC; stub deleted), `79424389e` (W.2.a client adopts), `066cd6cfd` (W.2.b server verifies + policy + lib/bin split), `9a3fc94e3` (W.2.b-fix1 graceful unknown-room + cleanup-preserving snapshot path), `7029d7d7f`/`a2b494942`/`0e702738e`/`68a9a1936` (W.3.1-3.4 test families 1-4), `420a6f61b` (W.5.1 SigningKey encapsulation + RFC 4231), `2955cd14c` (W.5.2 TLS test family), `eb9977b88` (W.5.3 S2C trust note). Known deliberate boundaries (NOT open defects): replay protection / nonces / sequence-number freshness is not implemented (HMAC proves authenticity, not freshness — a captured valid frame can be replayed); server→client messages are not signature-verified (authoritative-server asymmetric trust — a shared symmetric key cannot meaningfully authenticate S2C); the shipped client binary over TLS is untested (rustls cert validation rejects the self-signed dev cert — a cert-validation concern), though the server's TLS verify/kick path IS now tested. Full audit: `docs/audits/net_trio_signature_remediation_findings_2026-06.md`.<br><br>1.2 (2026-05-12): Deep investigation pass. Enriched §11 Open Questions 1, 4, 8, 9 with comprehensive factual context. Recovered creation commit for `astraweave-net-ecs` dep in `astraweave-stress-test` (commit `08befc6ec` — same as net-ecs's own birth commit). Verified Q8 dual-TLS-version situation factually via `Cargo.lock` (both `tokio-rustls 0.25.0` and `tokio-rustls 0.26.4` are present) and via `cargo tree` (0.26 comes from reqwest→hyper-rustls used by many crates including `astraweave-llm`, `astraweave-assets`; 0.25 is exclusive to `aw-net-server`). Q4 factual finding: empty `entity_states: HashMap::new()` was present from the crate's birth commit `08befc6ec` (2025-10-01) — stub from day one. Resolved the last `[INFERRED]` marker (§5 TLS_IMPLEMENTATION_SUMMARY.txt content). Added new §6 row: a third copy of `lib.rs`-like content exists at `archive/temp_files/temp/temp_lib.rs` (a `use aw_net_proto` archive).<br><br>1.1 (2026-05-12): Verification pass. Corrected §2 Stage 6 HMAC mechanism — `hmac::verify_slice` (via `digest-0.10.7/src/mac.rs:168-179`) strict-rejects any tag length ≠ `OutputSize`; the previous `[INFERRED]` "truncated comparison" claim was wrong. The real mechanism: `Sha256::OutputSize == 32`, sig is 16 bytes, so `verify_slice` returns `MacError` immediately on length mismatch — **all client signatures fail length validation before any byte comparison happens**. Resolved §7 Decision 5 Date marker — HMAC verification landed in commit `88434f3a2` (2025-11-18, "security: fix critical vulnerabilities in network server (Priority 1)"). Resolved §7 Decision 7 Date marker — TLS-by-default in release added in commit `4889a9a33` (2025-11-13, "feat: Integrate astraweave-security…"). Noted that `parking_lot::Mutex` (not `std::sync::Mutex`) is used in §3 and §9. |
| **Revision history** | 1.12 (2026-10-28): `de6f2725` is unreachable. `aa30a82f` is the main equivalent, and this revision was re-read there. Family 5 is 4 tests. Families 1-5 + w2b_fix1 are 41. #523 adds `failed_join_send_removes_the_player` and `failed_join_send_removes_the_player_on_the_tls_entry`, so the server is 46 and the standalone trio is 112. The test grep matches `#[tokio::test(flavor...)]`. Under Warn a bad tag still assigns `tokens` and `last_refill`; `last_input_seq` and `last_seen` stay bucket-gated. There is no dedicated workflow; client binaries run in `ci.yml` and proto fuzz is in `fuzz-nightly.yml`. <br><br>1.11 (2026-10-28): Verified at `de6f2725`. Plain and TLS sessions share `handle_socket`. `handle_socket_tls` delegates to it. `PlayerMembership` removes the player, and an empty room, on every exit from that handler, including a failed `MatchResult` or `JoinAccepted` send. The trailing cleanup block, `send_tls`, `recv_tls`, and `on_client_msg_tls` are gone. Line cites in 1.10 describe the duplicated handlers at `28ef548c`. <br><br>1.10 (2026-10-28): Line cites were read against main 28ef548c. HelloAck and JoinAccepted are not the same lines. The player insert happens before either send. Warn writes last_input_seq and last_seen only while the token bucket stays non-negative. The client TLS feature is rustls-tls-native-roots. spawn_server refuses the published key outside debug and test builds. --sig-failure-policy parses on every build. <br><br>1.9 (2026-10-28): A release server does not see the client's key. A published-key client joins; the first InputFrame is Close 1008 under Kick, and under --sig-failure-policy warn the connection can stay up after a bad tag (see 1.10 for bucket-gated last_input_seq/last_seen). A debug server keeps dev_default() when --shared-key-hex is absent. The client TLS feature is rustls-tls-native-roots. Checked against main b6f6c654. <br><br>1.8 (2026-10-27): `decode_msg` for `Codec::Bincode` uses `standard().with_limit::<MAX_LZ4_DECLARED_OUTPUT>()` (4 MiB). The parent `99382af7` uses `standard()` with no limit, so a length prefix allocates before the payload bytes exist. The LZ4 declared-size cap is unchanged. 1.7 (2026-10-16): `astraweave-net-ecs` opts into `tokio` feature `net`. The workspace dependency does not enable it.<br><br>1.6 (2026-10-15): `aw-net-server` uses rustls 0.23 with the ring provider. Certificate PEM is parsed with `rustls-pki-types`.<br><br>1.5 (2026-10-15): `/healthz` and `/regions` require `ServerConfig.admin_token` as a bearer token. `None` rejects every admin request. The listener still binds so `RunningServer.http_addr` stays valid. CLI flag `--admin-token`. 1.4 (2026-10-15): `ServerConfig::default` binds `127.0.0.1`. `spawn_server` refuses the published dev signing key outside debug and test builds. `decode_msg` rejects an LZ4 declared output above 4 MiB. 1.3 (2026-06-10): **Net-Trio-Remediation closeout.** The standalone trio's signature defect — client signed with the XOR `sign16` (16-byte tag) while the server verified HMAC-SHA256 (32-byte tag), so every verification failed and the server only `warn!`ed — is FIXED and ENFORCED. `aw-net-proto` now exposes a canonical signing surface (`SigningKey` with a private 32-byte field + redacted `Debug`; `sign`/`verify` (constant-time via `Mac::verify_slice`); `hmac_sha256`; `input_frame_sig_payload(seq, tick_ms, blob)`; `SIG_LEN = 32`). The `sign16` XOR stub, the `SessionKey` type, and the `session_key_hint` fields on `MatchResult`/`JoinAccepted` are DELETED; `InputFrame.sig` is now `[u8; 32]`. Both client (sign) and server (verify) build the MAC'd bytes via the single shared `input_frame_sig_payload`. The server is now lib+bin (`aw-net-server/src/lib.rs` ~1080 lines holds all logic; `src/main.rs` is a thin arg-parse → `run_server`). Verification runs FIRST in both plain and TLS handlers and applies `SignatureFailurePolicy { Kick (DEFAULT), Warn }`: Kick sends a WebSocket Close (code 1008) and routes the disconnect through the existing cleanup path; Warn retains legacy log-and-continue. Regression net: 104 tests (proto 59, server 41 across families 1-5 + w2b_fix1, client 4); a §5 adversarial refute pass ran and CONVERGED. Commit ledger: `561b20957` (W.1 canonical HMAC; stub deleted), `79424389e` (W.2.a client adopts), `066cd6cfd` (W.2.b server verifies + policy + lib/bin split), `9a3fc94e3` (W.2.b-fix1 graceful unknown-room + cleanup-preserving snapshot path), `7029d7d7f`/`a2b494942`/`0e702738e`/`68a9a1936` (W.3.1-3.4 test families 1-4), `420a6f61b` (W.5.1 SigningKey encapsulation + RFC 4231), `2955cd14c` (W.5.2 TLS test family), `eb9977b88` (W.5.3 S2C trust note). Known deliberate boundaries (NOT open defects): replay protection / nonces / sequence-number freshness is not implemented (HMAC proves authenticity, not freshness — a captured valid frame can be replayed); server→client messages are not signature-verified (authoritative-server asymmetric trust — a shared symmetric key cannot meaningfully authenticate S2C); the shipped client binary over TLS is untested (rustls cert validation rejects the self-signed dev cert — a cert-validation concern), though the server's TLS verify/kick path IS now tested. Full audit: `docs/audits/net_trio_signature_remediation_findings_2026-06.md`.<br><br>1.2 (2026-05-12): Deep investigation pass. Enriched §11 Open Questions 1, 4, 8, 9 with comprehensive factual context. Recovered creation commit for `astraweave-net-ecs` dep in `astraweave-stress-test` (commit `08befc6ec` — same as net-ecs's own birth commit). Verified Q8 dual-TLS-version situation factually via `Cargo.lock` (both `tokio-rustls 0.25.0` and `tokio-rustls 0.26.4` are present) and via `cargo tree` (0.26 comes from reqwest→hyper-rustls used by many crates including `astraweave-llm`, `astraweave-assets`; 0.25 is exclusive to `aw-net-server`). Q4 factual finding: empty `entity_states: HashMap::new()` was present from the crate's birth commit `08befc6ec` (2025-10-01) — stub from day one. Resolved the last `[INFERRED]` marker (§5 TLS_IMPLEMENTATION_SUMMARY.txt content). Added new §6 row: a third copy of `lib.rs`-like content exists at `archive/temp_files/temp/temp_lib.rs` (a `use aw_net_proto` archive).<br><br>1.1 (2026-05-12): Verification pass. Corrected §2 Stage 6 HMAC mechanism — `hmac::verify_slice` (via `digest-0.10.7/src/mac.rs:168-179`) strict-rejects any tag length ≠ `OutputSize`; the previous `[INFERRED]` "truncated comparison" claim was wrong. The real mechanism: `Sha256::OutputSize == 32`, sig is 16 bytes, so `verify_slice` returns `MacError` immediately on length mismatch — **all client signatures fail length validation before any byte comparison happens**. Resolved §7 Decision 5 Date marker — HMAC verification landed in commit `88434f3a2` (2025-11-18, "security: fix critical vulnerabilities in network server (Priority 1)"). Resolved §7 Decision 7 Date marker — TLS-by-default in release added in commit `4889a9a33` (2025-11-13, "feat: Integrate astraweave-security…"). Noted that `parking_lot::Mutex` (not `std::sync::Mutex`) is used in §3 and §9. |
| **Owner notes** | As of 1.11, `aw-net-server` has one connection handler. `handle_socket_tls` calls `handle_socket`. `PlayerMembership` removes the player when that task leaves, so a failed join send cannot leave a ghost. Two distinct integration paths share `aw-net-proto`: (1) the standalone `aw-net-server` / `aw-net-client` binaries communicate end-to-end over WSS with HMAC-SHA256 input signatures, token-bucket rate limiting, sled persistence, and matchmaking. As of revision 1.3 the signing is real and enforced: client and server agree on bytes via the canonical proto surface (`SigningKey` + `sign`/`verify` + `input_frame_sig_payload`), the server verifies FIRST, and the default `SignatureFailurePolicy::Kick` closes the connection (Close 1008) on a bad tag. (2) `astraweave-net-ecs` provides ECS Plugin scaffolding (`NetworkClientPlugin`, `NetworkServerPlugin`, components, simulation-stub systems) — but **workspace grep finds zero `use astraweave_net_ecs` outside the crate's own tests and benches**, including in `astraweave-stress-test` which declares the dep in `Cargo.toml`. The ECS layer is currently dormant code. There is no dedicated workflow for these four crates. Comprehensive CI runs the client binaries (`ci.yml:200`, `:313`, `:560`). `fuzz-nightly.yml:35` lists `net/aw-net-proto/fuzz`. |

---
Expand Down
Loading