From b590e06f422ab020cde8e05fcc41865c55d48ae8 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Thu, 18 Jun 2020 12:13:52 +0200 Subject: [PATCH] DTLS fixes - `SendFinished` resetting`dtls_expected_peer_handshake_number` should depend on side and if we are resuming a connection - No need to do a cookie exchange on session resumption --- src/internal.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/internal.c b/src/internal.c index 6d4b4b91a..c0f213e11 100644 --- a/src/internal.c +++ b/src/internal.c @@ -16623,7 +16623,10 @@ int SendFinished(WOLFSSL* ssl) ret = SendBuffered(ssl); #ifdef WOLFSSL_DTLS - if (ssl->options.side == WOLFSSL_SERVER_END) { + if ((!ssl->options.resuming && + ssl->options.side == WOLFSSL_SERVER_END) || + (ssl->options.resuming && + ssl->options.side == WOLFSSL_CLIENT_END)) { ssl->keys.dtls_handshake_number = 0; ssl->keys.dtls_expected_peer_handshake_number = 0; } @@ -27003,7 +27006,7 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx, XMEMCPY(&pv, input + i, OPAQUE16_LEN); ssl->chVersion = pv; /* store */ #ifdef WOLFSSL_DTLS - if (IsDtlsNotSctpMode(ssl) && !IsSCR(ssl)) { + if (IsDtlsNotSctpMode(ssl) && !IsSCR(ssl) && !ssl->options.resuming) { #if defined(NO_SHA) && defined(NO_SHA256) #error "DTLS needs either SHA or SHA-256" #endif /* NO_SHA && NO_SHA256 */ @@ -27153,7 +27156,7 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx, /* random */ XMEMCPY(ssl->arrays->clientRandom, input + i, RAN_LEN); #ifdef WOLFSSL_DTLS - if (IsDtlsNotSctpMode(ssl) && !IsSCR(ssl)) { + if (IsDtlsNotSctpMode(ssl) && !IsSCR(ssl) && !ssl->options.resuming) { ret = wc_HmacUpdate(&cookieHmac, input + i, RAN_LEN); if (ret != 0) return ret; } @@ -27186,7 +27189,8 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx, XMEMCPY(ssl->arrays->sessionID, input + i, b); #ifdef WOLFSSL_DTLS - if (IsDtlsNotSctpMode(ssl) && !IsSCR(ssl)) { + if (IsDtlsNotSctpMode(ssl) && !IsSCR(ssl) && + !ssl->options.resuming) { ret = wc_HmacUpdate(&cookieHmac, input + i - 1, b + 1); if (ret != 0) return ret; } @@ -27271,7 +27275,7 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx, #endif #ifdef WOLFSSL_DTLS - if (IsDtlsNotSctpMode(ssl) && !IsSCR(ssl)) { + if (IsDtlsNotSctpMode(ssl) && !IsSCR(ssl) && !ssl->options.resuming) { ret = wc_HmacUpdate(&cookieHmac, input + i - OPAQUE16_LEN, clSuites.suiteSz + OPAQUE16_LEN); @@ -27297,7 +27301,7 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx, #ifdef WOLFSSL_DTLS if (IsDtlsNotSctpMode(ssl)) { - if (!IsSCR(ssl)) { + if (!IsSCR(ssl) && !ssl->options.resuming) { byte newCookie[MAX_COOKIE_LEN]; ret = wc_HmacUpdate(&cookieHmac, input + i - 1, b + 1);