Gilles Peskine | a3ed34f | 2021-01-05 21:11:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Common code for SSL test programs |
| 3 | * |
| 4 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 5 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Gilles Peskine | a3ed34f | 2021-01-05 21:11:16 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef MBEDTLS_PROGRAMS_SSL_SSL_TEST_LIB_H |
| 9 | #define MBEDTLS_PROGRAMS_SSL_SSL_TEST_LIB_H |
| 10 | |
Bence Szépkúti | c662b36 | 2021-05-27 11:25:03 +0200 | [diff] [blame] | 11 | #include "mbedtls/build_info.h" |
Gilles Peskine | ab7ce96 | 2021-01-05 21:27:53 +0100 | [diff] [blame] | 12 | |
Gilles Peskine | ab7ce96 | 2021-01-05 21:27:53 +0100 | [diff] [blame] | 13 | #include "mbedtls/platform.h" |
Manuel Pégourié-Gonnard | 23fc437 | 2023-03-17 13:34:11 +0100 | [diff] [blame] | 14 | #include "mbedtls/md.h" |
Gilles Peskine | ab7ce96 | 2021-01-05 21:27:53 +0100 | [diff] [blame] | 15 | |
Gilles Peskine | 8133abd | 2021-02-08 21:20:12 +0100 | [diff] [blame] | 16 | #undef HAVE_RNG |
Ben Taylor | 4bb98be | 2025-05-07 14:21:20 +0100 | [diff] [blame] | 17 | #if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) || \ |
| 18 | defined(MBEDTLS_TEST_USE_PSA_CRYPTO_RNG) |
Gilles Peskine | 8133abd | 2021-02-08 21:20:12 +0100 | [diff] [blame] | 19 | #define HAVE_RNG |
| 20 | #elif defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_CTR_DRBG_C) |
| 21 | #define HAVE_RNG |
| 22 | #elif defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_HMAC_DRBG_C) && \ |
Gabor Mezei | c15ef93 | 2024-06-13 12:53:54 +0200 | [diff] [blame] | 23 | (defined(PSA_WANT_ALG_SHA_256) || defined(PSA_WANT_ALG_SHA_512)) |
Gilles Peskine | 8133abd | 2021-02-08 21:20:12 +0100 | [diff] [blame] | 24 | #define HAVE_RNG |
| 25 | #endif |
| 26 | |
| 27 | #if !defined(MBEDTLS_NET_C) || \ |
Andrzej Kurek | 03e0146 | 2022-01-03 12:53:24 +0100 | [diff] [blame] | 28 | !defined(MBEDTLS_SSL_TLS_C) |
| 29 | #define MBEDTLS_SSL_TEST_IMPOSSIBLE \ |
| 30 | "MBEDTLS_NET_C and/or " \ |
| 31 | "MBEDTLS_SSL_TLS_C not defined." |
Gilles Peskine | 8133abd | 2021-02-08 21:20:12 +0100 | [diff] [blame] | 32 | #elif !defined(HAVE_RNG) |
Andrzej Kurek | 03e0146 | 2022-01-03 12:53:24 +0100 | [diff] [blame] | 33 | #define MBEDTLS_SSL_TEST_IMPOSSIBLE \ |
Gilles Peskine | 8133abd | 2021-02-08 21:20:12 +0100 | [diff] [blame] | 34 | "No random generator is available.\n" |
Gilles Peskine | ab7ce96 | 2021-01-05 21:27:53 +0100 | [diff] [blame] | 35 | #else |
| 36 | #undef MBEDTLS_SSL_TEST_IMPOSSIBLE |
Gilles Peskine | 67638d6 | 2021-01-05 21:36:29 +0100 | [diff] [blame] | 37 | |
Gilles Peskine | 8133abd | 2021-02-08 21:20:12 +0100 | [diff] [blame] | 38 | #undef HAVE_RNG |
| 39 | |
Gilles Peskine | 67638d6 | 2021-01-05 21:36:29 +0100 | [diff] [blame] | 40 | #include <stdio.h> |
| 41 | #include <stdlib.h> |
| 42 | #include <string.h> |
| 43 | |
| 44 | #include "mbedtls/net_sockets.h" |
| 45 | #include "mbedtls/ssl.h" |
Glenn Strauss | 6eef563 | 2022-01-23 08:37:02 -0500 | [diff] [blame] | 46 | #include "mbedtls/ssl_ciphersuites.h" |
Gilles Peskine | 67638d6 | 2021-01-05 21:36:29 +0100 | [diff] [blame] | 47 | #include "mbedtls/entropy.h" |
| 48 | #include "mbedtls/ctr_drbg.h" |
Gilles Peskine | ba74904 | 2021-01-13 20:02:03 +0100 | [diff] [blame] | 49 | #include "mbedtls/hmac_drbg.h" |
Gilles Peskine | 67638d6 | 2021-01-05 21:36:29 +0100 | [diff] [blame] | 50 | #include "mbedtls/x509.h" |
| 51 | #include "mbedtls/error.h" |
| 52 | #include "mbedtls/debug.h" |
| 53 | #include "mbedtls/timing.h" |
| 54 | #include "mbedtls/base64.h" |
Mateusz Starzyk | 1aec646 | 2021-02-08 15:34:42 +0100 | [diff] [blame] | 55 | #include "test/certs.h" |
Gilles Peskine | 67638d6 | 2021-01-05 21:36:29 +0100 | [diff] [blame] | 56 | |
Gilles Peskine | 67638d6 | 2021-01-05 21:36:29 +0100 | [diff] [blame] | 57 | #include "psa/crypto.h" |
| 58 | #include "mbedtls/psa_util.h" |
Gilles Peskine | ab7ce96 | 2021-01-05 21:27:53 +0100 | [diff] [blame] | 59 | |
Gilles Peskine | 67638d6 | 2021-01-05 21:36:29 +0100 | [diff] [blame] | 60 | #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) |
| 61 | #include "mbedtls/memory_buffer_alloc.h" |
| 62 | #endif |
| 63 | |
| 64 | #include <test/helpers.h> |
| 65 | |
Harry Ramsey | c19b8e8 | 2025-02-11 14:14:00 +0000 | [diff] [blame] | 66 | #include "query_config.h" |
Gilles Peskine | 7c818d6 | 2021-01-05 22:33:13 +0100 | [diff] [blame] | 67 | |
Przemek Stekiel | da4fba6 | 2023-06-02 14:52:28 +0200 | [diff] [blame] | 68 | #define ALPN_LIST_SIZE 10 |
Przemek Stekiel | 45255e4 | 2023-06-29 13:56:36 +0200 | [diff] [blame] | 69 | #define GROUP_LIST_SIZE 25 |
Przemek Stekiel | da4fba6 | 2023-06-02 14:52:28 +0200 | [diff] [blame] | 70 | #define SIG_ALG_LIST_SIZE 5 |
| 71 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 72 | typedef struct eap_tls_keys { |
Gilles Peskine | 7c818d6 | 2021-01-05 22:33:13 +0100 | [diff] [blame] | 73 | unsigned char master_secret[48]; |
| 74 | unsigned char randbytes[64]; |
| 75 | mbedtls_tls_prf_types tls_prf_type; |
| 76 | } eap_tls_keys; |
| 77 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 78 | #if defined(MBEDTLS_SSL_DTLS_SRTP) |
Gilles Peskine | 7c818d6 | 2021-01-05 22:33:13 +0100 | [diff] [blame] | 79 | |
| 80 | /* Supported SRTP mode needs a maximum of : |
| 81 | * - 16 bytes for key (AES-128) |
| 82 | * - 14 bytes SALT |
| 83 | * One for sender, one for receiver context |
| 84 | */ |
| 85 | #define MBEDTLS_TLS_SRTP_MAX_KEY_MATERIAL_LENGTH 60 |
| 86 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 87 | typedef struct dtls_srtp_keys { |
Gilles Peskine | 7c818d6 | 2021-01-05 22:33:13 +0100 | [diff] [blame] | 88 | unsigned char master_secret[48]; |
| 89 | unsigned char randbytes[64]; |
| 90 | mbedtls_tls_prf_types tls_prf_type; |
| 91 | } dtls_srtp_keys; |
| 92 | |
| 93 | #endif /* MBEDTLS_SSL_DTLS_SRTP */ |
| 94 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 95 | typedef struct { |
Gilles Peskine | 7c818d6 | 2021-01-05 22:33:13 +0100 | [diff] [blame] | 96 | mbedtls_ssl_context *ssl; |
| 97 | mbedtls_net_context *net; |
| 98 | } io_ctx_t; |
| 99 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 100 | void my_debug(void *ctx, int level, |
| 101 | const char *file, int line, |
| 102 | const char *str); |
Gilles Peskine | 67638d6 | 2021-01-05 21:36:29 +0100 | [diff] [blame] | 103 | |
Raoul Strackx | 9ed9bc9 | 2020-06-22 14:08:57 +0200 | [diff] [blame] | 104 | #if defined(MBEDTLS_HAVE_TIME) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 105 | mbedtls_time_t dummy_constant_time(mbedtls_time_t *time); |
Raoul Strackx | 9ed9bc9 | 2020-06-22 14:08:57 +0200 | [diff] [blame] | 106 | #endif |
Gilles Peskine | 504c1a3 | 2021-01-05 23:40:14 +0100 | [diff] [blame] | 107 | |
Ben Taylor | 4bb98be | 2025-05-07 14:21:20 +0100 | [diff] [blame] | 108 | #if !defined(MBEDTLS_TEST_USE_PSA_CRYPTO_RNG) |
Gilles Peskine | 8eb2943 | 2021-02-03 20:07:11 +0100 | [diff] [blame] | 109 | /* If MBEDTLS_TEST_USE_PSA_CRYPTO_RNG is defined, the SSL test programs will use |
| 110 | * mbedtls_psa_get_random() rather than entropy+DRBG as a random generator. |
| 111 | * |
| 112 | * The constraints are: |
| 113 | * - Without the entropy module, the PSA RNG is the only option. |
| 114 | * - Without at least one of the DRBG modules, the PSA RNG is the only option. |
| 115 | * - The PSA RNG does not support explicit seeding, so it is incompatible with |
| 116 | * the reproducible mode used by test programs. |
| 117 | * - For good overall test coverage, there should be at least one configuration |
| 118 | * where the test programs use the PSA RNG while the PSA RNG is itself based |
| 119 | * on entropy+DRBG, and at least one configuration where the test programs |
| 120 | * do not use the PSA RNG even though it's there. |
Gilles Peskine | 8eb2943 | 2021-02-03 20:07:11 +0100 | [diff] [blame] | 121 | */ |
| 122 | #define MBEDTLS_TEST_USE_PSA_CRYPTO_RNG |
| 123 | #endif |
| 124 | |
Gilles Peskine | daa94c4 | 2021-01-13 18:38:27 +0100 | [diff] [blame] | 125 | /** A context for random number generation (RNG). |
Gilles Peskine | 8a8492b | 2021-01-13 18:17:32 +0100 | [diff] [blame] | 126 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 127 | typedef struct { |
Gilles Peskine | 8eb2943 | 2021-02-03 20:07:11 +0100 | [diff] [blame] | 128 | #if defined(MBEDTLS_TEST_USE_PSA_CRYPTO_RNG) |
| 129 | unsigned char dummy; |
| 130 | #else /* MBEDTLS_TEST_USE_PSA_CRYPTO_RNG */ |
Gilles Peskine | 8a8492b | 2021-01-13 18:17:32 +0100 | [diff] [blame] | 131 | mbedtls_entropy_context entropy; |
Gilles Peskine | ba74904 | 2021-01-13 20:02:03 +0100 | [diff] [blame] | 132 | #if defined(MBEDTLS_CTR_DRBG_C) |
Gilles Peskine | 8a8492b | 2021-01-13 18:17:32 +0100 | [diff] [blame] | 133 | mbedtls_ctr_drbg_context drbg; |
Gilles Peskine | ba74904 | 2021-01-13 20:02:03 +0100 | [diff] [blame] | 134 | #elif defined(MBEDTLS_HMAC_DRBG_C) |
| 135 | mbedtls_hmac_drbg_context drbg; |
| 136 | #else |
| 137 | #error "No DRBG available" |
| 138 | #endif |
Gilles Peskine | 8eb2943 | 2021-02-03 20:07:11 +0100 | [diff] [blame] | 139 | #endif /* MBEDTLS_TEST_USE_PSA_CRYPTO_RNG */ |
Gilles Peskine | 8a8492b | 2021-01-13 18:17:32 +0100 | [diff] [blame] | 140 | } rng_context_t; |
| 141 | |
Gilles Peskine | daa94c4 | 2021-01-13 18:38:27 +0100 | [diff] [blame] | 142 | /** Initialize the RNG. |
| 143 | * |
| 144 | * This function only initializes the memory used by the RNG context. |
| 145 | * Before using the RNG, it must be seeded with rng_seed(). |
| 146 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 147 | void rng_init(rng_context_t *rng); |
Gilles Peskine | daa94c4 | 2021-01-13 18:38:27 +0100 | [diff] [blame] | 148 | |
| 149 | /* Seed the random number generator. |
| 150 | * |
| 151 | * \param rng The RNG context to use. It must have been initialized |
| 152 | * with rng_init(). |
| 153 | * \param reproducible If zero, seed the RNG from entropy. |
| 154 | * If nonzero, use a fixed seed, so that the program |
| 155 | * will produce the same sequence of random numbers |
| 156 | * each time it is invoked. |
| 157 | * \param pers A null-terminated string. Different values for this |
| 158 | * string cause the RNG to emit different output for |
| 159 | * the same seed. |
| 160 | * |
| 161 | * return 0 on success, a negative value on error. |
| 162 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 163 | int rng_seed(rng_context_t *rng, int reproducible, const char *pers); |
Gilles Peskine | daa94c4 | 2021-01-13 18:38:27 +0100 | [diff] [blame] | 164 | |
| 165 | /** Deinitialize the RNG. Free any embedded resource. |
| 166 | * |
| 167 | * \param rng The RNG context to deinitialize. It must have been |
| 168 | * initialized with rng_init(). |
| 169 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 170 | void rng_free(rng_context_t *rng); |
Gilles Peskine | daa94c4 | 2021-01-13 18:38:27 +0100 | [diff] [blame] | 171 | |
Gilles Peskine | 535fb37 | 2021-01-13 18:59:46 +0100 | [diff] [blame] | 172 | /** Generate random data. |
| 173 | * |
| 174 | * This function is suitable for use as the \c f_rng argument to Mbed TLS |
| 175 | * library functions. |
| 176 | * |
Gilles Peskine | da9529f | 2021-01-25 13:42:42 +0100 | [diff] [blame] | 177 | * \param p_rng The random generator context. This must be a pointer to |
| 178 | * a #rng_context_t structure. |
Gilles Peskine | 535fb37 | 2021-01-13 18:59:46 +0100 | [diff] [blame] | 179 | * \param output The buffer to fill. |
| 180 | * \param output_len The length of the buffer in bytes. |
| 181 | * |
| 182 | * \return \c 0 on success. |
| 183 | * \return An Mbed TLS error code on error. |
| 184 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 185 | int rng_get(void *p_rng, unsigned char *output, size_t output_len); |
Gilles Peskine | 535fb37 | 2021-01-13 18:59:46 +0100 | [diff] [blame] | 186 | |
Przemek Stekiel | 85d692d | 2022-04-25 12:42:55 +0200 | [diff] [blame] | 187 | /** Parse command-line option: key_opaque_algs |
| 188 | * |
| 189 | * |
| 190 | * \param arg String value of key_opaque_algs |
| 191 | * Coma-separated pair of values among the following: |
| 192 | * - "rsa-sign-pkcs1" |
| 193 | * - "rsa-sign-pss" |
Przemek Stekiel | 85d692d | 2022-04-25 12:42:55 +0200 | [diff] [blame] | 194 | * - "ecdsa-sign" |
| 195 | * - "ecdh" |
| 196 | * - "none" (only acceptable for the second value). |
| 197 | * \param alg1 Address of pointer to alg #1 |
| 198 | * \param alg2 Address of pointer to alg #2 |
| 199 | * |
| 200 | * \return \c 0 on success. |
| 201 | * \return \c 1 on parse failure. |
| 202 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 203 | int key_opaque_alg_parse(const char *arg, const char **alg1, const char **alg2); |
Przemek Stekiel | 85d692d | 2022-04-25 12:42:55 +0200 | [diff] [blame] | 204 | |
bootstrap-prime | 6dbbf44 | 2022-05-17 19:30:44 -0400 | [diff] [blame] | 205 | /** Parse given opaque key algorithms to obtain psa algs and usage |
Przemek Stekiel | 01396a1 | 2022-05-02 13:41:53 +0200 | [diff] [blame] | 206 | * that will be passed to mbedtls_pk_wrap_as_opaque(). |
| 207 | * |
| 208 | * |
| 209 | * \param alg1 input string opaque key algorithm #1 |
Przemek Stekiel | cb20d20 | 2022-05-06 08:42:34 +0200 | [diff] [blame] | 210 | * \param alg2 input string opaque key algorithm #2 |
Przemek Stekiel | 01396a1 | 2022-05-02 13:41:53 +0200 | [diff] [blame] | 211 | * \param psa_alg1 output PSA algorithm #1 |
| 212 | * \param psa_alg2 output PSA algorithm #2 |
| 213 | * \param usage output key usage |
Przemek Stekiel | cb20d20 | 2022-05-06 08:42:34 +0200 | [diff] [blame] | 214 | * \param key_type key type used to set default psa algorithm/usage |
| 215 | * when alg1 in "none" |
Przemek Stekiel | 01396a1 | 2022-05-02 13:41:53 +0200 | [diff] [blame] | 216 | * |
| 217 | * \return \c 0 on success. |
| 218 | * \return \c 1 on parse failure. |
| 219 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 220 | int key_opaque_set_alg_usage(const char *alg1, const char *alg2, |
| 221 | psa_algorithm_t *psa_alg1, |
| 222 | psa_algorithm_t *psa_alg2, |
| 223 | psa_key_usage_t *usage, |
| 224 | mbedtls_pk_type_t key_type); |
Valerio Setti | 7541ebe | 2024-02-27 10:44:33 +0100 | [diff] [blame] | 225 | |
Valerio Setti | 90eca2a | 2024-02-28 10:45:43 +0100 | [diff] [blame] | 226 | #if defined(MBEDTLS_PK_C) |
Valerio Setti | 7541ebe | 2024-02-27 10:44:33 +0100 | [diff] [blame] | 227 | /** Turn a non-opaque PK context into an opaque one with folowing steps: |
| 228 | * - extract the key data and attributes from the PK context. |
| 229 | * - import the key material into PSA. |
| 230 | * - free the provided PK context and re-initilize it as an opaque PK context |
| 231 | * wrapping the PSA key imported in the above step. |
| 232 | * |
Gilles Peskine | 2e5a7ea | 2025-02-12 23:11:09 +0100 | [diff] [blame] | 233 | * \param[in,out] pk On input, the non-opaque PK context which contains the |
| 234 | * key to be wrapped. On output, the re-initialized PK |
Valerio Setti | 7541ebe | 2024-02-27 10:44:33 +0100 | [diff] [blame] | 235 | * context which represents the opaque version of the one |
| 236 | * provided as input. |
| 237 | * \param[in] psa_alg The primary algorithm that will be associated to the |
| 238 | * PSA key. |
| 239 | * \param[in] psa_alg2 The enrollment algorithm that will be associated to the |
| 240 | * PSA key. |
| 241 | * \param[in] psa_usage The PSA key usage policy. |
| 242 | * \param[out] key_id The PSA key identifier of the imported key. |
| 243 | * |
| 244 | * \return \c 0 on sucess. |
| 245 | * \return \c -1 on failure. |
| 246 | */ |
| 247 | int pk_wrap_as_opaque(mbedtls_pk_context *pk, psa_algorithm_t psa_alg, psa_algorithm_t psa_alg2, |
| 248 | psa_key_usage_t psa_usage, mbedtls_svc_key_id_t *key_id); |
Valerio Setti | 90eca2a | 2024-02-28 10:45:43 +0100 | [diff] [blame] | 249 | #endif /* MBEDTLS_PK_C */ |
Przemek Stekiel | 01396a1 | 2022-05-02 13:41:53 +0200 | [diff] [blame] | 250 | |
Ben Taylor | 4bb98be | 2025-05-07 14:21:20 +0100 | [diff] [blame] | 251 | #if defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) |
Gilles Peskine | 2146211 | 2021-01-13 23:53:09 +0100 | [diff] [blame] | 252 | /* The test implementation of the PSA external RNG is insecure. When |
| 253 | * MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG is enabled, before using any PSA crypto |
| 254 | * function that makes use of an RNG, you must call |
| 255 | * mbedtls_test_enable_insecure_external_rng(). */ |
Gilles Peskine | 1af872d | 2021-01-20 20:02:01 +0100 | [diff] [blame] | 256 | #include <test/fake_external_rng_for_test.h> |
Gilles Peskine | 2146211 | 2021-01-13 23:53:09 +0100 | [diff] [blame] | 257 | #endif |
Gilles Peskine | 504c1a3 | 2021-01-05 23:40:14 +0100 | [diff] [blame] | 258 | |
| 259 | #if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 260 | int ca_callback(void *data, mbedtls_x509_crt const *child, |
| 261 | mbedtls_x509_crt **candidates); |
Gilles Peskine | 504c1a3 | 2021-01-05 23:40:14 +0100 | [diff] [blame] | 262 | #endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */ |
| 263 | |
| 264 | /* |
| 265 | * Test recv/send functions that make sure each try returns |
Shaun Case | 8b0ecbc | 2021-12-20 21:14:10 -0800 | [diff] [blame] | 266 | * WANT_READ/WANT_WRITE at least once before succeeding |
Gilles Peskine | 504c1a3 | 2021-01-05 23:40:14 +0100 | [diff] [blame] | 267 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 268 | int delayed_recv(void *ctx, unsigned char *buf, size_t len); |
| 269 | int delayed_send(void *ctx, const unsigned char *buf, size_t len); |
Gilles Peskine | 504c1a3 | 2021-01-05 23:40:14 +0100 | [diff] [blame] | 270 | |
| 271 | /* |
| 272 | * Wait for an event from the underlying transport or the timer |
| 273 | * (Used in event-driven IO mode). |
| 274 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 275 | int idle(mbedtls_net_context *fd, |
Gilles Peskine | 504c1a3 | 2021-01-05 23:40:14 +0100 | [diff] [blame] | 276 | #if defined(MBEDTLS_TIMING_C) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 277 | mbedtls_timing_delay_context *timer, |
Gilles Peskine | 504c1a3 | 2021-01-05 23:40:14 +0100 | [diff] [blame] | 278 | #endif |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 279 | int idle_reason); |
Gilles Peskine | 504c1a3 | 2021-01-05 23:40:14 +0100 | [diff] [blame] | 280 | |
Gilles Peskine | 53dea74 | 2021-02-02 22:55:06 +0100 | [diff] [blame] | 281 | #if defined(MBEDTLS_TEST_HOOKS) |
| 282 | /** Initialize whatever test hooks are enabled by the compile-time |
| 283 | * configuration and make sense for the TLS test programs. */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 284 | void test_hooks_init(void); |
Gilles Peskine | 53dea74 | 2021-02-02 22:55:06 +0100 | [diff] [blame] | 285 | |
| 286 | /** Check if any test hooks detected a problem. |
| 287 | * |
Gilles Peskine | 00d0ad4 | 2021-02-15 11:02:51 +0100 | [diff] [blame] | 288 | * If a problem was detected, it's ok for the calling program to keep going, |
| 289 | * but it should ultimately exit with an error status. |
| 290 | * |
| 291 | * \note When implementing a test hook that detects errors on its own |
| 292 | * (as opposed to e.g. leaving the error for a memory sanitizer to |
| 293 | * report), make sure to print a message to standard error either at |
| 294 | * the time the problem is detected or during the execution of this |
| 295 | * function. This function does not indicate what problem was detected, |
| 296 | * so printing a message is the only way to provide feedback in the |
| 297 | * logs of the calling program. |
Gilles Peskine | 53dea74 | 2021-02-02 22:55:06 +0100 | [diff] [blame] | 298 | * |
| 299 | * \return Nonzero if a problem was detected. |
| 300 | * \c 0 if no problem was detected. |
| 301 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 302 | int test_hooks_failure_detected(void); |
Gilles Peskine | 53dea74 | 2021-02-02 22:55:06 +0100 | [diff] [blame] | 303 | |
| 304 | /** Free any resources allocated for the sake of test hooks. |
| 305 | * |
| 306 | * Call this at the end of the program so that resource leak analyzers |
| 307 | * don't complain. |
| 308 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 309 | void test_hooks_free(void); |
Gilles Peskine | 53dea74 | 2021-02-02 22:55:06 +0100 | [diff] [blame] | 310 | |
Gilles Peskine | 53dea74 | 2021-02-02 22:55:06 +0100 | [diff] [blame] | 311 | #endif /* !MBEDTLS_TEST_HOOKS */ |
| 312 | |
Przemek Stekiel | e7db09b | 2023-05-31 11:29:55 +0200 | [diff] [blame] | 313 | /* Helper functions for FFDH groups. */ |
Przemek Stekiel | 68e7544 | 2023-07-06 11:21:39 +0200 | [diff] [blame] | 314 | int parse_groups(const char *groups, uint16_t *group_list, size_t group_list_len); |
Przemek Stekiel | e7db09b | 2023-05-31 11:29:55 +0200 | [diff] [blame] | 315 | |
Gilles Peskine | 504c1a3 | 2021-01-05 23:40:14 +0100 | [diff] [blame] | 316 | #endif /* MBEDTLS_SSL_TEST_IMPOSSIBLE conditions: else */ |
Gilles Peskine | a3ed34f | 2021-01-05 21:11:16 +0100 | [diff] [blame] | 317 | #endif /* MBEDTLS_PROGRAMS_SSL_SSL_TEST_LIB_H */ |