Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: frozen on RSA key generation with public exponent 3 #29433

Closed
microshine opened this issue Sep 4, 2019 · 3 comments
Closed

crypto: frozen on RSA key generation with public exponent 3 #29433

microshine opened this issue Sep 4, 2019 · 3 comments
Labels
confirmed-bug Issues with confirmed bugs. crypto Issues and PRs related to the crypto subsystem.

Comments

@microshine
Copy link

  • Version: 10.16.3
  • Platform: Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019
  • Subsystem:

NodeJS is frozen on RSA key generation with public exponent 3. It works fine in NodeJS v12

const crypto = require("crypto");

const keys = crypto.generateKeyPairSync("rsa", {
  modulusLength: 2048,
  publicExponent: 3,
  publicKeyEncoding: {
    format: "der",
    type: "spki",
  },
  privateKeyEncoding: {
    format: "der",
    type: "pkcs8",
  },
});

console.log(keys);
@mscdex
Copy link
Contributor

mscdex commented Sep 4, 2019

For me (on Linux) node immediately segfaults when generating the key pair:

#0  __memmove_sse2_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:299
#1  0x0000555557d9de45 in BN_copy (a=0x555559c8fc30, b=0x555559c8fe80) at ../deps/openssl/openssl/crypto/bn/bn_lib.c:291
#2  0x0000555557e81fd0 in rsa_builtin_keygen (rsa=0x555559c89450, bits=2048, primes=2, e_value=0x555559c8fe80, cb=0x0) at ../deps/openssl/openssl/crypto/rsa/rsa_gen.c:144
#3  0x0000555557e81b07 in RSA_generate_multi_prime_key (rsa=0x555559c89450, bits=2048, primes=2, e_value=0x555559c8fe80, cb=0x0) at ../deps/openssl/openssl/crypto/rsa/rsa_gen.c:61
#4  0x0000555557e89f44 in pkey_rsa_keygen (ctx=0x555559c38630, pkey=0x555559c8c120) at ../deps/openssl/openssl/crypto/rsa/rsa_pmeth.c:743
#5  0x0000555557e40724 in EVP_PKEY_keygen (ctx=0x555559c38630, ppkey=0x7fffffff7530) at ../deps/openssl/openssl/crypto/evp/pmeth_gn.c:108
#6  0x0000555556d242d9 in node::crypto::GenerateKeyPairJob::GenerateKey (this=0x555559c39a90) at ../src/node_crypto.cc:5019
#7  0x0000555556d241d8 in node::crypto::GenerateKeyPairJob::DoThreadPoolWork (this=0x555559c39a90) at ../src/node_crypto.cc:4996
#8  0x0000555556d1b0b9 in node::crypto::GenerateKeyPair (args=..., n_opts=2, config=std::unique_ptr<node::crypto::KeyPairGenerationConfig> = {...}) at ../src/node_crypto.cc:5240
#9  0x0000555556d1b448 in node::crypto::GenerateKeyPairRSA (args=...) at ../src/node_crypto.cc:5262
#10 0x0000555556fd964a in v8::internal::FunctionCallbackArguments::Call (this=0x7fffffff7830, handler=0x28165991409) at ../deps/v8/src/api-arguments-inl.h:94
#11 0x0000555556fdc4ce in v8::internal::(anonymous namespace)::HandleApiCallHelper<false> (isolate=0x555559bc19f0, function=..., new_target=..., fun_data=..., receiver=..., args=...) at ../deps/v8/src/builtins/builtins-api.cc:109
#12 0x0000555556fda36b in v8::internal::Builtin_Impl_HandleApiCall (args=..., isolate=0x555559bc19f0) at ../deps/v8/src/builtins/builtins-api.cc:139
#13 0x0000555556fda105 in v8::internal::Builtin_HandleApiCall (args_length=14, args_object=0x7fffffff7a68, isolate=0x555559bc19f0) at ../deps/v8/src/builtins/builtins-api.cc:127

EDIT: Same crash happens through node v11.15.0. node v12.0.0 was the first release where it didn't crash.

@mscdex mscdex added confirmed-bug Issues with confirmed bugs. crypto Issues and PRs related to the crypto subsystem. v10.x labels Sep 4, 2019
@mscdex
Copy link
Contributor

mscdex commented Sep 4, 2019

After bisecting it seems at least the segfault I was experiencing was fixed in 0911e88.

BethGriggs pushed a commit that referenced this issue Oct 18, 2019
EVP_PKEY_CTX_set_rsa_keygen_pubexp() accepts ownership of the exponent
on success, so do not free it.

Fixes: #27087
Fixes: #29433

PR-URL: #27092
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
@tniessen
Copy link
Member

This bug was fixed in node 12 and 10.17.0.

The v11 line is affected, but EOL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. crypto Issues and PRs related to the crypto subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants