Add the ability to do client side tracing in quictestlib.c
authorMatt Caswell <matt@openssl.org>
Tue, 19 Sep 2023 15:40:25 +0000 (16:40 +0100)
committerMatt Caswell <matt@openssl.org>
Fri, 22 Sep 2023 12:56:43 +0000 (13:56 +0100)
We add a new flag QTEST_FLAG_CLIENT_TRACE to get debug tracing output if
required.

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22157)

doc/designs/quic-design/quic-fault-injector.md
test/helpers/quictestlib.c
test/helpers/quictestlib.h
test/quic_newcid_test.c
test/quicapitest.c
test/quicfaultstest.c

index 30db905ee84a6a7e3275e258eec7c598ef35ff4c..bea36b98cbf6211730eb5746fe920e2d4e868515 100644 (file)
@@ -215,7 +215,7 @@ typedef struct ossl_qf_encrypted_extensions {
 int qtest_create_quic_objects(OSSL_LIB_CTX *libctx, SSL_CTX *clientctx,
                               SSL_CTX *serverctx, char *certfile, char *keyfile,
                               int block, QUIC_TSERVER **qtserv, SSL **cssl,
-                              OSSL_QUIC_FAULT **fault);
+                              OSSL_QUIC_FAULT **fault, BIO **tracebio);
 
 /*
  * Free up a Fault Injector instance
@@ -440,7 +440,7 @@ static int test_unknown_frame(void)
         goto err;
 
     if (!TEST_true(qtest_create_quic_objects(NULL, cctx, NULL, cert, privkey, 0,
-                                             &qtserv, &cssl, &fault)))
+                                             &qtserv, &cssl, &fault, NULL)))
         goto err;
 
     if (!TEST_true(qtest_create_quic_connection(qtserv, cssl)))
@@ -523,7 +523,7 @@ static int test_no_transport_params(void)
         goto err;
 
     if (!TEST_true(qtest_create_quic_objects(NULL, cctx, NULL, cert, privkey, 0,
-                                             &qtserv, &cssl, &fault)))
+                                             &qtserv, &cssl, &fault, NULL)))
         goto err;
 
     if (!TEST_true(ossl_quic_fault_set_hand_enc_ext_listener(fault,
index 3c3cb73f969e408d4ff3abd7a023b88f9e8a6d54..bb2ae9b3ba2c71973767f5b68d53d63c3a5a77be 100644 (file)
@@ -77,7 +77,7 @@ static OSSL_TIME fake_now_cb(void *arg)
 int qtest_create_quic_objects(OSSL_LIB_CTX *libctx, SSL_CTX *clientctx,
                               SSL_CTX *serverctx, char *certfile, char *keyfile,
                               int flags, QUIC_TSERVER **qtserv, SSL **cssl,
-                              QTEST_FAULT **fault)
+                              QTEST_FAULT **fault, BIO **tracebio)
 {
     /* ALPN value as recognised by QUIC_TSERVER */
     unsigned char alpn[] = { 8, 'o', 's', 's', 'l', 't', 'e', 's', 't' };
@@ -85,6 +85,7 @@ int qtest_create_quic_objects(OSSL_LIB_CTX *libctx, SSL_CTX *clientctx,
     BIO *cbio = NULL, *sbio = NULL, *fisbio = NULL;
     BIO_ADDR *peeraddr = NULL;
     struct in_addr ina = {0};
+    BIO *tmpbio = NULL;
 
     *qtserv = NULL;
     if (fault != NULL)
@@ -96,6 +97,17 @@ int qtest_create_quic_objects(OSSL_LIB_CTX *libctx, SSL_CTX *clientctx,
             return 0;
     }
 
+    if ((flags & QTEST_FLAG_CLIENT_TRACE) != 0) {
+        tmpbio = BIO_new_fp(stdout, BIO_NOCLOSE);
+        if (!TEST_ptr(tmpbio))
+            goto err;
+
+        SSL_set_msg_callback(*cssl, SSL_trace);
+        SSL_set_msg_callback_arg(*cssl, tmpbio);
+    }
+    if (tracebio != NULL)
+        *tracebio = tmpbio;
+
     /* SSL_set_alpn_protos returns 0 for success! */
     if (!TEST_false(SSL_set_alpn_protos(*cssl, alpn, sizeof(alpn))))
         goto err;
@@ -224,6 +236,9 @@ int qtest_create_quic_objects(OSSL_LIB_CTX *libctx, SSL_CTX *clientctx,
     ossl_quic_tserver_free(*qtserv);
     if (fault != NULL)
         OPENSSL_free(*fault);
+    BIO_free(tmpbio);
+    if (tracebio != NULL)
+        *tracebio = NULL;
 
     return 0;
 }
index 4e61b8965d6102e07689c0a70ec021460ad21c33..e5190c62b1190e71e077c1859cfaeaae78bd5c37 100644 (file)
@@ -34,7 +34,8 @@ typedef struct qtest_fault_encrypted_extensions {
 #define QTEST_FLAG_NOISE        (1 << 2)
 /* Split datagrams such that each datagram contains one packet */
 #define QTEST_FLAG_PACKET_SPLIT (1 << 3)
-
+/* Turn on client side tracing */
+#define QTEST_FLAG_CLIENT_TRACE (1 << 4)
 /*
  * Given an SSL_CTX for the client and filenames for the server certificate and
  * keyfile, create a server and client instances as well as a fault injector
@@ -43,7 +44,7 @@ typedef struct qtest_fault_encrypted_extensions {
 int qtest_create_quic_objects(OSSL_LIB_CTX *libctx, SSL_CTX *clientctx,
                               SSL_CTX *serverctx, char *certfile, char *keyfile,
                               int flags, QUIC_TSERVER **qtserv, SSL **cssl,
-                              QTEST_FAULT **fault);
+                              QTEST_FAULT **fault, BIO **tracebio);
 
 /* Where QTEST_FLAG_FAKE_TIME is used, add millis to the current time */
 void qtest_add_time(uint64_t millis);
index cda55abca3cd3c6292bb1cebba99a42846b51f76..80a15e1b7ab0f66f218281dc5b3ac79b712ad75f 100644 (file)
@@ -68,7 +68,7 @@ static int test_ncid_frame(int fail)
         goto err;
 
     if (!TEST_true(qtest_create_quic_objects(NULL, cctx, NULL, cert, privkey, 0,
-                                             &qtserv, &cssl, &fault)))
+                                             &qtserv, &cssl, &fault, NULL)))
         goto err;
 
     if (!TEST_true(qtest_create_quic_connection(qtserv, cssl)))
index cd006b470349eb8c2029632d34eb7d721b3c2649..94562f3a5bf75896a6ef919f42cc53d32f601aac 100644 (file)
@@ -69,7 +69,7 @@ static int test_quic_write_read(int idx)
                                                             ? QTEST_FLAG_BLOCK
                                                             : 0,
                                                         &qtserv, &clientquic,
-                                                        NULL))
+                                                        NULL, NULL))
                 || !TEST_true(SSL_set_tlsext_host_name(clientquic, "localhost")))
             goto end;
 
@@ -220,7 +220,7 @@ static int test_fin_only_blocking(void)
                                                     cert, privkey,
                                                     QTEST_FLAG_BLOCK,
                                                     &qtserv, &clientquic,
-                                                    NULL))
+                                                    NULL, NULL))
             || !TEST_true(SSL_set_tlsext_host_name(clientquic, "localhost")))
         goto end;
 
@@ -380,7 +380,7 @@ static int test_version(void)
     if (!TEST_ptr(cctx)
             || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
                                                     privkey, 0, &qtserv,
-                                                    &clientquic, NULL))
+                                                    &clientquic, NULL, NULL))
             || !TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
         goto err;
 
@@ -502,7 +502,7 @@ static int test_ssl_trace(void)
                                                     privkey,
                                                     QTEST_FLAG_FAKE_TIME,
                                                     &qtserv,
-                                                    &clientquic, NULL)))
+                                                    &clientquic, NULL, NULL)))
         goto err;
 
     SSL_set_msg_callback(clientquic, SSL_trace);
@@ -829,7 +829,8 @@ static int test_bio_ssl(void)
         goto err;
 
     if (!TEST_true(qtest_create_quic_objects(libctx, NULL, NULL, cert, privkey,
-                                             0, &qtserv, &clientquic, NULL)))
+                                             0, &qtserv, &clientquic, NULL,
+                                             NULL)))
         goto err;
 
     msglen = strlen(msg);
@@ -946,7 +947,7 @@ static int test_back_pressure(void)
     if (!TEST_ptr(cctx)
             || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
                                                     privkey, 0, &qtserv,
-                                                    &clientquic, NULL))
+                                                    &clientquic, NULL, NULL))
             || !TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
         goto err;
 
@@ -1024,7 +1025,7 @@ static int test_multiple_dgrams(void)
             || !TEST_ptr(buf)
             || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
                                                     privkey, 0, &qtserv,
-                                                    &clientquic, NULL))
+                                                    &clientquic, NULL, NULL))
             || !TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
         goto err;
 
@@ -1088,7 +1089,8 @@ static int test_non_io_retry(int idx)
 
     flags = (idx >= 1) ? QTEST_FLAG_BLOCK : 0;
     if (!TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert, privkey,
-                                             flags, &qtserv, &clientquic, NULL))
+                                             flags, &qtserv, &clientquic, NULL,
+                                             NULL))
             || !TEST_true(qtest_create_quic_connection_ex(qtserv, clientquic,
                             SSL_ERROR_WANT_RETRY_VERIFY))
             || !TEST_int_eq(SSL_want(clientquic), SSL_RETRY_VERIFY)
@@ -1156,7 +1158,7 @@ static int test_quic_psk(void)
                /* No cert or private key for the server, i.e. PSK only */
             || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, NULL,
                                                     NULL, 0, &qtserv,
-                                                    &clientquic, NULL)))
+                                                    &clientquic, NULL, NULL)))
         goto end;
 
     SSL_set_psk_use_session_callback(clientquic, use_session_cb);
@@ -1215,7 +1217,7 @@ static int test_alpn(int idx)
                                                     privkey,
                                                     QTEST_FLAG_FAKE_TIME,
                                                     &qtserv,
-                                                    &clientquic, NULL)))
+                                                    &clientquic, NULL, NULL)))
         goto err;
 
     if (idx == 0) {
@@ -1328,7 +1330,7 @@ static int test_noisy_dgram(int idx)
             || !TEST_true(qtest_create_quic_objects(libctx, cctx, NULL, cert,
                                                     privkey, flags,
                                                     &qtserv,
-                                                    &clientquic, NULL)))
+                                                    &clientquic, NULL, NULL)))
         goto err;
 
     if (!TEST_true(qtest_create_quic_connection(qtserv, clientquic)))
index a6ba0dc05340e6ecd6c14f258efda60c5e974380..28f52cd6f22a26c923c0363dd1d56cfe4cfbf27c 100644 (file)
@@ -35,7 +35,7 @@ static int test_basic(void)
         goto err;
 
     if (!TEST_true(qtest_create_quic_objects(NULL, cctx, NULL, cert, privkey, 0,
-                                             &qtserv, &cssl, NULL)))
+                                             &qtserv, &cssl, NULL, NULL)))
         goto err;
 
     if (!TEST_true(qtest_create_quic_connection(qtserv, cssl)))
@@ -105,7 +105,7 @@ static int test_unknown_frame(void)
         goto err;
 
     if (!TEST_true(qtest_create_quic_objects(NULL, cctx, NULL, cert, privkey, 0,
-                                             &qtserv, &cssl, &fault)))
+                                             &qtserv, &cssl, &fault, NULL)))
         goto err;
 
     if (!TEST_true(qtest_create_quic_connection(qtserv, cssl)))
@@ -187,7 +187,7 @@ static int test_drop_extensions(int idx)
         goto err;
 
     if (!TEST_true(qtest_create_quic_objects(NULL, cctx, NULL, cert, privkey, 0,
-                                             &qtserv, &cssl, &fault)))
+                                             &qtserv, &cssl, &fault, NULL)))
         goto err;
 
     if (idx == 0) {
@@ -275,7 +275,7 @@ static int test_corrupted_data(int idx)
 
     if (!TEST_true(qtest_create_quic_objects(NULL, cctx, NULL, cert, privkey,
                                              QTEST_FLAG_FAKE_TIME, &qtserv,
-                                             &cssl, &fault)))
+                                             &cssl, &fault, NULL)))
         goto err;
 
     if (idx == 0) {