Repository navigation
client: tcp+tls with client certificates (--tls-cert, --tls-key, --tls-ca) - #3
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…s-ca) tcp+tls:// URLs were accepted but could not connect: go-modbus requires a client certificate and root CAs for Modbus/TCP Security, and modbusctl never set Config.TLSClientCert or TLSRootCAs. Every client command now takes --tls-cert, --tls-key and --tls-ca (MODBUSCTL_TLS_CERT, MODBUSCTL_TLS_KEY, MODBUSCTL_TLS_CA), embedded next to the serial settings and ignored for other URLs. The key defaults to the certificate file and the CA to the system roots. Unusable files are invalid input before anything is sent; an untrusted server or a rejected client certificate is a transport error. Tests: a throwaway PKI and a TLS listener in mbtest; record a go-modbus tcp+tls server, replay the capture over TCP and serve it back over TLS; every client command over TLS; untrusted server, untrusted client, missing and bad files; CLI flags, help and environment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Unusable TLS files on a tcp+tls:// URL are invalid input in every client path (device and recording links, fingerprint, identify, report server ID, SunSpec), also when a caller skips the CLI validation; and TLSConfig.Load reports each kind of unusable file, including system roots that cannot be read (through a seam). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
boeboe
force-pushed
the
feat/client-tls
branch
from
October 15, 2026 07:30
40dfce9 to
23ccfc1
Compare
This was referenced Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
--url tcp+tls://...was accepted but could not connect. go-modbus requires a client certificate and root CAs for Modbus/TCP Security, and modbusctl never setConfig.TLSClientCertorTLSRootCAs.Change
config.TLSConfigwith--tls-cert,--tls-keyand--tls-ca(MODBUSCTL_TLS_CERT,MODBUSCTL_TLS_KEY,MODBUSCTL_TLS_CA). It is embedded next toSerialConfigin every config that dials: read, decode, write, poll, scan, record, identify, reportserverid, fingerprint, diagnostic and every sunspec command. Other URLs ignore it.--tls-keydefaults to the--tls-certfile, which may hold both.--tls-cadefaults to the system roots and is loaded with go-modbusLoadCertPool.tcp+tls://. A missing certificate, a mismatched key or a bad CA file is invalid input (exit 3), and nothing is sent.buildDeviceClientConfig,openDeviceLinkandopenRecordingLinknow take the TLS settings and apply them.Not included
--tls-server-name. go-modbus v1.7.0 has no setting for it; it checks the device certificate against the URL host.server staticandserver replay. They still serve plain Modbus TCP.Tests
mbtest.NewPKI: a throwaway CA, server and client certificates written as PEM files.Device.ServeTLSadds MBAP over TLS with client authentication required.internal/modbus/e2e_tls_test.go:tcp+tlsserver (FC03 counter, FC08, FC17, FC20, FC24). The capture's target transport istls.server replay: the values arrive in order and FC17 matches.tcp+tlsserver and read it with the TLS client.cmd/client/tls_test.go: TLS flags on every command that has--url, the help text,client readandclient recordover TLS, and CLI exit codes.make checkpasses, with coverage at 96.2%.One behaviour to be aware of: with TLS 1.3, a server that rejects the client certificate only reports it on the first request.
client read/recordhave already created the capture file by then, as for any connection that fails after connecting. An untrusted server is caught at dial time and leaves no file.tcp+tls://URL are invalid input in every client path (device and recording links, fingerprint, identify, report server ID, SunSpec), also when a caller skips CLI validation.TLSConfig.Loadis tested for every kind of unusable file. Patch coverage is 94.4%; the rest aret.Fatalfbranches of the test PKI helper.🤖 Generated with Claude Code