Skip to content

Commit

Permalink
Add the ability to do client side tracing in quictestlib.c
Browse files Browse the repository at this point in the history
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 #22157)
  • Loading branch information
mattcaswell committed Sep 22, 2023
1 parent b1584a8 commit 8d8c0a9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 22 deletions.
6 changes: 3 additions & 3 deletions doc/designs/quic-design/quic-fault-injector.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 16 additions & 1 deletion test/helpers/quictestlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@ 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' };
QUIC_TSERVER_ARGS tserver_args = {0};
BIO *cbio = NULL, *sbio = NULL, *fisbio = NULL;
BIO_ADDR *peeraddr = NULL;
struct in_addr ina = {0};
BIO *tmpbio = NULL;

*qtserv = NULL;
if (fault != NULL)
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions test/helpers/quictestlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/quic_newcid_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
24 changes: 13 additions & 11 deletions test/quicapitest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)))
Expand Down
8 changes: 4 additions & 4 deletions test/quicfaultstest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8d8c0a9

Please sign in to comment.