Skip to content

feat: session password set/clear for password-protected PLCs (#792) - #799

Open
gijzelaerr wants to merge 1 commit into
masterfrom
feat/792-session-password
Open

feat: session password set/clear for password-protected PLCs (#792)#799
gijzelaerr wants to merge 1 commit into
masterfrom
feat/792-session-password

Conversation

@gijzelaerr

Copy link
Copy Markdown
Owner

Summary

  • Add set_session_password(password) and clear_session_password() to both snap7.Client (sync) and snap7.AsyncClient (async)
  • These send real S7 USERDATA PDUs (function group 5, Security) to unlock/lock password-protected PLCs, replacing the previous no-op stubs in ClientMixin
  • Password encoding matches the Sharp7/rs-snap7 wire format: XOR each byte with 0x55, rotate left by 3 bits, padded to 8 bytes

Changes

  • snap7/s7protocol.py: Add encode_password(), build_set_session_password_request(), build_clear_session_password_request(), and check_userdata_response() to S7Protocol
  • snap7/client.py: Override set_session_password / clear_session_password with real protocol operations (uses _send_receive_with_reconnect for auto-reconnect support)
  • snap7/async_client.py: Same async overrides using _send_receive
  • snap7/client_base.py: Remove old no-op stubs from ClientMixin (both concrete clients now implement the real protocol)
  • tests/test_s7protocol.py: Unit tests for password encoding (known test vectors), PDU structure, and check_userdata_response error handling
  • tests/test_async_client.py: Update async tests to verify connection-required behavior

Test plan

  • uv run pytest tests/ -x -q -- all 1639 tests pass
  • uv run pre-commit run --all-files -- all hooks pass (mypy, ruff, formatting)
  • End-to-end test against a password-protected PLC (requires hardware)

Closes #792

Add set_session_password() and clear_session_password() to both the
sync Client and async AsyncClient. These send real S7 USERDATA PDUs
(function group 5 / Security) to unlock password-protected PLCs,
replacing the old no-op stubs in ClientMixin.

The password encoding matches the Sharp7/rs-snap7 wire format:
XOR each byte with 0x55, then rotate left by 3 bits, padded to 8 bytes.
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.

Session password set/clear for password-protected PLCs

1 participant