Skip to content

Verify TLS servers against Julia's CA roots by default - #168

Merged
quinnj-bot[bot] merged 2 commits into
masterfrom
claude/tls-default-ca-roots
Nov 19, 2026
Merged

quinnj-bot[bot] merged 2 commits into
masterfrom
claude/tls-default-ca-roots

Conversation

@quinnj-bot

@quinnj-bot quinnj-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Why

On Linux and macOS, TLS connections fail with certificate verify failed unless the user adds tlsCAFile=... to the URI or sets SSL_CERT_FILE (#69). This affects every MongoDB Atlas user, because mongodb+srv:// turns TLS on. The cause: libmongoc's OpenSSL looks for CA certificates under the directory compiled into OpenSSL_jll, /workspace/destdir/ssl. That is the BinaryBuilder build prefix, and it does not exist on users' machines. On Windows, libmongoc reads the system certificate store, so Windows is not affected.

What changed

  • When a URI enables TLS (including mongodb+srv://) and does not set tlsCAFile, Mongoc.URI sets tlsCAFile to NetworkOptions.ca_roots_path(). Julia's other network clients (Downloads, LibGit2) use the same CA roots, and JULIA_SSL_CA_ROOTS_PATH overrides them.
  • Client and ClientPool both build on URI, so both get the default. The Client docstring describes it.

Scope

  • An explicit tlsCAFile, including the legacy sslCertificateAuthorityFile, is kept as given.
  • Windows is unchanged.
  • If ca_roots_path() is a directory (the user set SSL_CERT_DIR), the URI is unchanged. OpenSSL already reads that variable.

Blast Radius

The change applies only to TLS URIs on Linux, macOS, and FreeBSD. Those connections failed before unless the user set tlsCAFile or SSL_CERT_FILE, and both of those still work the same way. Project.toml adds the NetworkOptions stdlib to [deps]. That line is next to the OrderedCollections line that #152 adds, so whichever PR merges second has a one-line conflict: keep both lines.

Verification

  • Probed with a TLS handshake against a server with a public certificate (github.com:443, ?tls=true, no tlsCAFile). On master, it fails with certificate verify failed (20): unable to get local issuer certificate (macOS arm64 and Linux arm64 Docker). On this branch, the handshake succeeds and fails later with Invalid reply from server, because that server does not speak MongoDB.
  • Local MongoDB 5.0.33 with --tlsMode requireTLS and a test CA, with JULIA_SSL_CA_ROOTS_PATH set to that CA. On master, ping fails certificate verification. On this branch, ping returns ok for both Client and ClientPool. With tlsAllowInvalidCertificates=true it still connects, and an explicit tlsCAFile still wins.
  • On Linux with SSL_CERT_DIR=/etc/ssl/certs, the handshake succeeds on both master and this branch.
  • The new test fails twice on master and passes on this branch. Full suite on this branch (macOS, Julia 1.12.6, MongoDB 5.0.33): BSON 173, streams 32, MongoDB 255, exit 4.

Fixes #69

🤖 Generated with Claude Code

quinnj and others added 2 commits November 18, 2026 21:28
TLS URIs without tlsCAFile should verify server certificates against
NetworkOptions.ca_roots_path(). Without that default, libmongoc's
OpenSSL looks under the JLL build prefix and finds no CA certificates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
libmongoc's OpenSSL uses the CA paths compiled into OpenSSL_jll, which
point at the BinaryBuilder prefix (/workspace/destdir/ssl). TLS
connections from Linux and macOS therefore fail with "certificate verify
failed" unless the user sets tlsCAFile or SSL_CERT_FILE.

When a URI enables TLS and has no tlsCAFile, set it to
NetworkOptions.ca_roots_path() if that is a file. Windows keeps
libmongoc's system certificate store.

Fixes #69

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.84%. Comparing base (774a81f) to head (7aad0fa).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #168      +/-   ##
==========================================
+ Coverage   85.30%   85.84%   +0.54%     
==========================================
  Files          11       11              
  Lines        1660     1674      +14     
==========================================
+ Hits         1416     1437      +21     
+ Misses        244      237       -7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@quinnj-bot
quinnj-bot Bot merged commit 4cdcae7 into master Nov 19, 2026
14 checks passed
@quinnj-bot
quinnj-bot Bot deleted the claude/tls-default-ca-roots branch November 19, 2026 04:55
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.

SSL routines:tls_process_server_certificate:certificate verify failed when trying to connect to MongoDB Atlas

1 participant