mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-22 12:45:39 +01:00
Add debug_set_threshold() and thresholding of messages
This commit is contained in:
parent
92478c37a6
commit
c73079a78c
@ -2,7 +2,8 @@ PolarSSL ChangeLog (Sorted per branch, date)
|
|||||||
|
|
||||||
= PolarSSL 1.3 branch
|
= PolarSSL 1.3 branch
|
||||||
Features
|
Features
|
||||||
* debug_set_log_mode() function added to determine raw or full logging
|
* debug_set_log_mode() added to determine raw or full logging
|
||||||
|
* debug_set_threshold() added to ignore messages over threshold level
|
||||||
|
|
||||||
Changes
|
Changes
|
||||||
* POLARSSL_CONFIG_OPTIONS has been removed. All values are individually
|
* POLARSSL_CONFIG_OPTIONS has been removed. All values are individually
|
||||||
|
@ -52,14 +52,6 @@
|
|||||||
|
|
||||||
/* \} name SECTION: Module settings */
|
/* \} name SECTION: Module settings */
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Set the log mode for the debug functions globally
|
|
||||||
* (Default value: POLARSSL_DEBUG_DFL_MODE)
|
|
||||||
*
|
|
||||||
* \param log_mode The log mode to use (POLARSSL_DEBUG_LOG_FULL or
|
|
||||||
* POLARSSL_DEBUG_LOG_RAW)
|
|
||||||
*/
|
|
||||||
void debug_set_log_mode( int log_mode );
|
|
||||||
|
|
||||||
#define SSL_DEBUG_MSG( level, args ) \
|
#define SSL_DEBUG_MSG( level, args ) \
|
||||||
debug_print_msg( ssl, level, __FILE__, __LINE__, debug_fmt args );
|
debug_print_msg( ssl, level, __FILE__, __LINE__, debug_fmt args );
|
||||||
@ -100,6 +92,24 @@ void debug_set_log_mode( int log_mode );
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Set the log mode for the debug functions globally
|
||||||
|
* (Default value: POLARSSL_DEBUG_DFL_MODE)
|
||||||
|
*
|
||||||
|
* \param log_mode The log mode to use (POLARSSL_DEBUG_LOG_FULL or
|
||||||
|
* POLARSSL_DEBUG_LOG_RAW)
|
||||||
|
*/
|
||||||
|
void debug_set_log_mode( int log_mode );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Set the level threshold to handle globally. Messages that have a
|
||||||
|
* level over the threshold value are ignored.
|
||||||
|
* (Default value: 0 (No debug))
|
||||||
|
*
|
||||||
|
* \param threshold maximum level of messages to pass on
|
||||||
|
*/
|
||||||
|
void debug_set_threshold( int threshold );
|
||||||
|
|
||||||
char *debug_fmt( const char *format, ... );
|
char *debug_fmt( const char *format, ... );
|
||||||
|
|
||||||
void debug_print_msg( const ssl_context *ssl, int level,
|
void debug_print_msg( const ssl_context *ssl, int level,
|
||||||
|
@ -47,12 +47,18 @@
|
|||||||
#endif /* _MSC_VER */
|
#endif /* _MSC_VER */
|
||||||
|
|
||||||
static int debug_log_mode = POLARSSL_DEBUG_DFL_MODE;
|
static int debug_log_mode = POLARSSL_DEBUG_DFL_MODE;
|
||||||
|
static int debug_threshold = 0;
|
||||||
|
|
||||||
void debug_set_log_mode( int log_mode )
|
void debug_set_log_mode( int log_mode )
|
||||||
{
|
{
|
||||||
debug_log_mode = log_mode;
|
debug_log_mode = log_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void debug_set_threshold( int threshold )
|
||||||
|
{
|
||||||
|
debug_threshold = threshold;
|
||||||
|
}
|
||||||
|
|
||||||
char *debug_fmt( const char *format, ... )
|
char *debug_fmt( const char *format, ... )
|
||||||
{
|
{
|
||||||
va_list argp;
|
va_list argp;
|
||||||
@ -73,7 +79,7 @@ void debug_print_msg( const ssl_context *ssl, int level,
|
|||||||
char str[512];
|
char str[512];
|
||||||
int maxlen = sizeof( str ) - 1;
|
int maxlen = sizeof( str ) - 1;
|
||||||
|
|
||||||
if( ssl->f_dbg == NULL )
|
if( ssl->f_dbg == NULL || level > debug_threshold )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( debug_log_mode == POLARSSL_DEBUG_LOG_RAW )
|
if( debug_log_mode == POLARSSL_DEBUG_LOG_RAW )
|
||||||
@ -95,7 +101,7 @@ void debug_print_ret( const ssl_context *ssl, int level,
|
|||||||
int maxlen = sizeof( str ) - 1;
|
int maxlen = sizeof( str ) - 1;
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
|
|
||||||
if( ssl->f_dbg == NULL )
|
if( ssl->f_dbg == NULL || level > debug_threshold )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
||||||
@ -115,7 +121,7 @@ void debug_print_buf( const ssl_context *ssl, int level,
|
|||||||
char str[512];
|
char str[512];
|
||||||
size_t i, maxlen = sizeof( str ) - 1, idx = 0;
|
size_t i, maxlen = sizeof( str ) - 1, idx = 0;
|
||||||
|
|
||||||
if( ssl->f_dbg == NULL )
|
if( ssl->f_dbg == NULL || level > debug_threshold )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
||||||
@ -169,6 +175,9 @@ void debug_print_ecp( const ssl_context *ssl, int level,
|
|||||||
char str[512];
|
char str[512];
|
||||||
int maxlen = sizeof( str ) - 1;
|
int maxlen = sizeof( str ) - 1;
|
||||||
|
|
||||||
|
if( ssl->f_dbg == NULL || level > debug_threshold )
|
||||||
|
return;
|
||||||
|
|
||||||
snprintf( str, maxlen, "%s(X)", text );
|
snprintf( str, maxlen, "%s(X)", text );
|
||||||
str[maxlen] = '\0';
|
str[maxlen] = '\0';
|
||||||
debug_print_mpi( ssl, level, file, line, str, &X->X );
|
debug_print_mpi( ssl, level, file, line, str, &X->X );
|
||||||
@ -188,7 +197,7 @@ void debug_print_mpi( const ssl_context *ssl, int level,
|
|||||||
int j, k, maxlen = sizeof( str ) - 1, zeros = 1;
|
int j, k, maxlen = sizeof( str ) - 1, zeros = 1;
|
||||||
size_t i, n, idx = 0;
|
size_t i, n, idx = 0;
|
||||||
|
|
||||||
if( ssl->f_dbg == NULL || X == NULL )
|
if( ssl->f_dbg == NULL || X == NULL || level > debug_threshold )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for( n = X->n - 1; n > 0; n-- )
|
for( n = X->n - 1; n > 0; n-- )
|
||||||
@ -301,7 +310,7 @@ void debug_print_crt( const ssl_context *ssl, int level,
|
|||||||
char str[1024], prefix[64];
|
char str[1024], prefix[64];
|
||||||
int i = 0, maxlen = sizeof( prefix ) - 1, idx = 0;
|
int i = 0, maxlen = sizeof( prefix ) - 1, idx = 0;
|
||||||
|
|
||||||
if( ssl->f_dbg == NULL || crt == NULL )
|
if( ssl->f_dbg == NULL || crt == NULL || level > debug_threshold )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
if( debug_log_mode == POLARSSL_DEBUG_LOG_FULL )
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "polarssl/net.h"
|
#include "polarssl/net.h"
|
||||||
|
#include "polarssl/debug.h"
|
||||||
#include "polarssl/ssl.h"
|
#include "polarssl/ssl.h"
|
||||||
#include "polarssl/entropy.h"
|
#include "polarssl/entropy.h"
|
||||||
#include "polarssl/ctr_drbg.h"
|
#include "polarssl/ctr_drbg.h"
|
||||||
@ -61,11 +62,10 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
static void my_debug( void *ctx, int level, const char *str )
|
static void my_debug( void *ctx, int level, const char *str )
|
||||||
{
|
{
|
||||||
if( level < DEBUG_LEVEL )
|
((void) level);
|
||||||
{
|
|
||||||
fprintf( (FILE *) ctx, "%s", str );
|
fprintf( (FILE *) ctx, "%s", str );
|
||||||
fflush( (FILE *) ctx );
|
fflush( (FILE *) ctx );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
@ -82,6 +82,10 @@ int main( int argc, char *argv[] )
|
|||||||
((void) argc);
|
((void) argc);
|
||||||
((void) argv);
|
((void) argv);
|
||||||
|
|
||||||
|
#if defined(POLARSSL_DEBUG_C)
|
||||||
|
debug_set_threshold( DEBUG_LEVEL );
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 0. Initialize the RNG and the session data
|
* 0. Initialize the RNG and the session data
|
||||||
*/
|
*/
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "polarssl/certs.h"
|
#include "polarssl/certs.h"
|
||||||
#include "polarssl/x509.h"
|
#include "polarssl/x509.h"
|
||||||
#include "polarssl/error.h"
|
#include "polarssl/error.h"
|
||||||
|
#include "polarssl/debug.h"
|
||||||
|
|
||||||
#if defined(POLARSSL_TIMING_C)
|
#if defined(POLARSSL_TIMING_C)
|
||||||
#include "polarssl/timing.h"
|
#include "polarssl/timing.h"
|
||||||
@ -112,11 +113,10 @@ struct options
|
|||||||
|
|
||||||
static void my_debug( void *ctx, int level, const char *str )
|
static void my_debug( void *ctx, int level, const char *str )
|
||||||
{
|
{
|
||||||
if( level < opt.debug_level )
|
((void) level);
|
||||||
{
|
|
||||||
fprintf( (FILE *) ctx, "%s", str );
|
fprintf( (FILE *) ctx, "%s", str );
|
||||||
fflush( (FILE *) ctx );
|
fflush( (FILE *) ctx );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -589,6 +589,10 @@ int main( int argc, char *argv[] )
|
|||||||
goto usage;
|
goto usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(POLARSSL_DEBUG_C)
|
||||||
|
debug_set_threshold( opt.debug_level );
|
||||||
|
#endif
|
||||||
|
|
||||||
if( opt.force_ciphersuite[0] > 0 )
|
if( opt.force_ciphersuite[0] > 0 )
|
||||||
{
|
{
|
||||||
const ssl_ciphersuite_t *ciphersuite_info;
|
const ssl_ciphersuite_t *ciphersuite_info;
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include "polarssl/ssl.h"
|
#include "polarssl/ssl.h"
|
||||||
#include "polarssl/net.h"
|
#include "polarssl/net.h"
|
||||||
#include "polarssl/error.h"
|
#include "polarssl/error.h"
|
||||||
|
#include "polarssl/debug.h"
|
||||||
|
|
||||||
#if defined(POLARSSL_SSL_CACHE_C)
|
#if defined(POLARSSL_SSL_CACHE_C)
|
||||||
#include "polarssl/ssl_cache.h"
|
#include "polarssl/ssl_cache.h"
|
||||||
@ -73,11 +74,10 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
static void my_debug( void *ctx, int level, const char *str )
|
static void my_debug( void *ctx, int level, const char *str )
|
||||||
{
|
{
|
||||||
if( level < DEBUG_LEVEL )
|
((void) level);
|
||||||
{
|
|
||||||
fprintf( (FILE *) ctx, "%s", str );
|
fprintf( (FILE *) ctx, "%s", str );
|
||||||
fflush( (FILE *) ctx );
|
fflush( (FILE *) ctx );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
@ -108,6 +108,10 @@ int main( int argc, char *argv[] )
|
|||||||
pk_init( &pkey );
|
pk_init( &pkey );
|
||||||
entropy_init( &entropy );
|
entropy_init( &entropy );
|
||||||
|
|
||||||
|
#if defined(POLARSSL_DEBUG_C)
|
||||||
|
debug_set_threshold( DEBUG_LEVEL );
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 1. Load the certificates and private RSA key
|
* 1. Load the certificates and private RSA key
|
||||||
*/
|
*/
|
||||||
|
@ -51,6 +51,7 @@
|
|||||||
#include "polarssl/certs.h"
|
#include "polarssl/certs.h"
|
||||||
#include "polarssl/x509.h"
|
#include "polarssl/x509.h"
|
||||||
#include "polarssl/error.h"
|
#include "polarssl/error.h"
|
||||||
|
#include "polarssl/debug.h"
|
||||||
|
|
||||||
#if defined(POLARSSL_SSL_CACHE_C)
|
#if defined(POLARSSL_SSL_CACHE_C)
|
||||||
#include "polarssl/ssl_cache.h"
|
#include "polarssl/ssl_cache.h"
|
||||||
@ -137,11 +138,10 @@ struct options
|
|||||||
|
|
||||||
static void my_debug( void *ctx, int level, const char *str )
|
static void my_debug( void *ctx, int level, const char *str )
|
||||||
{
|
{
|
||||||
if( level < opt.debug_level )
|
((void) level);
|
||||||
{
|
|
||||||
fprintf( (FILE *) ctx, "%s", str );
|
fprintf( (FILE *) ctx, "%s", str );
|
||||||
fflush( (FILE *) ctx );
|
fflush( (FILE *) ctx );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -721,6 +721,10 @@ int main( int argc, char *argv[] )
|
|||||||
goto usage;
|
goto usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(POLARSSL_DEBUG_C)
|
||||||
|
debug_set_threshold( opt.debug_level );
|
||||||
|
#endif
|
||||||
|
|
||||||
if( opt.force_ciphersuite[0] > 0 )
|
if( opt.force_ciphersuite[0] > 0 )
|
||||||
{
|
{
|
||||||
const ssl_ciphersuite_t *ciphersuite_info;
|
const ssl_ciphersuite_t *ciphersuite_info;
|
||||||
|
@ -1,3 +1,18 @@
|
|||||||
|
Debug print msg (threshold 1, level 0)
|
||||||
|
debug_print_msg_threshold:1:0:"MyFile":999:"MyFile(0999)\: Text message, 2 == 2\n"
|
||||||
|
|
||||||
|
Debug print msg (threshold 1, level 1)
|
||||||
|
debug_print_msg_threshold:1:1:"MyFile":999:"MyFile(0999)\: Text message, 2 == 2\n"
|
||||||
|
|
||||||
|
Debug print msg (threshold 1, level 2)
|
||||||
|
debug_print_msg_threshold:1:2:"MyFile":999:""
|
||||||
|
|
||||||
|
Debug print msg (threshold 0, level 1)
|
||||||
|
debug_print_msg_threshold:0:1:"MyFile":999:""
|
||||||
|
|
||||||
|
Debug print msg (threshold 0, level 5)
|
||||||
|
debug_print_msg_threshold:0:5:"MyFile":999:""
|
||||||
|
|
||||||
Debug print return value #1
|
Debug print return value #1
|
||||||
debug_print_ret:POLARSSL_DEBUG_LOG_FULL:"MyFile":999:"Test return value":0:"MyFile(0999)\: Test return value() returned 0 (-0x0000)\n"
|
debug_print_ret:POLARSSL_DEBUG_LOG_FULL:"MyFile":999:"Test return value":0:"MyFile(0999)\: Test return value() returned 0 (-0x0000)\n"
|
||||||
|
|
||||||
|
@ -29,6 +29,28 @@ void string_debug(void *data, int level, const char *str)
|
|||||||
* END_DEPENDENCIES
|
* END_DEPENDENCIES
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* BEGIN_CASE */
|
||||||
|
void debug_print_msg_threshold( int threshold, int level, char *file, int line,
|
||||||
|
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;
|
||||||
|
|
||||||
|
debug_set_log_mode( POLARSSL_DEBUG_LOG_FULL );
|
||||||
|
debug_set_threshold( threshold );
|
||||||
|
ssl_set_dbg(&ssl, string_debug, &buffer);
|
||||||
|
|
||||||
|
debug_print_msg( &ssl, level, file, line,
|
||||||
|
debug_fmt("Text message, 2 == %d", 2 ) );
|
||||||
|
|
||||||
|
TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
|
||||||
|
}
|
||||||
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void debug_print_ret( int mode, char *file, int line, char *text, int value,
|
void debug_print_ret( int mode, char *file, int line, char *text, int value,
|
||||||
char *result_str )
|
char *result_str )
|
||||||
|
Loading…
Reference in New Issue
Block a user