Skip to content

tls: use options in getCACertificates() with X509Certificate#59349

Open
haramj wants to merge 29 commits intonodejs:mainfrom
haramj:haramjeong-patch-250805
Open

tls: use options in getCACertificates() with X509Certificate#59349
haramj wants to merge 29 commits intonodejs:mainfrom
haramj:haramjeong-patch-250805

Conversation

@haramj
Copy link
Member

@haramj haramj commented Aug 4, 2025

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:

  • 'pem' (default): Returns an array of PEM-encoded certificate strings. This is the new default to align with the name used in other Node.js crypto APIs.
  • 'der': Returns an array of certificate data as Buffer objects in DER format.
  • 'x509': Returns an array of crypto.X509Certificate instances, providing direct access to certificate properties.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/crypto
  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. tls Issues and PRs related to the tls subsystem. labels Aug 4, 2025
doc/api/tls.md Outdated
trusted store.
* When [`NODE_EXTRA_CA_CERTS`][] is used, this would also include certificates loaded from the specified
file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member Author

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..

@haramj
Copy link
Member Author

haramj commented Aug 4, 2025

@jasnell Thank you very much for the thorough and detailed reviews.
I really appreciate the time and effort you’re putting into this.
I’ll carefully go through all the feedback and address them step by step.

Additionally,
When building the docs, the tooling failed to recognize the X509Certificate type and composite return types like Array<Buffer|X509Certificate>, causing errors.
I tried fixing type annotations, references, and escape characters, but I'd appreciate guidance on the correct way to document such composite types officially.

@codecov
Copy link

codecov bot commented Aug 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.66%. Comparing base (2263b4d) to head (e787797).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #59349      +/-   ##
==========================================
- Coverage   89.68%   89.66%   -0.03%     
==========================================
  Files         676      676              
  Lines      206710   206751      +41     
  Branches    39584    39590       +6     
==========================================
- Hits       185398   185391       -7     
- Misses      13441    13495      +54     
+ Partials     7871     7865       -6     
Files with missing lines Coverage Δ
lib/tls.js 93.66% <100.00%> (+0.55%) ⬆️

... and 34 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@haramj
Copy link
Member Author

haramj commented Aug 11, 2025

The CI is failing due to a missing documentation anchor:
link not found: all_tls_tlsgetcacertificatestype
This seems unrelated to the changes in this PR — I didn’t modify that anchor or the associated section..

@haramj haramj changed the title tls: add 'as' option to getCACertificates() for X509Certificate output tls: use options in getCACertificates() with X509Certificate Aug 20, 2025
@haramj haramj force-pushed the haramjeong-patch-250805 branch from 2e19981 to d978079 Compare August 20, 2025 15:29
@haramj
Copy link
Member Author

haramj commented Aug 25, 2025

Hi, feedback has been addressed.
Is there anything else needed from me before this can move forward?

@haramj
Copy link
Member Author

haramj commented Aug 31, 2025

If you have some time, could you please review this? @nodejs/net, @joyeecheung

Copy link
Member

@jasnell jasnell left a 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 :-)

@haramj
Copy link
Member Author

haramj commented Sep 7, 2025

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.

@haramj
Copy link
Member Author

haramj commented Sep 7, 2025

@jasnell @joyeecheung
I've confirmed that the logic using the map() method in the getCACertificates function is causing the caching-related assert.strictEqual test to fail, because it creates a new copy every time.

So I added the caching logic, but now other tests are failing.

@nodejs-github-bot
Copy link
Collaborator

@haramj
Copy link
Member Author

haramj commented Sep 9, 2025

@jasnell @joyeecheung

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.

haramj and others added 29 commits March 24, 2026 14:22
Co-authored-by: James M Snell <jasnell@gmail.com>
Co-authored-by: James M Snell <jasnell@gmail.com>
Co-authored-by: James M Snell <jasnell@gmail.com>
Co-authored-by: James M Snell <jasnell@gmail.com>
Co-authored-by: James M Snell <jasnell@gmail.com>
Co-authored-by: Daeyeon Jeong <daeyeon.dev@gmail.com>
@haramj haramj force-pushed the haramjeong-patch-250805 branch from e2879a5 to e787797 Compare March 24, 2026 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. tls Issues and PRs related to the tls subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants