diff options
author | Roga Pria Sembada <rogaps@gmail.com> | 2017-09-05 01:49:28 +0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-09-20 01:16:28 -0700 |
commit | 873e5bd0b4c07f3ff983e683d3095f4327421a4f (patch) | |
tree | 100bd021ec469972c8392d646592164dbba64c85 /src/node_crypto.cc | |
parent | 3c65a83ac5c98b778ac91c64cb99a1a775c91c37 (diff) | |
download | android-node-v8-873e5bd0b4c07f3ff983e683d3095f4327421a4f.tar.gz android-node-v8-873e5bd0b4c07f3ff983e683d3095f4327421a4f.tar.bz2 android-node-v8-873e5bd0b4c07f3ff983e683d3095f4327421a4f.zip |
crypto: support multiple ECDH curves and auto
Using SSL_CTX_set1_curves_list() (OpenSSL 1.0.2+), this allows to set
colon separated ECDH curve names in SecureContext's ecdhCurve option.
The option can also be set to "auto" to select the curve automatically
from list built in OpenSSL by enabling SSL_CTX_set_ecdh_auto()
(OpenSSL 1.0.2+).
PR-URL: https://github.com/nodejs/node/pull/15206
Ref: https://github.com/nodejs/node/issues/15054
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Diffstat (limited to 'src/node_crypto.cc')
-rw-r--r-- | src/node_crypto.cc | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc index e1c8883508..452e085a2d 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -923,20 +923,14 @@ void SecureContext::SetECDHCurve(const FunctionCallbackInfo<Value>& args) { node::Utf8Value curve(env->isolate(), args[0]); - int nid = OBJ_sn2nid(*curve); - - if (nid == NID_undef) - return env->ThrowTypeError("First argument should be a valid curve name"); - - EC_KEY* ecdh = EC_KEY_new_by_curve_name(nid); - - if (ecdh == nullptr) - return env->ThrowTypeError("First argument should be a valid curve name"); - SSL_CTX_set_options(sc->ctx_, SSL_OP_SINGLE_ECDH_USE); - SSL_CTX_set_tmp_ecdh(sc->ctx_, ecdh); + SSL_CTX_set_ecdh_auto(sc->ctx_, 1); + + if (strcmp(*curve, "auto") == 0) + return; - EC_KEY_free(ecdh); + if (!SSL_CTX_set1_curves_list(sc->ctx_, *curve)) + return env->ThrowError("Failed to set ECDH curve"); } |