diff --git a/library/debug.c b/library/debug.c index c6788b62b..41769eca6 100644 --- a/library/debug.c +++ b/library/debug.c @@ -382,6 +382,8 @@ void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level, while( crt != NULL ) { + int ret; + mbedtls_pk_context *pk; char buf[1024]; mbedtls_snprintf( str, sizeof( str ), "%s #%d:\n", text, ++i ); @@ -390,7 +392,17 @@ void mbedtls_debug_print_crt( const mbedtls_ssl_context *ssl, int level, mbedtls_x509_crt_info( buf, sizeof( buf ) - 1, "", crt ); debug_print_line_by_line( ssl, level, file, line, buf ); - debug_print_pk( ssl, level, file, line, "crt->", &crt->pk ); + ret = mbedtls_x509_crt_pk_acquire( crt, &pk ); + if( ret != 0 ) + { + mbedtls_snprintf( str, sizeof( str ), + "mbedtls_x509_crt_pk_acquire() failed with -%#04x\n", + -ret ); + debug_send_line( ssl, level, file, line, str ); + return; + } + debug_print_pk( ssl, level, file, line, "crt->", pk ); + mbedtls_x509_crt_pk_release( crt, pk ); crt = crt->next; }