From d976673dd60ed3a0566419196f7e47d720ecc842 Mon Sep 17 00:00:00 2001 From: Yanray Wang Date: Mon, 17 Oct 2022 15:13:30 +0800 Subject: [PATCH] Add build version to the output of ssl_client2 Signed-off-by: Yanray Wang --- programs/ssl/ssl_client2.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index be474d473..451e23264 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -25,6 +25,10 @@ #include "test/psa_crypto_helpers.h" #endif /* MBEDTLS_USE_PSA_CRYPTO || MBEDTLS_SSL_PROTO_TLS1_3 */ +#if defined(MBEDTLS_VERSION_C) +#include "mbedtls/build_info.h" +#endif /* MBEDTLS_VERSION_C */ + #if defined(MBEDTLS_SSL_TEST_IMPOSSIBLE) int main( void ) { @@ -360,6 +364,14 @@ int main( void ) #define USAGE_TLS1_3_KEY_EXCHANGE_MODES "" #endif /* MBEDTLS_SSL_PROTO_TLS1_3 */ +#if defined(MBEDTLS_VERSION_C) +#define USAGE_BUILD_VERSION \ + " build_version=%%d default: none (disabled)\n" \ + " option: 1 (print the build version only a stop)\n" +#else +#define USAGE_BUILD_VERSION "" +#endif /* MBEDTLS_VERSION_C */ + /* USAGE is arbitrarily split to stay under the portable string literal * length limit: 4095 bytes in C99. */ #define USAGE1 \ @@ -375,6 +387,7 @@ int main( void ) " application data message is sent followed by\n" \ " a second non-empty message before attempting\n" \ " to read a response from the server\n" \ + USAGE_BUILD_VERSION \ " debug_level=%%d default: 0 (disabled)\n" \ " nbio=%%d default: 0 (blocking I/O)\n" \ " options: 1 (non-blocking), 2 (added delays)\n" \ @@ -984,6 +997,18 @@ int main( int argc, char *argv[] ) if( opt.debug_level < 0 || opt.debug_level > 65535 ) goto usage; } +#if defined(MBEDTLS_VERSION_C) + else if( strcmp( p, "build_version" ) == 0 ) + { + if( strcmp( q, "1" ) == 0 ) + { + mbedtls_printf( "build version: %s (build %u)\n", + MBEDTLS_VERSION_STRING, + MBEDTLS_VERSION_NUMBER ); + goto exit; + } + } +#endif /* MBEDTLS_VERSION_C */ else if( strcmp( p, "context_crt_cb" ) == 0 ) { opt.context_crt_cb = atoi( q ); @@ -2454,6 +2479,11 @@ int main( int argc, char *argv[] ) } } +#if defined(MBEDTLS_VERSION_C) + mbedtls_printf( "build version: %s (build %u)\n", + MBEDTLS_VERSION_STRING, MBEDTLS_VERSION_NUMBER ); +#endif /* MBEDTLS_VERSION_C */ + #if defined(MBEDTLS_X509_CRT_PARSE_C) /* * 5. Verify the server certificate