Skip to content

server: tcp+tls with client certificates (--tls-cert, --tls-key, --tls-ca) - #6

Merged
boeboe merged 1 commit into
mainfrom
feat/server-tls
Oct 16, 2026
Merged

boeboe merged 1 commit into
mainfrom
feat/server-tls

Conversation

@boeboe

@boeboe boeboe commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

server static and server replay serve Modbus/TCP Security (tcp+tls) when given --tls-cert. They served plain Modbus TCP only.

  • --tls-cert, --tls-key, --tls-ca (MODBUSCTL_TLS_CERT, MODBUSCTL_TLS_KEY, MODBUSCTL_TLS_CA, the variables the client reads) in config.ServerTLSConfig, embedded in StaticServerConfig and ReplayServerConfig.
  • --tls-cert turns TLS on; --tls-key defaults to the --tls-cert file. --tls-ca is required: the CA bundle that signs client certificates. go-modbus requires and verifies a client certificate on every connection.
  • validate.CheckStaticServerConfig/CheckReplayServerConfig load the files. A missing/unreadable file, mismatched key, --tls-cert without --tls-ca, or --tls-key/--tls-ca without --tls-cert is invalid input (exit 3), before the server binds or prints anything.
  • The listener line reads 🚀 Serving Modbus TCP Security (tcp+tls, client certificates required) on … port N.
  • Port default stays 502; docs use 802 (the Modbus/TCP Security convention).

Tests:

  • internal/modbus/e2e_tls_server_test.go: record over tcp+tls, replay over tcp+tls with ServeReplay and read back with the modbusctl TLS client until the last value; ServeStatic over tcp+tls (FC03 and FC17); server key in the certificate file; both servers reject a client cert of another CA, a server cert used as a client cert, a client that does not trust the server, and a plain TCP client (📊 Served 0 requests); bad server TLS files → invalid input with nothing printed.
  • TestE2ETLS_recordAndReplay now serves the capture back over TLS with the real server static instead of a go-modbus stand-in.
  • cmd/server/tls_test.go: same through the CLI flags, plus help and validation exit codes.
  • Config, env and validate unit tests.

README (new "Serving over Modbus/TCP Security" section, env table, features), command help examples and RELEASE.md (v3.2.0, unreleased) updated.

make check passes: 0 lint issues, -race tests green, coverage 96.4%.

🤖 Generated with Claude Code

…s-ca)

server static and server replay serve Modbus/TCP Security when given
--tls-cert: the server presents its certificate and requires a client
certificate signed by the --tls-ca bundle, which is therefore required.
The flags read MODBUSCTL_TLS_CERT, MODBUSCTL_TLS_KEY and MODBUSCTL_TLS_CA,
like the client. Bad or incomplete TLS files are invalid input before the
server binds. The listener line names tcp+tls when it is on.

End-to-end tests record over tcp+tls, serve the capture over tcp+tls with
both servers and read it back with the modbusctl TLS client, and check
that untrusted and plain-TCP clients are rejected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.95918% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/modbus/server.go 95.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@boeboe
boeboe merged commit 6d04305 into main Oct 16, 2026
7 checks passed
@boeboe
boeboe deleted the feat/server-tls branch October 16, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant