Skip to content

[v24.x backport] crypto and Web IDL fixes and features - #66233

Open
panva wants to merge 22 commits into
nodejs:v24.x-stagingfrom
panva:backport-v24-20260923
Open

panva wants to merge 22 commits into
nodejs:v24.x-stagingfrom
panva:backport-v24-20260923

Conversation

panva and others added 22 commits September 23, 2026 11:17
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: nodejs#64960
Fixes: nodejs#48379
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Aviv Keller <me@aviv.sh>
Hide TurboSHAKE and KangarooTwelve when FIPS is enabled. Reject cSHAKE
and KMAC parameters that require implementations outside the OpenSSL
provider, while keeping provider-backed paths available.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: nodejs#65172
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Use explicit brand predicates for interface conversion instead of
prototype ancestry. Update CryptoKey and AbortSignal together with the
shared converter contract.

Read internal AbortSignal state during composition. Preserve genuine
signals after prototype changes without invoking shadowed getters.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: GitHub Copilot
PR-URL: nodejs#65846
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Aviv Keller <me@aviv.sh>
Use the intrinsic growable getter instead of buffer.growable so
shadowed properties cannot bypass validation or reject fixed buffers.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: GitHub Copilot
PR-URL: nodejs#65845
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Let internal helpers access the private cache directly to avoid
repeating receiver checks.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: nodejs#65910
Refs: nodejs#65846
Reviewed-By: Xuguang Mei <meixuguang@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Avoid creating temporary EVP objects and repeating key validation while
retaining the private scalar range and public/private consistency
checks.

Assisted-by: GitHub Copilot
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: nodejs#65908
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Named modp14 parameters avoid generating and repeatedly validating a
custom prime. Keep the existing exchange counts and FIPS rejection
assertion. The separate deterministic padding test continues to cover
imported prime parameters.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: nodejs#65980
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Use the modp14 prime instead of generating fresh parameters for tests
of constructors, key setters, and memory retention. Keep generic
DiffieHellman instances and the existing setter and leak assertions.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: nodejs#65980
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Re-encrypting keys on each FIPS test run can produce ciphertext that
decrypts with valid padding under the wrong password, causing a decoder
error instead of the expected bad decrypt.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: nodejs#65983
Refs: https://github.com/nodejs/node/actions/runs/34595689099/job/103251404626?pr=65980
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: nodejs#65759
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Add isBoringSSL to the test crypto helpers and use it in tests and
benchmarks. Replace hasOpenSSL3 call sites with hasOpenSSL(3).

Assisted-by: Codex
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: nodejs#65762
Reviewed-By: Richard Lau <richard.lau@ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: nodejs#65956
Refs: https://openssl-library.org/post/2026-09-09-openssl-4.1-alpha/
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Richard Lau <richard.lau@ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Return the private key, end-entity certificate, and any other
non-matching certificates from a PKCS#12 (.p12/.pfx) bundle as a
KeyObject and X509Certificate instances.

Node.js already parses PKCS#12 in SecureContext::LoadPKCS12, which backs
tls's `pfx` option, but the results are consumed directly into an
SSL_CTX and never reach JavaScript. Callers who need the key or the
certificates for anything other than an immediate TLS connection have to
shell out to `openssl pkcs12` or take a userland dependency.
SecureContext::LoadPKCS12 now uses this same parsing logic.

The binding wraps d2i_PKCS12_bio() and PKCS12_parse() and follows their
semantics, matching the existing TLS path: the first private key is
returned, the end-entity certificate is the one associated with that
key, and any remaining certificates are returned through
`additionalCertificates`. A bundle containing no private key reports
`certificate` as null and returns its certificates through
`additionalCertificates`.

Absent and empty passphrases are kept distinct, since OpenSSL treats
them differently. Bundles that require OpenSSL's legacy provider throw
ERR_CRYPTO_UNSUPPORTED_OPERATION, reusing the error added for the TLS
path.

Signed-off-by: bmuenzenmeyer <brian.muenzenmeyer@gmail.com>
Co-authored-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: nodejs#65627
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Provider-backed keys can have no numeric OpenSSL ID. Identify and
construct asymmetric keys by algorithm name, replacing the custom PQC
name-to-NID substitution with provider-aware matching in ncrypto.

Centralize known algorithm names, public key-type names, capabilities,
and backend compatibility in ncrypto. Use named key generation jobs and
remove asymmetric EVP_PKEY constants from the internal JavaScript
binding.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: nodejs#65966
Reviewed-By: James M Snell <jasnell@gmail.com>
The fixed 20 ms tolerance in mark.any.js can fail when execution pauses
between creating a mark and reading the clock. Adapt the test in memory
to check the mark timestamp against readings before and after mark().
Keep the vendored fixture and subtest names unchanged.

Apply script modifiers to worker entry scripts as well so the check
covers both WPT globals, and remove the suite-wide flaky expectation.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: nodejs#66036
Fixes: nodejs#40449
Refs: nodejs#41203
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Use one owning KDF interface for HKDF expansion, PBKDF2 and scrypt,
sharing provider setup with Argon2.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: nodejs#66108
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Import RSA public keys through OSSL_DECODER on OpenSSL 3 so the
resulting keys stay provider-backed. Preserve the PKCS#1 input structure
and the ASN.1 encodings accepted by the legacy decoder.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: nodejs#66108
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Resolve provider ciphers before serializing private keys and retain the
fetched implementation across encoding configuration copies and async
key generation. Keep format-specific restrictions in the serializers.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: nodejs#66108
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Pass group names through EC key generation and report provider names
in key details without requiring an OpenSSL NID. Preserve established
curve aliases and synchronous invalid-curve errors.

Filter built-in curves through EC parameter generation and refresh
getCurves() results when FIPS properties change.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: nodejs#66108
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Retrieving asymmetricKeyDetails only needs the modulus, public exponent,
and RSA-PSS restrictions. Add a public-only Rsa view so provider-backed
keys do not also extract private components or probe additional primes.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: nodejs#66108
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Exercise getCiphers(), getHashes(), getMacs() and getCurves() through
one shared cache/FIPS driver and one snapshot fixture. Keep defensive
copies, generation changes, rejected and idempotent toggles, and
cross-worker invalidation consistent across the lists.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: nodejs#66108
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: nodejs#66111
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/crypto
  • @nodejs/gyp
  • @nodejs/performance
  • @nodejs/security-wg
  • @nodejs/web-standards

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. v24.x Issues that can be reproduced on v24.x or PRs targeting the v24.x-staging branch. labels Sep 23, 2026
@panva
panva requested a review from aduh95 September 23, 2026 09:57
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codecov

codecov Bot commented Sep 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.51569% with 155 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.28%. Comparing base (9e39360) to head (3b4cc93).
⚠️ Report is 562 commits behind head on v24.x-staging.

Files with missing lines Patch % Lines
src/crypto/crypto_keys.cc 82.08% 14 Missing and 29 partials ⚠️
src/crypto/crypto_pkcs12.cc 77.65% 7 Missing and 14 partials ⚠️
lib/internal/crypto/kem_hybrids.js 98.38% 19 Missing ⚠️
src/crypto/crypto_ec.cc 48.57% 10 Missing and 8 partials ⚠️
lib/internal/crypto/util.js 89.23% 7 Missing ⚠️
lib/internal/crypto/webidl.js 80.55% 7 Missing ⚠️
lib/internal/abort_controller.js 64.70% 6 Missing ⚠️
src/crypto/crypto_turboshake.cc 0.00% 4 Missing and 2 partials ⚠️
src/crypto/crypto_context.cc 80.00% 2 Missing and 3 partials ⚠️
lib/internal/crypto/webcrypto.js 96.47% 3 Missing ⚠️
... and 10 more
Additional details and impacted files
@@                Coverage Diff                @@
##           v24.x-staging   #66233      +/-   ##
=================================================
- Coverage          90.31%   90.28%   -0.03%     
=================================================
  Files                711      718       +7     
  Lines             228425   238012    +9587     
  Branches           43160    45238    +2078     
=================================================
+ Hits              206293   214896    +8603     
- Misses             14090    14624     +534     
- Partials            8042     8492     +450     
Files with missing lines Coverage Δ
lib/crypto.js 93.71% <100.00%> (+1.49%) ⬆️
lib/internal/crypto/cfrg.js 95.39% <100.00%> (-0.65%) ⬇️
lib/internal/crypto/keygen.js 98.30% <100.00%> (-0.14%) ⬇️
lib/internal/crypto/keys.js 98.27% <100.00%> (+0.83%) ⬆️
lib/internal/crypto/mac.js 99.01% <100.00%> (+0.01%) ⬆️
lib/internal/crypto/ml_dsa.js 97.03% <100.00%> (-0.49%) ⬇️
lib/internal/crypto/ml_kem.js 95.31% <100.00%> (-0.12%) ⬇️
lib/internal/webidl.js 99.46% <100.00%> (+0.01%) ⬆️
src/crypto/crypto_dh.cc 59.65% <100.00%> (+0.16%) ⬆️
src/crypto/crypto_dsa.cc 81.25% <100.00%> (ø)
... and 26 more

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

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

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

Labels

lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. v24.x Issues that can be reproduced on v24.x or PRs targeting the v24.x-staging branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants