Skip to content

Commit 944db2c

Browse files
Merge pull request #6726 from julek-wolfssl/dropped-ccs
Server should not ignore plaintext packets as long as it has stuff to rtx
2 parents 70c362f + c47600c commit 944db2c

2 files changed

Lines changed: 86 additions & 9 deletions

File tree

src/internal.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9199,13 +9199,21 @@ int VerifyForDtlsMsgPoolSend(WOLFSSL* ssl, byte type, word32 fragOffset)
91999199
* to be used for triggering retransmission of whole DtlsMsgPool.
92009200
* change cipher suite type is not verified here
92019201
*/
9202-
return ((fragOffset == 0) &&
9203-
(((ssl->options.side == WOLFSSL_SERVER_END) &&
9204-
((type == client_hello) ||
9205-
((ssl->options.verifyPeer) && (type == certificate)) ||
9206-
((!ssl->options.verifyPeer) && (type == client_key_exchange)))) ||
9207-
((ssl->options.side == WOLFSSL_CLIENT_END) &&
9208-
(type == hello_request || type == server_hello))));
9202+
if (fragOffset == 0) {
9203+
if (ssl->options.side == WOLFSSL_SERVER_END) {
9204+
if (type == client_hello)
9205+
return 1;
9206+
else if (ssl->options.verifyPeer && type == certificate)
9207+
return 1;
9208+
else if (!ssl->options.verifyPeer && type == client_key_exchange)
9209+
return 1;
9210+
}
9211+
else {
9212+
if (type == hello_request || type == server_hello)
9213+
return 1;
9214+
}
9215+
}
9216+
return 0;
92099217
}
92109218

92119219

@@ -20003,9 +20011,10 @@ static int HandleDTLSDecryptFailed(WOLFSSL* ssl)
2000320011

2000420012
static int DtlsShouldDrop(WOLFSSL* ssl, int retcode)
2000520013
{
20006-
if (ssl->options.handShakeDone && !IsEncryptionOn(ssl, 0)) {
20014+
if (ssl->options.handShakeDone && !IsEncryptionOn(ssl, 0) &&
20015+
!ssl->options.dtlsHsRetain) {
2000720016
WOLFSSL_MSG("Silently dropping plaintext DTLS message "
20008-
"on established connection.");
20017+
"on established connection when we have nothing to send.");
2000920018
return 1;
2001020019
}
2001120020

tests/api.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64936,6 +64936,73 @@ static int test_dtls_client_hello_timeout(void)
6493664936
return EXPECT_RESULT();
6493764937
}
6493864938

64939+
/* DTLS test when dropping the changed cipher spec message */
64940+
static int test_dtls_dropped_ccs(void)
64941+
{
64942+
EXPECT_DECLS;
64943+
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS)
64944+
WOLFSSL_CTX *ctx_c = NULL;
64945+
WOLFSSL_CTX *ctx_s = NULL;
64946+
WOLFSSL *ssl_c = NULL;
64947+
WOLFSSL *ssl_s = NULL;
64948+
struct test_memio_ctx test_ctx;
64949+
DtlsRecordLayerHeader* dtlsRH;
64950+
size_t len;
64951+
byte data[1];
64952+
64953+
64954+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
64955+
64956+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
64957+
wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method), 0);
64958+
64959+
/* CH1 */
64960+
ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
64961+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
64962+
/* HVR */
64963+
ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
64964+
ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
64965+
/* CH2 */
64966+
ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
64967+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
64968+
/* Server first flight */
64969+
ExpectIntEQ(wolfSSL_negotiate(ssl_s), -1);
64970+
ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
64971+
/* Client flight */
64972+
ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
64973+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
64974+
/* Server ccs + finished */
64975+
ExpectIntEQ(wolfSSL_negotiate(ssl_s), 1);
64976+
64977+
/* Drop the ccs */
64978+
dtlsRH = (DtlsRecordLayerHeader*)test_ctx.c_buff;
64979+
len = (size_t)((dtlsRH->length[0] << 8) | dtlsRH->length[1]);
64980+
ExpectIntEQ(len, 1);
64981+
ExpectIntEQ(dtlsRH->type, change_cipher_spec);
64982+
if (EXPECT_SUCCESS()) {
64983+
XMEMMOVE(test_ctx.c_buff, test_ctx.c_buff +
64984+
sizeof(DtlsRecordLayerHeader) + len, test_ctx.c_len -
64985+
(sizeof(DtlsRecordLayerHeader) + len));
64986+
}
64987+
test_ctx.c_len -= sizeof(DtlsRecordLayerHeader) + len;
64988+
64989+
/* Client rtx flight */
64990+
ExpectIntEQ(wolfSSL_negotiate(ssl_c), -1);
64991+
ExpectIntEQ(wolfSSL_get_error(ssl_c, -1), WOLFSSL_ERROR_WANT_READ);
64992+
ExpectIntEQ(wolfSSL_dtls_got_timeout(ssl_c), WOLFSSL_SUCCESS);
64993+
/* Server ccs + finished rtx */
64994+
ExpectIntEQ(wolfSSL_read(ssl_s, data, sizeof(data)), -1);
64995+
ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
64996+
/* Client processes finished */
64997+
ExpectIntEQ(wolfSSL_negotiate(ssl_c), 1);
64998+
64999+
wolfSSL_free(ssl_c);
65000+
wolfSSL_free(ssl_s);
65001+
wolfSSL_CTX_free(ctx_c);
65002+
wolfSSL_CTX_free(ctx_s);
65003+
#endif
65004+
return EXPECT_RESULT();
65005+
}
6493965006
/**
6494065007
* Make sure we don't send RSA Signature Hash Algorithms in the
6494165008
* CertificateRequest when we don't have any such ciphers set.
@@ -66286,6 +66353,7 @@ TEST_CASE testCases[] = {
6628666353
TEST_DECL(test_dtls_downgrade_scr),
6628766354
TEST_DECL(test_dtls_client_hello_timeout_downgrade),
6628866355
TEST_DECL(test_dtls_client_hello_timeout),
66356+
TEST_DECL(test_dtls_dropped_ccs),
6628966357
TEST_DECL(test_certreq_sighash_algos),
6629066358
/* This test needs to stay at the end to clean up any caches allocated. */
6629166359
TEST_DECL(test_wolfSSL_Cleanup)

0 commit comments

Comments
 (0)