Skip to content

feat: TLS and mutual TLS support, in-place reconfigure - #1

Merged
techfixpros merged 7 commits into
mainfrom
feat/mtls-client
Oct 11, 2026
Merged

techfixpros merged 7 commits into
mainfrom
feat/mtls-client

Conversation

@techfixpros

Copy link
Copy Markdown
Owner

Summary

Adds TLS and mutual TLS (client certificate) support so the integration can talk to a TLS-protected Docker socket proxy.

  • TLS helper (tls.py): builds an ssl.SSLContext from PEM text. Optional private CA, optional client certificate and key, optional key passphrase. Server verification is always on and there is no skip-verify option. TLS 1.2 minimum. VERIFY_X509_STRICT is relaxed so private CAs without an Authority Key Identifier work on Python 3.13+.
  • Config flow: optional CA / client certificate / client key uploads and passphrase on setup, validated against /version. New Reconfigure step edits an entry in place, so entities and history are kept; the unique ID follows the URL.
  • Coordinator: uses the context for both API calls; logs each distinct failure reason once (certificate verification, handshake, missing client certificate, refused, timeout, HTTP 401/403).
  • Diagnostics: redacts keys, passphrase, certificates and proxy host; includes certificate subject/expiry and coordinator state.
  • Tests and CI: pytest suite (41 tests, including end-to-end mTLS against a real local server) and a tests workflow.
  • Entries saved by earlier versions (no TLS keys) keep working unchanged. Version bumped to 1.1.0.

Compatibility

  • Minimum Home Assistant raised from 2024.1.0 to 2024.11.0 (needed for the reconfigure flow).
  • New manifest dependency: file_upload.

Testing

  • pytest: 41 passed on Home Assistant 2026.2.3 / Python 3.13.
  • Verified on a live install (v1.1.0-beta.1) against three real mTLS proxies: all three entries reconfigured in place and polling.
  • Not covered by automated tests: the real Home Assistant upload widgets (checked manually).

Add tls.py, which builds an ssl.SSLContext from PEM text: optional private
CA, optional client certificate/key (mutual TLS) and key passphrase.
Server verification is always on; TLS 1.2 is the minimum. VERIFY_X509_STRICT
is relaxed so private CAs whose certificates lack an Authority Key
Identifier still work on Python 3.13+. Failures carry precise translation
keys.

Add the config keys and the English/German strings, including a new
translations/en.json, which custom integrations need.
Add optional CA, client certificate, client key and passphrase fields to
setup, validated against /version with the resulting SSL context. Add a
reconfigure step that edits an entry in place (entities and history are
kept), updates the unique ID when the URL changes, keeps stored files when
a field is left empty and can remove all stored TLS material.

Requires the file_upload dependency and Home Assistant 2024.11.0 for
reconfigure support.
Build the SSL context at setup in the executor and pass it on both API
calls; invalid stored TLS material is a ConfigEntryError. Entries without
TLS data behave exactly as before. Failures are logged once per distinct
reason (certificate verification, handshake, missing client certificate,
refused, timeout, HTTP 401/403) with a recovery message.
Redact the client key, passphrase, certificate PEMs and proxy host. Include
certificate subject/expiry summaries and live coordinator state.
Add pytest tests (TLS helper, config flow and reconfigure, end-to-end mTLS
against a real local server, diagnostics redaction), a tests workflow,
README documentation for TLS/mTLS and troubleshooting, updated contributor
notes, and bump the version to 1.1.0.
Match the existing workflow, which pins its actions to full commit SHAs.
hassfest rejects URLs inside translation strings. Use a plain 'Proxy URL' label and describe the expected address in data_description instead.
@techfixpros
techfixpros merged commit a206194 into main Oct 11, 2026
4 of 5 checks passed
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