diff options
author | Matt Caswell <matt@openssl.org> | 2023-05-18 16:46:58 +0200 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2023-05-24 13:18:33 +0200 |
commit | 5cf99b4040eb1ef63b3254090d16299cad690b1e (patch) | |
tree | 84cb0a5a6e10ca358c45d8def9ec79bb8137f24b | |
parent | Add a test for the new QUIC tracing capability (diff) | |
download | openssl-5cf99b4040eb1ef63b3254090d16299cad690b1e.tar.xz openssl-5cf99b4040eb1ef63b3254090d16299cad690b1e.zip |
Create setter functions for the msg_callback and msg_callback_arg
We create setter functions for the msg_callback and msg_callback_arg so
that these values can be properly propagated to the QRX/QTX/TXP even
after the channel has been created.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20914)
-rw-r--r-- | include/internal/quic_channel.h | 12 | ||||
-rw-r--r-- | include/internal/quic_record_rx.h | 11 | ||||
-rw-r--r-- | include/internal/quic_record_tx.h | 10 | ||||
-rw-r--r-- | include/internal/quic_txp.h | 12 | ||||
-rw-r--r-- | ssl/quic/quic_channel.c | 50 | ||||
-rw-r--r-- | ssl/quic/quic_impl.c | 28 | ||||
-rw-r--r-- | ssl/quic/quic_local.h | 5 | ||||
-rw-r--r-- | ssl/quic/quic_record_rx.c | 15 | ||||
-rw-r--r-- | ssl/quic/quic_record_tx.c | 15 | ||||
-rw-r--r-- | ssl/quic/quic_txp.c | 28 | ||||
-rw-r--r-- | test/recipes/75-test_quicapi_data/ssltraceref.txt | 36 |
11 files changed, 132 insertions, 90 deletions
diff --git a/include/internal/quic_channel.h b/include/internal/quic_channel.h index ac73097985..74ee125f34 100644 --- a/include/internal/quic_channel.h +++ b/include/internal/quic_channel.h @@ -130,11 +130,6 @@ typedef struct quic_channel_args_st { */ OSSL_TIME (*now_cb)(void *arg); void *now_cb_arg; - - /* Message callback related arguments */ - ossl_msg_cb msg_callback; - void *msg_callback_arg; - SSL *msg_callback_s; } QUIC_CHANNEL_ARGS; typedef struct quic_channel_st QUIC_CHANNEL; @@ -328,6 +323,13 @@ void ossl_quic_channel_reject_stream(QUIC_CHANNEL *ch, QUIC_STREAM *qs); int ossl_quic_channel_replace_local_cid(QUIC_CHANNEL *ch, const QUIC_CONN_ID *conn_id); +/* Setters for the msg_callback and msg_callback_arg */ +void ossl_quic_channel_set_msg_callback(QUIC_CHANNEL *ch, + ossl_msg_cb msg_callback, + SSL *msg_callback_s); +void ossl_quic_channel_set_msg_callback_arg(QUIC_CHANNEL *ch, + void *msg_callback_arg); + # endif #endif diff --git a/include/internal/quic_record_rx.h b/include/internal/quic_record_rx.h index f372887f1b..b86d9a98b5 100644 --- a/include/internal/quic_record_rx.h +++ b/include/internal/quic_record_rx.h @@ -45,11 +45,6 @@ typedef struct ossl_qrx_args_st { /* Initial key phase. For debugging use only; always 0 in real use. */ unsigned char init_key_phase_bit; - - /* Message callback related arguments */ - ossl_msg_cb msg_callback; - void *msg_callback_arg; - SSL *msg_callback_s; } OSSL_QRX_ARGS; /* Instantiates a new QRX. */ @@ -65,6 +60,12 @@ OSSL_QRX *ossl_qrx_new(const OSSL_QRX_ARGS *args); */ void ossl_qrx_free(OSSL_QRX *qrx); +/* Setters for the msg_callback and msg_callback_arg */ +void ossl_qrx_set_msg_callback(OSSL_QRX *qrx, ossl_msg_cb msg_callback, + SSL *msg_callback_s); +void ossl_qrx_set_msg_callback_arg(OSSL_QRX *qrx, + void *msg_callback_arg); + /* * DCID Management * =============== diff --git a/include/internal/quic_record_tx.h b/include/internal/quic_record_tx.h index 21bfb9d01b..a12c3abe00 100644 --- a/include/internal/quic_record_tx.h +++ b/include/internal/quic_record_tx.h @@ -46,11 +46,6 @@ typedef struct ossl_qtx_args_st { /* Maximum datagram payload length (MDPL) for TX purposes. */ size_t mdpl; - - /* Message callback related arguments */ - ossl_msg_cb msg_callback; - void *msg_callback_arg; - SSL *msg_callback_s; } OSSL_QTX_ARGS; /* Instantiates a new QTX. */ @@ -63,6 +58,11 @@ void ossl_qtx_free(OSSL_QTX *qtx); void ossl_qtx_set_mutator(OSSL_QTX *qtx, ossl_mutate_packet_cb mutatecb, ossl_finish_mutate_cb finishmutatecb, void *mutatearg); +/* Setters for the msg_callback and the msg_callback_arg */ +void ossl_qtx_set_msg_callback(OSSL_QTX *qtx, ossl_msg_cb msg_callback, + SSL *msg_callback_s); +void ossl_qtx_set_msg_callback_arg(OSSL_QTX *qtx, void *msg_callback_arg); + /* * Secret Management * ----------------- diff --git a/include/internal/quic_txp.h b/include/internal/quic_txp.h index 54c25754eb..ad1c06f31e 100644 --- a/include/internal/quic_txp.h +++ b/include/internal/quic_txp.h @@ -49,11 +49,6 @@ typedef struct ossl_quic_tx_packetiser_args_st { OSSL_TIME (*now)(void *arg); /* Callback to get current time. */ void *now_arg; - /* Message callback related arguments */ - ossl_msg_cb msg_callback; - void *msg_callback_arg; - SSL *msg_callback_s; - /* * Injected dependencies - crypto streams. * @@ -172,6 +167,13 @@ void ossl_quic_tx_packetiser_schedule_ack_eliciting(OSSL_QUIC_TX_PACKETISER *txp int ossl_quic_tx_packetiser_schedule_conn_close(OSSL_QUIC_TX_PACKETISER *txp, const OSSL_QUIC_FRAME_CONN_CLOSE *f); +/* Setters for the msg_callback and msg_callback_arg */ +void ossl_quic_tx_packetiser_set_msg_callback(OSSL_QUIC_TX_PACKETISER *txp, + ossl_msg_cb msg_callback, + SSL *msg_callback_s); +void ossl_quic_tx_packetiser_set_msg_callback_arg(OSSL_QUIC_TX_PACKETISER *txp, + void *msg_callback_arg); + # endif #endif diff --git a/ssl/quic/quic_channel.c b/ssl/quic/quic_channel.c index 76546e2bd3..328c8bee8b 100644 --- a/ssl/quic/quic_channel.c +++ b/ssl/quic/quic_channel.c @@ -130,10 +130,6 @@ static int ch_init(QUIC_CHANNEL *ch) /* We plug in a network write BIO to the QTX later when we get one. */ qtx_args.libctx = ch->libctx; qtx_args.mdpl = QUIC_MIN_INITIAL_DGRAM_LEN; - /* Callback related arguments */ - qtx_args.msg_callback = ch->msg_callback; - qtx_args.msg_callback_arg = ch->msg_callback_arg; - qtx_args.msg_callback_s = ch->msg_callback_s; ch->rx_max_udp_payload_size = qtx_args.mdpl; ch->qtx = ossl_qtx_new(&qtx_args); @@ -212,10 +208,6 @@ static int ch_init(QUIC_CHANNEL *ch) txp_args.cc_data = ch->cc_data; txp_args.now = get_time; txp_args.now_arg = ch; - /* Callback related arguments */ - txp_args.msg_callback = ch->msg_callback; - txp_args.msg_callback_arg = ch->msg_callback_arg; - txp_args.msg_callback_s = ch->msg_callback_s; for (pn_space = QUIC_PN_SPACE_INITIAL; pn_space < QUIC_PN_SPACE_NUM; ++pn_space) { ch->crypto_send[pn_space] = ossl_quic_sstream_new(INIT_CRYPTO_BUF_LEN); @@ -248,10 +240,6 @@ static int ch_init(QUIC_CHANNEL *ch) qrx_args.demux = ch->demux; qrx_args.short_conn_id_len = rx_short_cid_len; qrx_args.max_deferred = 32; - /* Callback related arguments */ - qrx_args.msg_callback = ch->msg_callback; - qrx_args.msg_callback_arg = ch->msg_callback_arg; - qrx_args.msg_callback_s = ch->msg_callback_s; if ((ch->qrx = ossl_qrx_new(&qrx_args)) == NULL) goto err; @@ -360,16 +348,13 @@ QUIC_CHANNEL *ossl_quic_channel_new(const QUIC_CHANNEL_ARGS *args) if ((ch = OPENSSL_zalloc(sizeof(*ch))) == NULL) return NULL; - ch->libctx = args->libctx; - ch->propq = args->propq; - ch->is_server = args->is_server; - ch->tls = args->tls; - ch->mutex = args->mutex; - ch->now_cb = args->now_cb; - ch->now_cb_arg = args->now_cb_arg; - ch->msg_callback = args->msg_callback; - ch->msg_callback_arg = args->msg_callback_arg; - ch->msg_callback_s = args->msg_callback_s; + ch->libctx = args->libctx; + ch->propq = args->propq; + ch->is_server = args->is_server; + ch->tls = args->tls; + ch->mutex = args->mutex; + ch->now_cb = args->now_cb; + ch->now_cb_arg = args->now_cb_arg; if (!ch_init(ch)) { OPENSSL_free(ch); @@ -2524,3 +2509,24 @@ int ossl_quic_channel_replace_local_cid(QUIC_CHANNEL *ch, return 0; return 1; } + +void ossl_quic_channel_set_msg_callback(QUIC_CHANNEL *ch, + ossl_msg_cb msg_callback, + SSL *msg_callback_s) +{ + ch->msg_callback = msg_callback; + ch->msg_callback_s = msg_callback_s; + ossl_qtx_set_msg_callback(ch->qtx, msg_callback, msg_callback_s); + ossl_quic_tx_packetiser_set_msg_callback(ch->txp, msg_callback, + msg_callback_s); + ossl_qrx_set_msg_callback(ch->qrx, msg_callback, msg_callback_s); +} + +void ossl_quic_channel_set_msg_callback_arg(QUIC_CHANNEL *ch, + void *msg_callback_arg) +{ + ch->msg_callback_arg = msg_callback_arg; + ossl_qtx_set_msg_callback_arg(ch->qtx, msg_callback_arg); + ossl_quic_tx_packetiser_set_msg_callback_arg(ch->txp, msg_callback_arg); + ossl_qrx_set_msg_callback_arg(ch->qrx, msg_callback_arg); +} diff --git a/ssl/quic/quic_impl.c b/ssl/quic/quic_impl.c index c623a3c0b9..4ba87a32af 100644 --- a/ssl/quic/quic_impl.c +++ b/ssl/quic/quic_impl.c @@ -326,13 +326,13 @@ SSL *ossl_quic_new(SSL_CTX *ctx) qc->default_blocking = 1; qc->incoming_stream_policy = SSL_INCOMING_STREAM_POLICY_AUTO; qc->last_error = SSL_ERROR_NONE; - qc->msg_callback = ctx->msg_callback; - qc->msg_callback_arg = ctx->msg_callback_arg; - qc->msg_callback_s = ssl_base; if (!create_channel(qc)) goto err; + ossl_quic_channel_set_msg_callback(qc->ch, ctx->msg_callback, ssl_base); + ossl_quic_channel_set_msg_callback_arg(qc->ch, ctx->msg_callback_arg); + qc_update_reject_policy(qc); /* @@ -1045,7 +1045,7 @@ long ossl_quic_ctrl(SSL *s, int cmd, long larg, void *parg) return ctx.qc->default_ssl_mode; case SSL_CTRL_SET_MSG_CALLBACK_ARG: - ctx.qc->msg_callback_arg = parg; + ossl_quic_channel_set_msg_callback_arg(ctx.qc->ch, parg); /* This ctrl also needs to be passed to the internal SSL object */ return SSL_ctrl(ctx.qc->tls, cmd, larg, parg); @@ -1120,16 +1120,13 @@ static int create_channel(QUIC_CONNECTION *qc) { QUIC_CHANNEL_ARGS args = {0}; - args.libctx = qc->ssl.ctx->libctx; - args.propq = qc->ssl.ctx->propq; - args.is_server = qc->as_server; - args.tls = qc->tls; - args.mutex = qc->mutex; - args.now_cb = qc->override_now_cb; - args.now_cb_arg = qc->override_now_cb_arg; - args.msg_callback = qc->msg_callback; - args.msg_callback_arg = qc->msg_callback_arg; - args.msg_callback_s = qc->msg_callback_s; + args.libctx = qc->ssl.ctx->libctx; + args.propq = qc->ssl.ctx->propq; + args.is_server = qc->as_server; + args.tls = qc->tls; + args.mutex = qc->mutex; + args.now_cb = qc->override_now_cb; + args.now_cb_arg = qc->override_now_cb_arg; qc->ch = ossl_quic_channel_new(&args); if (qc->ch == NULL) @@ -2672,7 +2669,8 @@ long ossl_quic_callback_ctrl(SSL *s, int cmd, void (*fp) (void)) switch (cmd) { case SSL_CTRL_SET_MSG_CALLBACK: - ctx.qc->msg_callback = (ossl_msg_cb)fp; + ossl_quic_channel_set_msg_callback(ctx.qc->ch, (ossl_msg_cb)fp, + &ctx.qc->ssl); /* This callback also needs to be set on the internal SSL object */ return ssl3_callback_ctrl(ctx.qc->tls, cmd, fp);; diff --git a/ssl/quic/quic_local.h b/ssl/quic/quic_local.h index d4088d4b69..46b0e72014 100644 --- a/ssl/quic/quic_local.h +++ b/ssl/quic/quic_local.h @@ -195,11 +195,6 @@ struct quic_conn_st { * and SSL_ERROR_WANT_WRITE. */ int last_error; - - /* Message callback related arguments */ - ossl_msg_cb msg_callback; - void *msg_callback_arg; - SSL *msg_callback_s; }; /* Internal calls to the QUIC CSM which come from various places. */ diff --git a/ssl/quic/quic_record_rx.c b/ssl/quic/quic_record_rx.c index 266dee9d31..db70c119fa 100644 --- a/ssl/quic/quic_record_rx.c +++ b/ssl/quic/quic_record_rx.c @@ -176,9 +176,6 @@ OSSL_QRX *ossl_qrx_new(const OSSL_QRX_ARGS *args) qrx->short_conn_id_len = args->short_conn_id_len; qrx->init_key_phase_bit = args->init_key_phase_bit; qrx->max_deferred = args->max_deferred; - qrx->msg_callback = args->msg_callback; - qrx->msg_callback_arg = args->msg_callback_arg; - qrx->msg_callback_s = args->msg_callback_s; return qrx; } @@ -1207,3 +1204,15 @@ uint64_t ossl_qrx_get_max_forged_pkt_count(OSSL_QRX *qrx, return el == NULL ? UINT64_MAX : ossl_qrl_get_suite_max_forged_pkt(el->suite_id); } + +void ossl_qrx_set_msg_callback(OSSL_QRX *qrx, ossl_msg_cb msg_callback, + SSL *msg_callback_s) +{ + qrx->msg_callback = msg_callback; + qrx->msg_callback_s = msg_callback_s; +} + +void ossl_qrx_set_msg_callback_arg(OSSL_QRX *qrx, void *msg_callback_arg) +{ + qrx->msg_callback_arg = msg_callback_arg; +} diff --git a/ssl/quic/quic_record_tx.c b/ssl/quic/quic_record_tx.c index 748b4c358c..09862c7751 100644 --- a/ssl/quic/quic_record_tx.c +++ b/ssl/quic/quic_record_tx.c @@ -117,9 +117,6 @@ OSSL_QTX *ossl_qtx_new(const OSSL_QTX_ARGS *args) qtx->propq = args->propq; qtx->bio = args->bio; qtx->mdpl = args->mdpl; - qtx->msg_callback = args->msg_callback; - qtx->msg_callback_arg = args->msg_callback_arg; - qtx->msg_callback_s = args->msg_callback_s; return qtx; } @@ -1005,3 +1002,15 @@ uint64_t ossl_qtx_get_max_epoch_pkt_count(OSSL_QTX *qtx, uint32_t enc_level) return ossl_qrl_get_suite_max_pkt(el->suite_id); } + +void ossl_qtx_set_msg_callback(OSSL_QTX *qtx, ossl_msg_cb msg_callback, + SSL *msg_callback_s) +{ + qtx->msg_callback = msg_callback; + qtx->msg_callback_s = msg_callback_s; +} + +void ossl_qtx_set_msg_callback_arg(OSSL_QTX *qtx, void *msg_callback_arg) +{ + qtx->msg_callback_arg = msg_callback_arg; +} diff --git a/ssl/quic/quic_txp.c b/ssl/quic/quic_txp.c index b8bfb3592e..b04fe01115 100644 --- a/ssl/quic/quic_txp.c +++ b/ssl/quic/quic_txp.c @@ -69,6 +69,12 @@ struct ossl_quic_tx_packetiser_st { size_t scratch_len; /* number of bytes allocated for scratch */ OSSL_QTX_IOVEC *iovec; /* scratch iovec array for use with QTX */ size_t alloc_iovec; /* size of iovec array */ + + /* Message callback related arguments */ + ossl_msg_cb msg_callback; + void *msg_callback_arg; + SSL *msg_callback_s; + }; /* @@ -301,7 +307,7 @@ static int tx_helper_commit(struct tx_helper *h) return 0; } - if (h->txp->args.msg_callback != NULL && l > 0) { + if (h->txp->msg_callback != NULL && l > 0) { uint64_t ftype; int ctype = SSL3_RT_QUIC_FRAME_FULL; PACKET pkt; @@ -318,9 +324,9 @@ static int tx_helper_commit(struct tx_helper *h) || ftype == OSSL_QUIC_FRAME_TYPE_CRYPTO) ctype = SSL3_RT_QUIC_FRAME_HEADER; - h->txp->args.msg_callback(1, OSSL_QUIC1_VERSION, ctype, h->txn.data, l, - h->txp->args.msg_callback_s, - h->txp->args.msg_callback_arg); + h->txp->msg_callback(1, OSSL_QUIC1_VERSION, ctype, h->txn.data, l, + h->txp->msg_callback_s, + h->txp->msg_callback_arg); } h->scratch_bytes += l; @@ -2376,3 +2382,17 @@ int ossl_quic_tx_packetiser_schedule_conn_close(OSSL_QUIC_TX_PACKETISER *txp, txp->want_conn_close = 1; return 1; } + +void ossl_quic_tx_packetiser_set_msg_callback(OSSL_QUIC_TX_PACKETISER *txp, + ossl_msg_cb msg_callback, + SSL *msg_callback_s) +{ + txp->msg_callback = msg_callback; + txp->msg_callback_s = msg_callback_s; +} + +void ossl_quic_tx_packetiser_set_msg_callback_arg(OSSL_QUIC_TX_PACKETISER *txp, + void *msg_callback_arg) +{ + txp->msg_callback_arg = msg_callback_arg; +} diff --git a/test/recipes/75-test_quicapi_data/ssltraceref.txt b/test/recipes/75-test_quicapi_data/ssltraceref.txt index 3d093af5c7..095a945f6e 100644 --- a/test/recipes/75-test_quicapi_data/ssltraceref.txt +++ b/test/recipes/75-test_quicapi_data/ssltraceref.txt @@ -2,8 +2,8 @@ Sent TLS Record Header: Version = TLS 1.0 (0x301) Content Type = Handshake (22) - Length = 254 - ClientHello, Length=250 + Length = 256 + ClientHello, Length=252 client_version=0x303 (TLS 1.2) Random: gmt_unix_time=0x???????? @@ -13,12 +13,12 @@ Header: {0x13, 0x01} TLS_AES_128_GCM_SHA256 compression_methods (len=1) No Compression (0x00) - extensions, length = 207 - extension_type=UNKNOWN(57), length=47 + extensions, length = 209 + extension_type=UNKNOWN(57), length=49 0000 - 0c 00 0f 00 01 04 80 00-75 30 03 02 44 b0 0e ........u0..D.. - 000f - 01 04 04 04 80 20 00 00-05 04 80 10 00 00 06 ..... ......... - 001e - 04 80 10 00 00 07 04 80-10 00 00 08 01 00 09 ............... - 002d - 01 00 .. + 000f - 01 02 04 04 80 20 00 00-05 04 80 20 00 00 06 ..... ..... ... + 001e - 04 80 20 00 00 07 04 80-20 00 00 08 02 40 64 .. ..... ....@d + 002d - 09 02 40 64 ..@d extension_type=ec_point_formats(11), length=4 uncompressed (0) ansiX962_compressed_prime (1) @@ -67,7 +67,7 @@ Header: Sent Frame: Crypto Offset: 0 - Len: 254 + Len: 256 Sent Frame: Padding Sent Packet Packet Type: Initial @@ -134,14 +134,14 @@ Header: Content Type = ApplicationData (23) Length = 1022 Inner Content Type = Handshake (22) - EncryptedExtensions, Length=86 - extensions, length = 84 - extension_type=UNKNOWN(57), length=65 + EncryptedExtensions, Length=88 + extensions, length = 86 + extension_type=UNKNOWN(57), length=67 0000 - 0c 00 00 08 ?? ?? ?? ??-?? ?? ?? ?? 0f 08 ?? ....????????..? 000f - ?? ?? ?? ?? ?? ?? ?? 01-04 80 00 75 30 03 02 ???????....u0.. - 001e - 44 b0 0e 01 04 04 04 80-20 00 00 05 04 80 10 D....... ...... - 002d - 00 00 06 04 80 10 00 00-07 04 80 10 00 00 08 ............... - 003c - 01 01 09 01 00 ..... + 001e - 44 b0 0e 01 02 04 04 80-20 00 00 05 04 80 20 D....... ..... + 002d - 00 00 06 04 80 20 00 00-07 04 80 20 00 00 08 ..... ..... ... + 003c - 02 40 64 09 02 40 64 .@d..@d extension_type=application_layer_protocol_negotiation(16), length=11 ossltest @@ -234,22 +234,22 @@ YeeuLO02zToHhnQ6KbPXOrQAqcL1kngO4g+j/ru+4AZThFkdkGnltvk= No extensions Received Datagram - Length: 254 + Length: 256 Received Packet Packet Type: Handshake Version: 0x00000001 Destination Conn Id: <zero length id> Source Conn Id: 0x???????????????? - Payload length: 211 + Payload length: 213 Packet Number: 0x00000001 Received Frame: Crypto Offset: 1022 - Len: 190 + Len: 192 Received TLS Record Header: Version = TLS 1.2 (0x303) Content Type = ApplicationData (23) - Length = 190 + Length = 192 Inner Content Type = Handshake (22) CertificateVerify, Length=260 Signature Algorithm: rsa_pss_rsae_sha256 (0x0804) |