2013-08-20 11:48:36 +02:00
|
|
|
/* BEGIN_HEADER */
|
2010-02-18 19:16:31 +01:00
|
|
|
#include <polarssl/debug.h>
|
|
|
|
|
|
|
|
struct buffer_data
|
|
|
|
{
|
|
|
|
char buf[2000];
|
|
|
|
char *ptr;
|
|
|
|
};
|
|
|
|
|
2010-03-16 22:09:09 +01:00
|
|
|
void string_debug(void *data, int level, const char *str)
|
2010-02-18 19:16:31 +01:00
|
|
|
{
|
|
|
|
struct buffer_data *buffer = (struct buffer_data *) data;
|
2011-07-13 16:53:58 +02:00
|
|
|
((void) level);
|
2010-02-18 19:16:31 +01:00
|
|
|
|
|
|
|
memcpy(buffer->ptr, str, strlen(str));
|
|
|
|
buffer->ptr += strlen(str);
|
|
|
|
}
|
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
|
2014-04-25 14:29:10 +02:00
|
|
|
* depends_on:POLARSSL_DEBUG_C:POLARSSL_SSL_TLS_C
|
2013-08-20 11:48:36 +02:00
|
|
|
* END_DEPENDENCIES
|
|
|
|
*/
|
2011-05-26 15:16:06 +02:00
|
|
|
|
2014-04-25 14:29:10 +02:00
|
|
|
/* BEGIN_CASE */
|
2014-04-25 15:04:14 +02:00
|
|
|
void debug_print_ret( int mode, char *file, int line, char *text, int value,
|
2014-04-25 14:29:10 +02:00
|
|
|
char *result_str )
|
|
|
|
{
|
|
|
|
ssl_context ssl;
|
|
|
|
struct buffer_data buffer;
|
|
|
|
|
|
|
|
memset( &ssl, 0, sizeof( ssl_context ) );
|
|
|
|
memset( buffer.buf, 0, 2000 );
|
|
|
|
buffer.ptr = buffer.buf;
|
|
|
|
|
2014-04-25 15:04:14 +02:00
|
|
|
debug_set_log_mode( mode );
|
2014-04-25 14:29:10 +02:00
|
|
|
ssl_set_dbg(&ssl, string_debug, &buffer);
|
|
|
|
|
|
|
|
debug_print_ret( &ssl, 0, file, line, text, value);
|
|
|
|
|
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
2014-04-25 15:04:14 +02:00
|
|
|
void debug_print_buf( int mode, char *file, int line, char *text,
|
|
|
|
char *data_string, char *result_str )
|
2014-04-25 14:29:10 +02:00
|
|
|
{
|
|
|
|
unsigned char data[10000];
|
|
|
|
ssl_context ssl;
|
|
|
|
struct buffer_data buffer;
|
|
|
|
size_t data_len;
|
|
|
|
|
|
|
|
memset( &data, 0, sizeof( data ) );
|
|
|
|
memset( &ssl, 0, sizeof( ssl_context ) );
|
|
|
|
memset( buffer.buf, 0, 2000 );
|
|
|
|
buffer.ptr = buffer.buf;
|
|
|
|
|
|
|
|
data_len = unhexify( data, data_string );
|
|
|
|
|
2014-04-25 15:04:14 +02:00
|
|
|
debug_set_log_mode( mode );
|
2014-04-25 14:29:10 +02:00
|
|
|
ssl_set_dbg(&ssl, string_debug, &buffer);
|
|
|
|
|
|
|
|
debug_print_buf( &ssl, 0, file, line, text, data, data_len );
|
|
|
|
|
|
|
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2013-09-17 13:25:29 +02:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_FS_IO:POLARSSL_X509_CRT_PARSE_C */
|
2014-04-25 15:04:14 +02:00
|
|
|
void debug_print_crt( int mode, char *crt_file, char *file, int line,
|
|
|
|
char *prefix, char *result_str )
|
2010-02-18 19:16:31 +01:00
|
|
|
{
|
2013-09-18 14:13:26 +02:00
|
|
|
x509_crt crt;
|
2010-02-18 19:16:31 +01:00
|
|
|
ssl_context ssl;
|
|
|
|
struct buffer_data buffer;
|
|
|
|
|
2013-09-18 11:58:25 +02:00
|
|
|
x509_crt_init( &crt );
|
2010-02-18 19:16:31 +01:00
|
|
|
memset( &ssl, 0, sizeof( ssl_context ) );
|
|
|
|
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
|
|
|
|
2014-04-25 15:04:14 +02:00
|
|
|
debug_set_log_mode( mode );
|
2010-02-18 19:16:31 +01:00
|
|
|
ssl_set_dbg(&ssl, string_debug, &buffer);
|
|
|
|
|
2013-09-18 13:46:23 +02:00
|
|
|
TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 );
|
2013-08-20 11:48:36 +02:00
|
|
|
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
|
|
|
|
2013-09-17 13:25:29 +02:00
|
|
|
x509_crt_free( &crt );
|
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
|
|
|
|
2014-04-25 14:29:10 +02:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_BIGNUM_C */
|
2014-04-25 15:04:14 +02:00
|
|
|
void debug_print_mpi( int mode, 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
|
|
|
{
|
|
|
|
ssl_context ssl;
|
|
|
|
struct buffer_data buffer;
|
|
|
|
mpi val;
|
|
|
|
|
2011-05-05 13:49:20 +02:00
|
|
|
mpi_init( &val );
|
2011-03-14 21:41:31 +01:00
|
|
|
|
|
|
|
memset( &ssl, 0, sizeof( ssl_context ) );
|
|
|
|
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
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
TEST_ASSERT( mpi_read_string( &val, radix, value ) == 0 );
|
2014-04-25 15:04:14 +02:00
|
|
|
|
|
|
|
debug_set_log_mode( mode );
|
2011-03-14 21:41:31 +01:00
|
|
|
ssl_set_dbg(&ssl, string_debug, &buffer);
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
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
|
|
|
|
|
|
|
mpi_free( &val );
|
2011-03-14 21:41:31 +01:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|