-
Notifications
You must be signed in to change notification settings - Fork 30.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crypto.generatePrime results in an abort in FIPS mode #56377
Comments
const crypto = require('node:crypto');
crypto.setFips(true);
crypto.generatePrime(64,()=>{}); ➜ node git:(main) ✗ out/Debug/node ./main.js
# out/Debug/node[75750]: static bool node::crypto::RandomPrimeTraits::DeriveBits(Environment *, const RandomPrimeConfig &, ByteSource *) at ../src/crypto/crypto_random.cc:151
# Assertion failed: ncrypto::CSPRNG(nullptr, 0)
----- Native stack trace -----
1: 0x100590390 node::DumpNativeBacktrace(__sFILE*) [/Users/himself65/Code/node/out/Debug/node]
2: 0x1006fce3c node::Assert(node::AssertionInfo const&) [/Users/himself65/Code/node/out/Debug/node]
3: 0x100a24900 node::crypto::RandomPrimeTraits::DeriveBits(node::Environment*, node::crypto::RandomPrimeConfig const&, node::crypto::ByteSource*) [/Users/himself65/Code/node/out/Debug/node]
4: 0x100a27934 node::crypto::DeriveBitsJob<node::crypto::RandomPrimeTraits>::DoThreadPoolWork() [/Users/himself65/Code/node/out/Debug/node]
5: 0x100671608 node::ThreadPoolWork::ScheduleWork()::'lambda'(uv_work_s*)::operator()(uv_work_s*) const [/Users/himself65/Code/node/out/Debug/node]
6: 0x10067151c node::ThreadPoolWork::ScheduleWork()::'lambda'(uv_work_s*)::__invoke(uv_work_s*) [/Users/himself65/Code/node/out/Debug/node]
7: 0x1023c47c0 uv__queue_work [/Users/himself65/Code/node/out/Debug/node]
8: 0x1023c510c worker [/Users/himself65/Code/node/out/Debug/node]
9: 0x19e1042e4 _pthread_start [/usr/lib/system/libsystem_pthread.dylib]
10: 0x19e0ff0fc thread_start [/usr/lib/system/libsystem_pthread.dylib]
[1] 75750 abort out/Debug/node ./main.j |
might related to #46200 |
I saw one possible bug here, my mac doesn't support FIPS out/Debug/node --force-fips ./main.js
out/Debug/node: OpenSSL error when trying to enable FIPS:
40429E0702000000:error:12800067:DSO support routines:dlfcn_load:could not load the shared library:../deps/openssl/openssl/crypto/dso/dso_dlfcn.c:118:filename(/Users/himself65/Code/node/out/$(BUILDTYPE)/obj.target/deps/openssl/lib/openssl-modules/fips.dylib): dlopen(/Users/himself65/Code/node/out/$(BUILDTYPE)/obj.target/deps/openssl/lib/openssl-modules/fips.dylib, 0x0002): tried: '/Users/himself65/Code/node/out/$(BUILDTYPE)/obj.target/deps/openssl/lib/openssl-modules/fips.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/himself65/Code/node/out/$(BUILDTYPE)/obj.target/deps/openssl/lib/openssl-modules/fips.dylib' (no such file), '/Users/himself65/Code/node/out/$(BUILDTYPE)/obj.target/deps/openssl/lib/openssl-modules/fips.dylib' (no such file) |
with nvm version ➜ node git:(main) ✗ node --force-fips ./main.js
node: OpenSSL error when trying to enable FIPS:
40429E0702000000:error:12800067:DSO support routines:dlfcn_load:could not load the shared library:../deps/openssl/openssl/crypto/dso/dso_dlfcn.c:118:filename(/Users/iojs/build/ws/out/$(BUILDTYPE)/obj.target/deps/openssl/lib/openssl-modules/fips.dylib): dlopen(/Users/iojs/build/ws/out/$(BUILDTYPE)/obj.target/deps/openssl/lib/openssl-modules/fips.dylib, 0x0002): tried: '/Users/iojs/build/ws/out/$(BUILDTYPE)/obj.target/deps/openssl/lib/openssl-modules/fips.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/iojs/build/ws/out/$(BUILDTYPE)/obj.target/deps/openssl/lib/openssl-modules/fips.dylib' (no such file), '/Users/iojs/build/ws/out/$(BUILDTYPE)/obj.target/deps/openssl/lib/openssl-modules/fips.dylib' (no such file) P.S. why it's |
I was able to reproduce the issue on ubuntu so it's not related to that I do not think. This is specific to something with the random number generation in fips mode. Will be investigating |
Lines 334 to 347 in 72537f5
Specifically with node/src/crypto/crypto_random.cc Lines 150 to 151 in 72537f5
|
Version
v22.11.0
Platform
Subsystem
crypto
What steps will reproduce the bug?
Setup a node instance,
and run the following javascript code.
Then the node instance occurs an abort.
How often does it reproduce? Is there a required condition?
This abort can always be triggered following the steps above.
What is the expected behavior? Why is that the expected behavior?
If any error occurs, an exception or similar error-reporting stuff should be thrown, caught, and handled correctly. There is no reason to abort the whole node process.
What do you see instead?
Additional information
No response
The text was updated successfully, but these errors were encountered: