Commit Graph
100 Commits
Author SHA1 Message Date
Tobias Nießen 72151769b8 crypto: remove default encoding from DiffieHellman
getDefaultEncoding() always returns 'buffer' in Node.js 20.

In diffiehellman.js, this value is always used as input to either
toBuf(), encode(), or getArrayBufferOrView(). All of these functions
treat any falsy encoding just like 'buffer', so we can safely remove the
calls to getDefaultEncoding().

Refs: https://github.com/nodejs/node/pull/47182
PR-URL: https://github.com/nodejs/node/pull/49169
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2023-08-16 15:23:06 +00:00
Tobias Nießen 8ed4397985 crypto: remove default encoding from Hash/Hmac
getDefaultEncoding() always returns 'buffer' in Node.js 20. It requires
some careful justification but the default encoding can be eliminated
from hash.js entirely. The reasoning is almost identical with that in
https://github.com/nodejs/node/pull/49145 so I won't repeat it here.

Refs: https://github.com/nodejs/node/pull/47182
PR-URL: https://github.com/nodejs/node/pull/49167
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2023-08-16 14:54:05 +00:00
Tobias Nießen 556e95ad8f test: add test for effect of UV_THREADPOOL_SIZE
This (not particularly elegant) native addon tests the effect of
UV_THREADPOOL_SIZE on node-api. The test fails if Node.js allows more
than UV_THREADPOOL_SIZE async tasks to run concurrently, or if it limits
the number of concurrent async tasks to anything less than
UV_THREADPOOL_SIZE.

PR-URL: https://github.com/nodejs/node/pull/49165
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
2023-08-16 13:49:44 +00:00
Tobias Nießen 6f9d6f277b crypto: remove default encoding from sign/verify
getDefaultEncoding() always returns 'buffer' in Node.js 20. It requires
some careful justification but the default encoding can be eliminated
from sig.js entirely.

In Sign.prototype.update, we can safely remove the conditional
assignment of getDefaultEncoding() to encoding. This is because
SignUpdate() in crypto_sig.cc internally calls node::crypto::Decode,
which returns UTF8 for falsy encoding values. In other words, with the
conditional assignment, StringBytes::Write() ultimately receives the
encoding BUFFER, and without the conditional assignment, it receives the
encoding UTF8. However, StringBytes::Write() treats both encodings
identically, so there is no need to deviate from the internal default
encoding UTF8.

In Sign.prototype.sign, we can also safely remove the conditional
assignment of getDefaultEncoding() to encoding. Whether encoding is
falsy or 'buffer' makes no difference.

In Verify.prototype.verify, we can also safely remove the conditional
assignment of getDefaultEncoding() to sigEncoding. This is because the
function passes the sigEncoding to getArrayBufferOrView(), which passes
it to Buffer.from(). If sigEncoding is 'buffer', getArrayBufferOrView()
instead passes 'utf8' to Buffer.from(). Because the default encoding of
Buffer.from() is 'utf8', passing a falsy encoding to
getArrayBufferOrView() instead of 'buffer' results in the same behavior.

Refs: https://github.com/nodejs/node/pull/47182
PR-URL: https://github.com/nodejs/node/pull/49145
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-08-15 21:01:39 +00:00
Tobias Nießen 115f801ae4 test: fix assertion message in test_async.c
PR-URL: https://github.com/nodejs/node/pull/49146
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-08-15 11:55:34 +00:00
Tobias Nießen e117f16e09 doc: update process.binding deprecation text
As part of the recent security release, 4aa0eff7 updated the
documentation but bd7443ad did not.

PR-URL: https://github.com/nodejs/node/pull/49086
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
2023-08-11 19:13:59 +00:00
Tobias Nießen 1ceb8c113d node-api: avoid macro redefinition
Even though the redefinition complies with the C standard because the
second definition is "effectively the same" as the first definition,
it's best to avoid any redefinition.

Refs: https://github.com/nodejs/node/pull/28237
Refs: https://github.com/nodejs/node/pull/30006
PR-URL: https://github.com/nodejs/node/pull/48879
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-07-23 19:51:38 +00:00
Tobias Nießen 88ab2e7f21 permission: move PrintTree into unnamed namespace
This function is not declared outside of fs_permission.cc and thus
should not be visible outside the file during the linking stage.

PR-URL: https://github.com/nodejs/node/pull/48874
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
2023-07-23 19:35:38 +00:00
Tobias Nießen 1d1a85b17c permission: fix data types in PrintTree
* The first argument `node` should be a const pointer.
* The second argument `spaces` should not be a signed integer type.
* The local variable `child` should be size_t.
* The local variable `pair` in the range declaration should be a
  reference type to avoid copying the object.

Refs: https://github.com/nodejs/node/pull/48677
PR-URL: https://github.com/nodejs/node/pull/48770
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2023-07-14 23:42:39 +00:00
Tobias Nießen e8a1affab0 crypto: handle cert with invalid SPKI gracefully
When attempting to convert the SPKI of a X509Certificate to a KeyObject,
throw an error if the subjectPublicKey cannot be parsed instead of
aborting the process.

Fixes: https://hackerone.com/bugs?report_id=1884159
PR-URL: https://github.com/nodejs-private/node-private/pull/393
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
CVE-ID: CVE-2023-30588
2023-06-20 17:31:37 -03:00
Tobias Nießen 1b16ffa7e7 crypto,https,tls: disable engines if perms enabled
When the experimental permission model is enabled, the running
JavaScript code is subject to certain restrictions, all of which can
be bypassed or even disabled by native code due to the nature of the
permission model implementation. That is why Node.js native addons
are disabled by default when the permission model is enabled. However,
the built-in crypto, https, and tls modules still allow loading
custom OpenSSL engines. Because OpenSSL engines can execute arbitrary
(native) code while being loaded by Node.js, this has the same security
implications as allowing native addons. In other words, allowing user
code to load OpenSSL engines at runtime effectively enables bypassing
any supposed security restrictions.

This patch adds appropriate checks before attempting to dynamically
load an OpenSSL engine that throw an error if the permission model is
enabled.

PR-URL: https://github.com/nodejs-private/node-private/pull/409
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
CVE-ID: CVE-2023-30586
2023-06-20 17:30:20 -03:00
Tobias Nießen 0ae8bf8dbc msi: do not create AppData\Roaming\npm
This effectively reverts e431cae7e7 due to
security concerns. The directory is being created with elevated
privileges but its path may depend on an unprivileged user's environment
variables. Creating a directory in certain sensitive locations can cause
Windows to become inoperable.

Creating AppData\Roaming\npm was an intentional addition in order to
resolve https://github.com/nodejs/node-v0.x-archive/issues/8141, which
appears to have been a common issue for users of npm. However, this was
implemented before 4cfe5eb9af, which
changed the MSI installation scope to perMachine. There were concerns
about creating the npm directory in that PR, albeit not related to
security (see https://github.com/nodejs/node-v0.x-archive/pull/25640).

Refs: https://github.com/nodejs/node-v0.x-archive/issues/8141
Refs: https://github.com/nodejs/node-v0.x-archive/pull/8838
Refs: https://github.com/nodejs/node-v0.x-archive/pull/25640
PR-URL: https://github.com/nodejs-private/node-private/pull/408
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
CVE-ID: CVE-2023-30585
2023-06-20 17:30:15 -03:00
Tobias Nießen 4ee8ef269b quic: prevent copying ngtcp2_cid_token
PR-URL: https://github.com/nodejs/node/pull/48370
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-06-11 10:07:59 +00:00
Tobias Nießen 817c5799e2 doc: update outdated section on TLSv1.3-PSK
Recent OpenSSL versions support PSKs with non-SHA-256 TLSv1.3 ciphers,
e.g., TLS_AES_256_GCM_SHA384.

PR-URL: https://github.com/nodejs/node/pull/48123
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-05-24 22:22:59 +00:00
Tobias Nießen a0e11d7885 doc: improve HMAC key recommendations
Add a reference to potential problems with using strings as HMAC keys.
Also advise against exceeding the underlying hash function's block size
when generating HMAC keys from a cryptographically secure source of
entropy.

Refs: https://github.com/nodejs/node/pull/48052
Refs: https://github.com/nodejs/node/pull/37248
PR-URL: https://github.com/nodejs/node/pull/48121
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-05-24 20:21:07 +00:00
Tobias Nießen c3b84f1f33 src: remove INT_MAX asserts in SecretKeyGenTraits
Now that CSPRNG() does not silently fail when the length exceeds
INT_MAX anymore, there is no need for the two relevant assertions
in SecretKeyGenTraits anymore.

Refs: https://github.com/nodejs/node/pull/47515
PR-URL: https://github.com/nodejs/node/pull/48053
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2023-05-24 17:45:40 +00:00
Tobias Nießen 300f68e9d0 tools: fix race condition when npm installing
The update scripts that install dependencies from npm blindly assume
that `npm install` will always install the version that was previously
fetched as `dist-tags.latest`. That is not necessarily true, so instead
always install the specific version that the script thinks is current.

PR-URL: https://github.com/nodejs/node/pull/48101
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2023-05-23 09:45:56 +00:00
Tobias Nießen 2edd6cab1e doc: fix typo in crypto legacy streams API section
PR-URL: https://github.com/nodejs/node/pull/48122
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2023-05-22 23:34:18 +00:00
Tobias Nießen 85ac915045 doc: use secure key length for HMAC generateKey
The examples for generateKey() and generateKeySync() generate 64-bit
HMAC keys. That is inadequate for virtually any HMAC instance. As per
common NIST recommendations, the minimum should be roughly 112 bits, or
more commonly 128 bits.

Due to the design of HMAC itself, it is not unreasonable to choose the
underlying hash function's block size as the key length. For many
popular hash functions (SHA-256, SHA-224, SHA-1, MD5, ...) this happens
to be 64 bytes (bytes, not bits!). This is consistent with the HMAC
implementation in .NET, for example, even though it provides virtually
no benefit over a 256-bit key.

PR-URL: https://github.com/nodejs/node/pull/48052
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-05-19 23:58:58 +00:00
Tobias Nießen 32691bdf7d doc: clarify CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED
The error is not necessarily due to a client certificate engine. For
example, the `privateKeyEngine` option might just as well cause this
error and is independent of the client certificate.

Also mention that this is likely due to a compile-time option of OpenSSL
itself and not due to any particular engine.

PR-URL: https://github.com/nodejs/node/pull/47976
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2023-05-16 09:32:17 +00:00
Tobias Nießen f36461dc6a crypto: remove default encoding from cipher
Refs: https://github.com/nodejs/node/pull/47182
PR-URL: https://github.com/nodejs/node/pull/47998
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-05-16 01:22:33 +00:00
Tobias Nießen 29780bd666 doc: add heading for permission model limitations
These limitations are not specific to the file system, so they should
not be listed in the "File System Permissions" section.

PR-URL: https://github.com/nodejs/node/pull/47989
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Deokjin Kim <deokjin81.kim@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-05-15 17:41:29 +00:00
Tobias Nießen 5b4c7bd78f crypto: fix setEngine() when OPENSSL_NO_ENGINE set
When OpenSSL is configured with OPENSSL_NO_ENGINE, setEngine() currently
throws an internal error because the C++ binding does not export the
relevant function, which causes _setEngine() to be undefined within JS.

Instead, match the behavior of tls/secure-context.js and throw the
existing error code ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED when OpenSSL
has been configured with OPENSSL_NO_ENGINE.

PR-URL: https://github.com/nodejs/node/pull/47977
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
2023-05-15 15:39:11 +00:00
Tobias Nießen 93a19961a6 src: deduplicate X509Certificate::Fingerprint*
All three functions do the same, except using different cryptographic
hash functions. Move the common logic into a new template and use it
directly.

PR-URL: https://github.com/nodejs/node/pull/47978
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2023-05-15 12:49:00 +00:00
Tobias Nießen 92d3611fca test: mark test-esm-loader-http-imports as flaky
This test has been failing occasionally for weeks.

Refs: https://github.com/nodejs/node/issues/47836
Refs: https://github.com/nodejs/reliability/issues/564
PR-URL: https://github.com/nodejs/node/pull/47987
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2023-05-15 10:54:20 +00:00
Tobias Nießen c9ec72de45 doc: add missing deprecated blocks to cluster
I believe that these are required so that the respective APIs are
marked as deprecated in the table of contents.

PR-URL: https://github.com/nodejs/node/pull/47981
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Deokjin Kim <deokjin81.kim@gmail.com>
2023-05-14 18:23:26 +00:00
Tobias Nießen 226573b6a1 doc: update description of global
With widespread support for ES modules, the description of global is
outdated now.

PR-URL: https://github.com/nodejs/node/pull/47969
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-05-13 23:49:24 +00:00
Tobias Nießen 2e67401710 crypto: remove default encoding from scrypt
Refs: https://github.com/nodejs/node/pull/47182
PR-URL: https://github.com/nodejs/node/pull/47943
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-05-12 00:01:48 +00:00
Tobias Nießen 19afcba9d4 src: rename SKIP_CHECK_SIZE to SKIP_CHECK_STRLEN
SKIP_CHECK_VALUE is a string literal, so its size is the length of the
string in chars plus one. The buffer buf is also always null-terminated,
so its size should match the size of SKIP_CHECK_VALUE, which is _not_
SKIP_CHECK_SIZE.

Rename SKIP_CHECK_SIZE to be consistent with C/C++ terminology.

PR-URL: https://github.com/nodejs/node/pull/47845
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Shelley Vohr <shelley.vohr@gmail.com>
2023-05-10 13:20:04 +00:00
Tobias Nießen 0b3fcfcf35 quic: fix typo in endpoint.h
PR-URL: https://github.com/nodejs/node/pull/47911
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Deokjin Kim <deokjin81.kim@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
2023-05-08 09:47:28 +00:00
Tobias Nießen 9398ff1dea src: register ext reference for Fingerprint512
Refs: https://github.com/nodejs/node/pull/39809
Refs: https://github.com/nodejs/node/pull/40239
PR-URL: https://github.com/nodejs/node/pull/47892
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2023-05-08 01:50:26 +00:00
Tobias Nießen 29e6dd1d2d dgram: convert macro to template
It's not pretty either way, but a template is still preferable over a
macro.

PR-URL: https://github.com/nodejs/node/pull/47891
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2023-05-08 01:17:42 +00:00
Tobias Nießen 6fb10cad30 crypto: remove default encoding from pbkdf2
Refs: https://github.com/nodejs/node/pull/47182
PR-URL: https://github.com/nodejs/node/pull/47869
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-05-07 00:49:59 +00:00
Tobias Nießen 259ea3ed59 http2: improve nghttp2 error callback
The http2 implementation uses the deprecated function
nghttp2_session_callbacks_set_error_callback, which does not supply an
error code but only an error message. This so far forced node's error
callback to rely on the error message in order to distinguish between
different errors, which is fragile and inefficient.

Use the newer nghttp2_session_callbacks_set_error_callback2 function
instead, which is not deprecated and which provides the exact error code
to node's error callback.

PR-URL: https://github.com/nodejs/node/pull/47840
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2023-05-05 14:03:39 +00:00
Tobias Nießen d2d5789daa src: avoid strcmp() with Utf8Value
Having Utf8Value::operator==() without operator!=() is awkward in C++17,
so add the negated equality operator. Then, use either instead of
strcmp() where appropriate.

PR-URL: https://github.com/nodejs/node/pull/47827
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2023-05-04 22:35:11 +00:00
Tobias Nießen 76ae7be78d doc: replace EOL versions in README
PR-URL: https://github.com/nodejs/node/pull/47833
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Harshitha K P <harshitha014@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-05-03 19:06:29 +00:00
Tobias Nießen f68ff9fe88 doc: update BUILDING.md previous versions links
Remove EOL release lines and add missing supported release
lines.

PR-URL: https://github.com/nodejs/node/pull/47835
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2023-05-03 11:33:23 +00:00
Tobias Nießen 798db3c92a doc: fix --allow-* CLI flag references
PR-URL: https://github.com/nodejs/node/pull/47804
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
2023-05-01 22:24:33 +00:00
Tobias Nießen 3a3672ba6c doc: clarify fs permissions only affect fs module
As far as I can tell, the permission model implementation currently
does not restrict all file system operations but only those through
the fs module. WASI, for example, bypasses the permission model
entirely.

PR-URL: https://github.com/nodejs/node/pull/47782
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2023-05-01 16:19:48 +00:00
Tobias Nießen 609d2b0ff2 test: add and use tmpdir.hasEnoughSpace()
In general, we assume that the tmpdir will provide sufficient space for
most tests. Some tests, however, require hundreds of megabytes or even
gigabytes of space, which often causes them to fail, especially on our
macOS infrastructure. The most recent reliability report contains more
than 20 related CI failures.

This change adds a new function hasEnoughSpace() to the tmpdir module
that uses statfsSync() to guess whether allocating a certain amount of
space within the temporary directory will succeed.

This change also updates the most frequently failing tests to use the
new function such that the relevant parts of the tests are skipped if
tmpdir has insufficient space.

Refs: https://github.com/nodejs/reliability/issues/549
PR-URL: https://github.com/nodejs/node/pull/47767
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Richard Lau <rlau@redhat.com>
2023-05-01 15:23:49 +00:00
Tobias Nießen 1baf96aeb8 doc,test: fix concurrency option of test()
The documentation appears to still be wrong w.r.t. the meaning of the
concurrency option of the test() function. The implementation appears to
default to Infinity when the option is set to true. Is that intended or
a good idea? I don't know. It certainly makes more sense than what the
documentation says (which is basing the number of concurrent tasks
within a single thread on the number of CPU cores).

This changes the documentation to hopefully match the implementation and
adds a test that rules out the (rather arbitrary) behavior described in
the documentation.

Refs: https://github.com/nodejs/node/issues/47365
Refs: https://github.com/nodejs/node/pull/47642
PR-URL: https://github.com/nodejs/node/pull/47734
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-04-28 18:32:08 +00:00
Tobias Nießen 7ae1360358 src: fix typo in comment in quic/sessionticket.cc
PR-URL: https://github.com/nodejs/node/pull/47754
Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
Reviewed-By: Deokjin Kim <deokjin81.kim@gmail.com>
2023-04-28 04:28:55 +00:00
Tobias Nießen 36e4e3d86b test: remove spaces from test runner test names
PR-URL: https://github.com/nodejs/node/pull/47733
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
Reviewed-By: Deokjin Kim <deokjin81.kim@gmail.com>
2023-04-27 08:58:01 +00:00
Tobias Nießen 8becacb25d tools: fix skip message in update-cjs-module-lexer
Refs: https://github.com/nodejs/node/pull/47446
PR-URL: https://github.com/nodejs/node/pull/47701
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Deokjin Kim <deokjin81.kim@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2023-04-24 17:34:01 +00:00
Tobias Nießen a51c894937 doc: clarify concurrency model of test runner
Refs: https://github.com/nodejs/node/issues/47365
PR-URL: https://github.com/nodejs/node/pull/47642
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-04-24 15:38:12 +00:00
Tobias Nießen 86a8335a06 tools: keep PR titles/description up-to-date
Set the `update-pull-request-title-and-body` option when potentially
updating an existing PR with a dynamic title and/or description.

PR-URL: https://github.com/nodejs/node/pull/47621
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-04-21 14:38:48 +00:00
Tobias Nießen 9a7b9710e2 doc: improve fs permissions description
Fix a small grammatical mistake and improve the surrounding wording.

PR-URL: https://github.com/nodejs/node/pull/47596
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2023-04-19 17:40:46 +00:00
Tobias Nießen 4956271c93 tools: add update script for googletest
GoogleTest follows the Abseil Live at Head philosophy, and rarely
creates tags or GitHub releases, so instead, follow Google's
recommendation and update to the upstream HEAD every once in a while.

The tricky bit is properly updating googletest.gyp, and this script
might fail doing so in the future.

Refs: https://github.com/nodejs/security-wg/issues/828
PR-URL: https://github.com/nodejs/node/pull/47482
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2023-04-19 15:07:01 +00:00
Tobias Nießen 9b6f7f0ded doc: remove markdown link from heading
This is the only instance of such a link and it is rendered
incorrectly in the TOC.

PR-URL: https://github.com/nodejs/node/pull/47585
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2023-04-18 19:55:53 +00:00
Tobias Nießen 2a8913dbbf doc: fix typo in webcrypto metadata
PR-URL: https://github.com/nodejs/node/pull/47595
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-04-17 19:25:11 +00:00
Tobias Nießen b342a1b565 crypto: remove INT_MAX restriction in randomBytes
This restriction was due to an implementation detail in CSPRNG(). Now
that CSPRNG() properly handles lengths exceeding INT_MAX, remove this
artificial restriction.

Refs: https://github.com/nodejs/node/pull/47515
PR-URL: https://github.com/nodejs/node/pull/47559
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2023-04-17 17:26:02 +00:00
Tobias Nießen 4f5bb1a75a src: use v8::Boolean(b) over b ? True() : False()
Simplify existing code by using v8::Boolean::New() instead of equivalent
expressions that contain ternary operators.

PR-URL: https://github.com/nodejs/node/pull/47554
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
2023-04-16 18:26:06 +00:00
Tobias Nießen 8833099ef0 src: fix CSPRNG when length exceeds INT_MAX
CSPRNG implicitly casts the size_t length argument to a signed int when
calling RAND_bytes(), which leaves it up to the caller to ensure that
the length argument actually fits into such a signed int. However, not
all call sites explicitly ensure that, which could lead to subtle bugs.

In OpenSSL 3, use RAND_bytes_ex() instead, which does not require
casting the length to a signed int.

In OpenSSL 1.1.1, RAND_bytes_ex() is not supported, thus we have to
process blocks of size INT_MAX one by one.

PR-URL: https://github.com/nodejs/node/pull/47515
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-04-15 20:09:12 +00:00
Tobias Nießen 1cda3f36d0 crypto: replace THROW with CHECK for scrypt keylen
The JS layer already uses validateInt32(keylen, 'keylen', 0) to ensure
that the keylen argument fits into a signed 32-bit integer, thus, the
THROW statement in C++ is unreachable (unless the binding is accessed
directly, of course).

PR-URL: https://github.com/nodejs/node/pull/47407
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-04-09 09:22:51 +00:00
Tobias Nießen aa3dbe30c9 src: use stricter compile-time guidance
SnapshotSerializerDeserializer::GetName() appears to confuse static
analysis such as Coverity.

This changes the function structure to a sequence of if-else blocks and
marks all branch conditions as constexpr. (Unfortunately, this results
in a dangling 'else' keyword in the V macro.)

As per a request in the PR discussion, this change does _not_ ensure
that GetName<T>() can only be called for known types T and instead still
returns an empty string in that case.

Also use std::is_unsigned_v instead of !std::is_signed_v.

PR-URL: https://github.com/nodejs/node/pull/46509
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
2023-04-04 23:29:04 +00:00
Tobias Nießen 9b104be502 quic: do not dereference shared_ptr after move
The stored pointer is assumed to be nullptr after std::move.

PR-URL: https://github.com/nodejs/node/pull/47294
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2023-03-29 10:04:47 -07:00
Tobias Nießen f84ff93d96 doc: use serial comma in cli docs
Refs: https://github.com/nodejs/node/pull/11321
Refs: https://github.com/nodejs/node/pull/17384
PR-URL: https://github.com/nodejs/node/pull/47262
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Deokjin Kim <deokjin81.kim@gmail.com>
2023-03-27 09:27:08 +00:00
Tobias Nießen 9374700d7a crypto: remove DEFAULT_ENCODING
Citing 76b0bdf720 from 2012, "only use
this as a temporary measure."

Getting or setting DEFAULT_ENCODING has emitted a warning ever since
Node.js 10, so it seems appropriate to remove it in Node.js 20 five
years later. The last Node.js version that did not emit a warning
reached its end-of-life status at the end of 2019.

This commit only removes the public API so that the change can land in
time for Node.js 20.

Refs: https://github.com/nodejs/node-v0.x-archive/pull/4179
Refs: https://github.com/nodejs/node/pull/18333
PR-URL: https://github.com/nodejs/node/pull/47182
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Beth Griggs <bethanyngriggs@gmail.com>
Reviewed-By: Erick Wendel <erick.workspace@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2023-03-26 18:03:58 +00:00
Tobias Nießen 6311de3322 tools: upgrade Windows digital signature to SHA256
signtool still defaults to SHA1, which is vulnerable to certain
collisions. This switches to SHA256, which is stronger and which also
matches the hash function used by the signing certificate.

Technically, `/fd certHash` would be a better choice, but I don't know
if it is widely supported.

PR-URL: https://github.com/nodejs/node/pull/47206
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-03-25 18:27:46 +00:00
Tobias Nießen 002b30eaa5 doc: remove use of DEFAULT_ENCODING in PBKDF2 docs
There is no point in documenting this legacy behavior, which will emit a
warning when used.

PR-URL: https://github.com/nodejs/node/pull/47181
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-03-23 00:50:05 +00:00
Tobias Nießen 1a18b44028 src: replace impossible THROW with CHECK
The JS layer already verifies that divisor_bits is either a non-negative
32-bit signed integer or null/undefined, in which case it passes -1 to
the C++ layer. In either case, the C++ layer receives a 32-bit signed
integer greater than or equal to -1.

PR-URL: https://github.com/nodejs/node/pull/47168
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-03-22 11:41:15 +00:00
Tobias Nießen 7d84d67364 crypto: unify validation of checkPrime checks
Previously, the JS layer would validate that the value of the 'checks'
option was an unsigned 32-bit integer, otherwise throwing an appropriate
error but with a slightly misleading error message. Then the C++ layer
would validate that the value was an unsigned 31-bit integer, otherwise
throwing an appropriate error, but with a different (and even less
helpful) error message.

Instead, make the JS layer aware of the 31-bit restriction so that no
validation in C++ is necessary and so that the error message always
matches the exact requirement.

PR-URL: https://github.com/nodejs/node/pull/47165
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2023-03-22 11:41:06 +00:00
Tobias Nießen 1640aeb680 crypto: remove obsolete SSL_OP_* constants
None of these constants have any effect in recent OpenSSL versions, not
even in Node.js release lines that still use OpenSSL 1.1.1.

It is likely rare that these options are still used (intentionally), and
removing them is unlikely to break any existing applications. These
constants can only be passed to the secureOptions option of
tls.createSecureContext() and related APIs, and a value of undefined
will be ignored. Similarly, if a bitwise combination of multiple options
is used, undefined constants will not change the behavior because
(a | undefined | b) === (a | b) for (small) integers a and b.

Refs: https://github.com/nodejs/node/pull/46954
Refs: https://github.com/nodejs/node/pull/47066
PR-URL: https://github.com/nodejs/node/pull/47073
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2023-03-21 10:47:49 +00:00
Tobias Nießen fbd526b15a test: fix 'checks' validation test for checkPrime
This test had two problems:

* The first argument was a number in both cases, which is what caused
  the (expected) ERR_INVALID_ARG_TYPE error -- the validity of the
  'checks' option was not actually verified at all. Thus, the first
  argument should be valid for this particular test.
* The function returned by common.mustNotCall() was passed to
  assert.throws() as a third argument instead of being passed to
  checkPrime() as a third argument. (Isn't JavaScript great?) This again
  led to the (expected) ERR_INVALID_ARG_TYPE error, but again, the
  validity of the 'checks' option was not verified.

Fix both issues by ensuring that all arguments except the 'checks'
option are valid.

Refs: https://github.com/nodejs/node/pull/36997
PR-URL: https://github.com/nodejs/node/pull/47139
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-03-19 16:48:04 +00:00
Tobias Nießen aa30e16716 permission: fix some vulnerabilities in fs
Without this patch, any restrictions imposed by the permission model can
be easily bypassed, granting full read and write access to any file. On
Windows, this could even be used to delete files that are supposed to be
write-protected.

Fixes: https://github.com/nodejs/node/issues/47090
PR-URL: https://github.com/nodejs/node/pull/47091
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2023-03-19 12:58:28 +00:00
Tobias Nießen 9e9f68af95 test: mark test-http-max-sockets as flaky on win32
Refs: https://github.com/nodejs/node/issues/47116
PR-URL: https://github.com/nodejs/node/pull/47134
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Beth Griggs <bethanyngriggs@gmail.com>
2023-03-17 16:33:03 +00:00
Tobias Nießen 124bda90e9 src: remove SSL_CTX_get_tlsext_ticket_keys guards
OPENSSL_NO_TLSEXT was removed from OpenSSL a long time ago and both
OpenSSL and BoringSSL always unconditionally define
SSL_CTX_get_tlsext_ticket_keys now.

PR-URL: https://github.com/nodejs/node/pull/47068
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-03-15 16:38:58 +00:00
Tobias Nießen 1cfe058778 test: fix test-permission-deny-fs-wildcard (win32)
The test fails on Windows when the working directory is not on a 'C:'
drive. For example, it always fails during the coverage-windows GitHub
action, which runs tests on drive 'D:'.

Fixes: https://github.com/nodejs/node/issues/47093
PR-URL: https://github.com/nodejs/node/pull/47095
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
2023-03-15 01:57:15 +00:00
Tobias Nießen 51380f20cf doc: remove remaining SSL_OP_NETSCAPE_*_BUG
I missed these two in db81af61ce because I
went by OpenSSL's list of obsolete flags, which turned out to be
incomplete. See https://github.com/openssl/openssl/pull/20443.

Refs: https://github.com/nodejs/node/pull/46954
Refs: https://github.com/openssl/openssl/pull/20443
PR-URL: https://github.com/nodejs/node/pull/47066
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2023-03-13 17:49:39 +00:00
Tobias Nießen c2e4b1fa9a crypto: remove ALPN_ENABLED
This constant was likely introduced for feature detection, but it has
been pointless for a long time.

1. I am not aware of any possible Node.js build configuration (on any
   recent/supported release line) that would have crypto.constants but
   not crypto.constants.ALPN_ENABLED.
2. There is no evidence of this constant being used for feature
   detection in the ecosystem. In fact, both internal and external type
   definitions for crypto.constants simply assume that the constant
   exists.
3. There is no good reason for any modern TLS stack to not support ALPN.
   It looks like ALPN might have been optional in much earlier versions
   of OpenSSL, but all recent versions of OpenSSL unconditionally
   support ALPN as far as I can tell.

Refs: https://github.com/nodejs/node/pull/46956
PR-URL: https://github.com/nodejs/node/pull/47028
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2023-03-13 14:11:35 +00:00
Tobias Nießen 2660a321e1 tls: support automatic DHE
Node.js has so far only supported user-defined DHE parameters and even
recommended generating custom parameters. This change lets users set the
dhparam option to 'auto' instead, in which case DHE parameters of
sufficient strength are selected automatically (from a small set of
well-known parameters). This has been recommended by OpenSSL for quite a
while, and it makes it much easier for Node.js TLS servers to properly
support DHE-based perfect forward secrecy.

This also updates the documentation to prioritize ECDHE over DHE, mostly
because the former tends to be more efficient and is enabled by default.

PR-URL: https://github.com/nodejs/node/pull/46978
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2023-03-12 18:35:55 +00:00
Tobias Nießen bcebb914f5 test: simplify test-tls-ecdh-multiple
Avoid the process 'exit' event handler and use execFile instead of
manual stream operations.

Refs: https://github.com/nodejs/node/pull/46751
PR-URL: https://github.com/nodejs/node/pull/46963
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
2023-03-09 11:54:28 +00:00
Tobias Nießen 539dcee3bf src: remove TLSEXT_TYPE_alpn guard
TLSEXT_TYPE_application_layer_protocol_negotiation is always defined in
all supported OpenSSL versions. We also use this macro elsewhere without
guards, so if it did not exist, compilation would have already failed.

Besides that, it makes little sense to provide a TLS 1.3 implementation
that does not support ALPN.

PR-URL: https://github.com/nodejs/node/pull/46956
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-03-09 11:28:41 +00:00
Tobias Nießen ef454c89ba src: remove use of SSL_OP_SINGLE_DH_USE
This option does not have any effect in any supported OpenSSL version.

Refs: https://github.com/nodejs/node/pull/46954
PR-URL: https://github.com/nodejs/node/pull/46955
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2023-03-09 11:24:11 +00:00
Tobias Nießen db81af61ce doc: remove useless SSL_OP_* options
These 14 options do not have any effect in any supported version of
OpenSSL.

PR-URL: https://github.com/nodejs/node/pull/46954
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-03-06 21:18:44 +00:00
Tobias Nießen 00981eaf81 doc: fix description of TLS dhparam option
The dhparam option is not required for perfect forward secrecy in
general. It is only required for non-ECDHE secrecy, but ECDHE-based
secrecy is generally preferred anyway.

PR-URL: https://github.com/nodejs/node/pull/46949
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2023-03-06 15:29:19 +00:00
Tobias Nießen 06c660b1c6 test: simplify test-tls-ecdh-auto
Avoid the process 'exit' event handler and use execFile instead of
manual stream operations.

Refs: https://github.com/nodejs/node/pull/46751
PR-URL: https://github.com/nodejs/node/pull/46911
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2023-03-05 10:45:01 +00:00
Tobias Nießen 6ddd8ef39a doc: fix links to SSL_CTX_set_options
The old 1.0.2 docs do not exist anymore; link to the same file for
OpenSSL 3.0 instead.

PR-URL: https://github.com/nodejs/node/pull/46953
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-03-04 23:15:29 +00:00
Tobias Nießen 3abbc3829a src: fix useless call in permission.cc
FromMaybe() has no side effects and the return value is ignored.
Instead, if Set() fails, then another exception is pending, so
return early.

PR-URL: https://github.com/nodejs/node/pull/46833
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2023-02-27 13:39:26 +00:00
Tobias Nießen 0f10c87957 lib,src: fix a few typos in comments
PR-URL: https://github.com/nodejs/node/pull/46835
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
2023-02-25 20:29:59 +00:00
Tobias Nießen 78b911ddaf test: simplify test-tls-alert
Avoid the process 'exit' event handler and use execFile instead of
manual stream operations.

Refs: https://github.com/nodejs/node/pull/46751
PR-URL: https://github.com/nodejs/node/pull/46805
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-02-25 18:19:19 +00:00
Tobias Nießen d953049a71 test: improve control flow in test-tls-dhe
If this test fails, e.g., if the s_client output does not match the
expectation, the previous implementation would not produce any helpful
error messages. Rework the control flow to be more idiomatic. Avoid
callback chaining and stream operations.

Also, the TLS server 'close' event does not pass an error to the event
handler, so remove the respective assertion.

PR-URL: https://github.com/nodejs/node/pull/46751
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-02-24 09:14:37 +00:00
Tobias Nießen bc58a854e2 test: remove OpenSSL 1.0.2 error message compat
While upgrading from OpenSSL 1.0.2 to 1.1.1, these tests were modified
to recognize error messages from both OpenSSL releases. Given that
OpenSSL 1.0.2 has been unsupported for years, it is safe to remove the
older message patterns.

Refs: https://github.com/nodejs/node/pull/16130
PR-URL: https://github.com/nodejs/node/pull/46709
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-02-22 06:09:11 +00:00
Tobias Nießen c2039213ba test: use newish OpenSSL feature in test-tls-dhe
According to the comment that is being replaced here, this was not
possible with the current version of OpenSSL 1.0.2 at the time the test
was written. New OpenSSL versions appear to always print the length of
the temporary key.

Refs: https://github.com/nodejs/node-v0.x-archive/pull/8272
PR-URL: https://github.com/nodejs/node/pull/46708
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-02-20 02:04:14 +00:00
Tobias Nießen 2472b6742c test: fix assertions in test-snapshot-dns-lookup*
Due to the unfortunate nature of JavaScript, the extraneous arguments
are silently ignored. In this case, the assertion trivially passes
regardless of the given regular expressions.

Refs: https://github.com/nodejs/node/pull/44633
PR-URL: https://github.com/nodejs/node/pull/46618
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Harshitha K P <harshitha014@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-02-18 01:58:50 +00:00
Tobias Nießen f1a30b9bd4 test: cover publicExponent validation in OpenSSL
Add a test case for public exponents that are invalid according to some
internal OpenSSL validation logic, but which are accepted by node's own
validation logic.

PR-URL: https://github.com/nodejs/node/pull/46632
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
2023-02-18 00:27:24 +00:00
Tobias Nießen 3344bb764a src: avoid leaking snapshot fp on error
Call fclose() on the snapshot file regardless of whether reading the
snapshot data succeeded.

PR-URL: https://github.com/nodejs/node/pull/46497
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
2023-02-06 15:19:22 +00:00
Tobias Nießen 1e9ca451c1 src: check return value of ftell()
If ftell() returns -1L, abort instead of passing static_cast<size_t>(-1)
to the vector allocator and fread().

Refs: https://github.com/nodejs/node/pull/46463
PR-URL: https://github.com/nodejs/node/pull/46495
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
2023-02-06 14:59:36 +00:00
Tobias Nießen 8ba54e5049 src: get rid of fp arithmetic in ParseIPv4Host
Even though most compiler should not actually emit FPU instructions, it
is unnecessary to use floating-point arithmetic for powers of 2.

Also change some signed counters to unsigned integers.

PR-URL: https://github.com/nodejs/node/pull/46326
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-01-26 03:37:14 +00:00
Tobias Nießen f0e645321c src: use UNREACHABLE instead of CHECK(falsy)
Also remove some dead code following such statements.

PR-URL: https://github.com/nodejs/node/pull/46317
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
2023-01-25 14:00:21 +00:00
Tobias Nießen 8c308ab28c src: remove unreachable UNREACHABLE
All paths leading up to this UNREACHABLE either return or abort. (If
they did not, the compiler would at least emit a warning.)

PR-URL: https://github.com/nodejs/node/pull/46281
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
2023-01-22 00:28:16 +00:00
Tobias Nießen 5ccf4efbf8 src: replace unreachable code with static_assert
This function divides an unsigned 32-bit integer by 8, effectively
right-shifting it by three bits, so the result must be less than
INT_MAX.

Refs: https://github.com/nodejs/node/pull/46209
PR-URL: https://github.com/nodejs/node/pull/46250
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2023-01-21 06:37:51 +00:00
Tobias Nießen c47ad5815d src: use explicit C++17 fallthrough
This passes the strictest -Wimplicit-fallthrough setting.

PR-URL: https://github.com/nodejs/node/pull/46251
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-01-20 13:04:52 +00:00
Tobias Nießen 15d673dfbe src: replace unreachable code with static_assert
This function base64-decodes a given JavaScript string to obtain the
secret key, whose length must not exceed INT_MAX. However, because
JavaScript strings are limited to v8::String::kMaxLength chars and
because base64 decoding never yields more bytes than input chars, the
size of the decoded key must be strictly less than
v8::String::kMaxLength bytes. Therefore, it is sufficient to statically
assert that String::kMaxLength <= INT_MAX (which is always true because
String::kMaxLength itself is an int).

Aside from being unreachable, Coverity considers the current code
"suspicious" because it indicates that buffers larger than INT_MAX might
actually be allocated.

PR-URL: https://github.com/nodejs/node/pull/46209
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2023-01-17 10:01:26 +00:00
Tobias Nießen bcc2d583a7 src: hide kMaxDigestMultiplier outside HKDF impl
There is no reason to expose this constant outside of the HKDF
implementation, especially with such a generic name.

PR-URL: https://github.com/nodejs/node/pull/46206
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2023-01-16 02:44:00 +00:00
Tobias Nießen 03f18abf95 doc: fix (EC)DHE remark in TLS docs
It is not true that all TLS 1.3 cipher suites use ECDH.

TLS 1.3 allows DH over finite fields instead of elliptic curves.
Also, the key exchange mechanism is independent of the cipher suite
in TLS 1.3.

PR-URL: https://github.com/nodejs/node/pull/46114
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-01-08 13:12:35 +00:00
Tobias Nießen 6766172e58 doc: fix ERR_TLS_RENEGOTIATION_DISABLED text
PR-URL: https://github.com/nodejs/node/pull/46122
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2023-01-07 23:53:25 +00:00
Tobias Nießen b4666c38b9 doc: add missing documentation for paramEncoding
This option has existed ever since generateKeyPair was added in 2019 or
so, but I apparently forgot to document it.

PR-URL: https://github.com/nodejs/node/pull/45523
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2022-11-21 19:55:28 +00:00
Tobias Nießen ccd3a42dd9 doc: fix typo in threat model
Refs: https://github.com/nodejs/node/pull/45223
PR-URL: https://github.com/nodejs/node/pull/45558
Reviewed-By: Harshitha K P <harshitha014@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
2022-11-21 14:25:43 +00:00
Tobias Nießen 3439eb9475 doc: fix typo in maintaining-dependencies.md
PR-URL: https://github.com/nodejs/node/pull/45428
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2022-11-12 17:22:05 +00:00