From f11ccadfcf189290cea09ffcc6a7e6ff47cfc27d Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Fri, 4 Jan 2019 11:00:57 -0800 Subject: [PATCH 1/2] src: check curve ID existence instead of asn flags Simplify the code. The flag check was in the OpenSSL source, but reading through the docs and source, it is not necessary. Fixes: https://github.com/nodejs/node/pull/24358/files#r243099693 --- src/node_crypto.cc | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index ab355688888ee3..86a45b13b5e529 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -1738,21 +1738,18 @@ static Local X509ToObject(Environment* env, X509* cert) { CHECK_NULL(pub); } - if (EC_GROUP_get_asn1_flag(group) != 0) { + int nid = EC_GROUP_get_curve_name(group); + if (nid != 0) { // Curve is well-known, get its OID and NIST nick-name (if it has one). - int nid = EC_GROUP_get_curve_name(group); - if (nid != 0) { - if (const char* sn = OBJ_nid2sn(nid)) { - info->Set(context, env->asn1curve_string(), - OneByteString(env->isolate(), sn)).FromJust(); - } + if (const char* sn = OBJ_nid2sn(nid)) { + info->Set(context, env->asn1curve_string(), + OneByteString(env->isolate(), sn)).FromJust(); } - if (nid != 0) { - if (const char* nist = EC_curve_nid2nist(nid)) { - info->Set(context, env->nistcurve_string(), - OneByteString(env->isolate(), nist)).FromJust(); - } + + if (const char* nist = EC_curve_nid2nist(nid)) { + info->Set(context, env->nistcurve_string(), + OneByteString(env->isolate(), nist)).FromJust(); } } else { // Unnamed curves can be described by their mathematical properties, From ce270f108f3179bda5576d2961094aa246c41239 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Mon, 7 Jan 2019 08:41:00 -0800 Subject: [PATCH 2/2] fixup! src: check curve ID existence instead of asn flags --- src/node_crypto.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 86a45b13b5e529..deed3305df34b5 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -1738,18 +1738,18 @@ static Local X509ToObject(Environment* env, X509* cert) { CHECK_NULL(pub); } - int nid = EC_GROUP_get_curve_name(group); + const int nid = EC_GROUP_get_curve_name(group); if (nid != 0) { // Curve is well-known, get its OID and NIST nick-name (if it has one). if (const char* sn = OBJ_nid2sn(nid)) { info->Set(context, env->asn1curve_string(), - OneByteString(env->isolate(), sn)).FromJust(); + OneByteString(env->isolate(), sn)).FromJust(); } if (const char* nist = EC_curve_nid2nist(nid)) { info->Set(context, env->nistcurve_string(), - OneByteString(env->isolate(), nist)).FromJust(); + OneByteString(env->isolate(), nist)).FromJust(); } } else { // Unnamed curves can be described by their mathematical properties,