Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 1 | /* BEGIN_HEADER */ |
Valerio Setti | b4f5076 | 2024-01-17 10:24:52 +0100 | [diff] [blame] | 2 | #include "debug_internal.h" |
Mohammad Azim Khan | 67735d5 | 2017-04-06 11:55:43 +0100 | [diff] [blame] | 3 | #include "string.h" |
Valerio Setti | 1b08d42 | 2023-02-13 11:33:26 +0100 | [diff] [blame] | 4 | #include "mbedtls/pk.h" |
Yanray Wang | 5b60b42 | 2023-12-01 17:20:22 +0800 | [diff] [blame] | 5 | #include <test/ssl_helpers.h> |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 6 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 7 | struct buffer_data { |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 8 | char buf[2000]; |
| 9 | char *ptr; |
| 10 | }; |
| 11 | |
Bence Szépkúti | 1221052 | 2025-02-28 16:22:33 +0100 | [diff] [blame] | 12 | #if defined(MBEDTLS_SSL_TLS_C) |
Michael Schuster | 54300d4 | 2024-06-04 02:30:22 +0200 | [diff] [blame] | 13 | static void string_debug(void *data, int level, const char *file, int line, const char *str) |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 14 | { |
| 15 | struct buffer_data *buffer = (struct buffer_data *) data; |
Manuel Pégourié-Gonnard | fd47423 | 2015-06-23 16:34:24 +0200 | [diff] [blame] | 16 | char *p = buffer->ptr; |
Paul Bakker | 26b41a8 | 2011-07-13 14:53:58 +0000 | [diff] [blame] | 17 | ((void) level); |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 18 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 19 | memcpy(p, file, strlen(file)); |
| 20 | p += strlen(file); |
Manuel Pégourié-Gonnard | fd47423 | 2015-06-23 16:34:24 +0200 | [diff] [blame] | 21 | |
| 22 | *p++ = '('; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 23 | *p++ = '0' + (line / 1000) % 10; |
| 24 | *p++ = '0' + (line / 100) % 10; |
| 25 | *p++ = '0' + (line / 10) % 10; |
| 26 | *p++ = '0' + (line / 1) % 10; |
Manuel Pégourié-Gonnard | fd47423 | 2015-06-23 16:34:24 +0200 | [diff] [blame] | 27 | *p++ = ')'; |
| 28 | *p++ = ':'; |
| 29 | *p++ = ' '; |
| 30 | |
Manuel Pégourié-Gonnard | 7b23c51 | 2015-08-31 16:11:00 +0200 | [diff] [blame] | 31 | #if defined(MBEDTLS_THREADING_C) |
| 32 | /* Skip "thread ID" (up to the first space) as it is not predictable */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 33 | while (*str++ != ' ') { |
| 34 | ; |
| 35 | } |
Manuel Pégourié-Gonnard | 7b23c51 | 2015-08-31 16:11:00 +0200 | [diff] [blame] | 36 | #endif |
| 37 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 38 | memcpy(p, str, strlen(str)); |
| 39 | p += strlen(str); |
Paul Bakker | 92478c3 | 2014-04-25 15:18:34 +0200 | [diff] [blame] | 40 | |
| 41 | /* Detect if debug messages output partial lines and mark them */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 42 | if (p[-1] != '\n') { |
Manuel Pégourié-Gonnard | fd47423 | 2015-06-23 16:34:24 +0200 | [diff] [blame] | 43 | *p++ = '*'; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 44 | } |
Manuel Pégourié-Gonnard | fd47423 | 2015-06-23 16:34:24 +0200 | [diff] [blame] | 45 | |
| 46 | buffer->ptr = p; |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 47 | } |
Bence Szépkúti | 1221052 | 2025-02-28 16:22:33 +0100 | [diff] [blame] | 48 | #endif /* MBEDTLS_SSL_TLS_C */ |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 49 | /* END_HEADER */ |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 50 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 51 | /* BEGIN_DEPENDENCIES |
Bence Szépkúti | 1221052 | 2025-02-28 16:22:33 +0100 | [diff] [blame] | 52 | * depends_on:MBEDTLS_DEBUG_C |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 53 | * END_DEPENDENCIES |
| 54 | */ |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 55 | |
Bence Szépkúti | c6a8bf0 | 2025-02-28 22:32:15 +0100 | [diff] [blame^] | 56 | /* BEGIN_CASE */ |
| 57 | void printf_int_expr(intmax_t smuggle_format_expr, /* TODO: teach test framework about string expressions */ |
| 58 | intmax_t sizeof_x, intmax_t x, char *result) |
| 59 | { |
| 60 | const char *format = (char *) ((uintptr_t) smuggle_format_expr); |
| 61 | char *output = NULL; |
| 62 | const size_t n = strlen(result); |
| 63 | |
| 64 | /* Nominal case: buffer just large enough */ |
| 65 | TEST_CALLOC(output, n + 1); |
| 66 | if ((size_t) sizeof_x <= sizeof(int)) { // Any smaller integers would be promoted to an int due to calling a vararg function |
| 67 | TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, (int) x)); |
| 68 | } else if (sizeof_x == sizeof(long)) { |
| 69 | TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, (long) x)); |
| 70 | } else if (sizeof_x == sizeof(long long)) { |
| 71 | TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, (long long) x)); |
| 72 | } else { |
| 73 | TEST_FAIL( |
| 74 | "sizeof_x <= sizeof(int) || sizeof_x == sizeof(long) || sizeof_x == sizeof(long long)"); |
| 75 | } |
| 76 | TEST_MEMORY_COMPARE(result, n + 1, output, n + 1); |
| 77 | |
| 78 | exit: |
| 79 | mbedtls_free(output); |
| 80 | output = NULL; |
| 81 | } |
| 82 | /* END_CASE */ |
| 83 | |
Bence Szépkúti | 1221052 | 2025-02-28 16:22:33 +0100 | [diff] [blame] | 84 | /* BEGIN_CASE depends_on:MBEDTLS_SSL_TLS_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 85 | void debug_print_msg_threshold(int threshold, int level, char *file, |
| 86 | int line, char *result_str) |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 87 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 88 | mbedtls_ssl_context ssl; |
Manuel Pégourié-Gonnard | def0bbe | 2015-05-04 14:56:36 +0200 | [diff] [blame] | 89 | mbedtls_ssl_config conf; |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 90 | struct buffer_data buffer; |
| 91 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 92 | mbedtls_ssl_init(&ssl); |
| 93 | mbedtls_ssl_config_init(&conf); |
Valerio Setti | 3a994b7 | 2024-07-03 16:58:10 +0200 | [diff] [blame] | 94 | MD_OR_USE_PSA_INIT(); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 95 | memset(buffer.buf, 0, 2000); |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 96 | buffer.ptr = buffer.buf; |
| 97 | |
Yanray Wang | aad9449 | 2023-12-04 10:42:06 +0800 | [diff] [blame] | 98 | TEST_EQUAL(mbedtls_ssl_config_defaults(&conf, |
| 99 | MBEDTLS_SSL_IS_CLIENT, |
| 100 | MBEDTLS_SSL_TRANSPORT_STREAM, |
| 101 | MBEDTLS_SSL_PRESET_DEFAULT), |
| 102 | 0); |
Ronald Cron | aab4a54 | 2024-02-23 18:51:11 +0100 | [diff] [blame] | 103 | mbedtls_ssl_conf_rng(&conf, mbedtls_test_random, NULL); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 104 | mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer); |
Jerry Yu | b19ccc3 | 2021-08-09 17:44:56 +0800 | [diff] [blame] | 105 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 106 | TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0); |
Manuel Pégourié-Gonnard | d5a9e41 | 2015-05-04 11:11:42 +0200 | [diff] [blame] | 107 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 108 | mbedtls_debug_set_threshold(threshold); |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 109 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 110 | mbedtls_debug_print_msg(&ssl, level, file, line, |
| 111 | "Text message, 2 == %d", 2); |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 112 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 113 | TEST_ASSERT(strcmp(buffer.buf, result_str) == 0); |
Manuel Pégourié-Gonnard | d5a9e41 | 2015-05-04 11:11:42 +0200 | [diff] [blame] | 114 | |
| 115 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 116 | mbedtls_ssl_free(&ssl); |
| 117 | mbedtls_ssl_config_free(&conf); |
Valerio Setti | 8473390 | 2024-06-27 08:05:09 +0200 | [diff] [blame] | 118 | MD_OR_USE_PSA_DONE(); |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 119 | } |
| 120 | /* END_CASE */ |
| 121 | |
Bence Szépkúti | 1221052 | 2025-02-28 16:22:33 +0100 | [diff] [blame] | 122 | /* BEGIN_CASE depends_on:MBEDTLS_SSL_TLS_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 123 | void mbedtls_debug_print_ret(char *file, int line, char *text, int value, |
| 124 | char *result_str) |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 125 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 126 | mbedtls_ssl_context ssl; |
Manuel Pégourié-Gonnard | def0bbe | 2015-05-04 14:56:36 +0200 | [diff] [blame] | 127 | mbedtls_ssl_config conf; |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 128 | struct buffer_data buffer; |
| 129 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 130 | mbedtls_ssl_init(&ssl); |
| 131 | mbedtls_ssl_config_init(&conf); |
Valerio Setti | 3a994b7 | 2024-07-03 16:58:10 +0200 | [diff] [blame] | 132 | MD_OR_USE_PSA_INIT(); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 133 | memset(buffer.buf, 0, 2000); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 134 | buffer.ptr = buffer.buf; |
| 135 | |
Yanray Wang | aad9449 | 2023-12-04 10:42:06 +0800 | [diff] [blame] | 136 | TEST_EQUAL(mbedtls_ssl_config_defaults(&conf, |
| 137 | MBEDTLS_SSL_IS_CLIENT, |
| 138 | MBEDTLS_SSL_TRANSPORT_STREAM, |
| 139 | MBEDTLS_SSL_PRESET_DEFAULT), |
| 140 | 0); |
Ronald Cron | aab4a54 | 2024-02-23 18:51:11 +0100 | [diff] [blame] | 141 | mbedtls_ssl_conf_rng(&conf, mbedtls_test_random, NULL); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 142 | mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 143 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 144 | TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0); |
Jerry Yu | b19ccc3 | 2021-08-09 17:44:56 +0800 | [diff] [blame] | 145 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 146 | mbedtls_debug_print_ret(&ssl, 0, file, line, text, value); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 147 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 148 | TEST_ASSERT(strcmp(buffer.buf, result_str) == 0); |
Manuel Pégourié-Gonnard | d5a9e41 | 2015-05-04 11:11:42 +0200 | [diff] [blame] | 149 | |
| 150 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 151 | mbedtls_ssl_free(&ssl); |
| 152 | mbedtls_ssl_config_free(&conf); |
Valerio Setti | 8473390 | 2024-06-27 08:05:09 +0200 | [diff] [blame] | 153 | MD_OR_USE_PSA_DONE(); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 154 | } |
| 155 | /* END_CASE */ |
| 156 | |
Bence Szépkúti | 1221052 | 2025-02-28 16:22:33 +0100 | [diff] [blame] | 157 | /* BEGIN_CASE depends_on:MBEDTLS_SSL_TLS_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 158 | void mbedtls_debug_print_buf(char *file, int line, char *text, |
| 159 | data_t *data, char *result_str) |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 160 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 161 | mbedtls_ssl_context ssl; |
Manuel Pégourié-Gonnard | def0bbe | 2015-05-04 14:56:36 +0200 | [diff] [blame] | 162 | mbedtls_ssl_config conf; |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 163 | struct buffer_data buffer; |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 164 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 165 | mbedtls_ssl_init(&ssl); |
| 166 | mbedtls_ssl_config_init(&conf); |
Valerio Setti | 3a994b7 | 2024-07-03 16:58:10 +0200 | [diff] [blame] | 167 | MD_OR_USE_PSA_INIT(); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 168 | memset(buffer.buf, 0, 2000); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 169 | buffer.ptr = buffer.buf; |
| 170 | |
Yanray Wang | aad9449 | 2023-12-04 10:42:06 +0800 | [diff] [blame] | 171 | TEST_EQUAL(mbedtls_ssl_config_defaults(&conf, |
| 172 | MBEDTLS_SSL_IS_CLIENT, |
| 173 | MBEDTLS_SSL_TRANSPORT_STREAM, |
| 174 | MBEDTLS_SSL_PRESET_DEFAULT), |
| 175 | 0); |
Ronald Cron | aab4a54 | 2024-02-23 18:51:11 +0100 | [diff] [blame] | 176 | mbedtls_ssl_conf_rng(&conf, mbedtls_test_random, NULL); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 177 | mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 178 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 179 | TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0); |
Jerry Yu | b19ccc3 | 2021-08-09 17:44:56 +0800 | [diff] [blame] | 180 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 181 | mbedtls_debug_print_buf(&ssl, 0, file, line, text, data->x, data->len); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 182 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 183 | TEST_ASSERT(strcmp(buffer.buf, result_str) == 0); |
Manuel Pégourié-Gonnard | d5a9e41 | 2015-05-04 11:11:42 +0200 | [diff] [blame] | 184 | |
| 185 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 186 | mbedtls_ssl_free(&ssl); |
| 187 | mbedtls_ssl_config_free(&conf); |
Valerio Setti | 8473390 | 2024-06-27 08:05:09 +0200 | [diff] [blame] | 188 | MD_OR_USE_PSA_DONE(); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 189 | } |
| 190 | /* END_CASE */ |
| 191 | |
Bence Szépkúti | 1221052 | 2025-02-28 16:22:33 +0100 | [diff] [blame] | 192 | /* BEGIN_CASE depends_on:MBEDTLS_SSL_TLS_C:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 193 | void mbedtls_debug_print_crt(char *crt_file, char *file, int line, |
| 194 | char *prefix, char *result_str) |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 195 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 196 | mbedtls_x509_crt crt; |
| 197 | mbedtls_ssl_context ssl; |
Manuel Pégourié-Gonnard | def0bbe | 2015-05-04 14:56:36 +0200 | [diff] [blame] | 198 | mbedtls_ssl_config conf; |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 199 | struct buffer_data buffer; |
| 200 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 201 | mbedtls_ssl_init(&ssl); |
| 202 | mbedtls_ssl_config_init(&conf); |
| 203 | mbedtls_x509_crt_init(&crt); |
Valerio Setti | 92c3f36 | 2023-05-17 15:36:44 +0200 | [diff] [blame] | 204 | MD_OR_USE_PSA_INIT(); |
| 205 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 206 | memset(buffer.buf, 0, 2000); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 207 | buffer.ptr = buffer.buf; |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 208 | |
Yanray Wang | aad9449 | 2023-12-04 10:42:06 +0800 | [diff] [blame] | 209 | TEST_EQUAL(mbedtls_ssl_config_defaults(&conf, |
| 210 | MBEDTLS_SSL_IS_CLIENT, |
| 211 | MBEDTLS_SSL_TRANSPORT_STREAM, |
| 212 | MBEDTLS_SSL_PRESET_DEFAULT), |
| 213 | 0); |
Ronald Cron | aab4a54 | 2024-02-23 18:51:11 +0100 | [diff] [blame] | 214 | mbedtls_ssl_conf_rng(&conf, mbedtls_test_random, NULL); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 215 | mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer); |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 216 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 217 | TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0); |
Jerry Yu | b19ccc3 | 2021-08-09 17:44:56 +0800 | [diff] [blame] | 218 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 219 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0); |
| 220 | mbedtls_debug_print_crt(&ssl, 0, file, line, prefix, &crt); |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 221 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 222 | TEST_ASSERT(strcmp(buffer.buf, result_str) == 0); |
Paul Bakker | 58ef6ec | 2013-01-03 11:33:48 +0100 | [diff] [blame] | 223 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 224 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 225 | mbedtls_x509_crt_free(&crt); |
| 226 | mbedtls_ssl_free(&ssl); |
| 227 | mbedtls_ssl_config_free(&conf); |
Valerio Setti | 92c3f36 | 2023-05-17 15:36:44 +0200 | [diff] [blame] | 228 | MD_OR_USE_PSA_DONE(); |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 229 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 230 | /* END_CASE */ |
Paul Bakker | be4e7dc | 2011-03-14 20:41:31 +0000 | [diff] [blame] | 231 | |
Bence Szépkúti | 1221052 | 2025-02-28 16:22:33 +0100 | [diff] [blame] | 232 | /* BEGIN_CASE depends_on:MBEDTLS_SSL_TLS_C:MBEDTLS_BIGNUM_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 233 | void mbedtls_debug_print_mpi(char *value, char *file, int line, |
| 234 | char *prefix, char *result_str) |
Paul Bakker | be4e7dc | 2011-03-14 20:41:31 +0000 | [diff] [blame] | 235 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 236 | mbedtls_ssl_context ssl; |
Manuel Pégourié-Gonnard | def0bbe | 2015-05-04 14:56:36 +0200 | [diff] [blame] | 237 | mbedtls_ssl_config conf; |
Paul Bakker | be4e7dc | 2011-03-14 20:41:31 +0000 | [diff] [blame] | 238 | struct buffer_data buffer; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 239 | mbedtls_mpi val; |
Paul Bakker | be4e7dc | 2011-03-14 20:41:31 +0000 | [diff] [blame] | 240 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 241 | mbedtls_ssl_init(&ssl); |
| 242 | mbedtls_ssl_config_init(&conf); |
| 243 | mbedtls_mpi_init(&val); |
Valerio Setti | 3a994b7 | 2024-07-03 16:58:10 +0200 | [diff] [blame] | 244 | MD_OR_USE_PSA_INIT(); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 245 | memset(buffer.buf, 0, 2000); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 246 | buffer.ptr = buffer.buf; |
Paul Bakker | be4e7dc | 2011-03-14 20:41:31 +0000 | [diff] [blame] | 247 | |
Yanray Wang | aad9449 | 2023-12-04 10:42:06 +0800 | [diff] [blame] | 248 | TEST_EQUAL(mbedtls_ssl_config_defaults(&conf, |
| 249 | MBEDTLS_SSL_IS_CLIENT, |
| 250 | MBEDTLS_SSL_TRANSPORT_STREAM, |
| 251 | MBEDTLS_SSL_PRESET_DEFAULT), |
| 252 | 0); |
Ronald Cron | aab4a54 | 2024-02-23 18:51:11 +0100 | [diff] [blame] | 253 | mbedtls_ssl_conf_rng(&conf, mbedtls_test_random, NULL); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 254 | mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer); |
Jerry Yu | b19ccc3 | 2021-08-09 17:44:56 +0800 | [diff] [blame] | 255 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 256 | TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0); |
Manuel Pégourié-Gonnard | d5a9e41 | 2015-05-04 11:11:42 +0200 | [diff] [blame] | 257 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 258 | TEST_ASSERT(mbedtls_test_read_mpi(&val, value) == 0); |
Paul Bakker | eaebbd5 | 2014-04-25 15:04:14 +0200 | [diff] [blame] | 259 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 260 | mbedtls_debug_print_mpi(&ssl, 0, file, line, prefix, &val); |
Paul Bakker | be4e7dc | 2011-03-14 20:41:31 +0000 | [diff] [blame] | 261 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 262 | TEST_ASSERT(strcmp(buffer.buf, result_str) == 0); |
Paul Bakker | 6c591fa | 2011-05-05 11:49:20 +0000 | [diff] [blame] | 263 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 264 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 265 | mbedtls_mpi_free(&val); |
| 266 | mbedtls_ssl_free(&ssl); |
| 267 | mbedtls_ssl_config_free(&conf); |
Valerio Setti | 8473390 | 2024-06-27 08:05:09 +0200 | [diff] [blame] | 268 | MD_OR_USE_PSA_DONE(); |
Paul Bakker | be4e7dc | 2011-03-14 20:41:31 +0000 | [diff] [blame] | 269 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 270 | /* END_CASE */ |