]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Extend the noisy dgram test so that packets are also affected by noise
authorMatt Caswell <matt@openssl.org>
Tue, 19 Sep 2023 11:21:27 +0000 (12:21 +0100)
committerMatt Caswell <matt@openssl.org>
Fri, 22 Sep 2023 12:56:43 +0000 (13:56 +0100)
Where multiple packets are in a single datagram we split them so that all
packets can be affected by the noise

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 6381d720fff2b93eb092d7f34253d97536cbff54..3c3cb73f969e408d4ff3abd7a023b88f9e8a6d54 100644 (file)
@@ -141,6 +141,14 @@ int qtest_create_quic_objects(OSSL_LIB_CTX *libctx, SSL_CTX *clientctx,
             goto err;
     }
 
+    if ((flags & QTEST_FLAG_PACKET_SPLIT) != 0) {
+        BIO *pktsplitbio = BIO_new(bio_f_pkt_split_dgram_filter());
+
+        if (!TEST_ptr(pktsplitbio))
+            goto err;
+        cbio = BIO_push(pktsplitbio, cbio);
+    }
+
     if ((flags & QTEST_FLAG_NOISE) != 0) {
         BIO *noisebio = BIO_new(bio_f_noisy_dgram_filter());
 
index f18cd29481163557ad1a5703f815acf3995483ba..4e61b8965d6102e07689c0a70ec021460ad21c33 100644 (file)
@@ -32,6 +32,8 @@ typedef struct qtest_fault_encrypted_extensions {
 #define QTEST_FLAG_FAKE_TIME    (1 << 1)
 /* Introduce noise in the BIO */
 #define QTEST_FLAG_NOISE        (1 << 2)
+/* Split datagrams such that each datagram contains one packet */
+#define QTEST_FLAG_PACKET_SPLIT (1 << 3)
 
 /*
  * Given an SSL_CTX for the client and filenames for the server certificate and
index 023738a22bb1b5a8b3979a4c1eb3c76e511f59fc..cd006b470349eb8c2029632d34eb7d721b3c2649 100644 (file)
@@ -1301,7 +1301,15 @@ static int unreliable_server_read(QUIC_TSERVER *qtserv, uint64_t sid,
     return 0;
 }
 
-static int test_noisy_dgram(void)
+/*
+ * Create a connection and send data using an unreliable transport. We introduce
+ * random noise to drop, delay and duplicate datagrams.
+ * Test 0: Introduce random noise to datagrams
+ * Test 1: As with test 0 but also split datagrams containing multiple packets
+ *         into individual datagrams so that individual packets can be affected
+ *         by noise - not just a whole datagram.
+ */
+static int test_noisy_dgram(int idx)
 {
     SSL_CTX *cctx = SSL_CTX_new_ex(libctx, NULL, OSSL_QUIC_client_method());
     SSL *clientquic = NULL, *stream[2] = { NULL, NULL };
@@ -1311,12 +1319,14 @@ static int test_noisy_dgram(void)
     char *msg = "Hello world!";
     size_t msglen = strlen(msg), written, readbytes, i, j;
     unsigned char buf[80];
+    int flags = QTEST_FLAG_NOISE | QTEST_FLAG_FAKE_TIME;
+
+    if (idx == 1)
+        flags |= QTEST_FLAG_PACKET_SPLIT;
 
     if (!TEST_ptr(cctx)
             || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
-                                                    privkey,
-                                                    QTEST_FLAG_NOISE
-                                                    | QTEST_FLAG_FAKE_TIME,
+                                                    privkey, flags,
                                                     &qtserv,
                                                     &clientquic, NULL)))
         goto err;
@@ -1470,7 +1480,7 @@ int setup_tests(void)
     ADD_ALL_TESTS(test_non_io_retry, 2);
     ADD_TEST(test_quic_psk);
     ADD_ALL_TESTS(test_alpn, 2);
-    ADD_TEST(test_noisy_dgram);
+    ADD_ALL_TESTS(test_noisy_dgram, 2);
 
     return 1;
  err:
@@ -1481,6 +1491,7 @@ int setup_tests(void)
 void cleanup_tests(void)
 {
     bio_f_noisy_dgram_filter_free();
+    bio_f_pkt_split_dgram_filter_free();
     OPENSSL_free(cert);
     OPENSSL_free(privkey);
     OSSL_PROVIDER_unload(defctxnull);