crypto: cleanup root certificates and skip PEM deserialization#56999
crypto: cleanup root certificates and skip PEM deserialization#56999nodejs-github-bot merged 4 commits intonodejs:mainfrom
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.
Can we avoid strlen() from this function somehow?
There was a problem hiding this comment.
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)
|
|
||
| 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.
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.
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 |
- 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. PR-URL: #56999 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
- 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. PR-URL: nodejs#56999 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
- 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. PR-URL: #56999 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
- 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. PR-URL: #56999 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
- 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. PR-URL: #56999 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
- 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. PR-URL: #56999 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>