Skip to content

crypto: honor prime checks and support empty SEC1 passphrases - #67039

Open
boorad wants to merge 1 commit into
nodejs:mainfrom
boorad:fix/ncrypto-provider-behavior
Open

boorad wants to merge 1 commit into
nodejs:mainfrom
boorad:fix/ncrypto-provider-behavior

Conversation

@boorad

@boorad boorad commented Oct 26, 2026

Copy link
Copy Markdown

Fix two provider-backed ncrypto behaviors:

  • Allow an explicitly empty passphrase when exporting encrypted SEC1 EC PEM by extending the traditional-PEM helper already used for RSA. Include EC domain parameters in the encoder selection, matching the normal SEC1 path.
  • Honor requested primality-check counts above the minimum performed by one BN_check_prime() call. Preserve cancellation and error propagation, and handle allocation failure.

Adds a public API regression for empty/binary SEC1 passphrases and missing/incorrect passwords, plus cctests for requested prime-check counts and cancellation during a repeated check. The new empty-passphrase, count, and repeated-check cancellation assertions fail on the unpatched implementation.

Validation at f1c2aab89cbd0005c928f838390b5844aef1e6cc on macOS with the built Node v27.0.0-pre and bundled OpenSSL 4.1.0:

  • make -j8 node cctest: 298/298 cctests pass.
  • out/Release/cctest --gtest_filter='NodeCrypto.BignumPrime*': 2/2 pass.
  • Focused test-crypto-key-export-sec1-passphrase and existing test-crypto-keygen-missing-oid JavaScript tests: 2/2 pass.
  • Scoped JavaScript/C++ lint, changed-line clang-format, and git diff --check pass.

Proposed here first at the request of the ncrypto maintainers in nodejs/ncrypto#54. Explicit EC parameter handling already works on current Node and is excluded from this port.

Honor requested primality check counts with provider-backed OpenSSL.

Support empty passphrases for encrypted SEC1 PEM output.

Assisted-by: Codex
Signed-off-by: Brad Anderson <brad@sankatygroup.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto
  • @nodejs/security-wg

@nodejs-github-bot nodejs-github-bot added dependencies PRs that add, update, or configure Node.js dependencies. needs-ci PRs that need a full CI run. labels Oct 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (352e814) to head (f1c2aab).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67039      +/-   ##
==========================================
- Coverage   92.96%   90.65%   -2.32%     
==========================================
  Files         428      797     +369     
  Lines      195232   278268   +83036     
  Branches    30197    53514   +23317     
==========================================
+ Hits       181500   252253   +70753     
- Misses      13405    16391    +2986     
- Partials      327     9624    +9297     

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

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

Labels

dependencies PRs that add, update, or configure Node.js dependencies. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants