2013-08-20 09:48:36 +00:00
|
|
|
/* BEGIN_HEADER */
|
2015-03-09 17:05:11 +00:00
|
|
|
#include "mbedtls/debug.h"
|
2010-02-18 18:16:31 +00:00
|
|
|
|
|
|
|
struct buffer_data
|
|
|
|
{
|
|
|
|
char buf[2000];
|
|
|
|
char *ptr;
|
|
|
|
};
|
|
|
|
|
2010-03-16 21:09:09 +00:00
|
|
|
void string_debug(void *data, int level, const char *str)
|
2010-02-18 18:16:31 +00:00
|
|
|
{
|
|
|
|
struct buffer_data *buffer = (struct buffer_data *) data;
|
2011-07-13 14:53:58 +00:00
|
|
|
((void) level);
|
2010-02-18 18:16:31 +00:00
|
|
|
|
|
|
|
memcpy(buffer->ptr, str, strlen(str));
|
|
|
|
buffer->ptr += strlen(str);
|
2014-04-25 13:18:34 +00:00
|
|
|
|
|
|
|
/* Detect if debug messages output partial lines and mark them */
|
|
|
|
if( *(buffer->ptr - 1) != '\n' )
|
|
|
|
{
|
|
|
|
*buffer->ptr = '*';
|
|
|
|
buffer->ptr++;
|
|
|
|
}
|
2010-02-18 18:16:31 +00:00
|
|
|
}
|
2013-08-20 09:48:36 +00:00
|
|
|
/* END_HEADER */
|
2010-02-18 18:16:31 +00:00
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
/* BEGIN_DEPENDENCIES
|
2015-04-08 10:49:31 +00:00
|
|
|
* depends_on:MBEDTLS_DEBUG_C:MBEDTLS_SSL_TLS_C
|
2013-08-20 09:48:36 +00:00
|
|
|
* END_DEPENDENCIES
|
|
|
|
*/
|
2011-05-26 13:16:06 +00:00
|
|
|
|
2014-04-25 14:34:30 +00:00
|
|
|
/* BEGIN_CASE */
|
|
|
|
void debug_print_msg_threshold( int threshold, int level, char *file, int line,
|
|
|
|
char *result_str )
|
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_ssl_context ssl;
|
2014-04-25 14:34:30 +00:00
|
|
|
struct buffer_data buffer;
|
|
|
|
|
2015-05-04 09:11:42 +00:00
|
|
|
mbedtls_ssl_init( &ssl );
|
2014-04-25 14:34:30 +00:00
|
|
|
memset( buffer.buf, 0, 2000 );
|
|
|
|
buffer.ptr = buffer.buf;
|
|
|
|
|
2015-05-04 09:11:42 +00:00
|
|
|
TEST_ASSERT( mbedtls_ssl_setup( &ssl ) == 0 );
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_debug_set_log_mode( MBEDTLS_DEBUG_LOG_FULL );
|
|
|
|
mbedtls_debug_set_threshold( threshold );
|
|
|
|
mbedtls_ssl_set_dbg(&ssl, string_debug, &buffer);
|
2014-04-25 14:34:30 +00:00
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_debug_print_msg( &ssl, level, file, line,
|
|
|
|
mbedtls_debug_fmt("Text message, 2 == %d", 2 ) );
|
2014-04-25 14:34:30 +00:00
|
|
|
|
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
2015-05-04 09:11:42 +00:00
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_ssl_free( &ssl );
|
2014-04-25 14:34:30 +00:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2014-04-25 12:29:10 +00:00
|
|
|
/* BEGIN_CASE */
|
2015-04-08 10:49:31 +00:00
|
|
|
void mbedtls_debug_print_ret( int mode, char *file, int line, char *text, int value,
|
2014-04-25 12:29:10 +00:00
|
|
|
char *result_str )
|
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_ssl_context ssl;
|
2014-04-25 12:29:10 +00:00
|
|
|
struct buffer_data buffer;
|
|
|
|
|
2015-05-04 09:11:42 +00:00
|
|
|
mbedtls_ssl_init( &ssl );
|
2014-04-25 12:29:10 +00:00
|
|
|
memset( buffer.buf, 0, 2000 );
|
|
|
|
buffer.ptr = buffer.buf;
|
|
|
|
|
2015-05-04 09:11:42 +00:00
|
|
|
TEST_ASSERT( mbedtls_ssl_setup( &ssl ) == 0 );
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_debug_set_log_mode( mode );
|
|
|
|
mbedtls_ssl_set_dbg(&ssl, string_debug, &buffer);
|
2014-04-25 12:29:10 +00:00
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_debug_print_ret( &ssl, 0, file, line, text, value);
|
2014-04-25 12:29:10 +00:00
|
|
|
|
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
2015-05-04 09:11:42 +00:00
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_ssl_free( &ssl );
|
2014-04-25 12:29:10 +00:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
2015-04-08 10:49:31 +00:00
|
|
|
void mbedtls_debug_print_buf( int mode, char *file, int line, char *text,
|
2014-04-25 13:04:14 +00:00
|
|
|
char *data_string, char *result_str )
|
2014-04-25 12:29:10 +00:00
|
|
|
{
|
|
|
|
unsigned char data[10000];
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_ssl_context ssl;
|
2014-04-25 12:29:10 +00:00
|
|
|
struct buffer_data buffer;
|
|
|
|
size_t data_len;
|
|
|
|
|
2015-05-04 09:11:42 +00:00
|
|
|
mbedtls_ssl_init( &ssl );
|
2014-04-25 12:29:10 +00:00
|
|
|
memset( &data, 0, sizeof( data ) );
|
|
|
|
memset( buffer.buf, 0, 2000 );
|
|
|
|
buffer.ptr = buffer.buf;
|
|
|
|
|
|
|
|
data_len = unhexify( data, data_string );
|
|
|
|
|
2015-05-04 09:11:42 +00:00
|
|
|
TEST_ASSERT( mbedtls_ssl_setup( &ssl ) == 0 );
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_debug_set_log_mode( mode );
|
|
|
|
mbedtls_ssl_set_dbg(&ssl, string_debug, &buffer);
|
2014-04-25 12:29:10 +00:00
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_debug_print_buf( &ssl, 0, file, line, text, data, data_len );
|
2014-04-25 12:29:10 +00:00
|
|
|
|
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
2015-05-04 09:11:42 +00:00
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_ssl_free( &ssl );
|
2014-04-25 12:29:10 +00:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO:MBEDTLS_X509_CRT_PARSE_C */
|
|
|
|
void mbedtls_debug_print_crt( int mode, char *crt_file, char *file, int line,
|
2014-04-25 13:04:14 +00:00
|
|
|
char *prefix, char *result_str )
|
2010-02-18 18:16:31 +00:00
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_x509_crt crt;
|
|
|
|
mbedtls_ssl_context ssl;
|
2010-02-18 18:16:31 +00:00
|
|
|
struct buffer_data buffer;
|
|
|
|
|
2015-05-04 09:11:42 +00:00
|
|
|
mbedtls_ssl_init( &ssl );
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_x509_crt_init( &crt );
|
2010-02-18 18:16:31 +00:00
|
|
|
memset( buffer.buf, 0, 2000 );
|
2014-04-25 12:29:10 +00:00
|
|
|
buffer.ptr = buffer.buf;
|
2010-02-18 18:16:31 +00:00
|
|
|
|
2015-05-04 09:11:42 +00:00
|
|
|
TEST_ASSERT( mbedtls_ssl_setup( &ssl ) == 0 );
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_debug_set_log_mode( mode );
|
|
|
|
mbedtls_ssl_set_dbg(&ssl, string_debug, &buffer);
|
2010-02-18 18:16:31 +00:00
|
|
|
|
2015-04-08 10:49:31 +00: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 18:16:31 +00:00
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
2013-01-03 10:33:48 +00:00
|
|
|
|
2014-07-10 13:26:12 +00:00
|
|
|
exit:
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_x509_crt_free( &crt );
|
2015-05-04 09:11:42 +00:00
|
|
|
mbedtls_ssl_free( &ssl );
|
2010-02-18 18:16:31 +00:00
|
|
|
}
|
2013-08-20 09:48:36 +00:00
|
|
|
/* END_CASE */
|
2011-03-14 20:41:31 +00:00
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_BIGNUM_C */
|
|
|
|
void mbedtls_debug_print_mpi( int mode, int radix, char *value, char *file, int line,
|
2013-08-20 09:48:36 +00:00
|
|
|
char *prefix, char *result_str )
|
2011-03-14 20:41:31 +00:00
|
|
|
{
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_ssl_context ssl;
|
2011-03-14 20:41:31 +00:00
|
|
|
struct buffer_data buffer;
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_mpi val;
|
2011-03-14 20:41:31 +00:00
|
|
|
|
2015-05-04 09:11:42 +00:00
|
|
|
mbedtls_ssl_init( &ssl );
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_mpi_init( &val );
|
2011-03-14 20:41:31 +00:00
|
|
|
memset( buffer.buf, 0, 2000 );
|
2014-04-25 12:29:10 +00:00
|
|
|
buffer.ptr = buffer.buf;
|
2011-03-14 20:41:31 +00:00
|
|
|
|
2015-05-04 09:11:42 +00:00
|
|
|
TEST_ASSERT( mbedtls_ssl_setup( &ssl ) == 0 );
|
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
TEST_ASSERT( mbedtls_mpi_read_string( &val, radix, value ) == 0 );
|
2014-04-25 13:04:14 +00:00
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_debug_set_log_mode( mode );
|
|
|
|
mbedtls_ssl_set_dbg(&ssl, string_debug, &buffer);
|
2011-03-14 20:41:31 +00:00
|
|
|
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_debug_print_mpi( &ssl, 0, file, line, prefix, &val);
|
2011-03-14 20:41:31 +00:00
|
|
|
|
2013-08-20 09:48:36 +00:00
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
2011-05-05 11:49:20 +00:00
|
|
|
|
2014-07-10 13:26:12 +00:00
|
|
|
exit:
|
2015-04-08 10:49:31 +00:00
|
|
|
mbedtls_mpi_free( &val );
|
2015-05-04 09:11:42 +00:00
|
|
|
mbedtls_ssl_free( &ssl );
|
2011-03-14 20:41:31 +00:00
|
|
|
}
|
2013-08-20 09:48:36 +00:00
|
|
|
/* END_CASE */
|