summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2024-01-02 15:56:43 +0000
committerMatt Caswell <matt@openssl.org>2024-01-18 15:22:12 +0000
commit4074e6308860077bdd3b85b084ad63d3007e20e3 (patch)
treea5956aac87e6d6edaf5e0266dbc4b4e185cd65c9 /test
parent8c1f9de1d5517888e359d36c868fd315cb07fa6e (diff)
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 <tomas@openssl.org> Reviewed-by: Neil Horman <nhorman@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23182) (cherry picked from commit 563f4be8976ea776ec4fb90d084e2ce80c92f0d1)
Diffstat (limited to 'test')
-rw-r--r--test/sslapitest.c35
1 files changed, 35 insertions, 0 deletions
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);