From 96fb0ee9cf618339e5467eedfcba74145ba80c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 9 Jul 2019 12:54:17 +0200 Subject: [PATCH] Save Hello random bytes for later use --- include/mbedtls/ssl_internal.h | 6 ++++++ library/ssl_tls.c | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/mbedtls/ssl_internal.h b/include/mbedtls/ssl_internal.h index c584370e3..11d66eec4 100644 --- a/include/mbedtls/ssl_internal.h +++ b/include/mbedtls/ssl_internal.h @@ -642,6 +642,12 @@ struct mbedtls_ssl_transform z_stream ctx_deflate; /*!< compression context */ z_stream ctx_inflate; /*!< decompression context */ #endif + +#if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION) + /* We need the Hello random bytes in order to re-derive keys from the + * Master Secret and other session info, see ssl_populate_transform() */ + unsigned char randbytes[64]; /*!< ServerHello.random+ClientHello.random */ +#endif /* MBEDTLS_SSL_CONTEXT_SERIALIZATION */ }; /* diff --git a/library/ssl_tls.c b/library/ssl_tls.c index a978899d6..07201478b 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -1046,13 +1046,19 @@ static int ssl_populate_transform( mbedtls_ssl_transform *transform, (void) ssl; #endif - /* Copy info about negotiated version and extensions */ + /* + * Some data just needs copying into the structure + */ #if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC) && \ defined(MBEDTLS_SSL_SOME_MODES_USE_MAC) transform->encrypt_then_mac = encrypt_then_mac; #endif transform->minor_ver = minor_ver; +#if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION) + memcpy( transform->randbytes, randbytes, sizeof( transform->randbytes ) ); +#endif + /* * Get various info structures */