parent
d68434efba
commit
7b23c51595
@ -35,6 +35,8 @@ Changes
|
|||||||
* It is now possible to #include a user-provided configuration file at the
|
* It is now possible to #include a user-provided configuration file at the
|
||||||
end of the default config.h by defining MBEDTLS_USER_CONFIG_FILE on the
|
end of the default config.h by defining MBEDTLS_USER_CONFIG_FILE on the
|
||||||
compiler's command line.
|
compiler's command line.
|
||||||
|
* Prepend a "thread identifier" to debug messages (issue pointed out by
|
||||||
|
Hugo Leisink) (#210).
|
||||||
|
|
||||||
= mbed TLS 2.0.0 released 2015-07-13
|
= mbed TLS 2.0.0 released 2015-07-13
|
||||||
|
|
||||||
|
@ -43,6 +43,10 @@
|
|||||||
#define mbedtls_snprintf snprintf
|
#define mbedtls_snprintf snprintf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && !defined(inline)
|
||||||
|
#define inline __inline
|
||||||
|
#endif
|
||||||
|
|
||||||
#define DEBUG_BUF_SIZE 512
|
#define DEBUG_BUF_SIZE 512
|
||||||
|
|
||||||
static int debug_threshold = 0;
|
static int debug_threshold = 0;
|
||||||
@ -52,6 +56,27 @@ void mbedtls_debug_set_threshold( int threshold )
|
|||||||
debug_threshold = threshold;
|
debug_threshold = threshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* All calls to f_dbg must be made via this function
|
||||||
|
*/
|
||||||
|
static inline void debug_send_line( const mbedtls_ssl_context *ssl, int level,
|
||||||
|
const char *file, int line,
|
||||||
|
const char *str )
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* If in a threaded environment, we need a thread identifier.
|
||||||
|
* Since there is no portable way to get one, use the address of the ssl
|
||||||
|
* context instead, as it shouldn't be shared between threads.
|
||||||
|
*/
|
||||||
|
#if defined(MBEDTLS_THREADING_C)
|
||||||
|
char idstr[20 + DEBUG_BUF_SIZE]; /* 0x + 16 nibbles + ': ' */
|
||||||
|
mbedtls_snprintf( idstr, sizeof( idstr ), "%p: %s", ssl, str );
|
||||||
|
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, idstr );
|
||||||
|
#else
|
||||||
|
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
|
void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
|
||||||
const char *file, int line,
|
const char *file, int line,
|
||||||
const char *format, ... )
|
const char *format, ... )
|
||||||
@ -86,7 +111,7 @@ void mbedtls_debug_print_msg( const mbedtls_ssl_context *ssl, int level,
|
|||||||
str[ret + 1] = '\0';
|
str[ret + 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str );
|
debug_send_line( ssl, level, file, line, str );
|
||||||
}
|
}
|
||||||
|
|
||||||
void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
|
void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
|
||||||
@ -109,7 +134,7 @@ void mbedtls_debug_print_ret( const mbedtls_ssl_context *ssl, int level,
|
|||||||
mbedtls_snprintf( str, sizeof( str ), "%s() returned %d (-0x%04x)\n",
|
mbedtls_snprintf( str, sizeof( str ), "%s() returned %d (-0x%04x)\n",
|
||||||
text, ret, -ret );
|
text, ret, -ret );
|
||||||
|
|
||||||
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str );
|
debug_send_line( ssl, level, file, line, str );
|
||||||
}
|
}
|
||||||
|
|
||||||
void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
|
void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
|
||||||
@ -126,7 +151,7 @@ void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
|
|||||||
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "dumping '%s' (%u bytes)\n",
|
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "dumping '%s' (%u bytes)\n",
|
||||||
text, (unsigned int) len );
|
text, (unsigned int) len );
|
||||||
|
|
||||||
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str );
|
debug_send_line( ssl, level, file, line, str );
|
||||||
|
|
||||||
idx = 0;
|
idx = 0;
|
||||||
memset( txt, 0, sizeof( txt ) );
|
memset( txt, 0, sizeof( txt ) );
|
||||||
@ -140,7 +165,7 @@ void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
|
|||||||
if( i > 0 )
|
if( i > 0 )
|
||||||
{
|
{
|
||||||
mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
|
mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
|
||||||
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str );
|
debug_send_line( ssl, level, file, line, str );
|
||||||
|
|
||||||
idx = 0;
|
idx = 0;
|
||||||
memset( txt, 0, sizeof( txt ) );
|
memset( txt, 0, sizeof( txt ) );
|
||||||
@ -162,7 +187,7 @@ void mbedtls_debug_print_buf( const mbedtls_ssl_context *ssl, int level,
|
|||||||
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " " );
|
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " " );
|
||||||
|
|
||||||
mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
|
mbedtls_snprintf( str + idx, sizeof( str ) - idx, " %s\n", txt );
|
||||||
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str );
|
debug_send_line( ssl, level, file, line, str );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,7 +232,7 @@ void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
|
|||||||
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "value of '%s' (%d bits) is:\n",
|
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "value of '%s' (%d bits) is:\n",
|
||||||
text, (int) ( ( n * ( sizeof(mbedtls_mpi_uint) << 3 ) ) + j + 1 ) );
|
text, (int) ( ( n * ( sizeof(mbedtls_mpi_uint) << 3 ) ) + j + 1 ) );
|
||||||
|
|
||||||
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str );
|
debug_send_line( ssl, level, file, line, str );
|
||||||
|
|
||||||
idx = 0;
|
idx = 0;
|
||||||
for( i = n + 1, j = 0; i > 0; i-- )
|
for( i = n + 1, j = 0; i > 0; i-- )
|
||||||
@ -227,7 +252,7 @@ void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
|
|||||||
if( j > 0 )
|
if( j > 0 )
|
||||||
{
|
{
|
||||||
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "\n" );
|
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "\n" );
|
||||||
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str );
|
debug_send_line( ssl, level, file, line, str );
|
||||||
idx = 0;
|
idx = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -244,7 +269,7 @@ void mbedtls_debug_print_mpi( const mbedtls_ssl_context *ssl, int level,
|
|||||||
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " 00" );
|
idx += mbedtls_snprintf( str + idx, sizeof( str ) - idx, " 00" );
|
||||||
|
|
||||||
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "\n" );
|
mbedtls_snprintf( str + idx, sizeof( str ) - idx, "\n" );
|
||||||
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str );
|
debug_send_line( ssl, level, file, line, str );
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_BIGNUM_C */
|
#endif /* MBEDTLS_BIGNUM_C */
|
||||||
|
|
||||||
@ -261,7 +286,7 @@ static void debug_print_pk( const mbedtls_ssl_context *ssl, int level,
|
|||||||
|
|
||||||
if( mbedtls_pk_debug( pk, items ) != 0 )
|
if( mbedtls_pk_debug( pk, items ) != 0 )
|
||||||
{
|
{
|
||||||
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line,
|
debug_send_line( ssl, level, file, line,
|
||||||
"invalid PK context\n" );
|
"invalid PK context\n" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -282,7 +307,7 @@ static void debug_print_pk( const mbedtls_ssl_context *ssl, int level,
|
|||||||
mbedtls_debug_print_ecp( ssl, level, file, line, name, items[i].value );
|
mbedtls_debug_print_ecp( ssl, level, file, line, name, items[i].value );
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line,
|
debug_send_line( ssl, level, file, line,
|
||||||
"should not happen\n" );
|
"should not happen\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -305,7 +330,7 @@ static void debug_print_line_by_line( const mbedtls_ssl_context *ssl, int level,
|
|||||||
memcpy( str, start, len );
|
memcpy( str, start, len );
|
||||||
str[len] = '\0';
|
str[len] = '\0';
|
||||||
|
|
||||||
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str );
|
debug_send_line( ssl, level, file, line, str );
|
||||||
|
|
||||||
start = cur + 1;
|
start = cur + 1;
|
||||||
}
|
}
|
||||||
@ -327,7 +352,7 @@ void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level,
|
|||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
mbedtls_snprintf( str, sizeof( str ), "%s #%d:\n", text, ++i );
|
mbedtls_snprintf( str, sizeof( str ), "%s #%d:\n", text, ++i );
|
||||||
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str );
|
debug_send_line( ssl, level, file, line, str );
|
||||||
|
|
||||||
mbedtls_x509_crt_info( buf, sizeof( buf ) - 1, "", crt );
|
mbedtls_x509_crt_info( buf, sizeof( buf ) - 1, "", crt );
|
||||||
debug_print_line_by_line( ssl, level, file, line, buf );
|
debug_print_line_by_line( ssl, level, file, line, buf );
|
||||||
|
@ -25,6 +25,11 @@ void string_debug(void *data, int level, const char *file, int line, const char
|
|||||||
*p++ = ':';
|
*p++ = ':';
|
||||||
*p++ = ' ';
|
*p++ = ' ';
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_THREADING_C)
|
||||||
|
/* Skip "thread ID" (up to the first space) as it is not predictable */
|
||||||
|
while( *str++ != ' ' );
|
||||||
|
#endif
|
||||||
|
|
||||||
memcpy( p, str, strlen( str ) );
|
memcpy( p, str, strlen( str ) );
|
||||||
p += strlen( str );
|
p += strlen( str );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user