Skip to content

Fix: support TLS for HTTP and MQ connections#7

Merged
odesenfans merged 1 commit into
mainfrom
add-tls-support
May 18, 2026
Merged

Fix: support TLS for HTTP and MQ connections#7
odesenfans merged 1 commit into
mainfrom
add-tls-support

Conversation

@odesenfans
Copy link
Copy Markdown
Collaborator

Summary

Fixes security finding M1 from the internal review: the client previously hardcoded plaintext http:// for the aiohttp base URL and used plaintext AMQP for aio_pika.connect_robust(...). When the P2P daemons are not co-located with the client, credentials (including the MQ password) traverse the network in cleartext.

This PR adds opt-in TLS support to make_p2p_service_client so cross-host deployments can encrypt both transports.

New parameters

make_p2p_service_client gains four optional parameters:

  • http_use_tls: bool = False - when True, the base URL uses https:// instead of http://.
  • http_ssl_context: Optional[ssl.SSLContext] = None - optional custom SSLContext. When http_use_tls=True and this is None, aiohttp's TCPConnector receives ssl=True (default verifying context). When provided, it is passed through verbatim.
  • mq_use_tls: bool = False - plumbed to aio_pika.connect_robust(..., ssl=...).
  • mq_ssl_options: Optional[Dict[str, Any]] = None - plumbed to aio_pika.connect_robust(..., ssl_options=...). This is aio_pika's native dict-based API; no translation layer is added.

The MQ parameters are also threaded through declare_mq_objects so it remains usable directly.

Behavior change

None for existing callers. With both http_use_tls=False and mq_use_tls=False (the defaults), the factory takes the same code path as before: plaintext http:// base URL and aio_pika.connect_robust called with ssl=False, ssl_options=None. Existing localhost callers are unaffected.

Out of scope

Credential defaults (e.g. removing guest:guest) and HTTP request timeouts are intentionally left for separate PRs.

Test plan

  • Existing localhost deployment continues to work with the call site unchanged (defaults preserve plaintext behavior).
  • Setting http_use_tls=True against an HTTPS-enabled P2P daemon successfully completes identify().
  • Setting mq_use_tls=True (with appropriate mq_ssl_options and an AMQPS-enabled broker) successfully publishes and subscribes.
  • Providing a custom http_ssl_context (e.g. with a private CA) is honored by the connector.

Previously the client hardcoded plaintext http:// for the aiohttp base_url
and used plaintext AMQP for aio_pika.connect_robust(...). When the P2P
daemons are not co-located with the client, credentials (including the MQ
password) traverse the network in cleartext.

This change adds four optional parameters to make_p2p_service_client:
- http_use_tls / http_ssl_context: when enabled, the base URL uses https://
  and aiohttp gets a TCPConnector with the provided SSLContext (or True for
  the default verifying context).
- mq_use_tls / mq_ssl_options: plumbed through declare_mq_objects to
  aio_pika.connect_robust as ssl=... and ssl_options=... (aio_pika's native
  dict-based API).

Defaults are unchanged: with both *_use_tls=False, existing localhost
callers behave exactly as before.
@odesenfans odesenfans merged commit 1e992aa into main May 18, 2026
1 check passed
@odesenfans odesenfans deleted the add-tls-support branch May 18, 2026 22:32
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