From 12555c61d3a39c215476e841030a65eea0b3b997 Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Thu, 16 Aug 2018 12:47:53 +0100 Subject: [PATCH] Introduce function to parse total handshake length This commit introduces a static helper function ssl_get_hs_total_len() parsing the total message length field in the handshake header, and puts it to use in mbedtls_ssl_prepare_handshake_record(). --- library/ssl_tls.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/library/ssl_tls.c b/library/ssl_tls.c index 7e01aa35a..d7c61655e 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -55,6 +55,7 @@ #endif static void ssl_reset_in_out_pointers( mbedtls_ssl_context *ssl ); +static uint32_t ssl_get_hs_total_len( mbedtls_ssl_context *ssl ); /* Length of the "epoch" field in the record header */ static inline size_t ssl_ep_len( const mbedtls_ssl_context *ssl ) @@ -3659,6 +3660,12 @@ static int ssl_reassemble_dtls_handshake( mbedtls_ssl_context *ssl ) } #endif /* MBEDTLS_SSL_PROTO_DTLS */ +static uint32_t ssl_get_hs_total_len( mbedtls_ssl_context *ssl ) +{ + return( ( ssl->in_msg[1] << 16 ) | + ( ssl->in_msg[2] << 8 ) | + ssl->in_msg[3] ); +} int mbedtls_ssl_prepare_handshake_record( mbedtls_ssl_context *ssl ) { @@ -3669,10 +3676,7 @@ int mbedtls_ssl_prepare_handshake_record( mbedtls_ssl_context *ssl ) return( MBEDTLS_ERR_SSL_INVALID_RECORD ); } - ssl->in_hslen = mbedtls_ssl_hs_hdr_len( ssl ) + ( - ( ssl->in_msg[1] << 16 ) | - ( ssl->in_msg[2] << 8 ) | - ssl->in_msg[3] ); + ssl->in_hslen = mbedtls_ssl_hs_hdr_len( ssl ) + ssl_get_hs_total_len( ssl ); MBEDTLS_SSL_DEBUG_MSG( 3, ( "handshake message: msglen =" " %d, type = %d, hslen = %d",