2013-08-20 11:48:36 +02:00
|
|
|
/* BEGIN_HEADER */
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/debug.h"
|
2017-04-06 12:55:43 +02:00
|
|
|
#include "string.h"
|
2023-02-13 11:33:26 +01:00
|
|
|
#include "mbedtls/pk.h"
|
2010-02-18 19:16:31 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
struct buffer_data {
|
2010-02-18 19:16:31 +01:00
|
|
|
char buf[2000];
|
|
|
|
char *ptr;
|
|
|
|
};
|
|
|
|
|
2015-06-23 16:34:24 +02:00
|
|
|
void string_debug(void *data, int level, const char *file, int line, const char *str)
|
2010-02-18 19:16:31 +01:00
|
|
|
{
|
|
|
|
struct buffer_data *buffer = (struct buffer_data *) data;
|
2015-06-23 16:34:24 +02:00
|
|
|
char *p = buffer->ptr;
|
2011-07-13 16:53:58 +02:00
|
|
|
((void) level);
|
2010-02-18 19:16:31 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
memcpy(p, file, strlen(file));
|
|
|
|
p += strlen(file);
|
2015-06-23 16:34:24 +02:00
|
|
|
|
|
|
|
*p++ = '(';
|
2023-01-11 14:50:10 +01:00
|
|
|
*p++ = '0' + (line / 1000) % 10;
|
|
|
|
*p++ = '0' + (line / 100) % 10;
|
|
|
|
*p++ = '0' + (line / 10) % 10;
|
|
|
|
*p++ = '0' + (line / 1) % 10;
|
2015-06-23 16:34:24 +02:00
|
|
|
*p++ = ')';
|
|
|
|
*p++ = ':';
|
|
|
|
*p++ = ' ';
|
|
|
|
|
2015-08-31 16:11:00 +02:00
|
|
|
#if defined(MBEDTLS_THREADING_C)
|
|
|
|
/* Skip "thread ID" (up to the first space) as it is not predictable */
|
2023-01-11 14:50:10 +01:00
|
|
|
while (*str++ != ' ') {
|
|
|
|
;
|
|
|
|
}
|
2015-08-31 16:11:00 +02:00
|
|
|
#endif
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
memcpy(p, str, strlen(str));
|
|
|
|
p += strlen(str);
|
2014-04-25 15:18:34 +02:00
|
|
|
|
|
|
|
/* Detect if debug messages output partial lines and mark them */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (p[-1] != '\n') {
|
2015-06-23 16:34:24 +02:00
|
|
|
*p++ = '*';
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2015-06-23 16:34:24 +02:00
|
|
|
|
|
|
|
buffer->ptr = p;
|
2010-02-18 19:16:31 +01:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_HEADER */
|
2010-02-18 19:16:31 +01:00
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
/* BEGIN_DEPENDENCIES
|
2015-04-08 12:49:31 +02:00
|
|
|
* depends_on:MBEDTLS_DEBUG_C:MBEDTLS_SSL_TLS_C
|
2013-08-20 11:48:36 +02:00
|
|
|
* END_DEPENDENCIES
|
|
|
|
*/
|
2011-05-26 15:16:06 +02:00
|
|
|
|
2014-04-25 16:34:30 +02:00
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void debug_print_msg_threshold(int threshold, int level, char *file,
|
|
|
|
int line, char *result_str)
|
2014-04-25 16:34:30 +02:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_ssl_context ssl;
|
2015-05-04 14:56:36 +02:00
|
|
|
mbedtls_ssl_config conf;
|
2014-04-25 16:34:30 +02:00
|
|
|
struct buffer_data buffer;
|
|
|
|
|
2023-03-17 13:34:11 +01:00
|
|
|
MD_PSA_INIT();
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_init(&ssl);
|
|
|
|
mbedtls_ssl_config_init(&conf);
|
|
|
|
memset(buffer.buf, 0, 2000);
|
2014-04-25 16:34:30 +02:00
|
|
|
buffer.ptr = buffer.buf;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_config_defaults(&conf,
|
|
|
|
MBEDTLS_SSL_IS_CLIENT,
|
|
|
|
MBEDTLS_SSL_TRANSPORT_STREAM,
|
|
|
|
MBEDTLS_SSL_PRESET_DEFAULT);
|
2021-08-09 11:44:56 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer);
|
2021-08-09 11:44:56 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0);
|
2015-05-04 11:11:42 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_debug_set_threshold(threshold);
|
2014-04-25 16:34:30 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_debug_print_msg(&ssl, level, file, line,
|
|
|
|
"Text message, 2 == %d", 2);
|
2014-04-25 16:34:30 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(strcmp(buffer.buf, result_str) == 0);
|
2015-05-04 11:11:42 +02:00
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_free(&ssl);
|
|
|
|
mbedtls_ssl_config_free(&conf);
|
2023-03-17 13:34:11 +01:00
|
|
|
MD_PSA_DONE();
|
2014-04-25 16:34:30 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2014-04-25 14:29:10 +02:00
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_debug_print_ret(char *file, int line, char *text, int value,
|
|
|
|
char *result_str)
|
2014-04-25 14:29:10 +02:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_ssl_context ssl;
|
2015-05-04 14:56:36 +02:00
|
|
|
mbedtls_ssl_config conf;
|
2014-04-25 14:29:10 +02:00
|
|
|
struct buffer_data buffer;
|
|
|
|
|
2023-03-17 13:34:11 +01:00
|
|
|
MD_PSA_INIT();
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_init(&ssl);
|
|
|
|
mbedtls_ssl_config_init(&conf);
|
|
|
|
memset(buffer.buf, 0, 2000);
|
2014-04-25 14:29:10 +02:00
|
|
|
buffer.ptr = buffer.buf;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_config_defaults(&conf,
|
|
|
|
MBEDTLS_SSL_IS_CLIENT,
|
|
|
|
MBEDTLS_SSL_TRANSPORT_STREAM,
|
|
|
|
MBEDTLS_SSL_PRESET_DEFAULT);
|
2015-05-04 11:11:42 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer);
|
2014-04-25 14:29:10 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0);
|
2021-08-09 11:44:56 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_debug_print_ret(&ssl, 0, file, line, text, value);
|
2014-04-25 14:29:10 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(strcmp(buffer.buf, result_str) == 0);
|
2015-05-04 11:11:42 +02:00
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_free(&ssl);
|
|
|
|
mbedtls_ssl_config_free(&conf);
|
2023-03-17 13:34:11 +01:00
|
|
|
MD_PSA_DONE();
|
2014-04-25 14:29:10 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_debug_print_buf(char *file, int line, char *text,
|
|
|
|
data_t *data, char *result_str)
|
2014-04-25 14:29:10 +02:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_ssl_context ssl;
|
2015-05-04 14:56:36 +02:00
|
|
|
mbedtls_ssl_config conf;
|
2014-04-25 14:29:10 +02:00
|
|
|
struct buffer_data buffer;
|
|
|
|
|
2023-03-17 13:34:11 +01:00
|
|
|
MD_PSA_INIT();
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_init(&ssl);
|
|
|
|
mbedtls_ssl_config_init(&conf);
|
|
|
|
memset(buffer.buf, 0, 2000);
|
2014-04-25 14:29:10 +02:00
|
|
|
buffer.ptr = buffer.buf;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_config_defaults(&conf,
|
|
|
|
MBEDTLS_SSL_IS_CLIENT,
|
|
|
|
MBEDTLS_SSL_TRANSPORT_STREAM,
|
|
|
|
MBEDTLS_SSL_PRESET_DEFAULT);
|
2015-05-04 11:11:42 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer);
|
2014-04-25 14:29:10 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0);
|
2021-08-09 11:44:56 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_debug_print_buf(&ssl, 0, file, line, text, data->x, data->len);
|
2014-04-25 14:29:10 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(strcmp(buffer.buf, result_str) == 0);
|
2015-05-04 11:11:42 +02:00
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_free(&ssl);
|
|
|
|
mbedtls_ssl_config_free(&conf);
|
2023-03-17 13:34:11 +01:00
|
|
|
MD_PSA_DONE();
|
2014-04-25 14:29:10 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2020-10-09 10:19:39 +02:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C:!MBEDTLS_X509_REMOVE_INFO */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_debug_print_crt(char *crt_file, char *file, int line,
|
|
|
|
char *prefix, char *result_str)
|
2010-02-18 19:16:31 +01:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_x509_crt crt;
|
|
|
|
mbedtls_ssl_context ssl;
|
2015-05-04 14:56:36 +02:00
|
|
|
mbedtls_ssl_config conf;
|
2010-02-18 19:16:31 +01:00
|
|
|
struct buffer_data buffer;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_init(&ssl);
|
|
|
|
mbedtls_ssl_config_init(&conf);
|
|
|
|
mbedtls_x509_crt_init(&crt);
|
2023-05-17 15:36:44 +02:00
|
|
|
MD_OR_USE_PSA_INIT();
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
memset(buffer.buf, 0, 2000);
|
2014-04-25 14:29:10 +02:00
|
|
|
buffer.ptr = buffer.buf;
|
2010-02-18 19:16:31 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_config_defaults(&conf,
|
|
|
|
MBEDTLS_SSL_IS_CLIENT,
|
|
|
|
MBEDTLS_SSL_TRANSPORT_STREAM,
|
|
|
|
MBEDTLS_SSL_PRESET_DEFAULT);
|
2015-05-04 11:11:42 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer);
|
2010-02-18 19:16:31 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0);
|
2021-08-09 11:44:56 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(mbedtls_x509_crt_parse_file(&crt, crt_file) == 0);
|
|
|
|
mbedtls_debug_print_crt(&ssl, 0, file, line, prefix, &crt);
|
2010-02-18 19:16:31 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(strcmp(buffer.buf, result_str) == 0);
|
2013-01-03 11:33:48 +01:00
|
|
|
|
2014-07-10 15:26:12 +02:00
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_x509_crt_free(&crt);
|
|
|
|
mbedtls_ssl_free(&ssl);
|
|
|
|
mbedtls_ssl_config_free(&conf);
|
2023-05-17 15:36:44 +02:00
|
|
|
MD_OR_USE_PSA_DONE();
|
2010-02-18 19:16:31 +01:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|
2011-03-14 21:41:31 +01:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_BIGNUM_C */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_debug_print_mpi(char *value, char *file, int line,
|
|
|
|
char *prefix, char *result_str)
|
2011-03-14 21:41:31 +01:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_ssl_context ssl;
|
2015-05-04 14:56:36 +02:00
|
|
|
mbedtls_ssl_config conf;
|
2011-03-14 21:41:31 +01:00
|
|
|
struct buffer_data buffer;
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_mpi val;
|
2011-03-14 21:41:31 +01:00
|
|
|
|
2023-03-17 13:34:11 +01:00
|
|
|
MD_PSA_INIT();
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_init(&ssl);
|
|
|
|
mbedtls_ssl_config_init(&conf);
|
|
|
|
mbedtls_mpi_init(&val);
|
|
|
|
memset(buffer.buf, 0, 2000);
|
2014-04-25 14:29:10 +02:00
|
|
|
buffer.ptr = buffer.buf;
|
2011-03-14 21:41:31 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_config_defaults(&conf,
|
|
|
|
MBEDTLS_SSL_IS_CLIENT,
|
|
|
|
MBEDTLS_SSL_TRANSPORT_STREAM,
|
|
|
|
MBEDTLS_SSL_PRESET_DEFAULT);
|
2021-08-09 11:44:56 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_conf_dbg(&conf, string_debug, &buffer);
|
2021-08-09 11:44:56 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(mbedtls_ssl_setup(&ssl, &conf) == 0);
|
2015-05-04 11:11:42 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(mbedtls_test_read_mpi(&val, value) == 0);
|
2014-04-25 15:04:14 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_debug_print_mpi(&ssl, 0, file, line, prefix, &val);
|
2011-03-14 21:41:31 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(strcmp(buffer.buf, result_str) == 0);
|
2011-05-05 13:49:20 +02:00
|
|
|
|
2014-07-10 15:26:12 +02:00
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_mpi_free(&val);
|
|
|
|
mbedtls_ssl_free(&ssl);
|
|
|
|
mbedtls_ssl_config_free(&conf);
|
2023-03-17 13:34:11 +01:00
|
|
|
MD_PSA_DONE();
|
2011-03-14 21:41:31 +01:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|