From 9e1ec22c36bb1f96bbcaf834a97840fcced0ca1b Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Wed, 15 Aug 2018 15:54:43 +0100 Subject: [PATCH] Return MBEDTLS_ERR_SSL_EARLY_MESSAGE for future HS messages This leads future HS messages to traverse the buffering function ssl_buffer_message(), which however doesn't do anything at the moment for HS messages. Since the error code MBEDTLS_ERR_SSL_EARLY_MESSAGE is afterwards remapped to MBEDTLS_ERR_SSL_CONTINUE_PROCESSING -- which is what was returned prior to this commit when receiving a future handshake message -- this commit therefore does not yet introduce any change in observable behavior. --- library/ssl_tls.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/library/ssl_tls.c b/library/ssl_tls.c index 6a44145d7..bca5b403c 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -3656,6 +3656,14 @@ int mbedtls_ssl_prepare_handshake_record( mbedtls_ssl_context *ssl ) ( ssl->state == MBEDTLS_SSL_HANDSHAKE_OVER && ssl->in_msg[0] != MBEDTLS_SSL_HS_CLIENT_HELLO ) ) ) { + if( recv_msg_seq > ssl->handshake->in_msg_seq ) + { + MBEDTLS_SSL_DEBUG_MSG( 2, ( "received future handshake message of sequence number %u (next %u)", + recv_msg_seq, + ssl->handshake->in_msg_seq ) ); + return( MBEDTLS_ERR_SSL_EARLY_MESSAGE ); + } + /* Retransmit only on last message from previous flight, to avoid * too many retransmissions. * Besides, No sane server ever retransmits HelloVerifyRequest */