From 742bd830804be2fce4baff392030010ec5b35390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Fri, 12 May 2023 14:56:00 +0000 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. --- 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 8838226c591785..cf044e804ad05a 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, @@ -105,6 +106,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); }