Skip to content

crypto.alloc() for encryption key memory management #18896

Closed
@jorangreef

Description

@jorangreef

@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:

  1. Set the platform equivalents of MADV_DONTFORK , MADV_DONTDUMP, and mlock as far as possible.

  2. 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

  3. Hopefully do guarded heap allocations, but 1 and 2 would be enough for a start.

Metadata

Metadata

Assignees

Labels

cryptoIssues and PRs related to the crypto subsystem.feature requestIssues that request new features to be added to Node.js.memoryIssues and PRs related to the memory management or memory footprint.stale

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions