summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2023-09-19 16:52:00 +0100
committerMatt Caswell <matt@openssl.org>2023-09-22 13:56:43 +0100
commit0a2369fd446e27f59f0025d8d885c07a107df615 (patch)
tree8c96d12b0c97f643964dd1e37785ca6ee670cef1
parent8d8c0a901e5d65d68070fbe812d7e8c1449381e1 (diff)
Ensure client to server datagrams are noisy too
So far we've only applied noise to the server to client datagrams. Do the same thing the other way around. Reviewed-by: Tim Hudson <tjh@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22157)
-rw-r--r--test/helpers/quictestlib.c32
-rw-r--r--test/helpers/quictestlib.h6
-rw-r--r--test/quicapitest.c9
3 files changed, 36 insertions, 11 deletions
diff --git a/test/helpers/quictestlib.c b/test/helpers/quictestlib.c
index bb2ae9b3ba..6a72cc27be 100644
--- a/test/helpers/quictestlib.c
+++ b/test/helpers/quictestlib.c
@@ -159,6 +159,11 @@ int qtest_create_quic_objects(OSSL_LIB_CTX *libctx, SSL_CTX *clientctx,
if (!TEST_ptr(pktsplitbio))
goto err;
cbio = BIO_push(pktsplitbio, cbio);
+
+ pktsplitbio = BIO_new(bio_f_pkt_split_dgram_filter());
+ if (!TEST_ptr(pktsplitbio))
+ goto err;
+ sbio = BIO_push(pktsplitbio, sbio);
}
if ((flags & QTEST_FLAG_NOISE) != 0) {
@@ -167,6 +172,12 @@ int qtest_create_quic_objects(OSSL_LIB_CTX *libctx, SSL_CTX *clientctx,
if (!TEST_ptr(noisebio))
goto err;
cbio = BIO_push(noisebio, cbio);
+
+ noisebio = BIO_new(bio_f_noisy_dgram_filter());
+
+ if (!TEST_ptr(noisebio))
+ goto err;
+ sbio = BIO_push(noisebio, sbio);
}
SSL_set_bio(*cssl, cbio, cbio);
@@ -228,9 +239,9 @@ int qtest_create_quic_objects(OSSL_LIB_CTX *libctx, SSL_CTX *clientctx,
err:
SSL_CTX_free(tserver_args.ctx);
BIO_ADDR_free(peeraddr);
- BIO_free(cbio);
+ BIO_free_all(cbio);
BIO_free(fisbio);
- BIO_free(sbio);
+ BIO_free_all(sbio);
SSL_free(*cssl);
*cssl = NULL;
ossl_quic_tserver_free(*qtserv);
@@ -289,14 +300,14 @@ static void run_server_thread(void)
}
#endif
-static int wait_for_timeout(SSL *s, QUIC_TSERVER *qtserv)
+int qtest_wait_for_timeout(SSL *s, QUIC_TSERVER *qtserv)
{
struct timeval tv;
OSSL_TIME ctimeout, stimeout, mintimeout, now;
int cinf;
/* We don't need to wait in blocking mode */
- if (s == NULL || qtserv == NULL)
+ if (s == NULL || SSL_get_blocking_mode(s))
return 1;
/* Don't wait if either BIO has data waiting */
@@ -395,12 +406,13 @@ int qtest_create_quic_connection_ex(QUIC_TSERVER *qtserv, SSL *clientssl,
}
}
- if (!clienterr && retc <= 0)
+ qtest_add_time(1);
+ if (clientssl != NULL)
SSL_handle_events(clientssl);
+ if (qtserv != NULL)
+ ossl_quic_tserver_tick(qtserv);
if (!servererr && rets <= 0) {
- qtest_add_time(1);
- ossl_quic_tserver_tick(qtserv);
servererr = ossl_quic_tserver_is_term_any(qtserv);
if (!servererr)
rets = ossl_quic_tserver_is_handshake_confirmed(qtserv);
@@ -414,8 +426,10 @@ int qtest_create_quic_connection_ex(QUIC_TSERVER *qtserv, SSL *clientssl,
goto err;
}
- if (!wait_for_timeout(clientssl, qtserv))
- goto err;
+ if ((retc <= 0 && !clienterr) || (rets <= 0 && !servererr)) {
+ if (!qtest_wait_for_timeout(clientssl, qtserv))
+ goto err;
+ }
} while ((retc <= 0 && !clienterr)
|| (rets <= 0 && !servererr
#if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG)
diff --git a/test/helpers/quictestlib.h b/test/helpers/quictestlib.h
index e5190c62b1..844aec8a60 100644
--- a/test/helpers/quictestlib.h
+++ b/test/helpers/quictestlib.h
@@ -68,6 +68,12 @@ int qtest_supports_blocking(void);
int qtest_create_quic_connection(QUIC_TSERVER *qtserv, SSL *clientssl);
/*
+ * Check if both client and server have no data to read and are waiting on a
+ * timeout. If so, wait until the timeout has expired.
+ */
+int qtest_wait_for_timeout(SSL *s, QUIC_TSERVER *qtserv);
+
+/*
* Same as qtest_create_quic_connection but will stop (successfully) if the
* clientssl indicates SSL_ERROR_WANT_XXX as specified by |wanterr|
*/
diff --git a/test/quicapitest.c b/test/quicapitest.c
index 94562f3a5b..b02db15d65 100644
--- a/test/quicapitest.c
+++ b/test/quicapitest.c
@@ -1274,13 +1274,15 @@ static int unreliable_client_read(SSL *clientquic, SSL **stream, void *buf,
if (*stream != NULL) {
if (SSL_read_ex(*stream, buf, buflen, readbytes))
return 1;
- if (SSL_get_error(*stream, 0) != SSL_ERROR_WANT_READ)
+ if (!TEST_int_eq(SSL_get_error(*stream, 0), SSL_ERROR_WANT_READ))
return 0;
}
ossl_quic_tserver_tick(qtserv);
qtest_add_time(1);
+ qtest_wait_for_timeout(clientquic, qtserv);
}
+ TEST_error("No progress made");
return 0;
}
@@ -1293,13 +1295,16 @@ static int unreliable_server_read(QUIC_TSERVER *qtserv, uint64_t sid,
/* We just do this in a loop with a sleep for simplicity */
for (abortctr = 0; abortctr < MAX_LOOPS; abortctr++) {
- if (ossl_quic_tserver_read(qtserv, sid, buf, buflen, readbytes))
+ if (ossl_quic_tserver_read(qtserv, sid, buf, buflen, readbytes)
+ && *readbytes > 1)
return 1;
ossl_quic_tserver_tick(qtserv);
SSL_handle_events(clientquic);
qtest_add_time(1);
+ qtest_wait_for_timeout(clientquic, qtserv);
}
+ TEST_error("No progress made");
return 0;
}