[PR #831] [MERGED] feat(server): secure chat, as vanilla 26.3's server #2841

Closed
opened 2026-11-02 15:59:30 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/831
Author: @ludovic111
Created: 10/18/2026
Status: ✅ Merged
Merged: 10/18/2026
Merged by: @ludovic111

Base: main ← Head: feat/secure-chat


📝 Commits (1)

  • 454b384 feat(server): secure chat, as vanilla 26.3's server

📊 Changes

23 files changed (+2505 additions, -86 deletions)

View changed files

📝 Cargo.lock (+2 -0)
📝 crates/horizon-client/examples/lan_flat.rs (+3 -1)
📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/dedicated.rs (+13 -2)
📝 crates/horizon-client/src/game/lan.rs (+24 -9)
📝 crates/horizon-client/src/game/lan_actions.rs (+14 -8)
➕ crates/horizon-client/src/game/lan_chat.rs (+194 -0)
📝 crates/horizon-client/src/lan/guest.rs (+9 -0)
📝 crates/horizon-client/src/lan/hub.rs (+26 -53)
➕ crates/horizon-client/src/lan/hub/chat.rs (+500 -0)
📝 crates/horizon-client/src/lan/mod.rs (+48 -4)
📝 crates/horizon-protocol/Cargo.toml (+2 -0)
📝 crates/horizon-protocol/src/buf.rs (+10 -0)
📝 crates/horizon-protocol/src/lib.rs (+1 -0)
📝 crates/horizon-protocol/src/packets/play.rs (+60 -3)
📝 crates/horizon-protocol/src/rsa.rs (+90 -2)
➕ crates/horizon-protocol/src/secure_chat.rs (+491 -0)
📝 crates/horizon-server-files/Cargo.toml (+2 -0)
📝 crates/horizon-server-files/src/profiles.rs (+68 -0)
📝 docs/hosting.md (+3 -2)

...and 3 more files

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

What

The server now does secure chat the way vanilla 26.3's does. Before this PR, Horizon's server ignored chat signatures: every message was relayed unsigned, enforce-secure-profile did nothing, and the Login packet always said onlineMode=false, so vanilla clients never even sent a chat session.

Chat sessions (handleChatSessionUpdate):

  • The profile key is checked against the services' playerCertificateKeys. They are fetched lazily from authentication.getPublicKeys (profiles::fetch_profile_key_keys, SHA1withRSA).
  • A valid session is announced to everyone with PlayerInfoUpdate INITIALIZE_CHAT.
  • An invalid key is kicked with vanilla's message, and so is a key that expires earlier than the session's current one.
  • With no services keys, the session is ignored with vanilla's warning.

Signed chat (SignedMessageChain, LastSeenMessagesValidator(20), MessageSignatureCache(128), in horizon-protocol/src/secure_chat.rs):

  • Each message is verified: SHA256withRSA over the SignedMessageBody layout, chain links, order, expiry and the last-seen checksum.
  • Messages are relayed as PlayerChat with each connection's global index, the packed signature and the last-seen list.
  • Acknowledgements (ChatAck) are tracked, with the kick at 4096 pending messages.

Signed commands (ServerboundChatCommandSignedPacket):

  • say, me and msg carry their signed argument and go out as signed chat (say_command, emote_command, msg_command_*).
  • From an unsigned command packet, they go out as disguised chat, as vanilla's PlayerChatMessage.system.
  • With enforcement on, an unsigned command packet whose command has a message argument is refused (SignableCommand).

enforce-secure-profile: it only applies with online-mode and the services keys (DedicatedServer.enforceSecureProfile). The status response and the Login packet both report it.

Offline servers, and players without a chat session (Horizon's own client today, which has no Microsoft sign-in), chat unsigned as on vanilla. The log shows [Not Secure].

Log lines: vanilla's [Not Secure] prefix, the decoder's Failed to update secure chat state for X: '…', and the kicks. The lines are now written from the main loop. A kicked player's lost connection: line now gives the kick reason, not Disconnected. That also changes the line for /kick and the idle kick, which should now read as vanilla's (only the chat kicks were compared).

How tested

tools/test_secure_chat_parity.py (new) runs a vanilla 26.3 server and horizon-client --dedicated with the same scenarios. It uses a Java client (SecureChatClient) built on vanilla's own LocalChatSession, SignedMessageChain and SignedMessageValidator, test RSA keys made by the harness, and a mock services server (discovery, public keys, join/hasJoined). No real account is involved.

  • offline: Alice, Bob and Carol on an offline server.
    • Alice and Bob sign their chat; Carol has no session.
    • Signed chat and last seen; unsigned chat; say, me and msg signed and unsigned; Carol's unsigned arguments.
    • Bob, who isn't an operator, sends a mismatched signature (kicked).
    • A forged signature, a broken chain, and ChatAck(50) (kicked).
  • online: online mode with enforce-secure-profile.
    • Alice signs; Carol's unsigned chat and commands are refused.
    • Mallory joins with a key the services signed for another player, and is kicked.

Each client records the system, disguised and player chat it receives, with the verdict of vanilla's validator on every signature, and the disconnects. Result: secure chat: transcripts and chat log lines identical (offline 78 lines, online 36). I did not run it on origin/main, which ignores chat sessions and signatures.

Self-check:

cargo fmt --all --check                                        ok
cargo clippy --workspace --all-targets -- -D warnings          ok
cargo test -p horizon-protocol -p horizon-server-files -p horizon-client   ok (all passed)
tools/parity.py dedicated_server online_mode lan server_ops_feedback server_files server_dimension_players secure_chat
7 passed, 0 failed (16.9 min)

Needs Ludovic

Nothing to merge this. Horizon's own client still can't sign its chat: it needs a Microsoft sign-in to get a profile key (docs/microsoft-account.md, part d). Until then, it chats unsigned, which works everywhere except on online servers that enforce secure profiles.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/831 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/18/2026 **Status:** ✅ Merged **Merged:** 10/18/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/secure-chat` --- ### 📝 Commits (1) - [`454b384`](https://github.com/horizon-rust/horizon/commit/454b3842bb9fe9fec0b75fcfa599f14d78a3dd8d) feat(server): secure chat, as vanilla 26.3's server ### 📊 Changes **23 files changed** (+2505 additions, -86 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+2 -0) 📝 `crates/horizon-client/examples/lan_flat.rs` (+3 -1) 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/dedicated.rs` (+13 -2) 📝 `crates/horizon-client/src/game/lan.rs` (+24 -9) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+14 -8) ➕ `crates/horizon-client/src/game/lan_chat.rs` (+194 -0) 📝 `crates/horizon-client/src/lan/guest.rs` (+9 -0) 📝 `crates/horizon-client/src/lan/hub.rs` (+26 -53) ➕ `crates/horizon-client/src/lan/hub/chat.rs` (+500 -0) 📝 `crates/horizon-client/src/lan/mod.rs` (+48 -4) 📝 `crates/horizon-protocol/Cargo.toml` (+2 -0) 📝 `crates/horizon-protocol/src/buf.rs` (+10 -0) 📝 `crates/horizon-protocol/src/lib.rs` (+1 -0) 📝 `crates/horizon-protocol/src/packets/play.rs` (+60 -3) 📝 `crates/horizon-protocol/src/rsa.rs` (+90 -2) ➕ `crates/horizon-protocol/src/secure_chat.rs` (+491 -0) 📝 `crates/horizon-server-files/Cargo.toml` (+2 -0) 📝 `crates/horizon-server-files/src/profiles.rs` (+68 -0) 📝 `docs/hosting.md` (+3 -2) _...and 3 more files_ </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What The server now does secure chat the way vanilla 26.3's does. Before this PR, Horizon's server ignored chat signatures: every message was relayed unsigned, `enforce-secure-profile` did nothing, and the Login packet always said `onlineMode=false`, so vanilla clients never even sent a chat session. **Chat sessions** (`handleChatSessionUpdate`): - The profile key is checked against the services' `playerCertificateKeys`. They are fetched lazily from `authentication.getPublicKeys` (`profiles::fetch_profile_key_keys`, SHA1withRSA). - A valid session is announced to everyone with `PlayerInfoUpdate` `INITIALIZE_CHAT`. - An invalid key is kicked with vanilla's message, and so is a key that expires earlier than the session's current one. - With no services keys, the session is ignored with vanilla's warning. **Signed chat** (`SignedMessageChain`, `LastSeenMessagesValidator(20)`, `MessageSignatureCache(128)`, in `horizon-protocol/src/secure_chat.rs`): - Each message is verified: SHA256withRSA over the `SignedMessageBody` layout, chain links, order, expiry and the last-seen checksum. - Messages are relayed as `PlayerChat` with each connection's global index, the packed signature and the last-seen list. - Acknowledgements (`ChatAck`) are tracked, with the kick at 4096 pending messages. **Signed commands** (`ServerboundChatCommandSignedPacket`): - `say`, `me` and `msg` carry their signed argument and go out as signed chat (`say_command`, `emote_command`, `msg_command_*`). - From an unsigned command packet, they go out as disguised chat, as vanilla's `PlayerChatMessage.system`. - With enforcement on, an unsigned command packet whose command has a message argument is refused (`SignableCommand`). **`enforce-secure-profile`:** it only applies with `online-mode` and the services keys (`DedicatedServer.enforceSecureProfile`). The status response and the Login packet both report it. **Offline servers, and players without a chat session** (Horizon's own client today, which has no Microsoft sign-in), chat unsigned as on vanilla. The log shows `[Not Secure]`. **Log lines:** vanilla's `[Not Secure]` prefix, the decoder's `Failed to update secure chat state for X: '…'`, and the kicks. The lines are now written from the main loop. A kicked player's `lost connection:` line now gives the kick reason, not `Disconnected`. That also changes the line for `/kick` and the idle kick, which should now read as vanilla's (only the chat kicks were compared). ## How tested `tools/test_secure_chat_parity.py` (new) runs a vanilla 26.3 server and `horizon-client --dedicated` with the same scenarios. It uses a Java client (`SecureChatClient`) built on vanilla's own `LocalChatSession`, `SignedMessageChain` and `SignedMessageValidator`, test RSA keys made by the harness, and a mock services server (discovery, public keys, join/hasJoined). No real account is involved. - **offline:** Alice, Bob and Carol on an offline server. - Alice and Bob sign their chat; Carol has no session. - Signed chat and last seen; unsigned chat; `say`, `me` and `msg` signed and unsigned; Carol's unsigned arguments. - Bob, who isn't an operator, sends a mismatched signature (kicked). - A forged signature, a broken chain, and `ChatAck(50)` (kicked). - **online:** online mode with `enforce-secure-profile`. - Alice signs; Carol's unsigned chat and commands are refused. - Mallory joins with a key the services signed for another player, and is kicked. Each client records the system, disguised and player chat it receives, with the verdict of vanilla's validator on every signature, and the disconnects. Result: `secure chat: transcripts and chat log lines identical` (offline 78 lines, online 36). I did not run it on `origin/main`, which ignores chat sessions and signatures. Self-check: ``` cargo fmt --all --check ok cargo clippy --workspace --all-targets -- -D warnings ok cargo test -p horizon-protocol -p horizon-server-files -p horizon-client ok (all passed) tools/parity.py dedicated_server online_mode lan server_ops_feedback server_files server_dimension_players secure_chat 7 passed, 0 failed (16.9 min) ``` ## Needs Ludovic Nothing to merge this. Horizon's own client still can't sign its chat: it needs a Microsoft sign-in to get a profile key (docs/microsoft-account.md, part d). Until then, it chats unsigned, which works everywhere except on online servers that enforce secure profiles. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:59:30 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#2841
No description provided.