Secure SunSpec Modbus TLS test PKI (ECDSA P-256) + pymodbus 3.x update#117
Open
dersecure wants to merge 6 commits into
Open
Secure SunSpec Modbus TLS test PKI (ECDSA P-256) + pymodbus 3.x update#117dersecure wants to merge 6 commits into
dersecure wants to merge 6 commits into
Conversation
…iance
Replace the flat RSA test PKI with a Secure SunSpec Modbus compliant
certificate set and reorganise tls_data into a structured layout.
* All keys are now ECDSA on the NIST P-256 curve, required by the
mandatory Secure SunSpec Modbus cipher suites (ECDHE-ECDSA, P-256).
* Client certificates carry the SunSpec role extension at OID
1.3.6.1.4.1.50316.802.1 as an ASN.1 UTF8String with a single role.
* create_tls_certs.sh now generates every certificate the Secure
SunSpec Modbus conformance tests need:
- ca/ shared root + server/client intermediate CAs
- server/tls1_2|tls1_3 valid server certificates
- server/invalid/ expired, self-signed, foreign-CA, no-SAN
- client/tls1_2|tls1_3 one cert per mandatory SunSpec role
- client/invalid/ no-role, malformed-role (IA5String),
self-signed, foreign-CA, expired
- foreign_pki/ an untrusted CA for multiple-PKI tests
* tls_data/README.md documents the layout and trust relationships.
modbus.py and test_tls_client.py are updated to the new cert paths.
This PKI is the shared source of truth for the Secure SunSpec Modbus
TLS work in DERSim and the LabTest Modbus client.
pymodbus 2.5.3 is several major versions behind and its test-only API
(pymodbus.server.sync) was removed upstream, so test_tls_client.py
could not even be collected.
* requirements.txt: pymodbus==2.5.3 -> pymodbus>=3.9.0. pymodbus is
only used by the TLS test, not the sunspec2 library, so the bump
has no effect on the package itself.
* test_tls_client.py: import StartTlsServer from pymodbus.server and
build the slave context with ModbusSequentialDataBlock, per the
pymodbus 3.x API. Also fix the server to verify connecting clients
against the client CA chain (it previously used the server chain).
Verified: test_tls_client.py passes against the regenerated ECDSA
P-256 Secure SunSpec Modbus PKI.
* setup.py: package_data only globbed tls_data/* (non-recursive), so
installed distributions would omit the nested ca/, server/, client/
and foreign_pki/ certificates that modbus.py now references by
default. Add tls_data/*/* and tls_data/*/*/* so the whole PKI tree
ships; verified all 55 tls_data files are matched.
* test_tls_client.py: the parametrized cafile was unused (the device
hardcoded CAFILE_SERVER). Use the parameter and set it to the
server CA chain so the client correctly validates the server.
The related server-side trust fix (verify clients against the client
CA chain) already landed in the previous commit.
CI installed pymodbus 3.13 (requirements allowed >=3.9.0), where the
test-only API has moved on again and collection failed:
* ModbusSlaveContext was renamed ModbusDeviceContext; import either.
* ModbusServerContext takes 'devices' instead of 'slaves'; try both.
* ModbusSequentialDataBlock must start at address 1, not 0, or
pymodbus 3.13 raises "0 <= address < 65535" building SimData.
* requirements.txt: pin pymodbus>=3.13.0,<4.0 so CI resolves a
version whose API matches this test.
Full suite: 234 passed.
…s-pki Regenerate Modbus TLS test PKI for Secure SunSpec Modbus compliance
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.
Summary
Regenerates the Modbus TLS test PKI under
sunspec2/tests/tls_data/so it is Secure SunSpec Modbus compliant, reorganises it into a structured layout, and updates the TLS test to a currentpymodbus.What changed
Secure SunSpec Modbus test PKI (ECDSA P-256)
The previous PKI used RSA-2048 keys, which can only negotiate the non-conformant
ECDHE-RSAcipher suites. The mandatory Secure SunSpec Modbus suites are allECDHE-ECDSAon the P-256 curve, so every key (root, intermediates, leaves) is now ECDSA P-256. Client certificates carry the SunSpec role extension at OID1.3.6.1.4.1.50316.802.1as an ASN.1UTF8Stringholding exactly one role.create_tls_certs.shnow generates the full certificate set the Secure SunSpec Modbus conformance tests need — valid and deliberately-invalid — in a structured tree:tls_data/README.mddocuments the layout and trust relationships.modbus.py(CAFILE/CLIENT_CERTFILE/CLIENT_KEYFILE) is updated to the new paths, andsetup.pypackage_datanow ships the full nested tree.pymodbus update
pymodbuswas pinned at2.5.3, several major versions behind; its test-only API (pymodbus.server.sync) was removed upstream, sotest_tls_client.pycould not be collected.requirements.txtnow requirespymodbus>=3.13.0,<4.0, andtest_tls_client.pyis rewritten for the pymodbus 3.x API. pymodbus is only used by that test, not thesunspec2library.Verification
create_tls_certs.shruns clean on OpenSSL 3.1.2 and produces the full tree;openssl verifyconfirms the valid leaves chain to the root.ECDHE-ECDSA-AES128-GCM-SHA256at TLS 1.2.test_tls_client.pypasses against pymodbus 3.13; the full test suite passes (234 tests).This was developed and reviewed in the
dersecure/pysunspec2fork; it is offered upstream for the SunSpec Alliance repository.