From 6959f53896029b0468b7d9c59151d6fca4449251 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 27 Aug 2024 12:17:22 +0200 Subject: [PATCH] ssl_client1: Exit with an error status if the TLS connection failed Signed-off-by: Gilles Peskine --- programs/ssl/ssl_client1.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/programs/ssl/ssl_client1.c b/programs/ssl/ssl_client1.c index ee734b1ed1..e51bbd42a3 100644 --- a/programs/ssl/ssl_client1.c +++ b/programs/ssl/ssl_client1.c @@ -240,6 +240,9 @@ int main(void) } if (ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) { + mbedtls_printf("The return value %d from mbedtls_ssl_read() means that the server\n" + "closed the connection first. We're ok with that.\n", + MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY); break; } @@ -259,7 +262,9 @@ int main(void) mbedtls_ssl_close_notify(&ssl); - exit_code = MBEDTLS_EXIT_SUCCESS; + if (ret == 0 || ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) { + exit_code = MBEDTLS_EXIT_SUCCESS; + } exit: