commit 1a5c9284ebce5cd71cf7a3c29759a748c373ac85 Author: Tobias Nießen Date: Mon Jun 12 19:44:48 2023 +0200 doc,test: clarify behavior of DH generateKeys The DiffieHellman class is an old and thin wrapper around certain OpenSSL functions, many of which are deprecated in OpenSSL 3.0. Because the Node.js API mirrors the OpenSSL API, it adopts some of its peculiarities, but the Node.js documentation does not properly reflect these. Most importantly, despite the documentation saying otherwise, diffieHellman.generateKeys() does not generate a new private key when one has already been set or generated. Based on the documentation alone, users may be led to misuse the API in a way that results in key reuse, which can have drastic negative consequences for subsequent operations that consume the shared secret. These design issues in this old API have been around for many years, and we are not currently aware of any misuse in the ecosystem that falls into the above scenario. Changing the behavior of the API would be a significant breaking change and is thus not appropriate for a security release (nor is it a goal.) The reported issue is treated as CWE-1068 (after a vast amount of uncertainty whether to treat it as a vulnerability at all), therefore, this change only updates the documentation to match the actual behavior. Tests are also added that demonstrate this particular oddity. Newer APIs exist that can be used for some, but not all, Diffie-Hellman operations (e.g., crypto.diffieHellman() that was added in 2020). We should keep modernizing crypto APIs, but that is a non-goal for this security release. The ECDH class mirrors the DiffieHellman class in many ways, but it does not appear to be affected by this particular peculiarity. In particular, ecdh.generateKeys() does appear to always generate a new private key. PR-URL: https://github.com/nodejs-private/node-private/pull/426 Reviewed-By: Rafael Gonzaga Reviewed-By: Ben Noordhuis CVE-ID: CVE-2023-30590 Index: node-v12.22.12/doc/api/crypto.md =================================================================== --- node-v12.22.12.orig/doc/api/crypto.md +++ node-v12.22.12/doc/api/crypto.md @@ -632,12 +632,17 @@ added: v0.5.0 * `encoding` {string} The [encoding][] of the return value. * Returns: {Buffer | string} -Generates private and public Diffie-Hellman key values, and returns +Generates private and public Diffie-Hellman key values unless they have been +generated or computed already, and returns the public key in the specified `encoding`. This key should be transferred to the other party. If `encoding` is provided a string is returned; otherwise a [`Buffer`][] is returned. +This function is a thin wrapper around [`DH_generate_key()`][]. In particular, +once a private key has been generated or set, calling this function only updates +the public key but does not generate a new private key. + ### `diffieHellman.getGenerator([encoding])`