Skip to content

feat: secure remote connections with tls - #88

Open
Enn3Developer wants to merge 6 commits into
n/server-persistencefrom
n/secure-transport
Open

Enn3Developer wants to merge 6 commits into
n/server-persistencefrom
n/secure-transport

Conversation

@Enn3Developer

Copy link
Copy Markdown
Owner

No description provided.

@Enn3Developer Enn3Developer added this to the 0.1.0 milestone Sep 5, 2026
@Enn3Developer Enn3Developer added type: feat New gameplay or feature work area: server OpenPolytopia.Server/ dedicated server area: common OpenPolytopia.Common/ shared library area: netcode TCP transport, packet protocol, serialization labels Sep 5, 2026
@Enn3Developer Enn3Developer self-assigned this Sep 5, 2026
@claude

claude Bot commented Sep 5, 2026

Copy link
Copy Markdown

Claude finished @Enn3Developer's task in 37s —— View job


Summary

Adds TLS transport to client/server networking so credentials and game data aren't sent in plaintext once traffic leaves the local machine, while keeping loopback connections unencrypted for local dev and tests.

Changes

  • Client (ClientConnection.cs): wraps the socket in SslStream unless the target is loopback (or useTls overrides), validating against the OS trust store with no plaintext fallback; handshake has a 10s timeout, and Dispose() is now idempotent.
  • Server (ServerConnection.cs): accepts an optional X509Certificate2; when set, each accepted socket is TLS-authenticated in a background task (SetupClientAsync) so a slow/hostile handshake can't stall the accept loop, and failed/plaintext handshakes are dropped silently.
  • Shared (NetworkConnection.cs): now takes an arbitrary Stream (plaintext or TLS) instead of always using the raw NetworkStream, and disposes that stream on close to unblock reads / send TLS close-notify.
  • Server startup (GameServer.cs, new ServerTls.cs): loads a PKCS#12 certificate from OPENPOLYTOPIA_TLS_CERTIFICATE/OPENPOLYTOPIA_TLS_PASSWORD env vars and refuses to start bound to a non-loopback address without one.
  • Tests (TransportSecurityTest.cs): new coverage for TLS on/off defaults, handshake timeout/failure, untrusted-certificate rejection, plaintext-vs-TLS mismatch handling, and certificate loading/validation.

Worth a look

  • ServerConnection.SetupClientAsync swallows handshake failures with only a Console.Error.WriteLine — worth confirming this is sufficient observability for production.
  • Server startup now refuses non-loopback binds without a certificate (ServerTls.Validate), a behavior change for any existing deployment that ran plaintext on a public interface.
  • No client certificate / mutual TLS support — server trusts any client that completes the handshake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: common OpenPolytopia.Common/ shared library area: netcode TCP transport, packet protocol, serialization area: server OpenPolytopia.Server/ dedicated server type: feat New gameplay or feature work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant