From fb1a0bb97aa630cd303d9c7c30214483538a57f6 Mon Sep 17 00:00:00 2001 From: Hugo Landau Date: Fri, 8 Sep 2023 13:42:53 +0100 Subject: [PATCH] QLOG: Wire title-setting code to QUIC_CHANNEL and SSL_CTX Reviewed-by: Matt Caswell Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/22037) --- include/internal/quic_ssl.h | 9 +++++++++ ssl/quic/quic_channel_local.h | 2 +- ssl/quic/quic_impl.c | 17 +++++++++++++++++ ssl/ssl_lib.c | 3 +++ ssl/ssl_local.h | 4 ++++ 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/include/internal/quic_ssl.h b/include/internal/quic_ssl.h index a9822df7df..7a53af7f65 100644 --- a/include/internal/quic_ssl.h +++ b/include/internal/quic_ssl.h @@ -129,6 +129,15 @@ QUIC_CHANNEL *ossl_quic_conn_get_channel(SSL *s); int ossl_quic_has_pending(const SSL *s); int ossl_quic_get_shutdown(const SSL *s); +/* + * Set QLOG diagnostic title. String is copied internally on success and need + * not remain allocated. Only has any effect if logging has not already begun. + * For use by tests only. Setting this on a context affects any QCSO created + * after this is called but does not affect QCSOs already created from a + * context. + */ +int ossl_quic_set_diag_title(SSL_CTX *ctx, const char *title); + # endif #endif diff --git a/ssl/quic/quic_channel_local.h b/ssl/quic/quic_channel_local.h index 4cd4dd84b7..564b789f9c 100644 --- a/ssl/quic/quic_channel_local.h +++ b/ssl/quic/quic_channel_local.h @@ -439,7 +439,7 @@ struct quic_channel_st { size_t num_ack_range_scratch; /* Title for QLOG purposes. We own this copy. */ - char *quic_channel_local; + char *qlog_title; }; # endif diff --git a/ssl/quic/quic_impl.c b/ssl/quic/quic_impl.c index 1248013a4b..7c0d2c65b7 100644 --- a/ssl/quic/quic_impl.c +++ b/ssl/quic/quic_impl.c @@ -1510,6 +1510,7 @@ static int create_channel(QUIC_CONNECTION *qc) } #ifndef OPENSSL_NO_QLOG args.use_qlog = 1; /* disabled if env not set */ + args.qlog_title = qc->ssl.ctx->qlog_title; #endif port_args.channel_ctx = qc->ssl.ctx; @@ -3705,3 +3706,19 @@ QUIC_CHANNEL *ossl_quic_conn_get_channel(SSL *s) return ctx.qc->ch; } + +int ossl_quic_set_diag_title(SSL_CTX *ctx, const char *title) +{ +#ifndef OPENSSL_NO_QLOG + OPENSSL_free(ctx->qlog_title); + ctx->qlog_title = NULL; + + if (title == NULL) + return 1; + + if ((ctx->qlog_title = OPENSSL_strdup(title)) == NULL) + return 0; +#endif + + return 1; +} diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 71a39a1005..6788d2c104 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -4214,6 +4214,9 @@ void SSL_CTX_free(SSL_CTX *a) #endif OPENSSL_free(a->propq); +#ifndef OPENSSL_NO_QLOG + OPENSSL_free(a->qlog_title); +#endif OPENSSL_free(a); } diff --git a/ssl/ssl_local.h b/ssl/ssl_local.h index 211b72c6fe..1db5df46df 100644 --- a/ssl/ssl_local.h +++ b/ssl/ssl_local.h @@ -1189,6 +1189,10 @@ struct ssl_ctx_st { size_t client_cert_type_len; unsigned char *server_cert_type; size_t server_cert_type_len; + +# ifndef OPENSSL_NO_QLOG + char *qlog_title; /* Session title for QLOG */ +# endif }; typedef struct cert_pkey_st CERT_PKEY; -- 2.34.1