diff options
author | Filip Skokan <panva.ip@gmail.com> | 2021-01-25 16:18:27 +0300 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2021-02-02 12:42:01 +0300 |
commit | cb3b0ec4fcbef9d77bcb66338ca048b69ca2a31b (patch) | |
tree | f4ac19cb6ff831cba0035efc3977c3630bba6af1 /src | |
parent | 171001605377e898707db78fef827243e06546d8 (diff) |
crypto: generateKeyPair('ec') should not support NODE-ED* and NODE-X*
Fixes https://github.com/nodejs/node/issues/37055
PR-URL: https://github.com/nodejs/node/pull/37063
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/crypto/crypto_ec.cc | 28 | ||||
-rw-r--r-- | src/crypto/crypto_ec.h | 1 | ||||
-rw-r--r-- | src/crypto/crypto_keys.cc | 2 |
3 files changed, 18 insertions, 13 deletions
diff --git a/src/crypto/crypto_ec.cc b/src/crypto/crypto_ec.cc index c764124bdd0..1dd3b317633 100644 --- a/src/crypto/crypto_ec.cc +++ b/src/crypto/crypto_ec.cc @@ -36,17 +36,21 @@ int GetCurveFromName(const char* name) { int nid = EC_curve_nist2nid(name); if (nid == NID_undef) nid = OBJ_sn2nid(name); - // If there is still no match, check manually for known curves - if (nid == NID_undef) { - if (strcmp(name, "NODE-ED25519") == 0) { - nid = EVP_PKEY_ED25519; - } else if (strcmp(name, "NODE-ED448") == 0) { - nid = EVP_PKEY_ED448; - } else if (strcmp(name, "NODE-X25519") == 0) { - nid = EVP_PKEY_X25519; - } else if (strcmp(name, "NODE-X448") == 0) { - nid = EVP_PKEY_X448; - } + return nid; +} + +int GetOKPCurveFromName(const char* name) { + int nid; + if (strcmp(name, "NODE-ED25519") == 0) { + nid = EVP_PKEY_ED25519; + } else if (strcmp(name, "NODE-ED448") == 0) { + nid = EVP_PKEY_ED448; + } else if (strcmp(name, "NODE-X25519") == 0) { + nid = EVP_PKEY_X25519; + } else if (strcmp(name, "NODE-X448") == 0) { + nid = EVP_PKEY_X448; + } else { + nid = NID_undef; } return nid; } @@ -443,7 +447,7 @@ Maybe<bool> ECDHBitsTraits::AdditionalConfig( return Nothing<bool>(); } - params->id_ = GetCurveFromName(*name); + params->id_ = GetOKPCurveFromName(*name); params->private_ = private_key->Data(); params->public_ = public_key->Data(); diff --git a/src/crypto/crypto_ec.h b/src/crypto/crypto_ec.h index a6ec85947bf..00d9d0087b0 100644 --- a/src/crypto/crypto_ec.h +++ b/src/crypto/crypto_ec.h @@ -17,6 +17,7 @@ namespace node { namespace crypto { int GetCurveFromName(const char* name); +int GetOKPCurveFromName(const char* name); class ECDH final : public BaseObject { public: diff --git a/src/crypto/crypto_keys.cc b/src/crypto/crypto_keys.cc index cb548d10cf4..6a4d7950c86 100644 --- a/src/crypto/crypto_keys.cc +++ b/src/crypto/crypto_keys.cc @@ -1058,7 +1058,7 @@ void KeyObjectHandle::InitEDRaw(const FunctionCallbackInfo<Value>& args) { ? EVP_PKEY_new_raw_private_key : EVP_PKEY_new_raw_public_key; - int id = GetCurveFromName(*name); + int id = GetOKPCurveFromName(*name); switch (id) { case EVP_PKEY_X25519: |