diff --git a/library/ssl_tls.c b/library/ssl_tls.c index f89029b35..6239d67c0 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -5798,9 +5798,6 @@ static int ssl_parse_certificate_chain( mbedtls_ssl_context *ssl ) /* Make &ssl->in_msg[i] point to the beginning of the CRT chain. */ i += 3; - /* In case we tried to reuse a session but it failed. */ - ssl_clear_peer_cert( ssl->session_negotiate ); - /* Iterate through and parse the CRTs in the provided chain. */ while( i < ssl->in_hslen ) { @@ -6038,6 +6035,9 @@ int mbedtls_ssl_parse_certificate( mbedtls_ssl_context *ssl ) } #endif /* MBEDTLS_SSL_SRV_C */ + /* In case we tried to reuse a session but it failed. */ + ssl_clear_peer_cert( ssl->session_negotiate ); + if( ( ret = ssl_parse_certificate_chain( ssl ) ) != 0 ) { ssl->state++;