From e01c6e63cd31abd7fd7a9b81f32c029131001e6c Mon Sep 17 00:00:00 2001 From: Bruno Silvestre Date: Sun, 19 Mar 2023 11:43:09 -0300 Subject: [PATCH] Fix: check if PSK is available --- src/compat.h | 6 ++++++ src/config.c | 6 ++++++ src/context.c | 4 ++++ src/ssl.lua | 2 +- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/compat.h b/src/compat.h index ef8da4d..90a561b 100644 --- a/src/compat.h +++ b/src/compat.h @@ -54,4 +54,10 @@ //------------------------------------------------------------------------------ +#if !defined(LIBRESSL_VERSION_NUMBER) && !defined(OPENSSL_NO_PSK) +#define LSEC_ENABLE_PSK +#endif + +//------------------------------------------------------------------------------ + #endif diff --git a/src/config.c b/src/config.c index 7cf8239..6ff9d9c 100644 --- a/src/config.c +++ b/src/config.c @@ -74,6 +74,12 @@ LSEC_API int luaopen_ssl_config(lua_State *L) lua_pushboolean(L, 1); lua_rawset(L, -3); +#ifdef LSEC_ENABLE_PSK + lua_pushstring(L, "psk"); + lua_pushboolean(L, 1); + lua_rawset(L, -3); +#endif + #ifdef LSEC_ENABLE_DANE // DANE lua_pushstring(L, "dane"); diff --git a/src/context.c b/src/context.c index a7e766c..6e943eb 100644 --- a/src/context.c +++ b/src/context.c @@ -707,6 +707,7 @@ static int set_alpn_cb(lua_State *L) return 1; } +#if defined(LSEC_ENABLE_PSK) /** * Callback to select the PSK. */ @@ -841,6 +842,7 @@ static int set_client_psk_cb(lua_State *L) { lua_pushboolean(L, 1); return 1; } +#endif #if defined(LSEC_ENABLE_DANE) /* @@ -893,9 +895,11 @@ static luaL_Reg funcs[] = { {"setdhparam", set_dhparam}, {"setverify", set_verify}, {"setoptions", set_options}, +#if defined(LSEC_ENABLE_PSK) {"setpskhint", set_psk_identity_hint}, {"setserverpskcb", set_server_psk_cb}, {"setclientpskcb", set_client_psk_cb}, +#endif {"setmode", set_mode}, #if !defined(OPENSSL_NO_EC) {"setcurve", set_curve}, diff --git a/src/ssl.lua b/src/ssl.lua index 1933096..52c857a 100644 --- a/src/ssl.lua +++ b/src/ssl.lua @@ -202,7 +202,7 @@ local function newcontext(cfg) end -- PSK - if cfg.psk then + if config.capabilities.psk and cfg.psk then if cfg.mode == "client" then if type(cfg.psk) ~= "function" then return nil, "invalid PSK configuration"