Skip to content

Commit a0fef66

Browse files
committed
Add test case for dropped ccs
1 parent 357c9a6 commit a0fef66

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

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+
/* Make sure we don't send acks before getting a server hello */
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)