src: include crypto in the bootstrap snapshot · nodejs/node@457567f · GitHub
Skip to content

Commit 457567f

Browse files
joyeecheungnodejs-github-bot
authored andcommitted
src: include crypto in the bootstrap snapshot
To lazy load the run time options, the following properties are updated from value properties to accessor properties whose getter would turn them back to a value properties upon the initial access. - crypto.constants.defaultCipherList - crypto.pseudoRandomBytes - crypto.prng - crypto.rng PR-URL: #42203 Refs: #37476 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent de163d5 commit 457567f

7 files changed

Lines changed: 110 additions & 41 deletions

File tree

lib/crypto.js

Lines changed: 77 additions & 37 deletions

lib/internal/bootstrap/node.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ require('v8');
339339
require('vm');
340340
require('url');
341341
require('internal/options');
342+
if (config.hasOpenSSL) {
343+
require('crypto');
344+
}
342345

343346
function setupPrepareStackTrace() {
344347
const {

lib/internal/crypto/keygen.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ const {
6161
const { isArrayBufferView } = require('internal/util/types');
6262

6363
const { getOptionValue } = require('internal/options');
64-
const pendingDeprecation = getOptionValue('--pending-deprecation');
6564

6665
function wrapKey(key, ctor) {
6766
if (typeof key === 'string' ||
@@ -199,6 +198,9 @@ function createJob(mode, type, options) {
199198
const {
200199
hash, mgf1Hash, hashAlgorithm, mgf1HashAlgorithm, saltLength
201200
} = options;
201+
202+
const pendingDeprecation = getOptionValue('--pending-deprecation');
203+
202204
if (saltLength !== undefined && (!isInt32(saltLength) || saltLength < 0))
203205
throw new ERR_INVALID_ARG_VALUE('options.saltLength', saltLength);
204206
if (hashAlgorithm !== undefined && typeof hashAlgorithm !== 'string')

src/node_crypto.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ void Initialize(Local<Object> target,
7575
void* priv) {
7676
Environment* env = Environment::GetCurrent(context);
7777

78-
// TODO(joyeecheung): this needs to be called again if the instance is
79-
// deserialized from a snapshot with the crypto bindings.
8078
if (!InitCryptoOnce(env->isolate())) {
8179
return;
8280
}

src/node_main_instance.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "node_main_instance.h"
22
#include <memory>
3+
#if HAVE_OPENSSL
4+
#include "crypto/crypto_util.h"
5+
#endif // HAVE_OPENSSL
36
#include "debug_utils-inl.h"
47
#include "node_external_reference.h"
58
#include "node_internals.h"
@@ -205,6 +208,10 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code,
205208
env->InitializeInspector({});
206209
#endif
207210
env->DoneBootstrapping();
211+
212+
#if HAVE_OPENSSL
213+
crypto::InitCryptoOnce(isolate_);
214+
#endif // HAVE_OPENSSL
208215
} else {
209216
context = NewContext(isolate_);
210217
CHECK(!context.IsEmpty());

test/parallel/test-bootstrap-modules.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,26 @@ if (process.env.NODE_V8_COVERAGE) {
206206
expectedModules.add('Internal Binding profiler');
207207
}
208208

209+
if (common.hasCrypto) {
210+
expectedModules.add('Internal Binding crypto');
211+
expectedModules.add('NativeModule crypto');
212+
expectedModules.add('NativeModule internal/crypto/certificate');
213+
expectedModules.add('NativeModule internal/crypto/cipher');
214+
expectedModules.add('NativeModule internal/crypto/diffiehellman');
215+
expectedModules.add('NativeModule internal/crypto/hash');
216+
expectedModules.add('NativeModule internal/crypto/hashnames');
217+
expectedModules.add('NativeModule internal/crypto/hkdf');
218+
expectedModules.add('NativeModule internal/crypto/keygen');
219+
expectedModules.add('NativeModule internal/crypto/keys');
220+
expectedModules.add('NativeModule internal/crypto/pbkdf2');
221+
expectedModules.add('NativeModule internal/crypto/random');
222+
expectedModules.add('NativeModule internal/crypto/scrypt');
223+
expectedModules.add('NativeModule internal/crypto/sig');
224+
expectedModules.add('NativeModule internal/crypto/util');
225+
expectedModules.add('NativeModule internal/crypto/x509');
226+
expectedModules.add('NativeModule internal/streams/lazy_transform');
227+
}
228+
209229
const { internalBinding } = require('internal/test/binding');
210230
if (internalBinding('config').hasDtrace) {
211231
expectedModules.add('Internal Binding dtrace');

test/parallel/test-crypto-random.js

Lines changed: 0 additions & 1 deletion

0 commit comments

Comments
 (0)