Amortize std.crypto.Certificate.Bundle rescanning in std.http.Client
#25264
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Address a few inefficiencies in
std.http.Client. By default, the client loads the systems' CA bundle every time a new TLS/HTTPS connection is established. That's a good thing on the first connection attempt because it avoids loading the bundle if it's not going to be used. But by default, it's reloading the bundle on every new TLS connection, which can end up reading a lot of files from disk. It would be more efficient to only rescan the system CA bundle when the issuer certificate is not found in the current hashmap. But the difficulty with that approach is that rescanning requires an allocator, and the verify method is called bystd.crypto.tls.Client.init, which does not have an allocator.It's possible to workaround this in
std.http.Clientby introducing a verify callback function tostd.crypto.Certificate.Bundle. (It's analogous to OpenSSL'sSSL_CTX_set_cert_verify_callback.) Building on #25261, adding acallbacksource that takes a function pointer adds a mechanism for thestd.http.Clientto interceptverifycalls to aBundle, and callverifyRescaninstead, passing in it's allocator. TheverifyRescanonly rescans the system when a matching issuer can't be found in the loaded certificates.The
callbacksource also allows for some further cleanup ofno_verification&self_signedCA verification behavior, which can be implement now in specific callback functions.