Load the system CA bundle for verified clients#5
Load the system CA bundle for verified clients#5alanhoff wants to merge 2 commits intoendel:mainfrom
Conversation
Use the Zig system trust store by default when client certificate verification is enabled and no custom CA file is supplied. Keep ownership of the allocated CA bundle in the client lifecycle and cover the builder behavior with unit tests. Co-authored-by: Codex <noreply@openai.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the event-loop client TLS configuration path so that verified clients automatically use the system CA root store when no custom CA bundle is provided, while ensuring any internally-created CA bundle is owned and freed with the client lifecycle.
Changes:
- Add a
buildClientTlsConfighelper that loads the system CA bundle whenskip_cert_verify=falseand noca_cert_pathis provided. - Track and free internally-owned CA bundles in
event_loop.Clientto avoid allocation leaks. - Document the new verified-client behavior and add unit tests, wiring
event_loop.ziginto the test aggregator.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/event_loop.zig | Introduces TLS config builder with system CA auto-load, adds CA bundle ownership tracking, and adds unit tests. |
| src/test_all.zig | Imports event_loop.zig so its tests run in the aggregated test suite. |
| SPEC/RFC5280_CHAIN_VALIDATION.md | Updates spec notes to reflect new event_loop.ClientConfig behavior for system roots. |
| README.md | Documents that verified clients use the system root store when ca_cert_path is unset. |
Comments suppressed due to low confidence (2)
SPEC/RFC5280_CHAIN_VALIDATION.md:46
skip_cert_verifyis documented here as defaulting totrue, butevent_loop.ClientConfig.skip_cert_verifycurrently defaults tofalse(seesrc/event_loop.zig:860) and the README table reflectsfalse. Please clarify which config this caveat refers to (e.g.,tls13.TlsConfigvsevent_loop.ClientConfig) and update the default accordingly to avoid misleading users about verified-client behavior.
### Caveats
- `skip_cert_verify` defaults to `true` for backward compatibility
- V1 certificates (no extensions) are accepted as CAs when no basicConstraints is present — this matches common practice but is less strict than RFC 5280's recommendation
src/event_loop.zig:1118
- In
Client.init,connection.connect(...)is called beforealloc.create(connection.Connection). Ifalloc.createfails, the already-initializedconnvalue (which allocates internally) is dropped withoutdeinit(), leaking allocations on this error path. Consider allocatingconn_ptrfirst (with an init flag) or otherwise ensuringconn.deinit()is called when later allocations fail.
const conn = try connection.connect(
alloc,
config.server_name,
conn_config,
built_tls_config.tls_config,
null,
);
// Heap-allocate so pointers remain stable
const conn_ptr = try alloc.create(connection.Connection);
errdefer {
conn_ptr.deinit();
alloc.destroy(conn_ptr);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Clarify the TLS verification defaults in the RFC 5280 note and release the temporary client connection on the init error path before ownership is transferred. Co-authored-by: Codex <noreply@openai.com>
|
Addressed the follow-up review points on the latest head:
Local validation rerun on the updated branch:
|
|
Superseded by #6, which uses the semantic branch/title convention and includes the security impact details in the PR description. |
Summary
ClientConfigkeeps certificate verification enabled and no custom CA path is providedTesting