Ensure client to server datagrams are noisy too
authorMatt Caswell <matt@openssl.org>
Tue, 19 Sep 2023 15:52:00 +0000 (16:52 +0100)
committerMatt Caswell <matt@openssl.org>
Fri, 22 Sep 2023 12:56:43 +0000 (13:56 +0100)
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)

test/helpers/quictestlib.c
test/helpers/quictestlib.h
test/quicapitest.c

index bb2ae9b3ba2c71973767f5b68d53d63c3a5a77be..6a72cc27bea226e95a2dc75fc69a0464a15e9f9c 100644 (file)
@@ -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)
index e5190c62b1190e71e077c1859cfaeaae78bd5c37..844aec8a60be63ab302b7f4ef605076e2743bb3a 100644 (file)
@@ -67,6 +67,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|
index 94562f3a5bf75896a6ef919f42cc53d32f601aac..b02db15d65cbc07febe8e3c3cce06523c90ae8b6 100644 (file)
@@ -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;
 }