Skip to content

feat: secure remote connections with tls - #88

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

feat: secure remote connections with tls#88
Enn3Developer wants to merge 5 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 35s —— View job


Summary

Adds TLS to client/server networking so account credentials and game traffic aren't sent in plaintext, with certificate loading/validation split into a dedicated ServerTls helper.

Changes

  • Common/Network: ClientConnection wraps outbound sockets in SslStream (TLS 1.2/1.3) unless the target is loopback, validating against the OS trust store with no plaintext fallback; ClientConnection.Dispose is now idempotent via an Interlocked guard.
  • Common/Network: ServerConnection accepts an optional X509Certificate2 and, when set, performs the TLS handshake per-client in the background (with a 10s timeout) before registering the client, so one slow/hostile client can't stall the accept loop.
  • Common/Network: NetworkConnection accepts an injectable Stream (plaintext or TLS) and disposes it on close to unblock pending reads / send TLS close-notify.
  • Server: new ServerTls loads a PKCS#12 certificate from OPENPOLYTOPIA_TLS_CERTIFICATE/OPENPOLYTOPIA_TLS_PASSWORD env vars and refuses to start a non-loopback listener without one.
  • Server: GameServer loads/validates the certificate at construction and constructs ServerConnection lazily in RunAsync.
  • Tests: TransportSecurityTest.cs covers cert loading/validation and loopback vs. remote behavior.

Worth a look

  • Binding to null (all interfaces) is treated as non-loopback and now hard-requires a certificate — a behavior change for anyone running the server without bindAddress set to 127.0.0.1 and no cert configured.
  • No client certificate / mutual TLS — only server identity is authenticated.

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