-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crypto: cleanup root certificates and skip PEM deserialization #56999
Conversation
joyeecheung
commented
Feb 10, 2025
- We do not actually need them in PEM format, so just pass them around as X509 direcrtly.
- The cached global X509 structures were previously never cleaned up. Clean them up at process teardown.
- Use function-local static to ensure thread-safety in initialization.
- Add more comments about how the various options differ.
- We do not actually need them in PEM format, so just pass them around as X509 direcrtly. - The cached global X509 structures were previously never cleaned up. Clean them up at process teardown. - Use function-local static to ensure thread-safety in initialization. - Add more comments about how the various options differ.
Review requested:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #56999 +/- ##
==========================================
- Coverage 89.14% 89.10% -0.04%
==========================================
Files 665 665
Lines 193174 193203 +29
Branches 37189 37226 +37
==========================================
- Hits 172202 172151 -51
- Misses 13735 13764 +29
- Partials 7237 7288 +51
|
Fixed a typo and linter/formatter errors. |
Fixed without-ssl builds |
size_t bundled_root_cert_count = arraysize(root_certs); | ||
for (size_t i = 0; i < bundled_root_cert_count; i++) { | ||
X509* x509 = PEM_read_bio_X509( | ||
NodeBIO::NewFixed(root_certs[i], strlen(root_certs[i])).get(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid strlen() from this function somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, not without changing the perl script that generates the root certificates. Note that this code is not new, it just reverts the copying added by #56599 (which still leads to something like strlen in the string constructor). It has been using strlen since Node.js v0.x days or probably ever since Node.js started implementing TLS..(so > 10 years)
@@ -74,6 +73,10 @@ static const char system_cert_path[] = NODE_OPENSSL_SYSTEM_CERT_PATH; | |||
|
|||
static std::string extra_root_certs_file; // NOLINT(runtime/string) | |||
|
|||
static std::atomic<bool> has_cached_bundled_root_certs{false}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need thread safety here? Wouldn't the bundled root certs be only cached once on the initial boot, or am I missing something here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are initialized when the root store is first used e.g. when a TLS connection is first made. Not when e.g. the program is started to read a file and does not need to use TLS at all. If multiple workers are starting TLS connection at the same time then there can be a race in initialization.
Landed in 79f96b6 |