Skip to content

Commit

Permalink
src: check curve ID existence instead of asn flags
Browse files Browse the repository at this point in the history
Simplify the code. The flag check was in the OpenSSL source, but reading
through the docs and source, it is not necessary.

Refs: https://github.com/nodejs/node/pull/24358/files#r243099693
PR-URL: #25345
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
sam-github authored and addaleax committed Jan 8, 2019
1 parent bf3cb3f commit 4a6ec3b
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1738,21 +1738,18 @@ static Local<Object> X509ToObject(Environment* env, X509* cert) {
CHECK_NULL(pub);
}

if (EC_GROUP_get_asn1_flag(group) != 0) {
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).

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)) {

This comment has been minimized.

Copy link
@nornagon

nornagon Jan 8, 2019

Contributor

Should this be else if?

This comment has been minimized.

Copy link
@sam-github

sam-github Jan 8, 2019

Author Contributor

No, they are not mutually exclusive. From the tls docs:

asn1Curve <string> (Optional) The ASN.1 name of the OID of the elliptic curve. Well-known curves are identified by an OID. While it is unusual, it is possible that the curve is identified by its mathematical properties, in which case it will not have an OID. Example: 'prime256v1'.

nistCurve <string> (Optional) The NIST name for the elliptic curve, if it has one (not all well-known curves have been assigned names by NIST). Example: 'P-256'.
info->Set(context, env->nistcurve_string(),
OneByteString(env->isolate(), nist)).FromJust();
}
} else {
// Unnamed curves can be described by their mathematical properties,
Expand Down

0 comments on commit 4a6ec3b

Please sign in to comment.