diff --git a/include/mbedtls/ssl.h b/include/mbedtls/ssl.h index 3e8c9bef6..36b58f6b5 100644 --- a/include/mbedtls/ssl.h +++ b/include/mbedtls/ssl.h @@ -1501,6 +1501,7 @@ void mbedtls_ssl_conf_rng_ctx( mbedtls_ssl_config *conf, void *p_rng ); #endif /* MBEDTLS_SSL_CONF_RNG */ +#if defined(MBEDTLS_DEBUG_C) /** * \brief Set the debug callback * @@ -1518,6 +1519,7 @@ void mbedtls_ssl_conf_rng_ctx( mbedtls_ssl_config *conf, void mbedtls_ssl_conf_dbg( mbedtls_ssl_config *conf, void (*f_dbg)(void *, int, const char *, int, const char *), void *p_dbg ); +#endif /* MBEDTLS_DEBUG_C */ #if !defined(MBEDTLS_SSL_CONF_RECV) && \ !defined(MBEDTLS_SSL_CONF_SEND) && \ diff --git a/library/ssl_tls.c b/library/ssl_tls.c index 650dec739..1d67e51cf 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -8213,19 +8213,15 @@ void mbedtls_ssl_conf_rng_ctx( mbedtls_ssl_config *conf, } #endif +#if defined(MBEDTLS_DEBUG_C) void mbedtls_ssl_conf_dbg( mbedtls_ssl_config *conf, void (*f_dbg)(void *, int, const char *, int, const char *), void *p_dbg ) { -#if defined(MBEDTLS_DEBUG_C) conf->f_dbg = f_dbg; conf->p_dbg = p_dbg; -#else - ((void) conf); - ((void) f_dbg); - ((void) p_dbg); -#endif /* MBEDTLS_DEBUG_C */ } +#endif /* MBEDTLS_DEBUG_C */ #if !defined(MBEDTLS_SSL_CONF_RECV) && \ !defined(MBEDTLS_SSL_CONF_SEND) && \ diff --git a/programs/ssl/dtls_client.c b/programs/ssl/dtls_client.c index 700e19732..5bd5cbedd 100644 --- a/programs/ssl/dtls_client.c +++ b/programs/ssl/dtls_client.c @@ -83,6 +83,7 @@ int main( void ) #define DEBUG_LEVEL 0 +#if defined(MBEDTLS_DEBUG_C) static void my_debug( void *ctx, int level, const char *file, int line, const char *str ) @@ -92,6 +93,7 @@ static void my_debug( void *ctx, int level, mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str ); fflush( (FILE *) ctx ); } +#endif /* MBEDTLS_DEBUG_C */ int main( int argc, char *argv[] ) { @@ -191,7 +193,9 @@ int main( int argc, char *argv[] ) mbedtls_ssl_conf_authmode( &conf, MBEDTLS_SSL_VERIFY_OPTIONAL ); mbedtls_ssl_conf_ca_chain( &conf, &cacert, NULL ); mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg ); +#if defined(MBEDTLS_DEBUG_C) mbedtls_ssl_conf_dbg( &conf, my_debug, stdout ); +#endif if( ( ret = mbedtls_ssl_setup( &ssl, &conf ) ) != 0 ) { diff --git a/programs/ssl/dtls_server.c b/programs/ssl/dtls_server.c index e238a95ac..f2dcd2f88 100644 --- a/programs/ssl/dtls_server.c +++ b/programs/ssl/dtls_server.c @@ -92,6 +92,7 @@ int main( void ) #define DEBUG_LEVEL 0 +#if defined(MBEDTLS_DEBUG_C) static void my_debug( void *ctx, int level, const char *file, int line, const char *str ) @@ -101,6 +102,7 @@ static void my_debug( void *ctx, int level, mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str ); fflush( (FILE *) ctx ); } +#endif /* MBEDTLS_DEBUG_C */ int main( void ) { @@ -223,7 +225,9 @@ int main( void ) } mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg ); +#if defined(MBEDTLS_DEBUG_C) mbedtls_ssl_conf_dbg( &conf, my_debug, stdout ); +#endif #if defined(MBEDTLS_SSL_CACHE_C) && !defined(MBEDTLS_SSL_NO_SESSION_CACHE) mbedtls_ssl_conf_session_cache( &conf, &cache, diff --git a/programs/ssl/ssl_client1.c b/programs/ssl/ssl_client1.c index 28ecc21c0..2554946a8 100644 --- a/programs/ssl/ssl_client1.c +++ b/programs/ssl/ssl_client1.c @@ -73,6 +73,7 @@ int main( void ) #define DEBUG_LEVEL 1 +#if defined(MBEDTLS_DEBUG_C) static void my_debug( void *ctx, int level, const char *file, int line, const char *str ) @@ -82,6 +83,7 @@ static void my_debug( void *ctx, int level, mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str ); fflush( (FILE *) ctx ); } +#endif /* MBEDTLS_DEBUG_C */ int main( void ) { @@ -178,7 +180,9 @@ int main( void ) mbedtls_ssl_conf_authmode( &conf, MBEDTLS_SSL_VERIFY_OPTIONAL ); mbedtls_ssl_conf_ca_chain( &conf, &cacert, NULL ); mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg ); +#if defined(MBEDTLS_DEBUG_C) mbedtls_ssl_conf_dbg( &conf, my_debug, stdout ); +#endif if( ( ret = mbedtls_ssl_setup( &ssl, &conf ) ) != 0 ) { diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index c63b44550..5177ce950 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -450,6 +450,7 @@ struct options int query_config( const char *config ); +#if defined(MBEDTLS_DEBUG_C) static void my_debug( void *ctx, int level, const char *file, int line, const char *str ) @@ -465,6 +466,7 @@ static void my_debug( void *ctx, int level, basename, line, level, str ); fflush( (FILE *) ctx ); } +#endif /* MBEDTLS_DEBUG_C */ #if !defined(MBEDTLS_SSL_CONF_RECV) && \ @@ -1777,7 +1779,9 @@ int main( int argc, char *argv[] ) mbedtls_ssl_conf_rng_ctx( &conf, &ctr_drbg ); #endif +#if defined(MBEDTLS_DEBUG_C) mbedtls_ssl_conf_dbg( &conf, my_debug, stdout ); +#endif #if !defined(MBEDTLS_SSL_CONF_READ_TIMEOUT) mbedtls_ssl_conf_read_timeout( &conf, opt.read_timeout ); diff --git a/programs/ssl/ssl_fork_server.c b/programs/ssl/ssl_fork_server.c index b4a541411..c716ca9ef 100644 --- a/programs/ssl/ssl_fork_server.c +++ b/programs/ssl/ssl_fork_server.c @@ -90,6 +90,7 @@ int main( void ) #define DEBUG_LEVEL 0 +#if defined(MBEDTLS_DEBUG_C) static void my_debug( void *ctx, int level, const char *file, int line, const char *str ) @@ -99,6 +100,7 @@ static void my_debug( void *ctx, int level, mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str ); fflush( (FILE *) ctx ); } +#endif /* MBEDTLS_DEBUG_C */ int main( void ) { @@ -195,7 +197,9 @@ int main( void ) } mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg ); +#if defined(MBEDTLS_DEBUG_C) mbedtls_ssl_conf_dbg( &conf, my_debug, stdout ); +#endif mbedtls_ssl_conf_ca_chain( &conf, srvcert.next, NULL ); if( ( ret = mbedtls_ssl_conf_own_cert( &conf, &srvcert, &pkey ) ) != 0 ) diff --git a/programs/ssl/ssl_mail_client.c b/programs/ssl/ssl_mail_client.c index 58804684e..03d556e02 100644 --- a/programs/ssl/ssl_mail_client.c +++ b/programs/ssl/ssl_mail_client.c @@ -163,6 +163,7 @@ struct options int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */ } opt; +#if defined(MBEDTLS_DEBUG_C) static void my_debug( void *ctx, int level, const char *file, int line, const char *str ) @@ -172,6 +173,7 @@ static void my_debug( void *ctx, int level, mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str ); fflush( (FILE *) ctx ); } +#endif /* MBEDTLS_DEBUG_C */ static int do_handshake( mbedtls_ssl_context *ssl ) { @@ -619,7 +621,9 @@ int main( int argc, char *argv[] ) mbedtls_ssl_conf_authmode( &conf, MBEDTLS_SSL_VERIFY_OPTIONAL ); mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg ); +#if defined(MBEDTLS_DEBUG_C) mbedtls_ssl_conf_dbg( &conf, my_debug, stdout ); +#endif if( opt.force_ciphersuite[0] != DFL_FORCE_CIPHER ) mbedtls_ssl_conf_ciphersuites( &conf, opt.force_ciphersuite ); diff --git a/programs/ssl/ssl_pthread_server.c b/programs/ssl/ssl_pthread_server.c index 11298a5aa..6ce4faaca 100644 --- a/programs/ssl/ssl_pthread_server.c +++ b/programs/ssl/ssl_pthread_server.c @@ -433,7 +433,9 @@ int main( void ) } mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg ); +#if defined(MBEDTLS_DEBUG_C) mbedtls_ssl_conf_dbg( &conf, my_mutexed_debug, stdout ); +#endif /* mbedtls_ssl_cache_get() and mbedtls_ssl_cache_set() are thread-safe if * MBEDTLS_THREADING_C is set. diff --git a/programs/ssl/ssl_server.c b/programs/ssl/ssl_server.c index f5fcfda4a..849c14d95 100644 --- a/programs/ssl/ssl_server.c +++ b/programs/ssl/ssl_server.c @@ -85,6 +85,7 @@ int main( void ) #define DEBUG_LEVEL 0 +#if defined(MBEDTLS_DEBUG_C) static void my_debug( void *ctx, int level, const char *file, int line, const char *str ) @@ -94,6 +95,7 @@ static void my_debug( void *ctx, int level, mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str ); fflush( (FILE *) ctx ); } +#endif /* MBEDTLS_DEBUG_C */ int main( void ) { @@ -211,7 +213,9 @@ int main( void ) } mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg ); +#if defined(MBEDTLS_DEBUG_C) mbedtls_ssl_conf_dbg( &conf, my_debug, stdout ); +#endif #if defined(MBEDTLS_SSL_CACHE_C) && !defined(MBEDTLS_SSL_NO_SESSION_CACHE) mbedtls_ssl_conf_session_cache( &conf, &cache, diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c index 876a7a06c..ec3ead97e 100644 --- a/programs/ssl/ssl_server2.c +++ b/programs/ssl/ssl_server2.c @@ -582,6 +582,7 @@ struct options int query_config( const char *config ); +#if defined(MBEDTLS_DEBUG_C) static void my_debug( void *ctx, int level, const char *file, int line, const char *str ) @@ -596,6 +597,7 @@ static void my_debug( void *ctx, int level, mbedtls_fprintf( (FILE *) ctx, "%s:%04d: |%d| %s", basename, line, level, str ); fflush( (FILE *) ctx ); } +#endif /* MBEDTLS_DEBUG_C */ #if !defined(MBEDTLS_SSL_CONF_RECV) && \ @@ -2583,7 +2585,9 @@ int main( int argc, char *argv[] ) mbedtls_ssl_conf_rng_ctx( &conf, &ctr_drbg ); #endif +#if defined(MBEDTLS_DEBUG_C) mbedtls_ssl_conf_dbg( &conf, my_debug, stdout ); +#endif #if defined(MBEDTLS_SSL_CACHE_C) if( opt.cache_max != -1 ) diff --git a/programs/x509/cert_app.c b/programs/x509/cert_app.c index 3fc093e5d..0656ce768 100644 --- a/programs/x509/cert_app.c +++ b/programs/x509/cert_app.c @@ -117,6 +117,7 @@ struct options int permissive; /* permissive parsing */ } opt; +#if defined(MBEDTLS_DEBUG_C) static void my_debug( void *ctx, int level, const char *file, int line, const char *str ) @@ -126,6 +127,7 @@ static void my_debug( void *ctx, int level, mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str ); fflush( (FILE *) ctx ); } +#endif /* MBEDTLS_DEBUG_C */ static int my_verify( void *data, mbedtls_x509_crt *crt, int depth, uint32_t *flags ) { @@ -423,7 +425,9 @@ int main( int argc, char *argv[] ) mbedtls_ssl_conf_authmode( &conf, MBEDTLS_SSL_VERIFY_NONE ); mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg ); +#if defined(MBEDTLS_DEBUG_C) mbedtls_ssl_conf_dbg( &conf, my_debug, stdout ); +#endif if( ( ret = mbedtls_ssl_setup( &ssl, &conf ) ) != 0 ) {