tls_mbed_tls_lib.h (7791B)
1 /* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */ 2 /* 3 This file is part of GNU libmicrohttpd. 4 Copyright (C) 2025 Evgeny Grin (Karlson2k) 5 6 GNU libmicrohttpd is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Lesser General Public 8 License as published by the Free Software Foundation; either 9 version 2.1 of the License, or (at your option) any later version. 10 11 GNU libmicrohttpd is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Lesser General Public License for more details. 15 16 Alternatively, you can redistribute GNU libmicrohttpd and/or 17 modify it under the terms of the GNU General Public License as 18 published by the Free Software Foundation; either version 2 of 19 the License, or (at your option) any later version, together 20 with the eCos exception, as follows: 21 22 As a special exception, if other files instantiate templates or 23 use macros or inline functions from this file, or you compile this 24 file and link it with other works to produce a work based on this 25 file, this file does not by itself cause the resulting work to be 26 covered by the GNU General Public License. However the source code 27 for this file must still be made available in accordance with 28 section (3) of the GNU General Public License v2. 29 30 This exception does not invalidate any other reasons why a work 31 based on this file might be covered by the GNU General Public 32 License. 33 34 You should have received copies of the GNU Lesser General Public 35 License and the GNU General Public License along with this library; 36 if not, see <https://www.gnu.org/licenses/>. 37 */ 38 39 /** 40 * @file src/mhd2/tls_mbed_tls_lib.h 41 * @brief The wrapper for MbedTLS headers 42 * @author Karlson2k (Evgeny Grin) 43 */ 44 45 #ifndef MHD_TLS_MBED_TLS_LIB_H 46 #define MHD_TLS_MBED_TLS_LIB_H 1 47 48 #include "mhd_sys_options.h" 49 50 #ifndef MHD_SUPPORT_MBEDTLS 51 # error This header can be used only if MbedTLS is enabled 52 #endif 53 54 #ifndef __cplusplus 55 # define mhd_MBETLS_C_HDR_START /* Empty */ 56 # define mhd_MBETLS_C_HDR_FINISH /* Empty */ 57 #else /* __cplusplus */ 58 # define mhd_MBETLS_C_HDR_START extern "C" { 59 # define mhd_MBETLS_C_HDR_FINISH } 60 #endif /* __cplusplus */ 61 62 #include "microhttpd2_portability.h" 63 64 #if defined(MHD_WARN_IGNORE_STYLE_GCC) 65 MHD_WARN_PUSH_ 66 # ifdef HAVE_WZERO_AS_NULL_POINTER_CONSTANT 67 MHD_WARN_IGNORE_ ("-Wzero-as-null-pointer-constant") 68 # endif /* HAVE_WZERO_AS_NULL_POINTER_CONSTANT */ 69 # ifdef HAVE_WREDUNDANT_DECLS 70 MHD_WARN_IGNORE_ ("-Wredundant-decls") 71 # endif /* HAVE_WREDUNDANT_DECLS */ 72 # ifdef HAVE_WSWITCH_ENUM 73 MHD_WARN_IGNORE_ ("-Wswitch-enum") 74 # endif /* HAVE_WSWITCH_ENUM */ 75 # ifdef HAVE_WDOCUMENTATION_DEPRECATED_SYNC 76 MHD_WARN_IGNORE_ ("-Wdocumentation-deprecated-sync") 77 # endif /* HAVE_WDOCUMENTATION_DEPRECATED_SYNC */ 78 # ifdef HAVE_WDOCUMENTATION_UNKNOWN_COMMAND 79 MHD_WARN_IGNORE_ ("-Wdocumentation-unknown-command") 80 # endif /* HAVE_WDOCUMENTATION_UNKNOWN_COMMAND */ 81 # ifdef HAVE_WDOCUMENTATION_PEDANTIC 82 MHD_WARN_IGNORE_ ("-Wdocumentation-pedantic") 83 # endif /* HAVE_WDOCUMENTATION_PEDANTIC */ 84 # define mhd_RESTORE_MBEDTLS_MUTED_WARNS MHD_WARN_POP_ 85 #else /* ! MHD_WARN_IGNORE_STYLE_GCC */ 86 # define mhd_RESTORE_MBEDTLS_MUTED_WARNS /* empty */ 87 #endif /* ! MHD_WARN_IGNORE_STYLE_GCC */ 88 89 #include <mbedtls/build_info.h> 90 #include <mbedtls/platform.h> 91 #ifdef MBEDTLS_VERSION_C 92 # include <mbedtls/version.h> 93 #endif /* MBEDTLS_VERSION_C */ 94 95 #if ((MBEDTLS_VERSION_MAJOR + 0) < 3) 96 # error MbedTLS version 3.0 or later is required 97 #endif 98 #if ((MBEDTLS_VERSION_NUMBER + 0) < 0x03000000) 99 # error MbedTLS version 3.0 or later is required 100 #endif 101 102 /* #mhd_TLS_MBED_USE_PSA_FREE is MHD build-time user-definable macro */ 103 #if defined(MBEDTLS_PSA_CRYPTO_CLIENT) 104 # define mhd_TLS_MBED_USE_PSA 1 105 # ifdef MHD_TLS_MBED_USE_PSA_FREE 106 /* The application must not use MbedTLS directly */ 107 # define mhd_TLS_MBED_USE_PSA_FREE 1 108 # endif 109 #endif 110 111 #ifdef mhd_TLS_MBED_USE_PSA 112 # include <psa/crypto.h> 113 #endif /* mhd_TLS_MBED_USE_PSA */ 114 115 #ifdef MBEDTLS_MD_C 116 /* Actually MD must be available if TLS is enabled */ 117 # include <mbedtls/md.h> 118 #endif 119 120 #if ((MBEDTLS_VERSION_NUMBER + 0) >= 0x03050000) 121 # define mhd_TLS_MBED_HAS_SHA3_IDS 1 122 #endif 123 124 #ifdef MBEDTLS_ENTROPY_C 125 # include <mbedtls/entropy.h> 126 #endif /* MBEDTLS_ENTROPY_C */ 127 128 #ifdef mhd_TLS_MBED_USE_PSA 129 mhd_MBETLS_C_HDR_START 130 # include <mbedtls/psa_util.h> 131 mhd_MBETLS_C_HDR_FINISH 132 # define mhd_TLS_MBED_HAS_RNG_PSA 1 133 #elif defined(MHD_TLS_MBED_PREF_RNG_PSA) 134 # undef MHD_TLS_MBED_PREF_RNG_PSA 135 #endif 136 137 #ifdef MBEDTLS_HMAC_DRBG_C 138 # include <mbedtls/hmac_drbg.h> 139 # define mhd_TLS_MBED_HAS_RNG_HMAC 1 140 #elif defined(MHD_TLS_MBED_PREF_RNG_HMAC) 141 # undef MHD_TLS_MBED_PREF_RNG_HMAC 142 #endif /* MBEDTLS_HMAC_DRBG_C */ 143 144 #ifdef MBEDTLS_CTR_DRBG_C 145 # include <mbedtls/ctr_drbg.h> 146 # define mhd_TLS_MBED_HAS_RNG_CTR 1 147 #elif defined(MHD_TLS_MBED_PREF_RNG_CTR) 148 # undef MHD_TLS_MBED_PREF_RNG_CTR 149 #endif /* MBEDTLS_CTR_DRBG_C */ 150 151 #if !defined(MHD_TLS_MBED_PREF_RNG_PSA) && \ 152 !defined(MHD_TLS_MBED_PREF_RNG_HMAC) && \ 153 !defined(MHD_TLS_MBED_PREF_RNG_CTR) 154 # if defined(mhd_TLS_MBED_HAS_RNG_PSA) 155 # define MHD_TLS_MBED_PREF_RNG_PSA 1 156 # elif defined(mhd_TLS_MBED_HAS_RNG_HMAC) && \ 157 defined(MBEDTLS_MD_C) 158 # define MHD_TLS_MBED_PREF_RNG_HMAC 1 159 # define mhd_TLS_MBED_RNG_PREF_NEEDS_ENTROPY 1 160 # elif defined(mhd_TLS_MBED_HAS_RNG_CTR) 161 # define MHD_TLS_MBED_PREF_RNG_CTR 1 162 # define mhd_TLS_MBED_RNG_PREF_NEEDS_ENTROPY 1 163 # endif 164 #endif 165 166 #if defined(mhd_TLS_MBED_RNG_PREF_NEEDS_ENTROPY) && \ 167 defined(MBEDTLS_ENTROPY_C) 168 # define mhd_TLS_MBED_USE_LIB_ENTROPY 1 169 #endif 170 171 #if ((MBEDTLS_VERSION_NUMBER + 0) < 0x04000000) 172 /** 173 * TLS initialisation requires random generator 174 */ 175 # define mhd_TLS_MBED_INIT_TLS_REQ_RNG 1 176 #endif 177 178 #include <mbedtls/x509_crt.h> 179 180 #if !defined(MBEDTLS_X509_CRT_PARSE_C) 181 # error X.509 certificate parsing functions are required 182 #endif /* ! MBEDTLS_X509_CRT_PARSE_C */ 183 184 #include <mbedtls/pk.h> 185 186 #if !defined(MBEDTLS_PK_PARSE_C) 187 # error Public key parser is required 188 #endif /* ! MBEDTLS_PK_PARSE_C */ 189 190 #if !defined(MBEDTLS_PEM_PARSE_C) 191 # error PEM parser is required 192 #endif /* ! MBEDTLS_PEM_PARSE_C */ 193 194 /* Required header, checked in 'configure' */ 195 #include <mbedtls/ssl.h> 196 197 /* #MHD_TLS_MBED_SKIP_PLATFORM_SETUP and #MHD_TLS_MBED_USE_PLATFORM_TEARDOWN 198 are MHD build-time user-definable macros */ 199 /* User may set #MHD_TLS_MBED_SKIP_PLATFORM_SETUP and/or 200 #MHD_TLS_MBED_USE_PLATFORM_TEARDOWN when building MHD to control 201 automatic platform setup / teardown */ 202 #if defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT) && \ 203 !defined(MHD_TLS_MBED_SKIP_PLATFORM_SETUP) 204 # define mhd_TLS_MBED_HAS_PLATFORM_SETUP 1 205 # ifdef MHD_TLS_MBED_USE_PLATFORM_TEARDOWN 206 /* The application must not use MbedTLS directly */ 207 # define mhd_TLS_MBED_USE_PLATFORM_TEARDOWN 1 208 # endif 209 #endif 210 211 #ifdef MBEDTLS_NET_C 212 /* Actually, the header should be available unconditionally, but could be 213 accidently excluded if module is disabled. */ 214 # include <mbedtls/net_sockets.h> 215 #endif 216 217 #ifndef MBEDTLS_ERR_NET_RECV_FAILED 218 /* Unknown error when receiving the data */ 219 # define MBEDTLS_ERR_NET_RECV_FAILED (-0x004C) 220 #endif 221 #ifndef MBEDTLS_ERR_NET_SEND_FAILED 222 /* Unknown error when sending the data */ 223 # define MBEDTLS_ERR_NET_SEND_FAILED (-0x004E) 224 #endif 225 #ifndef MBEDTLS_ERR_NET_CONN_RESET 226 /* The network connection is broken */ 227 # define MBEDTLS_ERR_NET_CONN_RESET (-0x0050) 228 #endif 229 230 #ifdef MBEDTLS_DEBUG_C 231 # include <mbedtls/debug.h> 232 #endif 233 234 mhd_RESTORE_MBEDTLS_MUTED_WARNS 235 236 #endif /* ! MHD_TLS_MBED_TLS_LIB_H */