From 4074e6308860077bdd3b85b084ad63d3007e20e3 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Tue, 2 Jan 2024 15:56:43 +0000 Subject: Add a KTLS test where we write long app data records Check that we can write and read back long app data records when using KTLS. Reviewed-by: Tomas Mraz Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/23182) (cherry picked from commit 563f4be8976ea776ec4fb90d084e2ce80c92f0d1) --- test/sslapitest.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/sslapitest.c b/test/sslapitest.c index 7e01b72328..92e44e6cb1 100644 --- a/test/sslapitest.c +++ b/test/sslapitest.c @@ -1135,6 +1135,10 @@ static int execute_test_ktls(int cis_ktls, int sis_ktls, int cfd = -1, sfd = -1; int rx_supported; SSL_CONNECTION *clientsc, *serversc; + unsigned char *buf = NULL; + const size_t bufsz = SSL3_RT_MAX_PLAIN_LENGTH + 16; + int ret; + size_t offset = 0, i; if (!TEST_true(create_test_sockets(&cfd, &sfd, SOCK_STREAM, NULL))) goto end; @@ -1240,8 +1244,39 @@ static int execute_test_ktls(int cis_ktls, int sis_ktls, if (!TEST_true(ping_pong_query(clientssl, serverssl))) goto end; + buf = OPENSSL_zalloc(bufsz); + if (!TEST_ptr(buf)) + goto end; + + /* + * Write some data that exceeds the maximum record length. KTLS may choose + * to coalesce this data into a single buffer when we read it again. + */ + while ((ret = SSL_write(clientssl, buf, bufsz)) != (int)bufsz) { + if (!TEST_true(SSL_get_error(clientssl, ret) == SSL_ERROR_WANT_WRITE)) + goto end; + } + + /* Now check that we can read all the data we wrote */ + do { + ret = SSL_read(serverssl, buf + offset, bufsz - offset); + if (ret <= 0) { + if (!TEST_true(SSL_get_error(serverssl, ret) == SSL_ERROR_WANT_READ)) + goto end; + } else { + offset += ret; + } + } while (offset < bufsz); + + if (!TEST_true(offset == bufsz)) + goto end; + for (i = 0; i < bufsz; i++) + if (!TEST_true(buf[i] == 0)) + goto end; + testresult = 1; end: + OPENSSL_free(buf); if (clientssl) { SSL_shutdown(clientssl); SSL_free(clientssl); -- cgit v1.2.3