| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent de163d5 commit 457567f
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,8 +40,6 @@ const { | |||
| 40 | 40 | } = require('internal/errors').codes; | |
| 41 | 41 | const constants = internalBinding('constants').crypto; | |
| 42 | 42 | const { getOptionValue } = require('internal/options'); | |
| 43 | - const pendingDeprecation = getOptionValue('--pending-deprecation'); | ||
| 44 | - const fipsForced = getOptionValue('--force-fips'); | ||
| 45 | 43 | const { | |
| 46 | 44 | getFipsCrypto, | |
| 47 | 45 | setFipsCrypto, | |
@@ -221,8 +219,8 @@ module.exports = { | |||
| 221 | 219 | sign: signOneShot, | |
| 222 | 220 | setEngine, | |
| 223 | 221 | timingSafeEqual, | |
| 224 | - getFips: fipsForced ? getFipsForced : getFipsCrypto, | ||
| 225 | - setFips: fipsForced ? setFipsForced : setFipsCrypto, | ||
| 222 | + getFips, | ||
| 223 | + setFips, | ||
| 226 | 224 | verify: verifyOneShot, | |
| 227 | 225 | ||
| 228 | 226 | // Classes | |
@@ -243,23 +241,87 @@ module.exports = { | |||
| 243 | 241 | secureHeapUsed, | |
| 244 | 242 | }; | |
| 245 | 243 | ||
| 246 | - function setFipsForced(val) { | ||
| 247 | - if (val) return; | ||
| 248 | - throw new ERR_CRYPTO_FIPS_FORCED(); | ||
| 244 | + function getFips() { | ||
| 245 | + return getOptionValue('--force-fips') ? 1 : getFipsCrypto(); | ||
| 249 | 246 | } | |
| 250 | 247 | ||
| 251 | - function getFipsForced() { | ||
| 252 | - return 1; | ||
| 248 | + function setFips(val) { | ||
| 249 | + if (getOptionValue('--force-fips')) { | ||
| 250 | + if (val) return; | ||
| 251 | + throw new ERR_CRYPTO_FIPS_FORCED(); | ||
| 252 | + } else { | ||
| 253 | + setFipsCrypto(val); | ||
| 254 | + } | ||
| 253 | 255 | } | |
| 254 | 256 | ||
| 255 | 257 | function getRandomValues(array) { | |
| 256 | 258 | return lazyWebCrypto().crypto.getRandomValues(array); | |
| 257 | 259 | } | |
| 258 | 260 | ||
| 259 | 261 | ObjectDefineProperty(constants, 'defaultCipherList', { | |
| 260 | - value: getOptionValue('--tls-cipher-list') | ||
| 262 | + get() { | ||
| 263 | + const value = getOptionValue('--tls-cipher-list'); | ||
| 264 | + ObjectDefineProperty(this, 'defaultCipherList', { | ||
| 265 | + writable: true, | ||
| 266 | + configurable: true, | ||
| 267 | + enumerable: true, | ||
| 268 | + value | ||
| 269 | + }); | ||
| 270 | + return value; | ||
| 271 | + }, | ||
| 272 | + set(val) { | ||
| 273 | + ObjectDefineProperty(this, 'defaultCipherList', { | ||
| 274 | + writable: true, | ||
| 275 | + configurable: true, | ||
| 276 | + enumerable: true, | ||
| 277 | + value: val | ||
| 278 | + }); | ||
| 279 | + }, | ||
| 280 | + configurable: true, | ||
| 281 | + enumerable: true, | ||
| 261 | 282 | }); | |
| 262 | 283 | ||
| 284 | + function getRandomBytesAlias(key) { | ||
| 285 | + return { | ||
| 286 | + enumerable: false, | ||
| 287 | + configurable: true, | ||
| 288 | + get() { | ||
| 289 | + let value; | ||
| 290 | + if (getOptionValue('--pending-deprecation')) { | ||
| 291 | + value = deprecate( | ||
| 292 | + randomBytes, | ||
| 293 | + `crypto.${key} is deprecated.`, | ||
| 294 | + 'DEP0115'); | ||
| 295 | + } else { | ||
| 296 | + value = randomBytes; | ||
| 297 | + } | ||
| 298 | + ObjectDefineProperty( | ||
| 299 | + this, | ||
| 300 | + key, | ||
| 301 | + { | ||
| 302 | + enumerable: false, | ||
| 303 | + configurable: true, | ||
| 304 | + writable: true, | ||
| 305 | + value: value | ||
| 306 | + } | ||
| 307 | + ); | ||
| 308 | + return value; | ||
| 309 | + }, | ||
| 310 | + set(value) { | ||
| 311 | + ObjectDefineProperty( | ||
| 312 | + this, | ||
| 313 | + key, | ||
| 314 | + { | ||
| 315 | + enumerable: true, | ||
| 316 | + configurable: true, | ||
| 317 | + writable: true, | ||
| 318 | + value | ||
| 319 | + } | ||
| 320 | + ); | ||
| 321 | + } | ||
| 322 | + }; | ||
| 323 | + } | ||
| 324 | + | ||
| 263 | 325 | ObjectDefineProperties(module.exports, { | |
| 264 | 326 | createCipher: { | |
| 265 | 327 | enumerable: false, | |
@@ -273,8 +335,8 @@ ObjectDefineProperties(module.exports, { | |||
| 273 | 335 | }, | |
| 274 | 336 | // crypto.fips is deprecated. DEP0093. Use crypto.getFips()/crypto.setFips() | |
| 275 | 337 | fips: { | |
| 276 | - get: fipsForced ? getFipsForced : getFipsCrypto, | ||
| 277 | - set: fipsForced ? setFipsForced : setFipsCrypto | ||
| 338 | + get: getFips, | ||
| 339 | + set: setFips, | ||
| 278 | 340 | }, | |
| 279 | 341 | DEFAULT_ENCODING: { | |
| 280 | 342 | enumerable: false, | |
@@ -313,29 +375,7 @@ ObjectDefineProperties(module.exports, { | |||
| 313 | 375 | ||
| 314 | 376 | // Aliases for randomBytes are deprecated. | |
| 315 | 377 | // The ecosystem needs those to exist for backwards compatibility. | |
| 316 | - prng: { | ||
| 317 | - enumerable: false, | ||
| 318 | - configurable: true, | ||
| 319 | - writable: true, | ||
| 320 | - value: pendingDeprecation ? | ||
| 321 | - deprecate(randomBytes, 'crypto.prng is deprecated.', 'DEP0115') : | ||
| 322 | - randomBytes | ||
| 323 | - }, | ||
| 324 | - pseudoRandomBytes: { | ||
| 325 | - enumerable: false, | ||
| 326 | - configurable: true, | ||
| 327 | - writable: true, | ||
| 328 | - value: pendingDeprecation ? | ||
| 329 | - deprecate(randomBytes, | ||
| 330 | - 'crypto.pseudoRandomBytes is deprecated.', 'DEP0115') : | ||
| 331 | - randomBytes | ||
| 332 | - }, | ||
| 333 | - rng: { | ||
| 334 | - enumerable: false, | ||
| 335 | - configurable: true, | ||
| 336 | - writable: true, | ||
| 337 | - value: pendingDeprecation ? | ||
| 338 | - deprecate(randomBytes, 'crypto.rng is deprecated.', 'DEP0115') : | ||
| 339 | - randomBytes | ||
| 340 | - } | ||
| 378 | + prng: getRandomBytesAlias('prng'), | ||
| 379 | + pseudoRandomBytes: getRandomBytesAlias('pseudoRandomBytes'), | ||
| 380 | + rng: getRandomBytesAlias('rng') | ||
| 341 | 381 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -339,6 +339,9 @@ require('v8'); | |||
| 339 | 339 | require('vm'); | |
| 340 | 340 | require('url'); | |
| 341 | 341 | require('internal/options'); | |
| 342 | + if (config.hasOpenSSL) { | ||
| 343 | + require('crypto'); | ||
| 344 | + } | ||
| 342 | 345 | ||
| 343 | 346 | function setupPrepareStackTrace() { | |
| 344 | 347 | const { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,7 +61,6 @@ const { | |||
| 61 | 61 | const { isArrayBufferView } = require('internal/util/types'); | |
| 62 | 62 | ||
| 63 | 63 | const { getOptionValue } = require('internal/options'); | |
| 64 | - const pendingDeprecation = getOptionValue('--pending-deprecation'); | ||
| 65 | 64 | ||
| 66 | 65 | function wrapKey(key, ctor) { | |
| 67 | 66 | if (typeof key === 'string' || | |
@@ -199,6 +198,9 @@ function createJob(mode, type, options) { | |||
| 199 | 198 | const { | |
| 200 | 199 | hash, mgf1Hash, hashAlgorithm, mgf1HashAlgorithm, saltLength | |
| 201 | 200 | } = options; | |
| 201 | + | ||
| 202 | + const pendingDeprecation = getOptionValue('--pending-deprecation'); | ||
| 203 | + | ||
| 202 | 204 | if (saltLength !== undefined && (!isInt32(saltLength) || saltLength < 0)) | |
| 203 | 205 | throw new ERR_INVALID_ARG_VALUE('options.saltLength', saltLength); | |
| 204 | 206 | if (hashAlgorithm !== undefined && typeof hashAlgorithm !== 'string') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,8 +75,6 @@ void Initialize(Local<Object> target, | |||
| 75 | 75 | void* priv) { | |
| 76 | 76 | Environment* env = Environment::GetCurrent(context); | |
| 77 | 77 | ||
| 78 | - // TODO(joyeecheung): this needs to be called again if the instance is | ||
| 79 | - // deserialized from a snapshot with the crypto bindings. | ||
| 80 | 78 | if (!InitCryptoOnce(env->isolate())) { | |
| 81 | 79 | return; | |
| 82 | 80 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,8 @@ | |||
| 1 | 1 | #include "node_main_instance.h" | |
| 2 | 2 | #include <memory> | |
| 3 | + #if HAVE_OPENSSL | ||
| 4 | + #include "crypto/crypto_util.h" | ||
| 5 | + #endif // HAVE_OPENSSL | ||
| 3 | 6 | #include "debug_utils-inl.h" | |
| 4 | 7 | #include "node_external_reference.h" | |
| 5 | 8 | #include "node_internals.h" | |
@@ -205,6 +208,10 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code, | |||
| 205 | 208 | env->InitializeInspector({}); | |
| 206 | 209 | #endif | |
| 207 | 210 | env->DoneBootstrapping(); | |
| 211 | + | ||
| 212 | + #if HAVE_OPENSSL | ||
| 213 | + crypto::InitCryptoOnce(isolate_); | ||
| 214 | + #endif // HAVE_OPENSSL | ||
| 208 | 215 | } else { | |
| 209 | 216 | context = NewContext(isolate_); | |
| 210 | 217 | CHECK(!context.IsEmpty()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -206,6 +206,26 @@ if (process.env.NODE_V8_COVERAGE) { | |||
| 206 | 206 | expectedModules.add('Internal Binding profiler'); | |
| 207 | 207 | } | |
| 208 | 208 | ||
| 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 | + | ||
| 209 | 229 | const { internalBinding } = require('internal/test/binding'); | |
| 210 | 230 | if (internalBinding('config').hasDtrace) { | |
| 211 | 231 | expectedModules.add('Internal Binding dtrace'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -338,7 +338,6 @@ assert.throws( | |||
| 338 | 338 | const desc = Object.getOwnPropertyDescriptor(crypto, f); | |
| 339 | 339 | assert.ok(desc); | |
| 340 | 340 | assert.strictEqual(desc.configurable, true); | |
| 341 | - assert.strictEqual(desc.writable, true); | ||
| 342 | 341 | assert.strictEqual(desc.enumerable, false); | |
| 343 | 342 | }); | |
| 344 | 343 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments