-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
tls: use options in getCACertificates() with X509Certificate #59349
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
base: main
Are you sure you want to change the base?
Conversation
Review requested:
|
doc/api/tls.md
Outdated
@@ -2331,11 +2335,14 @@ Returns an array containing the CA certificates from various sources, depending | |||
trusted store. | |||
* When [`NODE_EXTRA_CA_CERTS`][] is used, this would also include certificates loaded from the specified | |||
file. | |||
|
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.
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.
It seems the white spaces are still there? Can you remove them?
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.
Okay. I'll remove the white space
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.
@joyeecheung Removing that white space will cause a format error in the document..
@jasnell Thank you very much for the thorough and detailed reviews. Additionally, |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #59349 +/- ##
==========================================
- Coverage 89.88% 88.26% -1.62%
==========================================
Files 667 701 +34
Lines 195217 206815 +11598
Branches 38325 39788 +1463
==========================================
+ Hits 175472 182553 +7081
- Misses 12210 16289 +4079
- Partials 7535 7973 +438
🚀 New features to boost your workflow:
|
The CI is failing due to a missing documentation anchor: |
Co-authored-by: James M Snell <[email protected]>
Co-authored-by: James M Snell <[email protected]>
Co-authored-by: James M Snell <[email protected]>
Co-authored-by: James M Snell <[email protected]>
Co-authored-by: James M Snell <[email protected]>
2e19981
to
d978079
Compare
Hi, feedback has been addressed. |
If you have some time, could you please review this? @nodejs/net, @joyeecheung |
Co-authored-by: Daeyeon Jeong <[email protected]>
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.
LGTM! Great job. Let's ask @joyeecheung to also take a look since it was her TODO :-)
Thank you so much for the review and the LGTM! I really appreciate your time. During my final testing, I discovered an unexpected failure related to caching, and also found a minor inconsistency with the documentation. I would like to push a fix for those before the PR is ready to merge. I'll push the updated changes shortly. |
@jasnell @joyeecheung So I added the caching logic, but now other tests are failing. |
I've successfully implemented support for new formats by clearly separating the logic for object input while maintaining the existing function's behavior. All tests have passed, and I believe the PR is ready for review. Thank you. |
lib/tls.js
Outdated
|
||
validateString(type, 'type'); | ||
|
||
switch (type) { |
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.
It seems to me this can just reuse the original function; keep that as something like function getCACertificatesAsStrings(type = 'default')
, and in function getCACertificates(options = undefined)
you just normalize the options first, then get the array of strings, then process it from there.
lib/tls.js
Outdated
return certs.map((cert) => { | ||
if (typeof cert === 'string') { | ||
return cert; | ||
} | ||
return `-----BEGIN CERTIFICATE-----\n${cert.toString('base64').match(/.{1,64}/g).join('\n')}\n-----END CERTIFICATE-----`; | ||
}); |
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 this branch is needed? It should just return the certs. They are already pem-encoded.
lib/tls.js
Outdated
return buffers; | ||
} | ||
|
||
return buffers.map((buf) => new X509Certificate(buf)); |
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.
Parsing it after a base64 decoding from JS land is a lot of detour, this can just directly return certs.map(cert => new X509Certificate(buf))
first if the type is x509
, the native land would just do the decoding and parsing at once, and it would be simpler in that case because the X509Certificate parser would actually attempt to decode it as PEM first before retrying with d2i_X509_bio anyway.
@joyeecheung I've applied the feedback. Could you take a look? |
Could you please take a look at this when you have a moment? Thanks! @joyeecheung |
This PR implements the TODO(joyeecheung) note to support X509Certificate output in tls.getCACertificates(). It introduces a new format option, enhancing the function's flexibility and aligning its API with Node.js's broader crypto module.
The function's behavior is now extended as follows:
API Enhancement: Adds an optional format parameter to tls.getCACertificates() to specify the output format.
Output Options: