diff --git a/CHANGELOG.md b/CHANGELOG.md index b03b71b..897e318 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,22 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), Pre-releases are not listed separately. A beta is a step towards the next public version, so its changes are folded into that version's entry as they land and are described against the **last public release**, never against the beta before it. What one beta corrected in an earlier beta does not appear at all: from the point of view of somebody upgrading between released versions, it never happened. +## [3.9.1] + +Reading a panel's schema without an `ssl_context` no longer logs a warning naming credentials the read never carries, and the two postures for which that warning was the only line now warn for themselves: a broker connection without TLS, and a pinned TLS +broker beside REST calls without an `ssl_context`. + +### Added + +- **`AsyncMqttBridge` logs one warning per bridge when its broker connection has no TLS (`use_tls=False`)**, saying that the broker username and password, all panel data and every command cross the network in plaintext, where the bridge said nothing. +- **`SpanMqttClient` logs one warning per client when `MqttClientConfig.ca_pem` pins its TLS broker connection and no `ssl_context` pins its REST calls**, saying that its schema reads go over unverified plaintext HTTP, which in that posture nothing else + reports. + +### Changed + +- **`get_homie_schema` no longer logs the plaintext-transport warning or uses up the once-per-panel warning slot**, which 3.4.0 and 3.4.1 had kept, because the read carries no credential in either direction and the slot it used belongs to the registration + behind it. + ## [3.9.0] Snapshots say whether a circuit declares a breaker rating and whether a panel publishes shared meters, and each broker connection subscribes once. diff --git a/README.md b/README.md index 6fcd5a9..3eb8e5a 100644 --- a/README.md +++ b/README.md @@ -435,8 +435,11 @@ unregister = client.register_leaf_mismatch_callback(moved) would otherwise see only an outage. It fires at most once per outage and is re-armed by the next successful connect. An expired leaf reports nothing, because nothing anyone does helps and the panel recovers on its own once it has the time again. Neither handshake can re-anchor anything: both are diagnostic, and the pin is the pin whatever the panel served. -The bootstrap REST calls take an `ssl_context` for the same purpose. `download_ca_cert` is the one exception and stays on plain HTTP — it fetches the anchor everything else is checked against, so it has nothing to check itself against, and its result must -be fingerprint-confirmed out of band before it is trusted. +The bootstrap REST calls take an `ssl_context` for the same purpose. `download_ca_cert` is the one exception and stays on plain HTTP — it fetches the anchor everything else is checked against, so it has nothing to check itself against. Its result is a +candidate, not an anchor: nothing in the response authenticates it, so a caller that stores it without comparing its fingerprint against one obtained another way is trusting on first use, and should say so. + +Pass the context built from the same PEM to `SpanMqttClient` or `create_span_client` as `ssl_context` as well. A client whose broker connection uses TLS pinned by `ca_pem`, and whose `ssl_context` is not set, reads its schema over unverified plaintext HTTP +and logs one `WARNING` saying so; those reads carry no credential. ### Pending-State Detection diff --git a/pyproject.toml b/pyproject.toml index 467be02..c567195 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "span-panel-api" -version = "3.9.0" +version = "3.9.1" description = "A client library for SPAN Panel API" authors = [ {name = "SpanPanel"} diff --git a/src/span_panel_api/_http.py b/src/span_panel_api/_http.py index 97066fc..58904b1 100644 --- a/src/span_panel_api/_http.py +++ b/src/span_panel_api/_http.py @@ -32,8 +32,8 @@ #: whether the panel speaks v2 at all, and `get_v2_status` reads the same answer #: for a caller that already knows it does. Named here rather than spelled out in #: each, so the two cannot drift apart the way their parsers had. Load-bearing -#: for `_warn_plaintext_transport`'s exemption: a request to this path is the -#: one the warning stays silent for, so a change here changes what warns. +#: for `_warn_plaintext_transport`'s exemption: a request to this path is one of +#: the three the warning stays silent for, so a change here changes what warns. V2_STATUS_PATH = "/api/v2/status" #: Exempt from the plaintext warning alongside `V2_STATUS_PATH`, named here @@ -41,6 +41,11 @@ #: `_warn_plaintext_transport`. CA_CERT_PATH = "/api/v2/certificate/ca" +#: Exempt from the plaintext warning alongside the two above, and named here for +#: the same reason. See `_warn_plaintext_transport` for why, and for what the +#: exemption leaves a consumer to do. +HOMIE_SCHEMA_PATH = "/api/v2/homie/schema" + #: The verbs the bootstrap API uses. Spelled as a `Literal` rather than passed #: through to `client.request()` so the dispatch below stays exhaustive and each #: call still reaches the named httpx method. @@ -174,44 +179,89 @@ def _reset_plaintext_warnings() -> None: _warned_plaintext_hosts.clear() -def _warn_plaintext_transport(host: str, path: str, ssl_context: ssl.SSLContext | None) -> None: - """Say out loud, once per panel, that its bootstrap traffic is not encrypted. - - **Two endpoints are exempt, and neither claims the once-per-host slot.** - The warning exists so an operator can tell a security property is off when - it could be on, and for both there is no "on". The CA download fetches the - very anchor verification would need — an unverified-TLS wrapping is - readable and forgeable by the same active on-path attacker, the payload is - a public certificate, and its authenticity control is the leaf check - callers run *after* the fetch. The status endpoint is the detection probe: - most prominently the request discovery makes against a device nobody has - configured, where no pin can exist because trust-on-first-use has not - happened and the only action available is configuring the panel — whose - flow pins before any credential moves, with a person confirming the - fingerprint. Neither call carries a credential in either direction, and - warning on them named credentials they never carry: the CA download's line - is what issue span#264 reported, and the status probe's is what a merely - *advertising* unconfigured panel produced at every boot. - - Two limits of the status exemption, stated rather than implied. The body - informs decisions — `proximityProven`, the serial an identity check reads — - and a plaintext answer is one anything on the path can write; the controls - for that are the panel's own registration gate and the pin the consumer's - flow acquires before a credential moves, not a log line. And a consumer - *can* probe a configured, pinned panel's status without its context; the - exemption means no warning will point that out, so a consumer owes every - probe of a configured host the entry's own transport. Not marking the host matters as - much as not warning — the probe runs first in every flow and a diagnostic - re-read runs on pinned entries, and neither may spend the slot a - credential-bearing call needs later. +def _warn_plaintext_transport( + host: str, + path: str, + ssl_context: ssl.SSLContext | None, + *, + json: dict[str, str] | None, + headers: dict[str, str] | None, +) -> None: + """Say out loud, once per panel, that its credential-bearing bootstrap traffic is not encrypted. In the same voice as the MQTT bridge's unpinned-CA warning, and for the same reason: a security property that is off by default is only a decision if the operator can tell it is off. ``ssl_context=None`` puts the request on - plaintext ``http://``, and two of these calls carry credentials -- - registration sends the panel passphrase and brings the broker password back, - and passphrase rotation sends a bearer token and brings the new broker - password back -- so anything on the path reads all of it. + plaintext ``http://``, and every call that still warns carries a credential + that anything on the path reads: registration sends the panel passphrase, + when it is given one, and brings an access token and the broker password + back; passphrase rotation sends a bearer token and brings the new broker + password back; and the three FQDN calls each send a bearer token. + + **Three endpoints are exempt, by the shape of the request, and none of them + claims the once-per-host slot.** A request is exempt only when its path is + one of the three *and* it sends no header and no body. None of the three + does today, so none carries a credential in either direction, and warning + on them named credentials they never carry. The exemption reads the + request rather than the path alone so that a credential added to one of + these calls later -- a bearer header on the schema read, say -- warns by + construction, instead of depending on somebody remembering to narrow the + exemption. What it can read is the request: it rests on none of the three + answering with a credential, which none of them, being unauthenticated, + has any reason to. Each path is exempt on its own ground. + + The CA download has no "on" to warn about. It fetches the very anchor + verification would need: an unverified-TLS wrapping is readable and + forgeable by the same active on-path attacker, the payload is a public + certificate, and its authenticity control is the leaf check callers run + *after* the fetch. Its warning is the line issue span#264 reported. + + The status endpoint is the detection probe, most prominently the request + discovery makes against a device nobody has configured. No pin can exist + there, because trust-on-first-use has not happened, and the only action + available is configuring the panel, whose flow pins before any credential + moves. That pin is trust on first use, not a confirmation: at first + contact there is nothing to compare the fingerprint against. Its warning + is what a merely *advertising* unconfigured panel produced at every boot. + + The schema read does have an "on", and is exempt because it carries no + credential and the decision it drives is checked elsewhere, not because it + cannot be protected. A forged answer can steer which parser reads the + panel, and two controls stand against that. The consumer this exemption + is for, Home Assistant, reads it unpinned in its config flow to refuse + firmware it cannot drive before a credential moves, and reads it again at + setup over the entry's pinned transport, where it refuses a flat panel. + And a session cross-checks the REST schema generation against the one the + panel publishes over MQTT once its tree is complete, refusing a + disagreement (`SpanMqttClient._assert_transports_agree_on_schema_generation`). + Its warning named the passphrase and the broker password the first time + each panel was discovered or added after a start, and spent the slot that + the registration behind it needed. A session's own schema reads keep a + signal of their own: `SpanMqttClient` warns once when its broker + connection uses TLS pinned by `MqttClientConfig.ca_pem` and its schema + reads have no `ssl_context`. Every other posture in which a session reads + its schema unverified already has a line from the bridge, which warns + about a broker connection without TLS and about a TLS one without a + pinned CA. + + The limits of these exemptions, stated rather than implied. The status body + informs decisions -- `proximityProven`, the serial an identity check reads + -- and a plaintext answer is one anything on the path can write; the + controls for that are the panel's own registration gate and the pin the + consumer's flow acquires before a credential moves, not a log line. A + forged schema also reaches past the parser choice, where neither control + above follows it: the schema-0 adapter takes the panel size and its field + metadata from the schema's `types`. Home Assistant refuses flat firmware, + so the exposure is another consumer of that adapter that reads the schema + without the entry's own transport. And a consumer *can* probe a + configured, pinned panel's status, or read its schema, without its + context; the exemption means no warning will point that out, so a + consumer owes every status probe and every schema read of a configured + host the entry's own transport. Not marking the host matters as + much as not warning -- the probe runs first in every flow, the schema read + runs before registration in a config flow, and a diagnostic re-read runs + on pinned entries, and none of them may spend the slot a + credential-bearing call needs later. **Called from the transport, not from the calls that bootstrap a client.** Warning at the call sites meant each new call site had to remember to, and @@ -221,17 +271,17 @@ def _warn_plaintext_transport(host: str, path: str, ssl_context: ssl.SSLContext **Scoped to the panel, not to the request or the client object.** Per request is a line somebody filters out. Per client object looks tighter and - is worse, because the CA download runs on every MQTT reconnect and builds a - fresh client each time -- so that key would produce a warning per reconnect, - which is precisely what the bridge's own once-per-bridge warning exists to - avoid. The panel is the thing the warning is actually about. + is worse, because a call made without an injected client builds a fresh + one each time -- so that key would warn on every such call, which is per + request under another name. The panel is the thing the warning is actually + about. The credential itself is never named. This is a warning *about* a secret, not a place to put one. """ if ssl_context is not None: return - if path in (CA_CERT_PATH, V2_STATUS_PATH): + if path in (CA_CERT_PATH, V2_STATUS_PATH, HOMIE_SCHEMA_PATH) and json is None and headers is None: return if host in _warned_plaintext_hosts: return @@ -342,7 +392,7 @@ async def _request( caller that supplied it. """ url = _build_url(host, port, path, ssl_context) - _warn_plaintext_transport(host, path, ssl_context) + _warn_plaintext_transport(host, path, ssl_context, json=json, headers=headers) try: async with _get_client(httpx_client, timeout, ssl_context) as client: match method: diff --git a/src/span_panel_api/auth.py b/src/span_panel_api/auth.py index 011c16a..7fcd1fa 100644 --- a/src/span_panel_api/auth.py +++ b/src/span_panel_api/auth.py @@ -21,7 +21,7 @@ import httpx -from ._http import CA_CERT_PATH, V2_STATUS_PATH, _Reply, _request +from ._http import CA_CERT_PATH, HOMIE_SCHEMA_PATH, V2_STATUS_PATH, _Reply, _request from .exceptions import ( SpanPanelAPIError, SpanPanelAuthError, @@ -413,14 +413,14 @@ async def download_ca_cert( """Download the PEM CA certificate from the SPAN Panel. **This call is unauthenticated and unverified by construction, and its - result must be fingerprint-confirmed by the caller before it is trusted.** - It is the bootstrap: it fetches the very anchor everything else is checked - against, so there is nothing for it to check itself against. Anything on the - path between here and the panel can answer it with a CA of its own, and the - response carries no evidence that would distinguish that from the real one. - Whoever calls this owes the trust decision -- comparing the fingerprint - against one recorded out of band, or against one pinned on a previous - install -- and until that is done the PEM is a candidate, not an anchor. + result is a candidate, not an anchor.** It is the bootstrap: it fetches the + very anchor everything else is checked against, so there is nothing for it + to check itself against. Anything on the path between here and the panel + can answer it with a CA of its own, and nothing in the response + authenticates it or distinguishes that from the real one. A caller that + stores it without comparing its fingerprint against one obtained another + way -- recorded out of band, or pinned on a previous install -- is trusting + on first use, and should say so. ``ssl_context`` exists here for the caller that *already holds* the anchor and wants a second copy over a verified channel: refetching to compare @@ -520,7 +520,11 @@ async def get_homie_schema( ) -> V2HomieSchema: """Fetch the Homie property schema from the SPAN Panel. - This endpoint is unauthenticated. + This endpoint is unauthenticated, and carries no credential in either + direction. Without ``ssl_context`` it is read over plaintext HTTP and, unlike + the calls that do carry one, says nothing about it, so read a configured + panel's schema over that panel's own transport. See + ``_warn_plaintext_transport``. Args: host: IP address or hostname of the SPAN Panel @@ -545,7 +549,7 @@ async def get_homie_schema( "GET", host, port, - "/api/v2/homie/schema", + HOMIE_SCHEMA_PATH, timeout=timeout, httpx_client=httpx_client, ssl_context=ssl_context, diff --git a/src/span_panel_api/factory.py b/src/span_panel_api/factory.py index 3ea19e5..50ee4ec 100644 --- a/src/span_panel_api/factory.py +++ b/src/span_panel_api/factory.py @@ -70,6 +70,10 @@ async def create_span_client( Separate from ``MqttClientConfig.ca_pem``, which anchors the *broker* connection. Both are the same panel CA; supply both, from one PEM. + Over a broker connection with TLS, supplying only one is logged as a + warning: by the bridge when ``ca_pem`` is missing, and by the client + when this is. A broker connection without TLS pins nothing, and the + bridge warns about it whatever is supplied. Returns: A connected-ready SpanMqttClient instance. diff --git a/src/span_panel_api/mqtt/client.py b/src/span_panel_api/mqtt/client.py index 66a8b31..000ca1f 100644 --- a/src/span_panel_api/mqtt/client.py +++ b/src/span_panel_api/mqtt/client.py @@ -197,6 +197,9 @@ def __init__( # certificate and its broker's with the one CA. `None` keeps these fetches # on plaintext HTTP, which is 3.0.1's behaviour. self._ssl_context = ssl_context + # Once per client, as the bridge's unpinned-CA warning is once per + # bridge. See `_warn_if_schema_reads_unverified`. + self._warned_unverified_schema = False # How long each setter waits for the panel to report the change back. # Injectable so a test asserting a refusal does not pay a real deadline. self._control_deadlines = control_deadlines or ControlDeadlines() @@ -287,6 +290,50 @@ async def _fetch_schema(self) -> V2HomieSchema: ssl_context=self._ssl_context, ) + def _warn_if_schema_reads_unverified(self) -> None: + """Say once that this client's schema reads are unverified, when nothing else would. + + The transport's plaintext warning does not speak for the schema read, + which carries no credential and whose parser decision is checked + elsewhere (see `_http._warn_plaintext_transport`). That leaves one + posture with no line at all. A consumer whose broker connection uses + TLS pinned by `MqttClientConfig.ca_pem`, and who passes no + `ssl_context`, has this client read the panel's schema over plaintext + HTTP, and the bridge says nothing because it is pinned. Every other + posture already has its line, or nothing unverified to report: a broker + connection without TLS gets the bridge's plaintext warning, which + `ca_pem` cannot silence because without TLS it pins nothing; a TLS one + without `ca_pem` gets the bridge's unpinned-CA warning; and with an + `ssl_context` the schema read is verified. + + **Once per client, the scope the bridge's own warning has, for the same + reason.** The client outlives every reconnect and every redispatch + refetch, as the bridge outlives every reconnect, so the line is said + once per session rather than once per read. A reload builds a new + client and says it again, as it builds a new bridge that does, so each + load of an entry that is not fully pinned logs one line about its + posture, whatever it lacks. Per host would go quiet after the + first load while the bridge's line went on repeating. + + **Said from `connect()`, not from `_fetch_schema`.** `create_span_client` + reads the schema before this client exists and hands it in, so a + warning at the fetch would say nothing about that read, and nothing at + all until the panel changed schema generation. + """ + broker = self._broker_config + if self._ssl_context is not None or not broker.use_tls or broker.ca_pem is None: + return + if self._warned_unverified_schema: + return + self._warned_unverified_schema = True + _LOGGER.warning( + "Homie schema reads for %s are not verified: MqttClientConfig.ca_pem pins the broker " + "connection, but no ssl_context was supplied, so this client reads the panel's schema " + "over plaintext HTTP. No credential is sent or received by those reads. Pass the same " + "CA as ssl_context to verify them.", + self._host, + ) + async def _preload_adapter(self, schema: V2HomieSchema) -> None: """Resolve this schema's adapter in a thread, ahead of building it. @@ -528,6 +575,11 @@ async def connect(self) -> None: # would be a second call to the same unauthenticated endpoint for a # value that cannot have changed. A directly-constructed client has no # schema yet, so it fetches here and dispatches in _build_adapter. + # + # Warned first, and whichever way the schema arrives: the line is about + # this client's own schema reads, and a schema handed in leaves their + # posture as it was. + self._warn_if_schema_reads_unverified() schema = self._schema if self._schema is not None else await self._fetch_schema() self._schema = schema await self._preload_adapter(schema) diff --git a/src/span_panel_api/mqtt/connection.py b/src/span_panel_api/mqtt/connection.py index 8ba3316..d377d48 100644 --- a/src/span_panel_api/mqtt/connection.py +++ b/src/span_panel_api/mqtt/connection.py @@ -160,6 +160,8 @@ def __init__( # `MqttClientConfig.ca_pem` for why `None` is still allowed. self._ca_pem = ca_pem self._warned_unpinned = False + # Once per bridge, as `_warned_unpinned` is. See `_warn_plaintext_broker`. + self._warned_plaintext = False # Terminal state. Set only for a failure that retrying cannot fix, which # today means exactly one thing: the panel's advertised CA no longer @@ -342,6 +344,35 @@ async def _trust_anchor_pem(self) -> str: ) return await download_ca_cert(self._panel_host, port=self._panel_http_port) + def _warn_plaintext_broker(self) -> None: + """Say once per bridge that its broker connection is not encrypted at all. + + ``use_tls=False`` puts the whole session on plaintext: the CONNECT + packet carries the broker username and password, and every message + after it -- every reading the panel publishes and every command sent + to it -- crosses the network readable, and writable, by anything on the + path. Nothing else on the MQTT side says so: its only other warning is + about the trust anchor, and a bridge without TLS resolves none. + + Once per bridge, the scope `_trust_anchor_pem` gives the unpinned-CA + warning and for its reason: a bridge outlives every reconnect, and a + line per reconnect through a day-long outage is a log nobody reads. + Said from `connect()`, which every bridge passes through before its + reconnect loop exists; a rebuild keeps the transport it was given. + """ + if self._warned_plaintext: + return + self._warned_plaintext = True + _LOGGER.warning( + "MQTT connection to %s:%s for %s is not encrypted: use_tls is False, so the broker " + "username and password, all panel data and every command sent to the panel cross the " + "network in plaintext, readable by anything on the path. Set MqttClientConfig.use_tls " + "to connect over TLS.", + self._host, + self._port, + self._panel_host, + ) + async def _diagnose_verification_failure(self) -> SpanPanelCAChangedError | None: """Say what a certificate-verification failure actually was. @@ -504,7 +535,8 @@ async def connect(self) -> None: Resolves the TLS trust anchor — the configured pin, or a fetch from the panel when there is none — configures TLS, connects via executor - (blocking I/O), and waits for CONNACK. + (blocking I/O), and waits for CONNACK. Without TLS it resolves no + anchor, and warns once per bridge that the connection is plaintext. Raises: SpanPanelAuthError: The broker refused the username or password @@ -544,6 +576,8 @@ async def connect(self) -> None: ssl_context = build_panel_ssl_context(ca_pem) except (ssl.SSLError, ValueError) as exc: raise SpanPanelConnectionError(f"Failed to build SSL context for {self._panel_host}") from exc + else: + self._warn_plaintext_broker() # Before a paho client exists, so a disconnect() during the CA fetch -- which # had no client to disconnect -- does not leave one connecting after it. self._raise_if_abandoned(attempt) diff --git a/src/span_panel_api/mqtt/models.py b/src/span_panel_api/mqtt/models.py index aa36187..72a827c 100644 --- a/src/span_panel_api/mqtt/models.py +++ b/src/span_panel_api/mqtt/models.py @@ -29,6 +29,10 @@ class MqttClientConfig: Separate from ``create_span_client``'s ``ssl_context``, which anchors the *REST* calls, because the two secure different transports. They are the same panel CA; a caller holding the PEM supplies both from it. + + ``use_tls=False`` drops TLS from the broker connection altogether, so + ``ca_pem`` pins nothing, and the bridge logs a warning once per bridge that + the broker credentials and all panel traffic cross in plaintext. """ broker_host: str diff --git a/tests/test_plaintext_broker_warning.py b/tests/test_plaintext_broker_warning.py new file mode 100644 index 0000000..171f414 --- /dev/null +++ b/tests/test_plaintext_broker_warning.py @@ -0,0 +1,98 @@ +"""A broker connection without TLS says so, once per bridge. + +`use_tls=False` puts the whole MQTT session on plaintext: the CONNECT packet +carries the broker username and password, and every reading and every command +after it crosses the network readable by anything on the path. The bridge's +only other warning is about its trust anchor, and a bridge without TLS resolves +none, so this posture used to log nothing at all. + +Scoped as the unpinned-CA warning is, to the bridge: a bridge outlives every +reconnect, so the line is said once per bridge rather than once per connect. +""" + +from __future__ import annotations + +import logging +from unittest.mock import MagicMock + +import pytest + +from span_panel_api.mqtt.connection import AsyncMqttBridge + +from conftest import SERIAL + +PLAINTEXT_LINE = "is not encrypted: use_tls is False" +PASSWORD = "correct-horse-battery-staple" + + +def _bridge(*, use_tls: bool) -> AsyncMqttBridge: + return AsyncMqttBridge( + host="broker.local", + port=9001, + username="user", + password=PASSWORD, + panel_host="panel.invalid", + serial_number=SERIAL, + transport="websockets", + use_tls=use_tls, + # Pinned, so a TLS bridge says nothing about its anchor either and the + # only line in question is this one. The fixture replaces the context + # builder, so the PEM is never parsed. + ca_pem="pinned-pem" if use_tls else None, + ) + + +def _plaintext_lines(caplog: pytest.LogCaptureFixture) -> list[logging.LogRecord]: + return [record for record in caplog.records if PLAINTEXT_LINE in record.getMessage()] + + +class TestAPlaintextBrokerSaysSo: + @pytest.mark.asyncio + async def test_it_warns_once_across_reconnects( + self, mqtt_client_mock: MagicMock, caplog: pytest.LogCaptureFixture + ) -> None: + """Two rebuilds and a second connect on the same bridge: one line for all of it.""" + bridge = _bridge(use_tls=False) + with caplog.at_level(logging.WARNING, logger="span_panel_api.mqtt.connection"): + await bridge.connect() + assert await bridge._rebuild_client() is True + assert await bridge._rebuild_client() is True + await bridge.disconnect() + await bridge.connect() + + lines = _plaintext_lines(caplog) + assert len(lines) == 1 + assert lines[0].levelno == logging.WARNING + message = lines[0].getMessage() + assert "broker.local:9001" in message + assert "username and password" in message + assert "plaintext" in message + # A warning about a credential, not a place to put one. + assert PASSWORD not in caplog.text + + await bridge.disconnect() + + @pytest.mark.asyncio + async def test_a_new_bridge_says_it_again(self, mqtt_client_mock: MagicMock, caplog: pytest.LogCaptureFixture) -> None: + """Per bridge, not per process: a reload builds a new bridge, as the unpinned-CA warning's does.""" + first = _bridge(use_tls=False) + second = _bridge(use_tls=False) + with caplog.at_level(logging.WARNING, logger="span_panel_api.mqtt.connection"): + await first.connect() + await second.connect() + + assert len(_plaintext_lines(caplog)) == 2 + + await first.disconnect() + await second.disconnect() + + @pytest.mark.asyncio + async def test_a_tls_bridge_never_says_it(self, mqtt_client_mock: MagicMock, caplog: pytest.LogCaptureFixture) -> None: + bridge = _bridge(use_tls=True) + with caplog.at_level(logging.WARNING, logger="span_panel_api.mqtt.connection"): + await bridge.connect() + assert await bridge._rebuild_client() is True + + assert _plaintext_lines(caplog) == [] + + await bridge.disconnect() diff --git a/tests/test_plaintext_warning.py b/tests/test_plaintext_warning.py index 56aa962..ba8c1ce 100644 --- a/tests/test_plaintext_warning.py +++ b/tests/test_plaintext_warning.py @@ -1,23 +1,35 @@ """Bootstrapping a panel over plaintext HTTP says so, once. -Without an `ssl_context` every bootstrap request is plain `http://`, and two of -them carry credentials: registration sends the panel passphrase and brings the -broker password back, and passphrase rotation sends a bearer token and brings -the new broker password back. Anything on the path reads all of it. That stays -the default, because requiring a pin would break every install on upgrade — but -the MQTT bridge has warned about its unpinned trust anchor since 3.1.0, and the -REST side said nothing at all. +Without an `ssl_context` every bootstrap request is plain `http://`, and the +ones that carry a credential warn: registration sends the panel passphrase, +when it is given one, and brings an access token and the broker password back; +passphrase rotation sends a bearer token and brings the new broker password +back; and the three FQDN calls each send a bearer token. Anything on the path +reads all of it. That stays the default, because requiring a pin would break +every install on upgrade — but the MQTT bridge has warned about its unpinned +trust anchor since 3.1.0, and the REST side said nothing at all. + +The three calls that carry no credential — the CA download, the status probe +and, since 3.9.1, the schema read — do not warn while their requests carry no +header and no body, and do not spend the warning a credential-bearing call +behind them needs. What the schema exemption would otherwise leave unsaid, a +session says itself: a client whose TLS broker is pinned and whose REST calls +are not warns once that its schema reads are unverified, and a bridge without +TLS warns that its whole connection is plaintext. The warning lives in the transport, so no call site can be added later that quietly skips it, and it is scoped to the panel rather than to a request or a -client object. Those are the same two constraints the MQTT bridge already -resolved the same way: the CA is refetched on every reconnect, from a fresh -client each time, so anything narrower than "once per panel" is a warning per -reconnect — a line nobody reads by the second hour of an outage. +client object. A call made without an injected client builds a fresh one each +time, so anything narrower than "once per panel" is a warning per call — a +line nobody reads by the second hour. """ from __future__ import annotations +from collections.abc import Awaitable, Callable, Iterator +import contextlib +from dataclasses import dataclass +import inspect import json import logging import ssl @@ -26,8 +38,23 @@ import httpx import pytest -from span_panel_api.auth import download_ca_cert, get_v2_status, regenerate_passphrase, register_v2 +from span_panel_api import auth, detection +from span_panel_api._http import CA_CERT_PATH, HOMIE_SCHEMA_PATH, V2_STATUS_PATH, _request +from span_panel_api.auth import ( + delete_fqdn, + download_ca_cert, + get_fqdn, + get_homie_schema, + get_v2_status, + regenerate_passphrase, + register_fqdn, + register_v2, + rotate_passphrase, +) from span_panel_api.detection import detect_api_version +from span_panel_api.exceptions import SpanPanelConnectionError +from span_panel_api.mqtt.client import SpanMqttClient +from span_panel_api.mqtt.connection import AsyncMqttBridge from span_panel_api.mqtt.models import MqttClientConfig HOST = "panel.invalid" @@ -86,7 +113,11 @@ def _warnings(caplog: pytest.LogCaptureFixture) -> list[str]: class TestEveryCredentialBearingCallWarns: - """Both of the calls that put a secret on the wire, not just registration.""" + """Not just registration: the two calls that move the most sensitive secrets, one by one. + + Every bootstrap call, the three FQDN calls included, is classified in + `TestEachBootstrapCallWarnsExactlyWhenItCarriesACredential`. + """ @pytest.mark.asyncio async def test_registration_warns(self, caplog: pytest.LogCaptureFixture) -> None: @@ -147,7 +178,7 @@ async def test_the_ca_download_never_warns(self, caplog: pytest.LogCaptureFixtur credential in either direction — the authenticity control is the leaf check its callers run *after* the fetch. Every caller also already says so in its own voice: the bridge's once-per-bridge unpinned warning, the - config flow's fingerprint confirmation, and the deferred pin's + config flow's log of the fingerprint it pinned, and the deferred pin's trust-on-first-use log line. Until 3.3.x this endpoint warned like the rest, naming credentials it never carries; that line is what issue span#264 reported. A caller that already holds the anchor and wants a @@ -177,10 +208,11 @@ async def test_the_status_probe_never_warns(self, caplog: pytest.LogCaptureFixtu there is nothing the operator can do but configure the panel. It carries no credential in either direction, and the flows that probe it on a configured-but-unpinned entry acquire the pin before any - credential moves, with a human confirming the fingerprint. The warning - here named credentials the call never carries and pointed at an action - nobody could take — the line that made an operator remove a healthy - emulator. The exemption's limits live in `_warn_plaintext_transport`'s + credential moves, by trust on first use rather than by anybody + confirming the fingerprint. The warning here named credentials the + call never carries and pointed at an action nobody could take — the + line that made an operator remove a healthy emulator. The exemption's + limits live in `_warn_plaintext_transport`'s docstring: a consumer probing a *configured* host owes that probe the entry's own transport, because no warning will say so anymore. """ @@ -215,6 +247,46 @@ async def test_the_status_probe_does_not_swallow_a_later_warning(self, caplog: p await regenerate_passphrase(HOST, "jwt", httpx_client=_client("put", rotate)) assert len(_warnings(caplog)) == 1 + @pytest.mark.asyncio + async def test_the_schema_read_never_warns(self, caplog: pytest.LogCaptureFixture) -> None: + """Exempted in 3.9.1, reversing what 3.4.0 and 3.4.1 kept on purpose. + + Those releases exempted the CA download and the status probe and left + the schema read warning, because its only callers were then a session + and the factory. Home Assistant, since 2.3.0, also reads it in its + config flow, before the CA is pinned, to refuse firmware it cannot + drive — so the line naming the passphrase and the broker password + appeared the first time each panel was discovered or added after a + start, for a read that carries neither, and spent the slot the + registration behind it needed. Unlike the other two it does have an + "on"; it is exempt because it carries no credential and the decision it + drives is checked elsewhere, by the consumer's own read over the pinned + transport and by the session's cross-check of the REST generation + against the MQTT one. What the exemption drops for a + session is said by the session instead (see + `TestTheSessionSaysWhatTheExemptionDrops`). + """ + answer = _json_response(SCHEMA_JSON, method="GET") + with caplog.at_level(logging.WARNING): + await get_homie_schema(HOST, httpx_client=_client("get", answer)) + assert len(_warnings(caplog)) == 0 + + @pytest.mark.asyncio + async def test_the_schema_read_does_not_swallow_a_later_warning(self, caplog: pytest.LogCaptureFixture) -> None: + """A config flow reads the schema before it registers, so the read must not spend the slot. + + Spent, the registration behind it — the call that actually sends the + passphrase and brings the broker password back — would say nothing. + """ + schema = _json_response(SCHEMA_JSON, method="GET") + with caplog.at_level(logging.WARNING): + await get_homie_schema(HOST, httpx_client=_client("get", schema)) + # The midpoint is the assertion: the slot must still be unspent + # here, so the warning below demonstrably belongs to registration. + assert len(_warnings(caplog)) == 0 + await register_v2(HOST, "home-assistant", "secret", httpx_client=_client("post", _json_response(V2_AUTH_JSON))) + assert len(_warnings(caplog)) == 1 + @pytest.mark.asyncio async def test_the_ca_download_does_not_swallow_a_later_warning(self, caplog: pytest.LogCaptureFixture) -> None: """Skipping the warning must not mark the host as already warned. @@ -293,8 +365,18 @@ class TestCreateSpanClient: """ @pytest.mark.asyncio - async def test_a_prebuilt_config_still_warns(self, caplog: pytest.LogCaptureFixture) -> None: - """This path sends no passphrase, but the schema fetch is still plaintext.""" + async def test_a_prebuilt_config_no_longer_warns_for_its_schema_read(self, caplog: pytest.LogCaptureFixture) -> None: + """Reversed in 3.9.1, deliberately: this path's one request carries no credential. + + It sends no passphrase, and its only bootstrap request is the schema + read, which until 3.9.0 raised the plaintext-transport warning here, + naming the passphrase and the broker password it never carries. The + read is now exempt (`test_the_schema_read_never_warns` says why). The + client is replaced here, so none of the lines a real client and its + bridge say about their posture can appear; those are + `TestTheSessionSaysWhatTheExemptionDrops`'s subject, including this + same factory path with a pinned TLS broker. + """ from span_panel_api.factory import create_span_client config = MqttClientConfig(broker_host="broker.local", username="user", password="pass") @@ -304,11 +386,13 @@ async def test_a_prebuilt_config_still_warns(self, caplog: pytest.LogCaptureFixt with caplog.at_level(logging.WARNING): await create_span_client(HOST, mqtt_config=config, serial_number="SYN-0000-0001", httpx_client=injected) - assert len(_warnings(caplog)) == 1 + # The read was made, so the silence is the exemption's and not a skipped request. + injected.get.assert_awaited_once() + assert len(_warnings(caplog)) == 0 @pytest.mark.asyncio async def test_the_registering_path_warns_exactly_once(self, caplog: pytest.LogCaptureFixture) -> None: - """Registration and the schema fetch are two requests to one panel.""" + """Registration and the schema read are two requests to one panel; the warning is registration's.""" from span_panel_api.factory import create_span_client injected = AsyncMock(spec=httpx.AsyncClient) @@ -322,3 +406,345 @@ async def test_the_registering_path_warns_exactly_once(self, caplog: pytest.LogC injected.post.assert_awaited_once() injected.get.assert_awaited_once() assert len(_warnings(caplog)) == 1 + + +STATUS_JSON = {"serialNumber": "SYN-0000-0001", "firmwareVersion": "f"} + + +@dataclass(frozen=True) +class _BootstrapCall: + """One public bootstrap call, driven through an injected client.""" + + label: str + function: Callable[..., Awaitable[object]] + method: str + answer: httpx.Response + carries_a_credential: bool + call: Callable[[AsyncMock], Awaitable[object]] + + +#: Every public bootstrap call, and whether it puts a credential on the wire in +#: either direction. `test_the_table_names_every_public_bootstrap_call` keeps it +#: complete, so a call added later cannot go unclassified. +_BOOTSTRAP_CALLS = ( + _BootstrapCall( + "registration", + register_v2, + "post", + _json_response(V2_AUTH_JSON), + True, + lambda injected: register_v2(HOST, "home-assistant", "secret", httpx_client=injected), + ), + # No passphrase goes up, but an access token and the broker password come back. + _BootstrapCall( + "door-bypass registration", + register_v2, + "post", + _json_response(V2_AUTH_JSON), + True, + lambda injected: register_v2(HOST, "home-assistant", None, httpx_client=injected), + ), + _BootstrapCall( + "passphrase rotation", + rotate_passphrase, + "put", + _json_response({"ebusBrokerPassword": "new-pass", "hopPassphrase": "new-hop"}, method="PUT"), + True, + lambda injected: rotate_passphrase(HOST, "jwt", httpx_client=injected), + ), + _BootstrapCall( + "passphrase regeneration", + regenerate_passphrase, + "put", + _json_response({"ebusBrokerPassword": "new-pass"}, method="PUT"), + True, + lambda injected: regenerate_passphrase(HOST, "jwt", httpx_client=injected), + ), + _BootstrapCall( + "FQDN registration", + register_fqdn, + "post", + _json_response({}), + True, + lambda injected: register_fqdn(HOST, "jwt", "panel.example", httpx_client=injected), + ), + _BootstrapCall( + "FQDN read", + get_fqdn, + "get", + _json_response({"ebusTlsFqdn": "panel.example"}, method="GET"), + True, + lambda injected: get_fqdn(HOST, "jwt", httpx_client=injected), + ), + _BootstrapCall( + "FQDN removal", + delete_fqdn, + "delete", + _json_response({}, method="DELETE"), + True, + lambda injected: delete_fqdn(HOST, "jwt", httpx_client=injected), + ), + _BootstrapCall( + "CA download", + download_ca_cert, + "get", + _text_response(PEM), + False, + lambda injected: download_ca_cert(HOST, httpx_client=injected), + ), + _BootstrapCall( + "schema read", + get_homie_schema, + "get", + _json_response(SCHEMA_JSON, method="GET"), + False, + lambda injected: get_homie_schema(HOST, httpx_client=injected), + ), + _BootstrapCall( + "status probe", + get_v2_status, + "get", + _json_response(STATUS_JSON, method="GET"), + False, + lambda injected: get_v2_status(HOST, httpx_client=injected), + ), + _BootstrapCall( + "detection probe", + detect_api_version, + "get", + _json_response(STATUS_JSON, method="GET"), + False, + lambda injected: detect_api_version(HOST, httpx_client=injected), + ), +) + + +class TestEachBootstrapCallWarnsExactlyWhenItCarriesACredential: + """The whole rule in one table: the warning names credentials, so only a call carrying one says it.""" + + @pytest.mark.asyncio + @pytest.mark.parametrize("bootstrap", _BOOTSTRAP_CALLS, ids=lambda bootstrap: bootstrap.label) + async def test_it_warns_exactly_when_it_carries_a_credential( + self, bootstrap: _BootstrapCall, caplog: pytest.LogCaptureFixture + ) -> None: + injected = _client(bootstrap.method, bootstrap.answer) + with caplog.at_level(logging.WARNING): + await bootstrap.call(injected) + sent = getattr(injected, bootstrap.method) + # The request was made, so a silent row is the exemption's and not a skipped call. + sent.assert_awaited_once() + if not bootstrap.carries_a_credential: + # A silent row is honest only while nothing but the URL goes up: a + # header or a body is where a credential would ride. + assert sent.await_args.kwargs.get("headers") is None + assert sent.await_args.kwargs.get("json") is None + assert len(_warnings(caplog)) == (1 if bootstrap.carries_a_credential else 0) + + def test_the_table_names_every_public_bootstrap_call(self) -> None: + """Every public coroutine the bootstrap modules define has a row, exported or not. + + Read from the modules rather than from `__all__`: a call that puts a + credential on the wire is no less on the wire for being left out of the + package's exports, and one added without a row would go unclassified. + """ + defined = { + name + for module in (auth, detection) + for name, function in inspect.getmembers(module, inspect.iscoroutinefunction) + if not name.startswith("_") and function.__module__ == module.__name__ + } + assert defined == {bootstrap.function.__name__ for bootstrap in _BOOTSTRAP_CALLS} + + +class TestTheExemptionReadsTheRequest: + """An exempt path stays silent only while its request carries nothing a credential could ride in. + + No public call sends a header or a body to an exempt path today, which is + why these drive the transport directly: the guarantee is about the call + somebody changes later, such as a bearer token added to the schema read. + """ + + @pytest.mark.asyncio + @pytest.mark.parametrize("path", [CA_CERT_PATH, V2_STATUS_PATH, HOMIE_SCHEMA_PATH]) + async def test_a_header_on_an_exempt_path_warns(self, path: str, caplog: pytest.LogCaptureFixture) -> None: + injected = _client("get", _json_response({}, method="GET")) + with caplog.at_level(logging.WARNING): + await _request( + "GET", HOST, None, path, timeout=1.0, httpx_client=injected, headers={"Authorization": "Bearer jwt"} + ) + assert len(_warnings(caplog)) == 1 + + @pytest.mark.asyncio + @pytest.mark.parametrize("path", ["/api/v2/auth/register", "/api/v2/auth/passphrase", auth._FQDN_PATH]) + async def test_no_other_path_is_exempt_even_when_bare(self, path: str, caplog: pytest.LogCaptureFixture) -> None: + """The three are the whole exempt set: a credential-bearing endpoint warns for its path alone. + + A request to one of these always carries something today, so only a + bare one shows that the path, and not just what rides with it, is what + keeps it warning. + """ + injected = _client("get", _json_response({}, method="GET")) + with caplog.at_level(logging.WARNING): + await _request("GET", HOST, None, path, timeout=1.0, httpx_client=injected) + assert len(_warnings(caplog)) == 1 + + @pytest.mark.asyncio + @pytest.mark.parametrize("path", [CA_CERT_PATH, V2_STATUS_PATH, HOMIE_SCHEMA_PATH]) + async def test_a_body_on_an_exempt_path_warns(self, path: str, caplog: pytest.LogCaptureFixture) -> None: + injected = _client("post", _json_response({})) + with caplog.at_level(logging.WARNING): + await _request("POST", HOST, None, path, timeout=1.0, httpx_client=injected, json={"hopPassphrase": "secret"}) + assert len(_warnings(caplog)) == 1 + + +SESSION_LINE = "Homie schema reads for" +BRIDGE_LINE = "obtained unauthenticated" +PLAINTEXT_BROKER_LINE = "is not encrypted: use_tls is False" +TRANSPORT_LINE = "Bootstrap traffic for" + + +def _lines(caplog: pytest.LogCaptureFixture, marker: str) -> list[str]: + return [line for line in _warnings(caplog) if marker in line] + + +def _session(*, ca_pem: str | None, ssl_context: ssl.SSLContext | None, use_tls: bool = True) -> SpanMqttClient: + return SpanMqttClient( + HOST, + "SYN-0000-0001", + MqttClientConfig(broker_host="broker.local", username="user", password="pass", use_tls=use_tls, ca_pem=ca_pem), + ssl_context=ssl_context, + ) + + +@contextlib.contextmanager +def _a_panel_with_no_broker() -> Iterator[AsyncMock]: + """A panel that serves its schema over either scheme and has no CA or broker to reach. + + Every client here builds its own HTTP client, plaintext or pinned, so the + class is replaced and every schema read lands on one mock, which is + yielded so a test can count the reads. A connect then ends where the + bridge would open a socket, after each posture line has had its chance: + a pinned bridge cannot build a context from the synthetic PEM, an + unpinned one cannot fetch its CA, and one without TLS cannot build a + broker client. All three raise `SpanPanelConnectionError`. + """ + with ( + patch("span_panel_api._http.httpx.AsyncClient") as mock_cls, + patch( + "span_panel_api.mqtt.connection.download_ca_cert", + AsyncMock(side_effect=SpanPanelConnectionError("no CA in this test")), + ), + patch.object( + AsyncMqttBridge, + "_make_paho_client", + side_effect=SpanPanelConnectionError("no broker in this test"), + ), + ): + dedicated = AsyncMock() + dedicated.__aenter__ = AsyncMock(return_value=dedicated) + dedicated.__aexit__ = AsyncMock(return_value=False) + dedicated.get = AsyncMock(return_value=_json_response(SCHEMA_JSON, method="GET")) + mock_cls.return_value = dedicated + yield dedicated + + +class TestTheSessionSaysWhatTheExemptionDrops: + """A pinned TLS broker beside unpinned REST calls is the one posture nothing else reports. + + Before 3.9.1 the transport warning was the only line a consumer in that + posture got about its schema reads, and the schema exemption removes it: + the bridge is pinned, so it says nothing either. The client now says it, + once, and stays silent wherever another line already covers the posture + or nothing is unverified. + """ + + @pytest.mark.asyncio + @pytest.mark.parametrize( + ("use_tls", "ca_pem", "pinned_rest", "session_lines", "unpinned_lines", "plaintext_lines"), + [ + pytest.param(True, PEM, False, 1, 0, 0, id="TLS broker pinned, REST not: the client says it"), + pytest.param(True, PEM, True, 0, 0, 0, id="TLS broker and REST pinned: nothing to say"), + pytest.param(True, None, False, 0, 1, 0, id="TLS, neither pinned: the bridge's unpinned line"), + pytest.param(True, None, True, 0, 1, 0, id="TLS, REST pinned, broker not: the bridge's unpinned line"), + # Without TLS `ca_pem` pins nothing, so the client must not claim it + # does; the bridge's plaintext line covers every one of these. + pytest.param(False, PEM, False, 0, 0, 1, id="no TLS, ca_pem set, REST not pinned: the bridge's plaintext line"), + pytest.param(False, PEM, True, 0, 0, 1, id="no TLS, ca_pem set, REST pinned: the bridge's plaintext line"), + pytest.param(False, None, False, 0, 0, 1, id="no TLS, nothing pinned: the bridge's plaintext line"), + pytest.param(False, None, True, 0, 0, 1, id="no TLS, REST pinned: the bridge's plaintext line"), + ], + ) + async def test_each_posture_gets_exactly_the_line_it_needs( + self, + use_tls: bool, + ca_pem: str | None, + pinned_rest: bool, + session_lines: int, + unpinned_lines: int, + plaintext_lines: int, + caplog: pytest.LogCaptureFixture, + ) -> None: + client = _session( + ca_pem=ca_pem, + ssl_context=ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) if pinned_rest else None, + use_tls=use_tls, + ) + with _a_panel_with_no_broker() as panel, caplog.at_level(logging.WARNING): + with pytest.raises(SpanPanelConnectionError): + await client.connect() + panel.get.assert_awaited_once() + assert len(_lines(caplog, SESSION_LINE)) == session_lines + assert len(_lines(caplog, BRIDGE_LINE)) == unpinned_lines + assert len(_lines(caplog, PLAINTEXT_BROKER_LINE)) == plaintext_lines + # No posture is told about its schema read by the transport any more. + assert _lines(caplog, TRANSPORT_LINE) == [] + + @pytest.mark.asyncio + async def test_the_mixed_posture_says_it_once_per_client(self, caplog: pytest.LogCaptureFixture) -> None: + """Once across the reads a session makes, as the bridge says its own line once across reconnects. + + A connect reads the schema, a redispatch reads it again, and a second + connect on the same client reuses it: one line for all of it, because a + line per read through a day of reconnects is a log nobody reads. + """ + client = _session(ca_pem=PEM, ssl_context=None) + with _a_panel_with_no_broker() as panel, caplog.at_level(logging.WARNING): + with pytest.raises(SpanPanelConnectionError): + await client.connect() + await client._redispatch_if_generation_changed() + with pytest.raises(SpanPanelConnectionError): + await client.connect() + assert panel.get.await_count == 2 + lines = _lines(caplog, SESSION_LINE) + assert len(lines) == 1 + assert HOST in lines[0] + assert "ssl_context" in lines[0] + assert "No credential" in lines[0] + + @pytest.mark.asyncio + async def test_a_new_client_says_it_again(self, caplog: pytest.LogCaptureFixture) -> None: + """Per client, not per host: a reload builds a new client, and the bridge's line repeats on one too.""" + with _a_panel_with_no_broker(), caplog.at_level(logging.WARNING): + for _ in range(2): + with pytest.raises(SpanPanelConnectionError): + await _session(ca_pem=PEM, ssl_context=None).connect() + assert len(_lines(caplog, SESSION_LINE)) == 2 + + @pytest.mark.asyncio + async def test_the_factory_read_is_covered(self, caplog: pytest.LogCaptureFixture) -> None: + """The factory reads the schema before the client exists and hands it in. + + So the client makes no read of its own at connect, and a line said only + at the client's fetch would say nothing about the one read this path + makes. It is said at connect instead, whichever way the schema arrived. + """ + from span_panel_api.factory import create_span_client + + config = MqttClientConfig(broker_host="broker.local", username="user", password="pass", ca_pem=PEM) + with _a_panel_with_no_broker() as panel, caplog.at_level(logging.WARNING): + with pytest.raises(SpanPanelConnectionError): + await create_span_client(HOST, mqtt_config=config, serial_number="SYN-0000-0001") + # The factory's read, and no other. + panel.get.assert_awaited_once() + assert len(_lines(caplog, SESSION_LINE)) == 1 + assert _lines(caplog, TRANSPORT_LINE) == [] diff --git a/uv.lock b/uv.lock index 216b125..ee3276a 100644 --- a/uv.lock +++ b/uv.lock @@ -974,7 +974,7 @@ wheels = [ [[package]] name = "span-panel-api" -version = "3.9.0" +version = "3.9.1" source = { editable = "." } dependencies = [ { name = "httpx" },