Commit Graph

256 Commits

Author SHA1 Message Date
Filip Skokan
159b4d7a94 crypto: allow zero-length IKM in HKDF and in webcrypto PBKDF2
PR-URL: https://github.com/nodejs/node/pull/44201
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2022-08-12 21:36:29 +02:00
Filip Skokan
85107bdd66 crypto: allow zero-length secret KeyObject
PR-URL: https://github.com/nodejs/node/pull/44201
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2022-08-12 21:36:27 +02:00
Filip Skokan
c6c4cdab36 crypto: fix webcrypto deriveBits validations
PR-URL: https://github.com/nodejs/node/pull/44173
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2022-08-12 21:31:14 +02: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
54ca9c9bfc crypto: fix webcrypto generateKey() AES key length validation error
PR-URL: https://github.com/nodejs/node/pull/44170
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2022-08-12 21:30:09 +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
Rich Trott
0e660ce09f
crypto: remove unneeded guard
createCFRGRaw() will always return an object. The error for an undefined
return value will never occur.

PR-URL: https://github.com/nodejs/node/pull/43856
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2022-07-18 05:49:16 +01:00
Filip Skokan
84db3e7b06
crypto: handle webcrypto generateKey() usages edge case
PR-URL: https://github.com/nodejs/node/pull/43454
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2022-06-25 06:22:35 +01:00
Filip Skokan
677bd668b7 crypto: fix webcrypto generateKey() with empty usages
PR-URL: https://github.com/nodejs/node/pull/43431
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-06-16 22:00:34 +02:00
Filip Skokan
288304c888 crypto: fix webcrypto digest() invalid algorithm
PR-URL: https://github.com/nodejs/node/pull/43431
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-06-16 22:00:33 +02:00
Filip Skokan
be03c09ab0 crypto: fix webcrypto RSA generateKey() use of publicExponent
PR-URL: https://github.com/nodejs/node/pull/43431
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-06-16 22:00:32 +02:00
Filip Skokan
f3c12bd62f crypto: fix webcrypto AES-KW keys accepting encrypt/decrypt usages
PR-URL: https://github.com/nodejs/node/pull/43431
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-06-16 22:00:31 +02:00
Filip Skokan
f654adf05a crypto: fix webcrypto deriveBits for non-byte lengths
PR-URL: https://github.com/nodejs/node/pull/43431
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-06-16 22:00:29 +02:00
Filip Skokan
5fad0b9366
crypto: fix webcrypto import of cfrg raw public keys
PR-URL: https://github.com/nodejs/node/pull/43404
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2022-06-15 14:33:55 +01: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
LiviaMedeiros
f3376f086b
crypto: use kEmptyObject
PR-URL: https://github.com/nodejs/node/pull/43159
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-06-11 12:18:12 +02: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
Antoine du Hamel
06d8606960
lib: use null-prototype objects for property descriptors
Refs: https://github.com/nodejs/node/pull/42921

PR-URL: https://github.com/nodejs/node/pull/43270
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
2022-06-03 09:23:58 +01:00
Filip Skokan
12af4319b5
crypto: align webcrypto RSA key import/export with other implementations
closes #39959
see https://github.com/w3c/webcrypto/issues/307
see https://github.com/w3c/webcrypto/pull/305

PR-URL: https://github.com/nodejs/node/pull/42816
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2022-05-25 15:31:14 +01:00
Livia Medeiros
a5b8730525
crypto: adjust minimum length in generateKey('hmac', ...)
Also affects generateKeySync('hmac', ...)

PR-URL: https://github.com/nodejs/node/pull/42944
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2022-05-04 20:31:23 +01:00
Tobias Nießen
75dbb86c58
crypto: clean up parameter validation in HKDF
PR-URL: https://github.com/nodejs/node/pull/42924
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
2022-05-02 18:46:04 +01:00
Filip Skokan
603803ecb7
crypto: validate this in all webcrypto methods and getters
PR-URL: https://github.com/nodejs/node/pull/42815
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2022-04-23 18:42:45 +01:00
Antoine du Hamel
1e761654d3
doc: consolidate use of multiple-byte units
Refs: https://en.wikipedia.org/wiki/Byte#Multiple-byte_units

PR-URL: https://github.com/nodejs/node/pull/42587
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
2022-04-20 00:46:37 +02:00
Rich Trott
49547abe99 lib: prepare files for no-var lint rule
PR-URL: https://github.com/nodejs/node/pull/42573
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2022-04-04 10:53:28 +00:00
Mohammed Keyvanzadeh
aed18dfe59
crypto: cleanup validation
Many of the validations could be simplified and cleaned up by using
validators and to keep consistency.

PR-URL: https://github.com/nodejs/node/pull/39841
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2022-04-04 11:38:35 +01:00
Filip Skokan
5d0eb10c80
crypto: do not add undefined hash in webcrypto normalizeAlgorithm
PR-URL: https://github.com/nodejs/node/pull/42559
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2022-04-03 11:11:21 +01:00
Filip Skokan
4fa6c89cd5
crypto: cleanup webcrypto jwk code
PR-URL: https://github.com/nodejs/node/pull/42562
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2022-04-03 11:11:02 +01:00
Filip Skokan
18bd02f245
crypto: fix webcrypto derive key lengths
PR-URL: https://github.com/nodejs/node/pull/42542
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2022-04-02 15:54:35 +01:00
Joyee Cheung
457567f72c src: include crypto in the bootstrap snapshot
To lazy load the run time options, the following properties
are updated from value properties to accessor properties
whose getter would turn them back to a value properties
upon the initial access.

- crypto.constants.defaultCipherList
- crypto.pseudoRandomBytes
- crypto.prng
- crypto.rng

PR-URL: https://github.com/nodejs/node/pull/42203
Refs: https://github.com/nodejs/node/issues/37476
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-03-11 17:15:13 +00:00
Tobias Nießen
36fb79030e
crypto: fix X509Certificate toLegacyObject
PR-URL: https://github.com/nodejs/node/pull/42124
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2022-03-09 16:36:40 +00:00
Tobias Nießen
e8697cfe38
crypto: improve prime size argument validation
The current validation in JavaScript is insufficient and also produces
an incorrect error message, restricting the size parameter to 32-bit
values, whereas the C++ backend restricts the size parameter to the
positive range of an int.

This change tightens the validation in JavaScript and adapts the error
message accordingly, making the validation in C++ superfluous.

Refs: https://github.com/nodejs/node/pull/42207

PR-URL: https://github.com/nodejs/node/pull/42234
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2022-03-08 17:33:38 +00:00
Antoine du Hamel
6ee4228498
crypto: validate this value for webcrypto.getRandomValues
PR-URL: https://github.com/nodejs/node/pull/41760
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2022-02-26 17:12:48 +00:00
Filip Skokan
aa97c9d973
crypto: add KeyObject.prototype.equals method
PR-URL: https://github.com/nodejs/node/pull/42093
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2022-02-26 13:51:09 +00:00
Antoine du Hamel
849991c6c4
crypto: expose Web Crypto API on the global scope
PR-URL: https://github.com/nodejs/node/pull/41938
Refs: https://developer.mozilla.org/en-US/docs/Web/API/crypto_property
Refs: https://github.com/nodejs/node/pull/41782
Refs: https://w3c.github.io/webcrypto
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2022-02-14 16:14:49 +00:00
Mestery
998e5acc69
lib: move kEnumerableProperty to internal/util
PR-URL: https://github.com/nodejs/node/pull/41877
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-02-11 17:30:47 +00:00
Mohammed Keyvanzadeh
8c4b8b201a
lib: replace validator and error
Refs: https://github.com/nodejs/node/pull/41660

PR-URL: https://github.com/nodejs/node/pull/41678
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2022-02-05 08:36:48 -08:00
Antoine du Hamel
7123a00b03
crypto: fix webcrypto.subtle signature
PR-URL: https://github.com/nodejs/node/pull/41761
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2022-01-31 23:23:15 +01:00
Rich Trott
c05c8837c1 crypto: revise variables for const use instead of let
This prepares the code for enabling the no-cond-assign rule.

PR-URL: https://github.com/nodejs/node/pull/41614
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2022-01-22 19:38:04 -08:00
Tobias Nießen
18365d8ee6 crypto: change default check(Host|Email) behavior
This changes the default behavior of the X509Certificate functions
checkHost and checkEmail to match the default behavior of OpenSSL's
X509_check_host and X509_check_email functions, respectively, which
is also what RFC 2818 mandates for HTTPS.

Refs: https://github.com/nodejs/node/pull/36804
Refs: https://github.com/nodejs/node/pull/41569

PR-URL: https://github.com/nodejs/node/pull/41600
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2022-01-22 18:36:47 +01:00
LiviaMedeiros
b8de7aa4c2 crypto: adjust types for getRandomValues
prevents Web Crypto API's getRandomValues from accepting DataView

Fixes: https://github.com/nodejs/node/issues/41480
Refs: https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues

PR-URL: https://github.com/nodejs/node/pull/41481
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
2022-01-22 15:20:40 +01:00
Tobias Nießen
6d666491ce crypto: remove checkIP options argument
None of the supported options have any effect on X509_check_ip_asc.

Refs: https://github.com/openssl/openssl/pull/17536

PR-URL: https://github.com/nodejs/node/pull/41571
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2022-01-19 19:10:18 +01:00
Tobias Nießen
da1b59fc13 crypto: support RFC 2818 compatible checkHost
The 'subject' option should not only accept the values 'always' and
'never' because neither is compatible with RFC 2818, i.e., HTTPS. This
change adds a third value 'default', which implies the behavior that
HTTPS mandates.

The new 'default' case matches the default behavior of OpenSSL for both
DNS names and email addresses.

Future Node.js versions should change the default option value from
'always' to 'default'.

Refs: https://github.com/nodejs/node/pull/36804

PR-URL: https://github.com/nodejs/node/pull/41569
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2022-01-19 16:05:32 +01:00
Rich Trott
55ceaec111 tools,benchmark,lib,test: enable no-case-declarations lint rule
PR-URL: https://github.com/nodejs/node/pull/41385
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Tierney Cyren <hello@bnb.im>
Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2022-01-05 07:42:19 -08:00
3nprob
79d681501d src: add x509.fingerprint512 to crypto module
PR-URL: https://github.com/nodejs/node/pull/39809
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2021-11-10 15:26:28 +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
Guilherme Bernal
61df3d88a7
crypto: don't call callback twice in case crypto.randomBytes fails
PR-URL: https://github.com/nodejs/node/pull/40157
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
2021-09-22 10:01:12 +02: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
Voltrex
55379eb454 crypto: use validateObject
The `validateObject()` validator can be used to cleanup validation and
keep consistency.

PR-URL: https://github.com/nodejs/node/pull/39872
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: James M Snell <jasnell@gmail.com>
2021-09-17 06:38:54 +00:00