Skip to content

Commit 91af907

Browse files
authored
Merge pull request #8777 from rizlik/dtls_reject_v11
Drop DTLS packets with bogus minor version number
2 parents e67536c + 22f41a8 commit 91af907

4 files changed

Lines changed: 55 additions & 0 deletions

File tree

src/internal.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11788,6 +11788,10 @@ static int GetDtlsRecordHeader(WOLFSSL* ssl, word32* inOutIdx,
1178811788
*inOutIdx += ENUM_LEN + VERSION_SZ;
1178911789
ato16(ssl->buffers.inputBuffer.buffer + *inOutIdx, &ssl->keys.curEpoch);
1179011790

11791+
if (rh->pvMajor == DTLS_MAJOR && rh->pvMinor == DTLS_BOGUS_MINOR) {
11792+
return SEQUENCE_ERROR;
11793+
}
11794+
1179111795
#ifdef WOLFSSL_DTLS_CID
1179211796
if (rh->type == dtls12_cid && (cidSz = DtlsGetCidRxSize(ssl)) == 0)
1179311797
return DTLS_CID_ERROR;

tests/api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68025,6 +68025,7 @@ TEST_CASE testCases[] = {
6802568025
TEST_DECL(test_wolfSSL_dtls_cid_parse),
6802668026
TEST_DECL(test_dtls13_epochs),
6802768027
TEST_DECL(test_dtls13_ack_order),
68028+
TEST_DECL(test_dtls_version_checking),
6802868029
TEST_DECL(test_ocsp_status_callback),
6802968030
TEST_DECL(test_ocsp_basic_verify),
6803068031
TEST_DECL(test_ocsp_response_parsing),

tests/api/test_dtls.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,3 +727,52 @@ int test_dtls13_ack_order(void)
727727
#endif
728728
return EXPECT_RESULT();
729729
}
730+
731+
int test_dtls_version_checking(void)
732+
{
733+
EXPECT_DECLS;
734+
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS)
735+
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
736+
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
737+
struct test_memio_ctx test_ctx;
738+
739+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
740+
741+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
742+
wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method),
743+
0);
744+
745+
/* CH */
746+
ExpectIntEQ(wolfSSL_connect(ssl_c), WOLFSSL_FATAL_ERROR);
747+
ExpectIntEQ(wolfSSL_get_error(ssl_c, WOLFSSL_FATAL_ERROR),
748+
WOLFSSL_ERROR_WANT_READ);
749+
750+
/* modify CH DTLS header to have version 1.1 (0xfe, 0xfe) */
751+
ExpectIntGE(test_ctx.s_len, 3);
752+
if (EXPECT_SUCCESS()) {
753+
test_ctx.s_buff[1] = 0xfe;
754+
test_ctx.s_buff[2] = 0xfe;
755+
}
756+
757+
ExpectIntEQ(wolfSSL_accept(ssl_s), WOLFSSL_FATAL_ERROR);
758+
ExpectIntEQ(wolfSSL_get_error(ssl_s, WOLFSSL_FATAL_ERROR),
759+
WOLFSSL_ERROR_WANT_READ);
760+
/* server should drop the message */
761+
ExpectIntEQ(test_ctx.c_len, 0);
762+
763+
wolfSSL_free(ssl_c);
764+
ssl_c = wolfSSL_new(ctx_c);
765+
ExpectNotNull(ssl_c);
766+
wolfSSL_SetIOWriteCtx(ssl_c, &test_ctx);
767+
wolfSSL_SetIOReadCtx(ssl_c, &test_ctx);
768+
769+
/* try again */
770+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
771+
772+
wolfSSL_free(ssl_c);
773+
wolfSSL_CTX_free(ctx_c);
774+
wolfSSL_free(ssl_s);
775+
wolfSSL_CTX_free(ctx_s);
776+
#endif /* HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES && WOLFSSL_DTLS */
777+
return EXPECT_RESULT();
778+
}

tests/api/test_dtls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ int test_dtls13_basic_connection_id(void);
2727
int test_wolfSSL_dtls_cid_parse(void);
2828
int test_dtls13_epochs(void);
2929
int test_dtls13_ack_order(void);
30+
int test_dtls_version_checking(void);
3031

3132
#endif /* TESTS_API_DTLS_H */

0 commit comments

Comments
 (0)