Add the ability to do client side tracing in quictestlib.c

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)
This commit is contained in:
Matt Caswell 2023-09-19 16:40:25 +01:00
parent b1584a85d0
commit 8d8c0a901e
6 changed files with 40 additions and 22 deletions

View 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,

View 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;
}

View 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);

View 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)))

View 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)))

View 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) {