GeezerVison is showing github.com — Revert "src: seed V8 from the OS CSPRNG instead of OpenSSL's DRBG" · nodejs/node@c558d85
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/node.cc +6-30Lines changed: 6 additions & 30 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 49 | 49 |
| 50 | 50 | #if HAVE_OPENSSL | 51 | 51 | #include "ncrypto.h" | 52 | | -#if OPENSSL_VERSION_MAJOR >= 3 | 53 | | -#include <openssl/provider.h> | 54 | | -#endif | 55 | 52 | #include "node_crypto.h" | 56 | 53 | #if OPENSSL_VERSION_MAJOR >= 3 && !defined(CONF_MFLAGS_IGNORE_MISSING_FILE) | 57 | 54 | // OpenSSL hides this deprecated macro under OPENSSL_NO_DEPRECATED, but the | @@ -1324,36 +1321,15 @@ InitializeOncePerProcessInternal(const std::vector<std::string>& args, | 1324 | 1321 | } | 1325 | 1322 | crypto::InstallFipsIndicatorCallback(); | 1326 | 1323 |
| 1327 | | - // Activating the default provider here keeps --openssl-legacy-provider | 1328 | | - // working. Its explicit load disables OpenSSL's fallback, and the eager | 1329 | | - // CSPRNG check used to activate the provider as a side effect. Only | 1330 | | - // check the seeding when that provider is missing or FIPS is on, so a | 1331 | | - // configuration without a DRBG still aborts at startup instead of | 1332 | | - // hanging at the first crypto call. Otherwise the DRBG is instantiated | 1333 | | - // on first use. | 1334 | | -#if OPENSSL_VERSION_MAJOR >= 3 | 1335 | | - const bool check_csprng = ncrypto::isFipsEnabled() || | 1336 | | - !OSSL_PROVIDER_available(nullptr, "default"); | 1337 | | -#else | 1338 | | - const bool check_csprng = true; | 1339 | | -#endif | 1340 | | - if (check_csprng) { | 1341 | | - CHECK(ncrypto::CSPRNG(nullptr, 0)); | 1342 | | - } | | 1324 | + // Ensure CSPRNG is properly seeded. | | 1325 | + CHECK(ncrypto::CSPRNG(nullptr, 0)); | 1343 | 1326 |
| 1344 | | - // V8 uses the entropy for hash seeds, ASLR and Math.random(), none of | 1345 | | - // it cryptographic. Going through OpenSSL would instantiate the DRBG | 1346 | | - // and build the default provider's algorithm tables on every startup. | 1347 | | - // V8 falls back to very weak entropy when the source fails, so abort | 1348 | | - // instead. | 1349 | 1327 | V8::SetEntropySource([](unsigned char* buffer, size_t length) { | 1350 | | -#ifdef _AIX | 1351 | | - // uv_random() reads /dev/random on AIX, which blocks. OpenSSL seeds | 1352 | | - // from /dev/urandom there. | | 1328 | + // V8 falls back to very weak entropy when this function fails | | 1329 | + // and /dev/urandom isn't available. That wouldn't be so bad if | | 1330 | + // the entropy was only used for Math.random() but it's also used for | | 1331 | + // hash table and address space layout randomization. Better to abort. | 1353 | 1332 | CHECK(ncrypto::CSPRNG(buffer, length)); | 1354 | | -#else | 1355 | | - CHECK_EQ(uv_random(nullptr, nullptr, buffer, length, 0, nullptr), 0); | 1356 | | -#endif | 1357 | 1333 | return true; | 1358 | 1334 | }); | 1359 | 1335 | #endif // !defined(OPENSSL_IS_BORINGSSL) | |
Collapse file Copy file name to clipboardExpand all lines: test/addons/openssl-providers/test-legacy-provider-option.js -3Lines changed: 0 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,6 +22,3 @@ if (getFips()) { | 22 | 22 | common.skip('this test cannot be run in FIPS mode'); | 23 | 23 | } | 24 | 24 | providers.testProviderPresent('legacy'); | 25 | | -// The explicit legacy load disables OpenSSL's provider fallback, so the | 26 | | -// default provider has to be active before it runs. | 27 | | -providers.testProviderPresent('default'); |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/openssl3-conf/random_unavailable.cnf -7Lines changed: 0 additions & 7 deletions Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-crypto-no-algorithm.js -18Lines changed: 0 additions & 18 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -57,21 +57,3 @@ if (isMainThread) { | 57 | 57 | assert(common.nodeProcessAborted(cp.status, cp.signal), | 58 | 58 | `process did not abort, code:${cp.status} signal:${cp.signal}`); | 59 | 59 | } | 60 | | - | 61 | | -// AIX keeps OpenSSL as V8's entropy source, so a DRBG that cannot be | 62 | | -// fetched still aborts at startup there. | 63 | | -if (!common.isAIX) { | 64 | | - // A configuration whose random section names a DRBG that cannot be | 65 | | - // fetched starts normally; the first crypto call fails, without a hang. | 66 | | - const fixtures = require('../common/fixtures'); | 67 | | - const { spawnSync } = require('node:child_process'); | 68 | | - const randomConf = fixtures.path('openssl3-conf', 'random_unavailable.cnf'); | 69 | | - const cp = spawnSync(process.execPath, | 70 | | - [ `--openssl-config=${randomConf}`, '-e', | 71 | | - 'require("node:crypto").randomBytes(8)' ], | 72 | | - { encoding: 'utf8' }); | 73 | | - assert(!common.nodeProcessAborted(cp.status, cp.signal), | 74 | | - `process aborted, code:${cp.status} signal:${cp.signal}`); | 75 | | - assert.strictEqual(cp.status, 1); | 76 | | - assert.match(cp.stderr, /unable to fetch drbg/); | 77 | | -} |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-crypto-secure-heap.js -35Lines changed: 0 additions & 35 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -70,28 +70,6 @@ if (process.argv[2] === 'child') { | 70 | 70 | return; | 71 | 71 | } | 72 | 72 |
| 73 | | -if (process.argv[2] === 'workers') { | 74 | | - // Eight Workers held alive at once. A 1 KiB secure heap has room for a | 75 | | - // few DRBGs only, so an isolate setup that drew its entropy through | 76 | | - // OpenSSL would fail for the later Workers and abort the process. | 77 | | - const { Worker } = require('worker_threads'); | 78 | | - const i32 = new Int32Array(new SharedArrayBuffer(4)); | 79 | | - let online = 0; | 80 | | - for (let i = 0; i < 8; i++) { | 81 | | - const worker = new Worker( | 82 | | - 'const { workerData } = require("worker_threads");' + | 83 | | - 'Atomics.wait(workerData.i32, 0, 0);', | 84 | | - { eval: true, workerData: { i32 } }); | 85 | | - worker.on('online', () => { | 86 | | - if (++online === 8) { | 87 | | - Atomics.store(i32, 0, 1); | 88 | | - Atomics.notify(i32, 0); | 89 | | - } | 90 | | - }); | 91 | | - } | 92 | | - return; | 93 | | -} | 94 | | - | 95 | 73 | const child = fork( | 96 | 74 | process.argv[1], | 97 | 75 | ['child'], | @@ -101,19 +79,6 @@ child.on('exit', common.mustCall((code) => { | 101 | 79 | assert.strictEqual(code, 0); | 102 | 80 | })); | 103 | 81 |
| 104 | | -// AIX keeps OpenSSL as V8's entropy source, so a Worker's isolate setup | 105 | | -// still draws on the secure heap there. | 106 | | -if (!common.isAIX) { | 107 | | - const child = fork( | 108 | | - process.argv[1], | 109 | | - ['workers'], | 110 | | - { execArgv: ['--secure-heap=1024', '--secure-heap-min=4'] }); | 111 | | - child.on('exit', common.mustCall((code, signal) => { | 112 | | - assert.strictEqual(signal, null); | 113 | | - assert.strictEqual(code, 0); | 114 | | - })); | 115 | | -} | 116 | | - | 117 | 82 | { | 118 | 83 | const child = fork(fixtures.path('a.js'), { | 119 | 84 | execArgv: ['--secure-heap=3', '--secure-heap-min=3'], | |
|