From 13b4ea85eacbef2dc32ec19fc462bc0415620b7d Mon Sep 17 00:00:00 2001 From: "Evgeny Grin (Karlson2k)" Date: Fri, 17 Jan 2025 15:34:01 +0100 Subject: [PATCH] MHD_daemon_get_info_fixed(): added information about used TLS backend --- src/include/microhttpd2.h | 14 ++++++++++ src/include/microhttpd2_main.h.in | 14 ++++++++++ src/mhd2/daemon_get_info.c | 46 +++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h index fd4d6da1..46420853 100644 --- a/src/include/microhttpd2.h +++ b/src/include/microhttpd2.h @@ -9204,6 +9204,15 @@ enum MHD_DaemonInfoFixedType */ MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD = 3 , + /** + * Get the TLS backend used by the daemon. + * The value #MHD_TLS_BACKEND_ANY is never set in the returned data. + * The value #MHD_TLS_BACKEND_NONE is set if the daemon does not use TLS. + * If MHD built without TLS support then #MHD_TLS_BACKEND_NONE is always set. + * The result is placed in @a v_tls_backend member. + */ + MHD_DAEMON_INFO_FIXED_TLS_TYPE = 100 + , /* * Sentinel * */ /** @@ -9237,6 +9246,11 @@ union MHD_DaemonInfoFixedData */ uint_least16_t v_port; + /** + * The TLS backend + */ + enum MHD_TlsBackend v_tls_backend; + /** * Unused member. * Help enforcing future-proof alignment of the union. diff --git a/src/include/microhttpd2_main.h.in b/src/include/microhttpd2_main.h.in index 778fa100..24b0c244 100644 --- a/src/include/microhttpd2_main.h.in +++ b/src/include/microhttpd2_main.h.in @@ -4582,6 +4582,15 @@ enum MHD_DaemonInfoFixedType */ MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD = 3 , + /** + * Get the TLS backend used by the daemon. + * The value #MHD_TLS_BACKEND_ANY is never set in the returned data. + * The value #MHD_TLS_BACKEND_NONE is set if the daemon does not use TLS. + * If MHD built without TLS support then #MHD_TLS_BACKEND_NONE is always set. + * The result is placed in @a v_tls_backend member. + */ + MHD_DAEMON_INFO_FIXED_TLS_TYPE = 100 + , /* * Sentinel * */ /** @@ -4615,6 +4624,11 @@ union MHD_DaemonInfoFixedData */ uint_least16_t v_port; + /** + * The TLS backend + */ + enum MHD_TlsBackend v_tls_backend; + /** * Unused member. * Help enforcing future-proof alignment of the union. diff --git a/src/mhd2/daemon_get_info.c b/src/mhd2/daemon_get_info.c index c771018a..2f5a2f15 100644 --- a/src/mhd2/daemon_get_info.c +++ b/src/mhd2/daemon_get_info.c @@ -26,12 +26,20 @@ #include "mhd_sys_options.h" +#include "mhd_unreachable.h" + #include "sys_base_types.h" #include "sys_sockets_types.h" #include "mhd_socket_type.h" #include "mhd_daemon.h" #include "events_process.h" +#ifdef MHD_SUPPORT_HTTPS +# include "mhd_tls_choice.h" +# ifdef MHD_USE_MULTITLS +# include "tls_multi_daemon_data.h" +# endif +#endif #include "mhd_public_api.h" @@ -84,6 +92,44 @@ MHD_daemon_get_info_fixed_sz (struct MHD_Daemon *daemon, return MHD_SC_INFO_GET_TYPE_NOT_SUPP_BY_BUILD; #endif break; + case MHD_DAEMON_INFO_FIXED_TLS_TYPE: + if (sizeof(output_buf->v_tls_backend) > output_buf_size) + return MHD_SC_INFO_GET_BUFF_TOO_SMALL; + if (! mhd_D_HAS_TLS (daemon)) + output_buf->v_tls_backend = MHD_TLS_BACKEND_NONE; + else + { +#if ! defined(MHD_SUPPORT_HTTPS) + mhd_UNREACHABLE (); +#elif defined(MHD_USE_MULTITLS) + switch (daemon->tls->choice) + { +# ifdef MHD_SUPPORT_GNUTLS + case mhd_TLS_MULTI_ROUTE_GNU: + output_buf->v_tls_backend = MHD_TLS_BACKEND_GNUTLS; + break; +# endif +# ifdef MHD_SUPPORT_OPENSSL + case mhd_TLS_MULTI_ROUTE_OPEN: + output_buf->v_tls_backend = MHD_TLS_BACKEND_OPENSSL; + break; +# endif + case mhd_TLS_MULTI_ROUTE_NONE: + default: + mhd_UNREACHABLE (); + break; + } +#elif defined(MHD_SUPPORT_GNUTLS) + output_buf->v_tls_backend = MHD_TLS_BACKEND_GNUTLS; +#elif defined(MHD_SUPPORT_OPENSSL) + output_buf->v_tls_backend = MHD_TLS_BACKEND_OPENSSL; +#else +#error No TLS backends enabled, while TLS support is enabled +#endif + } + break; + return MHD_SC_OK; + case MHD_DAEMON_INFO_FIXED_SENTINEL: default: break;