nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
106.39k stars 28.99k forks source link

Use system random generator in crypto #5798

Closed speakeasypuncture closed 6 years ago

speakeasypuncture commented 8 years ago

randomBytes uses OpenSSL as its random number generator. It would be wiser and less errorprone to use a system RNG like urandom on Unix platforms, getrandom syscall on Linux and CryptGenRandom on Windows.

FiloSottile commented 6 years ago

Thanks for summarizing, but I don't think that captures the point. We are not advocating for reimplementing something that's in a library (for whatever reason), but for removing the library entirely. The library implements a user-space CSPRNG on top of kernel entropy, it might be good or bad, doesn't matter, we are arguing for not using one at all.

What you say is valid about primitives, which have to be implemented somewhere, but here we are talking about removing a layer from a system, where each layer is an independent point of failure.

As for "they are the ones that know about security", OpenSSL is bound by a lot of legacy, BoringSSL and libsodium are widely regarded as secure modern implementations, and those use the kernel CSPRNG.

davisjam commented 6 years ago

@FiloSottile Thanks, I've amended my post. Holler if you're still unhappy with my representations.

atoponce commented 2 years ago

What's the current status with this issue?

technion commented 2 years ago

@atoponce I could well have made a mistake somewhere, but tracing randomBytes appears to land here:

https://github.com/nodejs/node/blob/f69a4f61b2c133878159a9573ac438d58f8a05ac/src/crypto/crypto_random.cc

In which we first call RAND_status and then RAND_byes, these being OpenSSL functions.