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"
|
2022-10-18 13:16:04 +02:00
|
|
|
#include "mbedtls/legacy_or_psa.h"
|
2010-02-18 19:16:31 +01:00
|
|
|
|
|
|
|
struct buffer_data
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2015-06-23 16:34:24 +02:00
|
|
|
memcpy( p, file, strlen( file ) );
|
|
|
|
p += strlen( file );
|
|
|
|
|
|
|
|
*p++ = '(';
|
|
|
|
*p++ = '0' + ( line / 1000 ) % 10;
|
|
|
|
*p++ = '0' + ( line / 100 ) % 10;
|
|
|
|
*p++ = '0' + ( line / 10 ) % 10;
|
|
|
|
*p++ = '0' + ( line / 1 ) % 10;
|
|
|
|
*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 */
|
|
|
|
while( *str++ != ' ' );
|
|
|
|
#endif
|
|
|
|
|
2015-06-23 16:34:24 +02: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 */
|
2015-06-23 16:34:24 +02:00
|
|
|
if( p[-1] != '\n' )
|
|
|
|
*p++ = '*';
|
|
|
|
|
|
|
|
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 */
|
2017-05-30 15:23:15 +02: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;
|
|
|
|
|
2015-05-04 11:11:42 +02:00
|
|
|
mbedtls_ssl_init( &ssl );
|
2015-05-04 14:56:36 +02:00
|
|
|
mbedtls_ssl_config_init( &conf );
|
2014-04-25 16:34:30 +02:00
|
|
|
memset( buffer.buf, 0, 2000 );
|
|
|
|
buffer.ptr = buffer.buf;
|
|
|
|
|
2021-08-09 11:44:56 +02:00
|
|
|
mbedtls_ssl_config_defaults( &conf,
|
|
|
|
MBEDTLS_SSL_IS_CLIENT,
|
|
|
|
MBEDTLS_SSL_TRANSPORT_STREAM,
|
|
|
|
MBEDTLS_SSL_PRESET_DEFAULT );
|
|
|
|
|
|
|
|
mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer);
|
|
|
|
|
2015-05-04 14:56:36 +02:00
|
|
|
TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
|
2015-05-04 11:11:42 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_debug_set_threshold( threshold );
|
2014-04-25 16:34:30 +02:00
|
|
|
|
2015-06-29 20:14:19 +02:00
|
|
|
mbedtls_debug_print_msg( &ssl, level, file, line,
|
2015-06-29 20:08:23 +02:00
|
|
|
"Text message, 2 == %d", 2 );
|
2014-04-25 16:34:30 +02:00
|
|
|
|
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
2015-05-04 11:11:42 +02:00
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_ssl_free( &ssl );
|
2015-05-04 14:56:36 +02:00
|
|
|
mbedtls_ssl_config_free( &conf );
|
2014-04-25 16:34:30 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2014-04-25 14:29:10 +02:00
|
|
|
/* BEGIN_CASE */
|
2017-05-30 15:23:15 +02: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;
|
|
|
|
|
2015-05-04 11:11:42 +02:00
|
|
|
mbedtls_ssl_init( &ssl );
|
2015-05-04 14:56:36 +02:00
|
|
|
mbedtls_ssl_config_init( &conf );
|
2014-04-25 14:29:10 +02:00
|
|
|
memset( buffer.buf, 0, 2000 );
|
|
|
|
buffer.ptr = buffer.buf;
|
|
|
|
|
2021-08-09 11:44:56 +02: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
|
|
|
|
2015-05-11 09:50:24 +02:00
|
|
|
mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer);
|
2014-04-25 14:29:10 +02:00
|
|
|
|
2021-08-09 11:44:56 +02:00
|
|
|
TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_debug_print_ret( &ssl, 0, file, line, text, value);
|
2014-04-25 14:29:10 +02:00
|
|
|
|
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
2015-05-04 11:11:42 +02:00
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_ssl_free( &ssl );
|
2015-05-04 14:56:36 +02:00
|
|
|
mbedtls_ssl_config_free( &conf );
|
2014-04-25 14:29:10 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
2017-05-30 15:23:15 +02:00
|
|
|
void mbedtls_debug_print_buf( char * file, int line, char * text,
|
2018-06-29 12:05:32 +02:00
|
|
|
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;
|
|
|
|
|
2015-05-04 11:11:42 +02:00
|
|
|
mbedtls_ssl_init( &ssl );
|
2015-05-04 14:56:36 +02:00
|
|
|
mbedtls_ssl_config_init( &conf );
|
2014-04-25 14:29:10 +02:00
|
|
|
memset( buffer.buf, 0, 2000 );
|
|
|
|
buffer.ptr = buffer.buf;
|
|
|
|
|
2021-08-09 11:44:56 +02: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
|
|
|
|
2015-05-11 09:50:24 +02:00
|
|
|
mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer);
|
2014-04-25 14:29:10 +02:00
|
|
|
|
2021-08-09 11:44:56 +02:00
|
|
|
TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
|
|
|
|
|
2017-06-09 05:32:58 +02:00
|
|
|
mbedtls_debug_print_buf( &ssl, 0, file, line, text, data->x, data->len );
|
2014-04-25 14:29:10 +02:00
|
|
|
|
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
2015-05-04 11:11:42 +02:00
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_ssl_free( &ssl );
|
2015-05-04 14:56:36 +02:00
|
|
|
mbedtls_ssl_config_free( &conf );
|
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 */
|
2017-05-30 15:23:15 +02: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;
|
|
|
|
|
2015-05-04 11:11:42 +02:00
|
|
|
mbedtls_ssl_init( &ssl );
|
2015-05-04 14:56:36 +02:00
|
|
|
mbedtls_ssl_config_init( &conf );
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_x509_crt_init( &crt );
|
2010-02-18 19:16:31 +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
|
|
|
|
2021-08-09 11:44:56 +02: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
|
|
|
|
2015-05-11 09:50:24 +02:00
|
|
|
mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer);
|
2010-02-18 19:16:31 +01:00
|
|
|
|
2021-08-09 11:44:56 +02:00
|
|
|
TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
|
|
|
|
|
2015-04-08 12:49:31 +02: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
|
|
|
|
2013-08-20 11:48:36 +02: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:
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_x509_crt_free( &crt );
|
2015-05-04 11:11:42 +02:00
|
|
|
mbedtls_ssl_free( &ssl );
|
2015-05-04 14:56:36 +02:00
|
|
|
mbedtls_ssl_config_free( &conf );
|
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 */
|
2022-07-07 12:37:24 +02:00
|
|
|
void mbedtls_debug_print_mpi( char * value, char * file, int line,
|
2017-05-30 15:23:15 +02:00
|
|
|
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
|
|
|
|
2015-05-04 11:11:42 +02:00
|
|
|
mbedtls_ssl_init( &ssl );
|
2015-05-04 14:56:36 +02:00
|
|
|
mbedtls_ssl_config_init( &conf );
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_mpi_init( &val );
|
2011-03-14 21:41:31 +01:00
|
|
|
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
|
|
|
|
2021-08-09 11:44:56 +02:00
|
|
|
mbedtls_ssl_config_defaults( &conf,
|
|
|
|
MBEDTLS_SSL_IS_CLIENT,
|
|
|
|
MBEDTLS_SSL_TRANSPORT_STREAM,
|
|
|
|
MBEDTLS_SSL_PRESET_DEFAULT );
|
|
|
|
|
|
|
|
mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer);
|
|
|
|
|
2015-05-04 14:56:36 +02:00
|
|
|
TEST_ASSERT( mbedtls_ssl_setup( &ssl, &conf ) == 0 );
|
2015-05-04 11:11:42 +02:00
|
|
|
|
2022-07-07 12:02:27 +02:00
|
|
|
TEST_ASSERT( mbedtls_test_read_mpi( &val, value ) == 0 );
|
2014-04-25 15:04:14 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_debug_print_mpi( &ssl, 0, file, line, prefix, &val);
|
2011-03-14 21:41:31 +01:00
|
|
|
|
2013-08-20 11:48:36 +02: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:
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_mpi_free( &val );
|
2015-05-04 11:11:42 +02:00
|
|
|
mbedtls_ssl_free( &ssl );
|
2015-05-04 14:56:36 +02:00
|
|
|
mbedtls_ssl_config_free( &conf );
|
2011-03-14 21:41:31 +01:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|