Filip Skokan
1ccae7cce4
crypto: unify asymmetric key import through KeyObjectHandle::Init
...
Consolidate all asymmetric key import paths (DER/PEM, JWK, raw) into
a single KeyObjectHandle::Init() entry point with a uniform signature.
Remove the per-type C++ init methods (InitECRaw, InitEDRaw, InitPqcRaw,
InitJwk, InitECPrivateRaw) and their JS-side callers, replacing them
with shared C++ and JS helpers.
createPublicKey, createPrivateKey, sign, verify, and other operations
that accept key material now handle JWK and raw formats directly in
C++, removing redundant JS-to-C++ key handle round-trips.
Signed-off-by: Filip Skokan <panva.ip@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/62499
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2026-03-31 19:57:34 +00:00
Filip Skokan
d4fa60cf9f
crypto: add raw key formats support to the KeyObject APIs
...
Add raw key format support (raw-public, raw-private, raw-seed) to
KeyObject.prototype.export(), crypto.createPrivateKey(),
and crypto.createPublicKey() for applicable asymmetric keys (EC,
CFRG curves, ML-DSA, ML-KEM, and SLH-DSA).
Also wire these to the Web Cryptography APIs and remove the unnecessary
KeyExportJob. The KeyExportJob classes were removed because the export
operations they performed are not computationally expensive. They're
just serialization of already-available key data (SPKI, PKCS8, raw
bytes). Running them as async CryptoJobs on the libuv thread pool added
unnecessary overhead and complexity for operations that complete
instantly.
PR-URL: https://github.com/nodejs/node/pull/62240
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2026-03-26 10:31:26 +01:00
Renegade334
8869210dd8
crypto: use return await when returning Promises from async functions
...
This offers _some_ resistance to `%Promise.prototype%` pollution.
Refs: https://github.com/nodejs/node/issues/59699
PR-URL: https://github.com/nodejs/node/pull/59841
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Jordan Harband <ljharb@gmail.com >
Reviewed-By: Filip Skokan <panva.ip@gmail.com >
2025-09-12 14:21:50 +00:00
Renegade334
7a205d0ac0
crypto: use async functions for non-stub Promise-returning functions
...
These were intended to mimic simple async functions, but exceptions
thrown in the function body would be returned synchronously, not
wrapped in a rejected Promise.
PR-URL: https://github.com/nodejs/node/pull/59841
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Jordan Harband <ljharb@gmail.com >
Reviewed-By: Filip Skokan <panva.ip@gmail.com >
2025-09-12 14:21:49 +00:00
Renegade334
33e3e423d9
crypto: avoid calls to promise.catch()
...
This avoids explicit calls to the user-mutable
`%Promise.prototype%.catch`, and by association, implicit calls to the
user-mutable `%Promise.prototype%.then`.
PR-URL: https://github.com/nodejs/node/pull/59841
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Jordan Harband <ljharb@gmail.com >
Reviewed-By: Filip Skokan <panva.ip@gmail.com >
2025-09-12 14:21:49 +00:00
Filip Skokan
0124e0e0d7
crypto: support Ed448 and ML-DSA context parameter in Web Cryptography
...
PR-URL: https://github.com/nodejs/node/pull/59570
Reviewed-By: James M Snell <jasnell@gmail.com >
2025-09-07 13:17:42 +00:00
Filip Skokan
9d744b5b63
crypto: use CryptoKey internal slots in Web Cryptography
...
PR-URL: https://github.com/nodejs/node/pull/59538
Fixes: https://github.com/nodejs/node/issues/59535
Fixes: https://github.com/nodejs/node/issues/59534
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com >
2025-08-21 14:14:57 +00:00
Filip Skokan
700a965dc3
crypto: prepare webcrypto key import/export for modern algorithms
...
PR-URL: https://github.com/nodejs/node/pull/59284
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com >
2025-08-05 13:25:29 +00:00
Filip Skokan
d18f4878cf
src: refactor SubtleCrypto algorithm and length validations
...
PR-URL: https://github.com/nodejs/node/pull/57319
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2025-03-08 06:38:17 -08:00
Filip Skokan
6fdd4e6dcf
src: refactor SubtleCrypto algorithm and length validations
...
PR-URL: https://github.com/nodejs/node/pull/57273
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Jason Zhang <xzha4350@gmail.com >
Reviewed-By: Mattias Buelens <mattias@buelens.com >
2025-03-04 17:45:51 +00:00
Filip Skokan
90e3e5e173
crypto: add KeyObject.prototype.toCryptoKey
...
PR-URL: https://github.com/nodejs/node/pull/55262
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2024-10-06 18:09:02 +00:00
Filip Skokan
b64006c0ed
crypto: ensure invalid SubtleCrypto JWK data import results in DataError
...
PR-URL: https://github.com/nodejs/node/pull/55041
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
2024-09-23 15:28:44 +00:00
Filip Skokan
cd6b86bb5a
crypto: ensure valid point on elliptic curve in SubtleCrypto.importKey
...
PR-URL: https://github.com/nodejs/node/pull/50234
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
2023-10-20 16:25:42 +00:00
Antoine du Hamel
ab8942848b
lib: enforce use of trailing commas
...
PR-URL: https://github.com/nodejs/node/pull/46881
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
Reviewed-By: Jacob Smith <jacob@frende.me >
2023-03-06 10:44:14 +01:00
Filip Skokan
3ef38c4bd7
crypto: use WebIDL converters in WebCryptoAPI
...
WebCryptoAPI functions' arguments are now coersed and validated as per
their WebIDL definitions like in other Web Crypto API implementations.
This further improves interoperability with other implementations of
Web Crypto API.
PR-URL: https://github.com/nodejs/node/pull/46067
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2023-01-17 08:57:58 +00:00
Filip Skokan
a6dd939ce8
crypto: refactor verify acceptable key usage functions
...
PR-URL: https://github.com/nodejs/node/pull/45569
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2022-11-26 14:41:28 +00:00
Filip Skokan
8fef4746fc
crypto: fix ECDH webcrypto public CryptoKey usages
...
PR-URL: https://github.com/nodejs/node/pull/45569
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2022-11-26 14:41:27 +00:00
Filip Skokan
e73e89eedf
crypto: use DataError for webcrypto keyData import failures
...
PR-URL: https://github.com/nodejs/node/pull/45569
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2022-11-26 14:41:24 +00:00
Filip Skokan
73a5112583
crypto: handle more webcrypto errors with OperationError
...
PR-URL: https://github.com/nodejs/node/pull/45320
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2022-11-07 06:35:35 +00:00
Antoine du Hamel
eb32a8443a
lib: add lint rule to protect against Object.prototype.then pollution
...
PR-URL: https://github.com/nodejs/node/pull/45061
Reviewed-By: Jacob Smith <jacob@frende.me >
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
2022-10-21 03:12:03 +00:00
Filip Skokan
0d80e7344e
crypto: add causes to applicable webcrypto's OperationError
...
PR-URL: https://github.com/nodejs/node/pull/44890
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
2022-10-10 01:12:28 +00:00
Filip Skokan
4b7761441e
crypto: fix webcrypto EC key namedCurve validation errors
...
PR-URL: https://github.com/nodejs/node/pull/44172
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2022-08-12 21:30:41 +02:00
Filip Skokan
ac1b90eed1
crypto: fix webcrypto operation errors to be OperationError
...
PR-URL: https://github.com/nodejs/node/pull/44171
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2022-08-12 19:29:14 +00:00
Filip Skokan
4420d5218c
crypto: fix webcrypto JWK EC and OKP import crv check
...
PR-URL: https://github.com/nodejs/node/pull/43346
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2022-06-15 12:44:07 +01:00
Filip Skokan
fbfb91ba33
crypto: remove Node.js-specific webcrypto extensions
...
PR-URL: https://github.com/nodejs/node/pull/43310
Reviewed-By: James M Snell <jasnell@gmail.com >
2022-06-11 08:04:20 +01:00
Filip Skokan
7e5da97d15
crypto: add CFRG curves to Web Crypto API
...
PR-URL: https://github.com/nodejs/node/pull/42507
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2022-06-04 07:20:27 +01:00
gc
28f711b552
crypto: remove incorrect constructor invocation
...
PR-URL: https://github.com/nodejs/node/pull/40300
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Filip Skokan <panva.ip@gmail.com >
2021-10-05 20:51:54 +02:00
Shelley Vohr
17bb7b2936
crypto: handle initEDRaw pkey failure
...
PR-URL: https://github.com/nodejs/node/pull/40188
Reviewed-By: Filip Skokan <panva.ip@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-09-25 07:50:12 -07:00
Filip Skokan
453bb6be99
crypto: fix webcrypto ed(25519|448) spki/pkcs8 import
...
PR-URL: https://github.com/nodejs/node/pull/40131
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2021-09-20 08:29:46 +02:00
Filip Skokan
5d34ef509e
crypto: check webcrypto asymmetric key types during importKey
...
PR-URL: https://github.com/nodejs/node/pull/39962
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-09-07 18:25:39 +00:00
XadillaX
2de139b5d5
lib: make lazyDOMException more common
...
PR-URL: https://github.com/nodejs/node/pull/39105
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
2021-06-28 13:44:28 +08:00
Filip Skokan
e8cb6446ef
crypto: reconcile oneshot sign/verify sync and async implementations
...
PR-URL: https://github.com/nodejs/node/pull/37816
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
2021-04-08 10:08:26 +02:00
Filip Skokan
25985d6522
crypto: add optional callback to crypto.sign and crypto.verify
...
PR-URL: https://github.com/nodejs/node/pull/37500
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
2021-03-10 15:11:17 -08:00
Antoine du Hamel
75259c7492
crypto: refactor hasAnyNotIn to avoid unsafe array iteration
...
PR-URL: https://github.com/nodejs/node/pull/37433
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com >
2021-02-26 16:34:04 +01:00
Filip Skokan
8ddee73efc
crypto: check ed/x webcrypto key import algorithm names
...
PR-URL: https://github.com/nodejs/node/pull/37305
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-02-26 11:16:52 +01:00
Antoine du Hamel
08a2383a5e
crypto: refactor to avoid unsafe array iteration
...
PR-URL: https://github.com/nodejs/node/pull/37364
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com >
2021-02-19 12:55:54 +01:00
Filip Skokan
51249a11c0
crypto: fix subtle.importKey JWK OKP public key import
...
PR-URL: https://github.com/nodejs/node/pull/37255
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2021-02-09 21:26:45 +01:00
Filip Skokan
8b65004193
crypto: generateKeyPair('ec') should not support NODE-ED* and NODE-X*
...
Fixes https://github.com/nodejs/node/issues/37055
PR-URL: https://github.com/nodejs/node/pull/37063
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com >
2021-01-27 14:55:03 +01:00
James M Snell
bd899bc656
crypto: experimental (Ed/X)25519/(Ed/X)448 support
...
Implements initial experimental support for Curve25519 and
Curve448 support for both ECDH and sign/verify in Web Crypto.
Introduced as a Node.js-specific extension to Web Crypto.
Signed-off-by: James M Snell <jasnell@gmail.com >
Fixes: https://github.com/nodejs/node/issues/36076
PR-URL: https://github.com/nodejs/node/pull/36879
Reviewed-By: Filip Skokan <panva.ip@gmail.com >
2021-01-18 08:12:08 -08:00
Filip Skokan
e8fe38f7cf
crypto: fix webcrypto ECDH JWK import
...
This fixes the importKey operation when importing a JWK for the ECDH
algorithm. As per the Web Crypto API specification the JWK `alg`
property is not checked (as opposed to ECDSA).
PR-URL: https://github.com/nodejs/node/pull/35855
Fixes: https://github.com/nodejs/node/issues/35812
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2020-10-30 05:48:12 +01:00
James M Snell
dae283d96f
crypto: refactoring internals, add WebCrypto
...
Fixes: https://github.com/nodejs/node/issues/678
Refs: https://github.com/nodejs/node/issues/26854
Signed-off-by: James M Snell <jasnell@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/35093
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2020-10-07 17:27:05 -07:00