Skip to content

crypto: improve system certificate enumeration logic on macOS#62576

Open
deepak1556 wants to merge 1 commit intonodejs:mainfrom
deepak1556:robo/cleanup_macos_system_cert_api
Open

crypto: improve system certificate enumeration logic on macOS#62576
deepak1556 wants to merge 1 commit intonodejs:mainfrom
deepak1556:robo/cleanup_macos_system_cert_api

Conversation

@deepak1556
Copy link
Copy Markdown
Contributor

In VSCode we are looking to adopt the builtin system certificate api over our current implementation https://github.com/microsoft/vscode-proxy-agent/blob/59cc268f93f52fdfd0c7ac1f25aadefae74965fb/src/index.ts#L1189-L1201

As part of the rollout we observed a drop in certificate count (some machines also got 0 certs) from the builtin api and I was validating the cases with additional error telemetry https://gist.github.com/deepak1556/ef6c141e0cd3f5381cbf6f37fc590acf. It confirmed the failures are on the valid path, all the certs had no explicit trust settings and were getting filtered under the fallback SecTrustEvaluateWithError path.

The changes in this PR are some cleanups and some misalign in logic with chromium implementation noticed while working on the error api. Each commit has additional context on the change.

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run. labels Apr 3, 2026
@deepak1556 deepak1556 marked this pull request as draft April 3, 2026 12:40
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.80%. Comparing base (ae1c0e4) to head (1fe7f74).
⚠️ Report is 52 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62576      +/-   ##
==========================================
+ Coverage   89.79%   89.80%   +0.01%     
==========================================
  Files         697      699       +2     
  Lines      215773   216465     +692     
  Branches    41297    41384      +87     
==========================================
+ Hits       193749   194398     +649     
- Misses      14117    14155      +38     
- Partials     7907     7912       +5     
Files with missing lines Coverage Δ
src/crypto/crypto_context.cc 72.09% <ø> (+0.11%) ⬆️

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

@deepak1556 deepak1556 force-pushed the robo/cleanup_macos_system_cert_api branch from 3325bb6 to 2871528 Compare April 3, 2026 14:01
@deepak1556 deepak1556 marked this pull request as ready for review April 3, 2026 14:03
Copy link
Copy Markdown
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

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

LGTM, thanks. Is it possible to add some tests? We have some integration tests in test/system-ca, see the README there for how to add the certificates and how to clean them up.

(caveat: the tests don't actually run without you doing a local mv test/system-ca/test.cfg.py test/system-ca/testcfg.py, it's currently a weird bug we rely on to not run it in the CI because the CI isn't prepped for this..)

@deepak1556 deepak1556 marked this pull request as draft April 3, 2026 14:56
@deepak1556 deepak1556 marked this pull request as ready for review April 4, 2026 20:08
@deepak1556 deepak1556 requested a review from joyeecheung April 4, 2026 20:08
@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 6, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 6, 2026
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

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

lgtm

@deepak1556
Copy link
Copy Markdown
Contributor Author

Looks like unrelated CI failures. Seems to have been addressed by 449a93a. Rebasing.

@joyeecheung
Copy link
Copy Markdown
Member

Looks like it got closed by the other vscode PR?

@deepak1556 deepak1556 reopened this Apr 13, 2026
@deepak1556
Copy link
Copy Markdown
Contributor Author

Ah missed that, Thanks!

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 13, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 13, 2026
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@joyeecheung joyeecheung added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Apr 13, 2026
@joyeecheung joyeecheung removed the commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. label Apr 13, 2026
@joyeecheung
Copy link
Copy Markdown
Member

hmm, wait, I don't think they are suitable for squashing @deepak1556 do you need them to land as separate commits or can you squash them into one?

@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Apr 13, 2026
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/62576
✔  Done loading data for nodejs/node/pull/62576
----------------------------------- PR info ------------------------------------
Title      crypto: improve system certificate enumeration logic on macOS (#62576)
Author     Robo <hop2deep@gmail.com> (@deepak1556)
Branch     deepak1556:robo/cleanup_macos_system_cert_api -> nodejs:main
Labels     crypto, c++, needs-ci
Commits    5
 - crypto: fix macOS default for missing kSecTrustSettingsResult
 - crypto: fix leak and improve cert enumeration
 - crypto: add comment for SecTrustEvaluateWithError policy
 - src: fix formatting in crypto_context.cc
 - test: add macOS certificate filtering tests
Committers 1
 - deepak1556 <hop2deep@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/62576
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/62576
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Fri, 03 Apr 2026 12:29:50 GMT
   ✔  Approvals: 2
   ✔  - Joyee Cheung (@joyeecheung) (TSC): https://github.com/nodejs/node/pull/62576#pullrequestreview-4099386193
   ✔  - Gürgün Dayıoğlu (@gurgunday): https://github.com/nodejs/node/pull/62576#pullrequestreview-4061571023
   ✘  1 GitHub CI job(s) failed:
   ✘    - test-macOS: FAILURE (https://github.com/nodejs/node/actions/runs/24142256015/job/70446614310)
   ℹ  Last Full PR CI on 2026-04-13T14:29:35Z: https://ci.nodejs.org/job/node-test-pull-request/72671/
- Querying data for job/node-test-pull-request/72671/
✔  Build data downloaded
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/24364295251

1) Fixed macOS default for missing kSecTrustSettingsResult

When kSecTrustSettingsResult is absent from a trust settings dictionary,
Apple specifies kSecTrustSettingsResultTrustRoot as the default value.

Previously, the trust result evaluation (deny check, self-issued check,
TrustAsRoot check) was inside the block that only executed when
kSecTrustSettingsResult was explicitly present. When the key was absent,
the function fell through to return UNSPECIFIED, incorrectly rejecting
self-signed certificates that should have been trusted via the default.

Move the trust result evaluation outside the conditional block so the
default value of kSecTrustSettingsResultTrustRoot flows through the
same code path as explicit values. This aligns with Chromium's
trust_store_mac.cc implementation.

2) Fix CFRelease leak in IsTrustDictionaryTrustedForPolicy: the
CFDictionaryRef returned by SecPolicyCopyProperties(policy_ref)
was not released when the policy OID matched kSecPolicyAppleSSL.

3) Deduplicate certificates: SecItemCopyMatching can return the same
certificate from multiple keychains.

4) Filter expired certificates.
@deepak1556 deepak1556 force-pushed the robo/cleanup_macos_system_cert_api branch from 5af88e7 to 1fe7f74 Compare April 13, 2026 21:52
@deepak1556
Copy link
Copy Markdown
Contributor Author

deepak1556 commented Apr 13, 2026

Started separate commits for review. Definitely, not required to land as individual commits. Went ahead and squashed them. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-failed An error occurred while landing this pull request using GitHub Actions. crypto Issues and PRs related to the crypto subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants