Description
@indutny and everyone working on the crypto
module:
At present, using a Buffer
for a crypto key exposes the key to core dumps, swapping, and forking. The user also has to remember to erase the key once done. Granted, core dumps and swapping can be disabled system wide, but some libraries such as libsodium
take care of this automatically, without the user having to know the fine details.
Would you be open to a crypto.alloc()
method to allocate buffers for use as crypto keys and help with crypto memory management, this would:
-
Set the platform equivalents of
MADV_DONTFORK
,MADV_DONTDUMP
, andmlock
as far as possible. -
Automatically zero buffers at GC time before freeing, along the lines of https://github.com/jedisct1/libsodium/blob/be58b2e6664389d9c7993b55291402934b43b3ca/src/libsodium/sodium/utils.c#L78:L101
-
Hopefully do guarded heap allocations, but 1 and 2 would be enough for a start.