-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
crypto.alloc() for encryption key memory management #18896
Copy link
Copy link
Closed
Labels
cryptoIssues and PRs related to the crypto subsystem.Issues and PRs related to the crypto subsystem.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.memoryIssues and PRs related to the memory management or memory footprint.Issues and PRs related to the memory management or memory footprint.stale
Metadata
Metadata
Assignees
Labels
cryptoIssues and PRs related to the crypto subsystem.Issues and PRs related to the crypto subsystem.feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.memoryIssues and PRs related to the memory management or memory footprint.Issues and PRs related to the memory management or memory footprint.stale
@indutny and everyone working on the
cryptomodule:At present, using a
Bufferfor 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 aslibsodiumtake 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, andmlockas 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.