From af379f0a0f4c343208a434d3036ff47c07f61f17 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Thu, 12 Jan 2023 20:43:05 -0800 Subject: [PATCH] DTLS Handshake Sequence The DTLS server needs to save the message_seq number of the client hello for use in both the hello verify request in the stateless start and for the server hello. Move the stashing of the value earlier in DoClientHello(). (Issue #5224) --- src/internal.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/internal.c b/src/internal.c index 1afa361f9..a0802ce1f 100644 --- a/src/internal.c +++ b/src/internal.c @@ -32839,6 +32839,18 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx, #ifdef WOLFSSL_DTLS if (IsDtlsNotSctpMode(ssl) && IsDtlsNotSrtpMode(ssl) && !IsSCR(ssl)) { byte process = 0; + if (((ssl->keys.dtls_sequence_number_hi == ssl->keys.curSeq_hi && + ssl->keys.dtls_sequence_number_lo < ssl->keys.curSeq_lo) || + (ssl->keys.dtls_sequence_number_hi < ssl->keys.curSeq_hi))) { + /* We should continue with the same sequence number as the + * Client Hello if available. */ + ssl->keys.dtls_sequence_number_hi = ssl->keys.curSeq_hi; + ssl->keys.dtls_sequence_number_lo = ssl->keys.curSeq_lo; + } + /* We should continue with the same handshake number as the + * Client Hello. */ + ssl->keys.dtls_handshake_number = + ssl->keys.dtls_peer_handshake_number; ret = DoClientHelloStateless(ssl, input, inOutIdx, helloSz, &process); if (ret != 0 || !process) { @@ -32856,22 +32868,6 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx, /* protocol version */ XMEMCPY(&pv, input + i, OPAQUE16_LEN); ssl->chVersion = pv; /* store */ -#ifdef WOLFSSL_DTLS - if (IsDtlsNotSctpMode(ssl) && IsDtlsNotSrtpMode(ssl) && !IsSCR(ssl)) { - if (((ssl->keys.dtls_sequence_number_hi == ssl->keys.curSeq_hi && - ssl->keys.dtls_sequence_number_lo < ssl->keys.curSeq_lo) || - (ssl->keys.dtls_sequence_number_hi < ssl->keys.curSeq_hi))) { - /* We should continue with the same sequence number as the - * Client Hello if available. */ - ssl->keys.dtls_sequence_number_hi = ssl->keys.curSeq_hi; - ssl->keys.dtls_sequence_number_lo = ssl->keys.curSeq_lo; - } - /* We should continue with the same handshake number as the - * Client Hello. */ - ssl->keys.dtls_handshake_number = - ssl->keys.dtls_peer_handshake_number; - } -#endif /* WOLFSSL_DTLS */ i += OPAQUE16_LEN; /* Legacy protocol version cannot negotiate TLS 1.3 or higher. */