Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2021-01-04 20:06:26 +0300
committerJames M Snell <jasnell@gmail.com>2021-01-11 21:39:00 +0300
commit03c056401f23fe83ab6f16741759182e95a407bd (patch)
tree6154d6acc17d824790e7664b0fa9a1564bb77dc4 /src/node_options.cc
parentb4378aa38a7971b4da35210f8ced8961fdf3bf41 (diff)
crypto: implement basic secure heap support
Adds two new command line arguments: * `--secure-heap=n`, which causes node.js to initialize an openssl secure heap of `n` bytes on openssl initialization. * `--secure-heap-min=n`, which specifies the minimum allocation from the secure heap. * A new method `crypto.secureHeapUsed()` that returns details about the total and used secure heap allocation. The secure heap is an openssl feature that allows certain kinds of potentially sensitive information (such as private key BigNums) to be allocated from a dedicated memory area that is protected against pointer over- and underruns. The secure heap is a fixed size, so it's important that users pick a large enough size to cover the crypto operations they intend to utilize. The secure heap is disabled by default. Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/36779 Refs: https://github.com/nodejs/node/pull/36729 Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Diffstat (limited to 'src/node_options.cc')
-rw-r--r--src/node_options.cc24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/node_options.cc b/src/node_options.cc
index e90dcd93231..9f59e7ee4f8 100644
--- a/src/node_options.cc
+++ b/src/node_options.cc
@@ -7,6 +7,8 @@
#include <errno.h>
#include <sstream>
+#include <limits>
+#include <algorithm>
#include <cstdlib> // strtoul, errno
using v8::Boolean;
@@ -64,6 +66,20 @@ void PerProcessOptions::CheckOptions(std::vector<std::string>* errors) {
errors->push_back("either --use-openssl-ca or --use-bundled-ca can be "
"used, not both");
}
+
+ // Any value less than 2 disables use of the secure heap.
+ if (secure_heap >= 2) {
+ if ((secure_heap & (secure_heap - 1)) != 0)
+ errors->push_back("--secure-heap must be a power of 2");
+ secure_heap_min =
+ std::min({
+ secure_heap,
+ secure_heap_min,
+ static_cast<int64_t>(std::numeric_limits<int>::max())});
+ secure_heap_min = std::max(static_cast<int64_t>(2), secure_heap_min);
+ if ((secure_heap_min & (secure_heap_min - 1)) != 0)
+ errors->push_back("--secure-heap-min must be a power of 2");
+ }
#endif
if (use_largepages != "off" &&
use_largepages != "on" &&
@@ -760,6 +776,14 @@ PerProcessOptionsParser::PerProcessOptionsParser(
&PerProcessOptions::force_fips_crypto,
kAllowedInEnvironment);
#endif
+ AddOption("--secure-heap",
+ "total size of the OpenSSL secure heap",
+ &PerProcessOptions::secure_heap,
+ kAllowedInEnvironment);
+ AddOption("--secure-heap-min",
+ "minimum allocation size from the OpenSSL secure heap",
+ &PerProcessOptions::secure_heap_min,
+ kAllowedInEnvironment);
#endif
AddOption("--use-largepages",
"Map the Node.js static code to large pages. Options are "