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 | |
Manuel Pégourié-Gonnard | fd47423 | 2015-06-23 16:34:24 +0200 | [diff] [blame] | 12 | 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] | 13 | { |
| 14 | struct buffer_data *buffer = (struct buffer_data *) data; |
Manuel Pégourié-Gonnard | fd47423 | 2015-06-23 16:34:24 +0200 | [diff] [blame] | 15 | char *p = buffer->ptr; |
Paul Bakker | 26b41a8 | 2011-07-13 14:53:58 +0000 | [diff] [blame] | 16 | ((void) level); |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 17 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 18 | memcpy(p, file, strlen(file)); |
| 19 | p += strlen(file); |
Manuel Pégourié-Gonnard | fd47423 | 2015-06-23 16:34:24 +0200 | [diff] [blame] | 20 | |
| 21 | *p++ = '('; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 22 | *p++ = '0' + (line / 1000) % 10; |
| 23 | *p++ = '0' + (line / 100) % 10; |
| 24 | *p++ = '0' + (line / 10) % 10; |
| 25 | *p++ = '0' + (line / 1) % 10; |
Manuel Pégourié-Gonnard | fd47423 | 2015-06-23 16:34:24 +0200 | [diff] [blame] | 26 | *p++ = ')'; |
| 27 | *p++ = ':'; |
| 28 | *p++ = ' '; |
| 29 | |
Manuel Pégourié-Gonnard | 7b23c51 | 2015-08-31 16:11:00 +0200 | [diff] [blame] | 30 | #if defined(MBEDTLS_THREADING_C) |
| 31 | /* 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] | 32 | while (*str++ != ' ') { |
| 33 | ; |
| 34 | } |
Manuel Pégourié-Gonnard | 7b23c51 | 2015-08-31 16:11:00 +0200 | [diff] [blame] | 35 | #endif |
| 36 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 37 | memcpy(p, str, strlen(str)); |
| 38 | p += strlen(str); |
Paul Bakker | 92478c3 | 2014-04-25 15:18:34 +0200 | [diff] [blame] | 39 | |
| 40 | /* Detect if debug messages output partial lines and mark them */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 41 | if (p[-1] != '\n') { |
Manuel Pégourié-Gonnard | fd47423 | 2015-06-23 16:34:24 +0200 | [diff] [blame] | 42 | *p++ = '*'; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 43 | } |
Manuel Pégourié-Gonnard | fd47423 | 2015-06-23 16:34:24 +0200 | [diff] [blame] | 44 | |
| 45 | buffer->ptr = p; |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 46 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 47 | /* END_HEADER */ |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 48 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 49 | /* BEGIN_DEPENDENCIES |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 50 | * depends_on:MBEDTLS_DEBUG_C:MBEDTLS_SSL_TLS_C |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 51 | * END_DEPENDENCIES |
| 52 | */ |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 53 | |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 54 | /* BEGIN_CASE */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 55 | void debug_print_msg_threshold(int threshold, int level, char *file, |
| 56 | int line, char *result_str) |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 57 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 58 | mbedtls_ssl_context ssl; |
Manuel Pégourié-Gonnard | def0bbe | 2015-05-04 14:56:36 +0200 | [diff] [blame] | 59 | mbedtls_ssl_config conf; |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 60 | struct buffer_data buffer; |
| 61 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 62 | mbedtls_ssl_init(&ssl); |
| 63 | mbedtls_ssl_config_init(&conf); |
Valerio Setti | 3a994b7 | 2024-07-03 16:58:10 +0200 | [diff] [blame] | 64 | MD_OR_USE_PSA_INIT(); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 65 | memset(buffer.buf, 0, 2000); |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 66 | buffer.ptr = buffer.buf; |
| 67 | |
Yanray Wang | aad9449 | 2023-12-04 10:42:06 +0800 | [diff] [blame] | 68 | TEST_EQUAL(mbedtls_ssl_config_defaults(&conf, |
| 69 | MBEDTLS_SSL_IS_CLIENT, |
| 70 | MBEDTLS_SSL_TRANSPORT_STREAM, |
| 71 | MBEDTLS_SSL_PRESET_DEFAULT), |
| 72 | 0); |
Ronald Cron | aab4a54 | 2024-02-23 18:51:11 +0100 | [diff] [blame] | 73 | mbedtls_ssl_conf_rng(&conf, mbedtls_test_random, NULL); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 74 | mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer); |
Jerry Yu | b19ccc3 | 2021-08-09 17:44:56 +0800 | [diff] [blame] | 75 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 76 | TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0); |
Manuel Pégourié-Gonnard | d5a9e41 | 2015-05-04 11:11:42 +0200 | [diff] [blame] | 77 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 78 | mbedtls_debug_set_threshold(threshold); |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 79 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 80 | mbedtls_debug_print_msg(&ssl, level, file, line, |
| 81 | "Text message, 2 == %d", 2); |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 82 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 83 | TEST_ASSERT(strcmp(buffer.buf, result_str) == 0); |
Manuel Pégourié-Gonnard | d5a9e41 | 2015-05-04 11:11:42 +0200 | [diff] [blame] | 84 | |
| 85 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 86 | mbedtls_ssl_free(&ssl); |
| 87 | mbedtls_ssl_config_free(&conf); |
Valerio Setti | 8473390 | 2024-06-27 08:05:09 +0200 | [diff] [blame] | 88 | MD_OR_USE_PSA_DONE(); |
Paul Bakker | c73079a | 2014-04-25 16:34:30 +0200 | [diff] [blame] | 89 | } |
| 90 | /* END_CASE */ |
| 91 | |
| 92 | /* BEGIN_CASE */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 93 | void mbedtls_debug_print_ret(char *file, int line, char *text, int value, |
| 94 | char *result_str) |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 95 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 96 | mbedtls_ssl_context ssl; |
Manuel Pégourié-Gonnard | def0bbe | 2015-05-04 14:56:36 +0200 | [diff] [blame] | 97 | mbedtls_ssl_config conf; |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 98 | struct buffer_data buffer; |
| 99 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 100 | mbedtls_ssl_init(&ssl); |
| 101 | mbedtls_ssl_config_init(&conf); |
Valerio Setti | 3a994b7 | 2024-07-03 16:58:10 +0200 | [diff] [blame] | 102 | MD_OR_USE_PSA_INIT(); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 103 | memset(buffer.buf, 0, 2000); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 104 | buffer.ptr = buffer.buf; |
| 105 | |
Yanray Wang | aad9449 | 2023-12-04 10:42:06 +0800 | [diff] [blame] | 106 | TEST_EQUAL(mbedtls_ssl_config_defaults(&conf, |
| 107 | MBEDTLS_SSL_IS_CLIENT, |
| 108 | MBEDTLS_SSL_TRANSPORT_STREAM, |
| 109 | MBEDTLS_SSL_PRESET_DEFAULT), |
| 110 | 0); |
Ronald Cron | aab4a54 | 2024-02-23 18:51:11 +0100 | [diff] [blame] | 111 | mbedtls_ssl_conf_rng(&conf, mbedtls_test_random, NULL); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 112 | mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 113 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 114 | TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0); |
Jerry Yu | b19ccc3 | 2021-08-09 17:44:56 +0800 | [diff] [blame] | 115 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 116 | mbedtls_debug_print_ret(&ssl, 0, file, line, text, value); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 117 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 118 | TEST_ASSERT(strcmp(buffer.buf, result_str) == 0); |
Manuel Pégourié-Gonnard | d5a9e41 | 2015-05-04 11:11:42 +0200 | [diff] [blame] | 119 | |
| 120 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 121 | mbedtls_ssl_free(&ssl); |
| 122 | mbedtls_ssl_config_free(&conf); |
Valerio Setti | 8473390 | 2024-06-27 08:05:09 +0200 | [diff] [blame] | 123 | MD_OR_USE_PSA_DONE(); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 124 | } |
| 125 | /* END_CASE */ |
| 126 | |
| 127 | /* BEGIN_CASE */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 128 | void mbedtls_debug_print_buf(char *file, int line, char *text, |
| 129 | data_t *data, char *result_str) |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 130 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 131 | mbedtls_ssl_context ssl; |
Manuel Pégourié-Gonnard | def0bbe | 2015-05-04 14:56:36 +0200 | [diff] [blame] | 132 | mbedtls_ssl_config conf; |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 133 | struct buffer_data buffer; |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 134 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 135 | mbedtls_ssl_init(&ssl); |
| 136 | mbedtls_ssl_config_init(&conf); |
Valerio Setti | 3a994b7 | 2024-07-03 16:58:10 +0200 | [diff] [blame] | 137 | MD_OR_USE_PSA_INIT(); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 138 | memset(buffer.buf, 0, 2000); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 139 | buffer.ptr = buffer.buf; |
| 140 | |
Yanray Wang | aad9449 | 2023-12-04 10:42:06 +0800 | [diff] [blame] | 141 | TEST_EQUAL(mbedtls_ssl_config_defaults(&conf, |
| 142 | MBEDTLS_SSL_IS_CLIENT, |
| 143 | MBEDTLS_SSL_TRANSPORT_STREAM, |
| 144 | MBEDTLS_SSL_PRESET_DEFAULT), |
| 145 | 0); |
Ronald Cron | aab4a54 | 2024-02-23 18:51:11 +0100 | [diff] [blame] | 146 | mbedtls_ssl_conf_rng(&conf, mbedtls_test_random, NULL); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 147 | mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 148 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 149 | TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0); |
Jerry Yu | b19ccc3 | 2021-08-09 17:44:56 +0800 | [diff] [blame] | 150 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 151 | 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] | 152 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 153 | TEST_ASSERT(strcmp(buffer.buf, result_str) == 0); |
Manuel Pégourié-Gonnard | d5a9e41 | 2015-05-04 11:11:42 +0200 | [diff] [blame] | 154 | |
| 155 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 156 | mbedtls_ssl_free(&ssl); |
| 157 | mbedtls_ssl_config_free(&conf); |
Valerio Setti | 8473390 | 2024-06-27 08:05:09 +0200 | [diff] [blame] | 158 | MD_OR_USE_PSA_DONE(); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 159 | } |
| 160 | /* END_CASE */ |
| 161 | |
Hanno Becker | 612a2f1 | 2020-10-09 09:19:39 +0100 | [diff] [blame] | 162 | /* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 163 | void mbedtls_debug_print_crt(char *crt_file, char *file, int line, |
| 164 | char *prefix, char *result_str) |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 165 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 166 | mbedtls_x509_crt crt; |
| 167 | mbedtls_ssl_context ssl; |
Manuel Pégourié-Gonnard | def0bbe | 2015-05-04 14:56:36 +0200 | [diff] [blame] | 168 | mbedtls_ssl_config conf; |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 169 | struct buffer_data buffer; |
| 170 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 171 | mbedtls_ssl_init(&ssl); |
| 172 | mbedtls_ssl_config_init(&conf); |
| 173 | mbedtls_x509_crt_init(&crt); |
Valerio Setti | 92c3f36 | 2023-05-17 15:36:44 +0200 | [diff] [blame] | 174 | MD_OR_USE_PSA_INIT(); |
| 175 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 176 | memset(buffer.buf, 0, 2000); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 177 | buffer.ptr = buffer.buf; |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 178 | |
Yanray Wang | aad9449 | 2023-12-04 10:42:06 +0800 | [diff] [blame] | 179 | TEST_EQUAL(mbedtls_ssl_config_defaults(&conf, |
| 180 | MBEDTLS_SSL_IS_CLIENT, |
| 181 | MBEDTLS_SSL_TRANSPORT_STREAM, |
| 182 | MBEDTLS_SSL_PRESET_DEFAULT), |
| 183 | 0); |
Ronald Cron | aab4a54 | 2024-02-23 18:51:11 +0100 | [diff] [blame] | 184 | mbedtls_ssl_conf_rng(&conf, mbedtls_test_random, NULL); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 185 | mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer); |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 186 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 187 | TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0); |
Jerry Yu | b19ccc3 | 2021-08-09 17:44:56 +0800 | [diff] [blame] | 188 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 189 | TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0); |
| 190 | mbedtls_debug_print_crt(&ssl, 0, file, line, prefix, &crt); |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 191 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 192 | TEST_ASSERT(strcmp(buffer.buf, result_str) == 0); |
Paul Bakker | 58ef6ec | 2013-01-03 11:33:48 +0100 | [diff] [blame] | 193 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 194 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 195 | mbedtls_x509_crt_free(&crt); |
| 196 | mbedtls_ssl_free(&ssl); |
| 197 | mbedtls_ssl_config_free(&conf); |
Valerio Setti | 92c3f36 | 2023-05-17 15:36:44 +0200 | [diff] [blame] | 198 | MD_OR_USE_PSA_DONE(); |
Paul Bakker | 1f76115 | 2010-02-18 18:16:31 +0000 | [diff] [blame] | 199 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 200 | /* END_CASE */ |
Paul Bakker | be4e7dc | 2011-03-14 20:41:31 +0000 | [diff] [blame] | 201 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 202 | /* BEGIN_CASE depends_on:MBEDTLS_BIGNUM_C */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 203 | void mbedtls_debug_print_mpi(char *value, char *file, int line, |
| 204 | char *prefix, char *result_str) |
Paul Bakker | be4e7dc | 2011-03-14 20:41:31 +0000 | [diff] [blame] | 205 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 206 | mbedtls_ssl_context ssl; |
Manuel Pégourié-Gonnard | def0bbe | 2015-05-04 14:56:36 +0200 | [diff] [blame] | 207 | mbedtls_ssl_config conf; |
Paul Bakker | be4e7dc | 2011-03-14 20:41:31 +0000 | [diff] [blame] | 208 | struct buffer_data buffer; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 209 | mbedtls_mpi val; |
Paul Bakker | be4e7dc | 2011-03-14 20:41:31 +0000 | [diff] [blame] | 210 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 211 | mbedtls_ssl_init(&ssl); |
| 212 | mbedtls_ssl_config_init(&conf); |
| 213 | mbedtls_mpi_init(&val); |
Valerio Setti | 3a994b7 | 2024-07-03 16:58:10 +0200 | [diff] [blame] | 214 | MD_OR_USE_PSA_INIT(); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 215 | memset(buffer.buf, 0, 2000); |
Paul Bakker | 57ffa55 | 2014-04-25 14:29:10 +0200 | [diff] [blame] | 216 | buffer.ptr = buffer.buf; |
Paul Bakker | be4e7dc | 2011-03-14 20:41:31 +0000 | [diff] [blame] | 217 | |
Yanray Wang | aad9449 | 2023-12-04 10:42:06 +0800 | [diff] [blame] | 218 | TEST_EQUAL(mbedtls_ssl_config_defaults(&conf, |
| 219 | MBEDTLS_SSL_IS_CLIENT, |
| 220 | MBEDTLS_SSL_TRANSPORT_STREAM, |
| 221 | MBEDTLS_SSL_PRESET_DEFAULT), |
| 222 | 0); |
Ronald Cron | aab4a54 | 2024-02-23 18:51:11 +0100 | [diff] [blame] | 223 | mbedtls_ssl_conf_rng(&conf, mbedtls_test_random, NULL); |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 224 | mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer); |
Jerry Yu | b19ccc3 | 2021-08-09 17:44:56 +0800 | [diff] [blame] | 225 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 226 | TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0); |
Manuel Pégourié-Gonnard | d5a9e41 | 2015-05-04 11:11:42 +0200 | [diff] [blame] | 227 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 228 | TEST_ASSERT(mbedtls_test_read_mpi(&val, value) == 0); |
Paul Bakker | eaebbd5 | 2014-04-25 15:04:14 +0200 | [diff] [blame] | 229 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 230 | mbedtls_debug_print_mpi(&ssl, 0, file, line, prefix, &val); |
Paul Bakker | be4e7dc | 2011-03-14 20:41:31 +0000 | [diff] [blame] | 231 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 232 | TEST_ASSERT(strcmp(buffer.buf, result_str) == 0); |
Paul Bakker | 6c591fa | 2011-05-05 11:49:20 +0000 | [diff] [blame] | 233 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 234 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 235 | mbedtls_mpi_free(&val); |
| 236 | mbedtls_ssl_free(&ssl); |
| 237 | mbedtls_ssl_config_free(&conf); |
Valerio Setti | 8473390 | 2024-06-27 08:05:09 +0200 | [diff] [blame] | 238 | MD_OR_USE_PSA_DONE(); |
Paul Bakker | be4e7dc | 2011-03-14 20:41:31 +0000 | [diff] [blame] | 239 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 240 | /* END_CASE */ |