2013-08-20 11:48:36 +02:00
|
|
|
/* BEGIN_HEADER */
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/debug.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++ = ' ';
|
|
|
|
|
|
|
|
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 */
|
|
|
|
void debug_print_msg_threshold( int threshold, int level, char *file, int line,
|
|
|
|
char *result_str )
|
|
|
|
{
|
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;
|
|
|
|
|
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 );
|
2015-05-11 09:50:24 +02:00
|
|
|
mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer);
|
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 */
|
2015-06-23 16:34:24 +02:00
|
|
|
void mbedtls_debug_print_ret( char *file, int line, char *text, int value,
|
2014-04-25 14:29:10 +02:00
|
|
|
char *result_str )
|
|
|
|
{
|
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;
|
|
|
|
|
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-05-11 09:50:24 +02:00
|
|
|
mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer);
|
2014-04-25 14:29:10 +02:00
|
|
|
|
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 */
|
2015-06-23 16:34:24 +02:00
|
|
|
void mbedtls_debug_print_buf( char *file, int line, char *text,
|
2014-04-25 15:04:14 +02:00
|
|
|
char *data_string, char *result_str )
|
2014-04-25 14:29:10 +02:00
|
|
|
{
|
|
|
|
unsigned char data[10000];
|
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;
|
|
|
|
size_t data_len;
|
|
|
|
|
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( &data, 0, sizeof( data ) );
|
|
|
|
memset( buffer.buf, 0, 2000 );
|
|
|
|
buffer.ptr = buffer.buf;
|
|
|
|
|
|
|
|
data_len = unhexify( data, data_string );
|
|
|
|
|
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-05-11 09:50:24 +02:00
|
|
|
mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer);
|
2014-04-25 14:29:10 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_debug_print_buf( &ssl, 0, file, line, text, data, 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 */
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
|
2015-06-23 16:34:24 +02:00
|
|
|
void mbedtls_debug_print_crt( char *crt_file, char *file, int line,
|
2014-04-25 15:04:14 +02:00
|
|
|
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
|
|
|
|
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-05-11 09:50:24 +02:00
|
|
|
mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer);
|
2010-02-18 19:16:31 +01:00
|
|
|
|
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 */
|
2015-06-23 16:34:24 +02:00
|
|
|
void mbedtls_debug_print_mpi( int radix, char *value, char *file, int line,
|
2013-08-20 11:48:36 +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
|
|
|
|
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
|
|
|
TEST_ASSERT( mbedtls_mpi_read_string( &val, radix, value ) == 0 );
|
2014-04-25 15:04:14 +02:00
|
|
|
|
2015-05-11 09:50:24 +02:00
|
|
|
mbedtls_ssl_conf_dbg( &conf, string_debug, &buffer);
|
2011-03-14 21:41:31 +01: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 */
|