From d976673dd60ed3a0566419196f7e47d720ecc842 Mon Sep 17 00:00:00 2001 From: Yanray Wang Date: Mon, 17 Oct 2022 15:13:30 +0800 Subject: [PATCH 1/5] 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 From ff4181e2460f6370d46caf16e2d1b3ecd729153a Mon Sep 17 00:00:00 2001 From: Yanray Wang Date: Tue, 18 Oct 2022 18:16:08 +0800 Subject: [PATCH 2/5] Fix build error in cmake while printing digital build version Signed-off-by: Yanray Wang --- programs/ssl/ssl_client2.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index 451e23264..59a96d212 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -27,6 +27,7 @@ #if defined(MBEDTLS_VERSION_C) #include "mbedtls/build_info.h" +#include "mbedtls/version.h" #endif /* MBEDTLS_VERSION_C */ #if defined(MBEDTLS_SSL_TEST_IMPOSSIBLE) @@ -1004,7 +1005,7 @@ int main( int argc, char *argv[] ) { mbedtls_printf( "build version: %s (build %u)\n", MBEDTLS_VERSION_STRING, - MBEDTLS_VERSION_NUMBER ); + mbedtls_version_get_number() ); goto exit; } } @@ -2481,7 +2482,7 @@ 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 ); + MBEDTLS_VERSION_STRING, mbedtls_version_get_number() ); #endif /* MBEDTLS_VERSION_C */ #if defined(MBEDTLS_X509_CRT_PARSE_C) From 076b2d062f4e33776be5d05795386c341d71c4e1 Mon Sep 17 00:00:00 2001 From: Yanray Wang Date: Fri, 21 Oct 2022 11:09:45 +0800 Subject: [PATCH 3/5] Improve the method of printing string build version Following changes are introduced with this commit: - Call mbedtls_version_get_string before printing string build version instead of printing macro directly - Output build version in the beginning of ssl_client2 program Signed-off-by: Yanray Wang --- programs/ssl/ssl_client2.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index 59a96d212..ae4bb5702 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -26,7 +26,6 @@ #endif /* MBEDTLS_USE_PSA_CRYPTO || MBEDTLS_SSL_PROTO_TLS1_3 */ #if defined(MBEDTLS_VERSION_C) -#include "mbedtls/build_info.h" #include "mbedtls/version.h" #endif /* MBEDTLS_VERSION_C */ @@ -1003,9 +1002,11 @@ int main( int argc, char *argv[] ) { if( strcmp( q, "1" ) == 0 ) { + char version_str[10]; + memset( version_str, 0, 10 ); + mbedtls_version_get_string( version_str ); mbedtls_printf( "build version: %s (build %u)\n", - MBEDTLS_VERSION_STRING, - mbedtls_version_get_number() ); + version_str, mbedtls_version_get_number() ); goto exit; } } @@ -1722,6 +1723,14 @@ int main( int argc, char *argv[] ) } #endif /* MBEDTLS_SSL_ALPN */ +#if defined(MBEDTLS_VERSION_C) + char version_str[10]; + memset( version_str, 0, 10 ); + mbedtls_version_get_string( version_str ); + mbedtls_printf( "build version: %s (build %u)\n", + version_str, mbedtls_version_get_number() ); +#endif /* MBEDTLS_VERSION_C */ + /* * 0. Initialize the RNG and the session data */ @@ -2480,11 +2489,6 @@ int main( int argc, char *argv[] ) } } -#if defined(MBEDTLS_VERSION_C) - mbedtls_printf( "build version: %s (build %u)\n", - MBEDTLS_VERSION_STRING, mbedtls_version_get_number() ); -#endif /* MBEDTLS_VERSION_C */ - #if defined(MBEDTLS_X509_CRT_PARSE_C) /* * 5. Verify the server certificate From 84645e92c61d91e2ee8b40053cb83336a77e33a9 Mon Sep 17 00:00:00 2001 From: Yanray Wang Date: Thu, 27 Oct 2022 10:17:09 +0800 Subject: [PATCH 4/5] Simplify code of adding output in ssl_client2 - print build version macro defined in build_info.h directly - Remove all the MBEDTLS_VERSION_C guards as build version information is always available in build_info.h Signed-off-by: Yanray Wang --- programs/ssl/ssl_client2.c | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index e74656ee7..e3fdb1f7c 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -25,10 +25,6 @@ #include "test/psa_crypto_helpers.h" #endif /* MBEDTLS_USE_PSA_CRYPTO || MBEDTLS_SSL_PROTO_TLS1_3 */ -#if defined(MBEDTLS_VERSION_C) -#include "mbedtls/version.h" -#endif /* MBEDTLS_VERSION_C */ - #if defined(MBEDTLS_SSL_TEST_IMPOSSIBLE) int main( void ) { @@ -364,14 +360,6 @@ 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 \ @@ -387,8 +375,9 @@ 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" \ + " build_version=%%d default: none (disabled)\n" \ + " option: 1 (print build version only and stop)\n" \ " nbio=%%d default: 0 (blocking I/O)\n" \ " options: 1 (non-blocking), 2 (added delays)\n" \ " event=%%d default: 0 (loop)\n" \ @@ -995,20 +984,16 @@ 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 ) { - char version_str[10]; - memset( version_str, 0, 10 ); - mbedtls_version_get_string( version_str ); - mbedtls_printf( "build version: %s (build %u)\n", - version_str, mbedtls_version_get_number() ); + mbedtls_printf( "build version: %s (build %d)\n", + MBEDTLS_VERSION_STRING_FULL, + MBEDTLS_VERSION_NUMBER ); goto exit; } } -#endif /* MBEDTLS_VERSION_C */ else if( strcmp( p, "context_crt_cb" ) == 0 ) { opt.context_crt_cb = atoi( q ); @@ -1721,13 +1706,8 @@ int main( int argc, char *argv[] ) } #endif /* MBEDTLS_SSL_ALPN */ -#if defined(MBEDTLS_VERSION_C) - char version_str[10]; - memset( version_str, 0, 10 ); - mbedtls_version_get_string( version_str ); - mbedtls_printf( "build version: %s (build %u)\n", - version_str, mbedtls_version_get_number() ); -#endif /* MBEDTLS_VERSION_C */ + mbedtls_printf( "build version: %s (build %d)\n", + MBEDTLS_VERSION_STRING_FULL, MBEDTLS_VERSION_NUMBER ); /* * 0. Initialize the RNG and the session data From eaf46d1291d57ed36d31cf14ca61edf5505b9972 Mon Sep 17 00:00:00 2001 From: Yanray Wang Date: Fri, 28 Oct 2022 10:38:37 +0800 Subject: [PATCH 5/5] Add output of build version in ssl_server2 Usage: - By default, build version is printed out in the beginning of ssl_server2 application. - ./ssl_server2 build_version=1 only prints build verison and stop Signed-off-by: Yanray Wang --- programs/ssl/ssl_server2.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c index 1fd63d2d0..7aead3ade 100644 --- a/programs/ssl/ssl_server2.c +++ b/programs/ssl/ssl_server2.c @@ -489,6 +489,8 @@ int main( void ) " server_addr=%%s default: (all interfaces)\n" \ " server_port=%%d default: 4433\n" \ " debug_level=%%d default: 0 (disabled)\n" \ + " build_version=%%d default: none (disabled)\n" \ + " option: 1 (print build version only and stop)\n" \ " buffer_size=%%d default: 200 \n" \ " (minimum: 1)\n" \ " response_size=%%d default: about 152 (basic response)\n" \ @@ -1745,6 +1747,16 @@ int main( int argc, char *argv[] ) if( opt.debug_level < 0 || opt.debug_level > 65535 ) goto usage; } + else if( strcmp( p, "build_version" ) == 0 ) + { + if( strcmp( q, "1" ) == 0 ) + { + mbedtls_printf( "build version: %s (build %d)\n", + MBEDTLS_VERSION_STRING_FULL, + MBEDTLS_VERSION_NUMBER ); + goto exit; + } + } else if( strcmp( p, "nbio" ) == 0 ) { opt.nbio = atoi( q ); @@ -2576,6 +2588,9 @@ int main( int argc, char *argv[] ) } #endif /* MBEDTLS_SSL_ALPN */ + mbedtls_printf( "build version: %s (build %d)\n", + MBEDTLS_VERSION_STRING_FULL, MBEDTLS_VERSION_NUMBER ); + /* * 0. Initialize the RNG and the session data */