src: modify SecureContext::SetCACert to not create root certificate store #56301
+82
−3
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.
This modification is mainly to optimize the startup performance of http2 and https servers (or may be tls clients's first connection?) When the user specifies a ca, it skips loading more than 100 root certificates built into node.js, and the startup speed is 15 ms faster.
In
SecureContext::SetCACert
funciton we cound get the existing cert store from the SSL context instead ofGetCertStoreOwnedByThisSecureContext()
(in which calls NewRootCertStore()) to avoid creating X509_STORE based on root_certs (more than 130), which is very slow.According to the documentation, when passing in the ca option, you do not add it to the node.js built-in root certificates but replace them, so you do not need to use the built-in root certificate to initialize the x509 store.
node/doc/api/tls.md
Lines 1984 to 2004 in 8253290
The slow loading of root certificates is a known issue of openssl3 (openssl/openssl#16871) and has not been fixed. @mhdawson
There are also related issues in node.js:
before optimization
after optimization
cc @nodejs/crypto @nodejs/tls
If anyone can help me benchmark it, I'd be very grateful.