Skip to content

fix ssl: respect SSL_CERT_FILE and REQUESTS_CA_BUNDLE for CA bundle - #1033

Closed
Tyagiquamar wants to merge 1 commit into
massive-com:masterfrom
Tyagiquamar:fix/respect-ssl-ca-bundle-env
Closed

Tyagiquamar wants to merge 1 commit into
massive-com:masterfrom
Tyagiquamar:fix/respect-ssl-ca-bundle-env

Conversation

@Tyagiquamar

Copy link
Copy Markdown
Contributor

What changed

  • massive/rest/base.py: new _default_ca_bundle() helper returns SSL_CERT_FILE if set, else REQUESTS_CA_BUNDLE if set, else certifi.where(). BaseClient now passes it as ca_certs to the urllib3.PoolManager instead of hardcoded certifi.where().
  • massive/websocket/__init__.py: the wss:// SSLContext loads verify locations from the same helper (removes the now-unused direct certifi import).
  • Added test_rest/test_ssl_ca_bundle.py with 3 tests (precedence, fallback, certifi default) asserting both the helper and the pool connection_pool_kw.

Why

Fixes #998. Behind TLS-inspecting corporate proxies the SDK failed with CERTIFICATE_VERIFY_FAILED because it always used the bundled certifi CA, ignoring the standard env vars that requests, httpx, and urllib3 conventions honor.

Testing

Docker python:3.11-bookworm:

  • python -m unittest test_rest.test_ssl_ca_bundle — 3 passed; errors on base (helper absent, env ignored).
  • Full python -m unittest discover -s test_rest — 42 passed.
  • black --check on all three touched files — clean (repo uses black per Makefile).

@Tyagiquamar

Copy link
Copy Markdown
Contributor Author

Hi team, following up to check if anyone has bandwidth to review this PR when convenient. Thanks!

@justinpolygon

Copy link
Copy Markdown
Collaborator

Hey @Tyagiquamar, yeah I'll take a look. Sorry for the delay.

justinpolygon added a commit that referenced this pull request Oct 16, 2026
Combines the community PRs that change how the REST client builds its
urllib3 pool (#968, #1008, #1026, #1033, #1034).

- CA bundle: both clients verify TLS with ca_certs if given, then the
  SSL_CERT_FILE or REQUESTS_CA_BUNDLE environment variable, then
  certifi (#998).
- RESTClient(maxsize=10): connections kept per host. urllib3 defaults
  to 1, so threaded clients kept opening new TLS connections.
- RESTClient(connection_pool_kw=...): other urllib3 pool options,
  merged over the defaults (#1009).
- RESTClient(proxy=...): explicit proxy URL, with credentials from the
  URL. Proxy environment variables aren't read, so existing traffic
  doesn't change route. The WebSocket client already uses the system
  proxy via websockets.

Co-authored-by: SACHU JAMES <142034811+SachuJames@users.noreply.github.com>
Co-authored-by: Mohd Quamar Tyagi <104281681+Tyagiquamar@users.noreply.github.com>
Co-authored-by: jakobovski-arb <201493996+jakobovski-arb@users.noreply.github.com>
Co-authored-by: Roman Zydyk <31843161+romanzdk@users.noreply.github.com>
Co-authored-by: Kevin Chiu <2712+kevinchiu@users.noreply.github.com>
justinpolygon added a commit that referenced this pull request Oct 16, 2026
Adds connection options to the clients, combining #968, #1008, #1026,
#1033 and #1034 (contributors are credited as co-authors).

- **Custom CA:** `ca_certs=` on `RESTClient` and `WebSocketClient`,
defaulting to `SSL_CERT_FILE` / `REQUESTS_CA_BUNDLE`, then certifi.
Closes #998.
- **Pool size:** `RESTClient(maxsize=10)`. urllib3 defaults to 1
connection per host.
- **Pool options:** `RESTClient(connection_pool_kw={...})`, merged over
the defaults. Closes #1009.
- **Proxy:** `RESTClient(proxy="http://user:pass@host:port")`. Proxy env
vars aren't read, so nobody's traffic changes route.

The README has a new **Network Configuration** section with examples for
each case (custom CA, proxy, threads, other pool options).

All new parameters are optional and added at the end of the signatures.
The one behavior change: if `SSL_CERT_FILE` or `REQUESTS_CA_BUNDLE`
points to a file, it's now used instead of certifi (as `requests` and
Python do). If it points to a file that doesn't exist, it's skipped with
a warning, so a stale value doesn't break anyone.

Verified against the live API through a local TLS-inspecting proxy
(mitmproxy with auth): REST and WebSocket connect with the proxy's CA
(argument or env var) and fail certificate verification without it;
wrong proxy credentials get 407. Under 16 threads, `maxsize=10` opened
16 TLS connections vs 57–70 with urllib3's default.

---------

Co-authored-by: SACHU JAMES <142034811+SachuJames@users.noreply.github.com>
Co-authored-by: Mohd Quamar Tyagi <104281681+Tyagiquamar@users.noreply.github.com>
Co-authored-by: jakobovski-arb <201493996+jakobovski-arb@users.noreply.github.com>
Co-authored-by: Roman Zydyk <31843161+romanzdk@users.noreply.github.com>
Co-authored-by: Kevin Chiu <2712+kevinchiu@users.noreply.github.com>
@justinpolygon

Copy link
Copy Markdown
Collaborator

Thanks for this! We combined it with a few related PRs in #1040 (you're credited as a co-author), released in v2.9.0. SSL_CERT_FILE / REQUESTS_CA_BUNDLE now work for both REST and WebSocket, and there's also a ca_certs= argument. Closing in favor of #1040.

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.

SDK does not respect SSL_CERT_FILE or REQUESTS_CA_BUNDLE environment variables

3 participants