Skip to content

Commit 7147388

Browse files
committed
test: drop short ciphertext message in dtls
1 parent 1096a98 commit 7147388

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

tests/api/test_dtls.c

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,64 @@ static int test_dtls13_short_read(void)
874874

875875
#endif /* WOLFSSL_DTLS13 */
876876

877+
static int test_dtls_short_ciphertext(void)
878+
{
879+
EXPECT_DECLS;
880+
WOLFSSL_CTX *ctx_c = NULL, *ctx_s = NULL;
881+
WOLFSSL *ssl_c = NULL, *ssl_s = NULL;
882+
struct test_memio_ctx test_ctx;
883+
unsigned char readBuf[50];
884+
885+
XMEMSET(&test_ctx, 0, sizeof(test_ctx));
886+
887+
/* Setup DTLS contexts */
888+
ExpectIntEQ(test_memio_setup(&test_ctx, &ctx_c, &ctx_s, &ssl_c, &ssl_s,
889+
wolfDTLSv1_2_client_method, wolfDTLSv1_2_server_method),
890+
0);
891+
892+
/* Complete handshake */
893+
ExpectIntEQ(test_memio_do_handshake(ssl_c, ssl_s, 10, NULL), 0);
894+
895+
/* Create a message, that looks encrypted but shorter than minimum ciphertext length */
896+
/* create the data in the buffer */
897+
ExpectIntEQ(wolfSSL_write(ssl_c, "bad", 3), 3);
898+
899+
/* check client wrote the record */
900+
ExpectIntGT(test_ctx.s_len, 14);
901+
902+
/* modify the length field to be smaller than the content */
903+
test_ctx.s_buff[11] = 0x00;
904+
test_ctx.s_buff[12] = 0x02;
905+
/* modify the amount of data to send */
906+
test_ctx.s_len = 15;
907+
908+
/* Try to read the malformed record */
909+
wolfSSL_SetLoggingPrefix("server");
910+
ExpectIntEQ(wolfSSL_read(ssl_s, readBuf, sizeof(readBuf)), -1);
911+
ExpectIntEQ(wolfSSL_get_error(ssl_s, -1), WOLFSSL_ERROR_WANT_READ);
912+
ExpectIntEQ(test_ctx.s_len, 0);
913+
914+
ExpectIntEQ(test_dtls_communication(ssl_s, ssl_c), TEST_SUCCESS);
915+
916+
/* Cleanup */
917+
wolfSSL_SetLoggingPrefix("client");
918+
ExpectIntEQ(wolfSSL_shutdown(ssl_c), WOLFSSL_SHUTDOWN_NOT_DONE);
919+
wolfSSL_SetLoggingPrefix("server");
920+
ExpectIntEQ(wolfSSL_shutdown(ssl_s), WOLFSSL_SHUTDOWN_NOT_DONE);
921+
wolfSSL_SetLoggingPrefix("client");
922+
ExpectIntEQ(wolfSSL_shutdown(ssl_c), 1);
923+
wolfSSL_SetLoggingPrefix("server");
924+
ExpectIntEQ(wolfSSL_shutdown(ssl_s), 1);
925+
926+
wolfSSL_SetLoggingPrefix(NULL);
927+
wolfSSL_free(ssl_c);
928+
wolfSSL_CTX_free(ctx_c);
929+
wolfSSL_free(ssl_s);
930+
wolfSSL_CTX_free(ctx_s);
931+
932+
return EXPECT_RESULT();
933+
}
934+
877935
static int test_dtls12_short_read(void)
878936
{
879937
EXPECT_DECLS;
@@ -980,10 +1038,11 @@ int test_dtls_record_length_mismatch(void)
9801038
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES) && defined(WOLFSSL_DTLS)
9811039
ExpectIntEQ(test_dtls12_record_length_mismatch(), TEST_SUCCESS);
9821040
ExpectIntEQ(test_dtls12_short_read(), TEST_SUCCESS);
1041+
ExpectIntEQ(test_dtls_short_ciphertext(), TEST_SUCCESS);
9831042
#ifdef WOLFSSL_DTLS13
9841043
ExpectIntEQ(test_dtls13_longer_length(), TEST_SUCCESS);
9851044
ExpectIntEQ(test_dtls13_short_read(), TEST_SUCCESS);
9861045
#endif /* WOLFSSL_DTLS13 */
9871046
#endif
9881047
return EXPECT_RESULT();
989-
}
1048+
}

tests/api/test_dtls.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,4 @@ int test_wolfSSL_dtls_cid_parse(void);
2828
int test_dtls13_epochs(void);
2929
int test_dtls13_ack_order(void);
3030
int test_dtls_record_length_mismatch(void);
31-
3231
#endif /* TESTS_API_DTLS_H */

0 commit comments

Comments
 (0)