From 8cabfe7c6e419fd75464c5d68ced269453ac9c8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Mon, 15 May 2023 17:39:11 +0200 Subject: [PATCH] crypto: fix setEngine() when OPENSSL_NO_ENGINE set When OpenSSL is configured with OPENSSL_NO_ENGINE, setEngine() currently throws an internal error because the C++ binding does not export the relevant function, which causes _setEngine() to be undefined within JS. Instead, match the behavior of tls/secure-context.js and throw the existing error code ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED when OpenSSL has been configured with OPENSSL_NO_ENGINE. PR-URL: https://github.com/nodejs/node/pull/47977 Reviewed-By: Ben Noordhuis Reviewed-By: Filip Skokan Reviewed-By: Luigi Pinca Reviewed-By: Richard Lau --- lib/internal/crypto/util.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/internal/crypto/util.js b/lib/internal/crypto/util.js index 835ab26165683c..8f4dc17f10c11b 100644 --- a/lib/internal/crypto/util.js +++ b/lib/internal/crypto/util.js @@ -44,6 +44,7 @@ const normalizeHashName = require('internal/crypto/hashnames'); const { hideStackFrames, codes: { + ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED, ERR_CRYPTO_ENGINE_UNKNOWN, ERR_INVALID_ARG_TYPE, ERR_INVALID_ARG_VALUE, @@ -110,6 +111,8 @@ function setEngine(id, flags) { if (flags === 0) flags = ENGINE_METHOD_ALL; + if (typeof _setEngine !== 'function') + throw new ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED(); if (!_setEngine(id, flags)) throw new ERR_CRYPTO_ENGINE_UNKNOWN(id); }