Skip to content

Commit cb68910

Browse files
authored
Merge pull request #7466 from julek-wolfssl/gh/7273
Mark all record sequence numbers before stateful parsing as read
2 parents 2335eb6 + 7644d79 commit cb68910

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

src/dtls.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,11 +1010,20 @@ int DoClientHelloStateless(WOLFSSL* ssl, const byte* input, word32 helloSz,
10101010
ssl->options.dtlsStateful = 1;
10111011
/* Update the window now that we enter the stateful parsing */
10121012
#ifdef WOLFSSL_DTLS13
1013-
if (isTls13)
1013+
if (isTls13) {
1014+
/* Set record numbers before current record number as read */
1015+
Dtls13Epoch* e;
10141016
ret = Dtls13UpdateWindowRecordRecvd(ssl);
1017+
e = Dtls13GetEpoch(ssl, ssl->keys.curEpoch64);
1018+
if (e != NULL)
1019+
XMEMSET(e->window, 0xFF, sizeof(e->window));
1020+
}
10151021
else
10161022
#endif
10171023
DtlsUpdateWindow(ssl);
1024+
/* Set record numbers before current record number as read */
1025+
XMEMSET(ssl->keys.peerSeq->window, 0xFF,
1026+
sizeof(ssl->keys.peerSeq->window));
10181027
}
10191028
}
10201029

tests/api.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70740,6 +70740,59 @@ static int test_dtls_empty_keyshare_with_cookie(void)
7074070740
return EXPECT_RESULT();
7074170741
}
7074270742

70743+
static int test_dtls_old_seq_number(void)
70744+
{
70745+
EXPECT_DECLS;
70746+
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS)
70747+
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
70748+
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
70749+
struct test_memio_ctx test_ctx;
70750+
70751+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
70752+
70753+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
70754+
wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
70755+
70756+
/* CH1 */
70757+
ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
70758+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
70759+
/* HVR */
70760+
ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
70761+
ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
70762+
/* CH2 */
70763+
ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
70764+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
70765+
/* Server first flight */
70766+
ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
70767+
ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
70768+
/* Client second flight */
70769+
ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
70770+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
70771+
/* Modify the sequence number */
70772+
{
70773+
DtlsRecordLayerHeader* dtlsRH = (DtlsRecordLayerHeader*)test_ctx.s_buff;
70774+
XMEMSET(dtlsRH->sequence_number, 0, sizeof(dtlsRH->sequence_number));
70775+
}
70776+
/* Server second flight */
70777+
ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
70778+
ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
70779+
/* Server should not do anything as a pkt was dropped */
70780+
ExpectIntEQ(test_ctx.c_len, 0);
70781+
ExpectIntEQ(test_ctx.s_len, 0);
70782+
/* Trigger rtx */
70783+
ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
70784+
70785+
/* Complete connection */
70786+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
70787+
70788+
wolfSSL_free(ssl_c);
70789+
wolfSSL_CTX_free(ctx_c);
70790+
wolfSSL_free(ssl_s);
70791+
wolfSSL_CTX_free(ctx_s);
70792+
#endif
70793+
return EXPECT_RESULT();
70794+
}
70795+
7074370796
#if defined(HAVE_IO_TESTS_DEPENDENCIES) && defined(WOLFSSL_TLS13) && \
7074470797
defined(HAVE_LIBOQS)
7074570798
static void test_tls13_pq_groups_ctx_ready(WOLFSSL_CTX* ctx)
@@ -72965,6 +73018,7 @@ TEST_CASE testCases[] = {
7296573018
TEST_DECL(test_dtls_frag_ch),
7296673019
TEST_DECL(test_dtls13_frag_ch_pq),
7296773020
TEST_DECL(test_dtls_empty_keyshare_with_cookie),
73021+
TEST_DECL(test_dtls_old_seq_number),
7296873022
TEST_DECL(test_tls13_pq_groups),
7296973023
TEST_DECL(test_tls13_early_data),
7297073024
TEST_DECL(test_tls_multi_handshakes_one_record),

0 commit comments

Comments
 (0)