From 41d58465c0185c910ddca6f6637515579faeff28 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Tue, 24 Nov 2020 16:06:35 +0100 Subject: [PATCH 1/2] Adapt wolfSSL_dtls_got_timeout to secure renegotiation usage Reset DTLS stored messages on a FreeHandshakeResources call even if secure renegotiation is enabled. Without this, in a server initiated rehandshake, the server would keep old messages (ChangeCipherSpec and Finished) even when it sent a HelloRequest message. --- src/internal.c | 20 ++++++++++---------- src/ssl.c | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/internal.c b/src/internal.c index a13d1e5eb..a2cbdeff6 100644 --- a/src/internal.c +++ b/src/internal.c @@ -6488,6 +6488,16 @@ void SSL_ResourceFree(WOLFSSL* ssl) void FreeHandshakeResources(WOLFSSL* ssl) { +#ifdef WOLFSSL_DTLS + /* DTLS_POOL */ + if (ssl->options.dtls) { + DtlsMsgPoolReset(ssl); + DtlsMsgListDelete(ssl->dtls_rx_msg_list, ssl->heap); + ssl->dtls_rx_msg_list = NULL; + ssl->dtls_rx_msg_list_sz = 0; + } +#endif + #ifdef HAVE_SECURE_RENEGOTIATION if (ssl->secure_renegotiation && ssl->secure_renegotiation->enabled) { WOLFSSL_MSG("Secure Renegotiation needs to retain handshake resources"); @@ -6532,16 +6542,6 @@ void FreeHandshakeResources(WOLFSSL* ssl) } } -#ifdef WOLFSSL_DTLS - /* DTLS_POOL */ - if (ssl->options.dtls) { - DtlsMsgPoolReset(ssl); - DtlsMsgListDelete(ssl->dtls_rx_msg_list, ssl->heap); - ssl->dtls_rx_msg_list = NULL; - ssl->dtls_rx_msg_list_sz = 0; - } -#endif - #if defined(WOLFSSL_TLS13) && defined(WOLFSSL_POST_HANDSHAKE_AUTH) && \ defined(HAVE_SESSION_TICKET) if (!ssl->options.tls1_3) diff --git a/src/ssl.c b/src/ssl.c index a5e20b6ef..3110519c3 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -11633,7 +11633,7 @@ int wolfSSL_dtls_got_timeout(WOLFSSL* ssl) if (ssl == NULL) return WOLFSSL_FATAL_ERROR; - if (!ssl->options.handShakeDone && + if ((IsSCR(ssl) || !ssl->options.handShakeDone) && (DtlsMsgPoolTimeout(ssl) < 0 || DtlsMsgPoolSend(ssl, 0) < 0)) { result = WOLFSSL_FATAL_ERROR; From 95132b1c5516d2d2daffb60851901b22064bda88 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Tue, 24 Nov 2020 17:03:40 +0100 Subject: [PATCH 2/2] Make renegotiation information available outside of OPENSSL_EXTRA --- src/ssl.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index 3110519c3..1d11f052b 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -25303,18 +25303,6 @@ long wolfSSL_get_options(const WOLFSSL* ssl) #endif /* OPENSSL_EXTRA || WOLFSSL_WPAS_SMALL */ -#ifdef OPENSSL_EXTRA - -long wolfSSL_clear_options(WOLFSSL* ssl, long opt) -{ - WOLFSSL_ENTER("SSL_clear_options"); - if(ssl == NULL) - return WOLFSSL_FAILURE; - ssl->options.mask &= ~opt; - return ssl->options.mask; -} - - #if defined(HAVE_SECURE_RENEGOTIATION) \ || defined(HAVE_SERVER_RENEGOTIATION_INFO) /* clears the counter for number of renegotiations done @@ -25360,6 +25348,18 @@ int wolfSSL_SSL_renegotiate_pending(WOLFSSL *s) } #endif /* HAVE_SECURE_RENEGOTIATION || HAVE_SERVER_RENEGOTIATION_INFO */ +#ifdef OPENSSL_EXTRA + +long wolfSSL_clear_options(WOLFSSL* ssl, long opt) +{ + WOLFSSL_ENTER("SSL_clear_options"); + if(ssl == NULL) + return WOLFSSL_FAILURE; + ssl->options.mask &= ~opt; + return ssl->options.mask; +} + + #ifndef NO_DH long wolfSSL_set_tmp_dh(WOLFSSL *ssl, WOLFSSL_DH *dh) {