]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Create setter functions for the msg_callback and msg_callback_arg
authorMatt Caswell <matt@openssl.org>
Thu, 18 May 2023 14:46:58 +0000 (15:46 +0100)
committerMatt Caswell <matt@openssl.org>
Wed, 24 May 2023 11:18:33 +0000 (12:18 +0100)
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)

include/internal/quic_channel.h
include/internal/quic_record_rx.h
include/internal/quic_record_tx.h
include/internal/quic_txp.h
ssl/quic/quic_channel.c
ssl/quic/quic_impl.c
ssl/quic/quic_local.h
ssl/quic/quic_record_rx.c
ssl/quic/quic_record_tx.c
ssl/quic/quic_txp.c
test/recipes/75-test_quicapi_data/ssltraceref.txt

index ac73097985884ede8f71c01c848e073bb1f723a3..74ee125f342ee297ea441d5fa687244cc5dc8446 100644 (file)
@@ -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
index f372887f1b2ce136d365c0289ed3178e10b5e05c..b86d9a98b5b0a39ebb26e26926094dca971501e7 100644 (file)
@@ -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
  * ===============
index 21bfb9d01b03427c5f5f4b586e99a2e3b2ed4827..a12c3abe009a5fafa229adf95465ac7e85d0737c 100644 (file)
@@ -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
  * -----------------
index 54c25754eb87b5bb623ddc32cb0e1a4dd3a4912f..ad1c06f31e86b1fe390f60cef6b6f515c34d93f5 100644 (file)
@@ -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
index 76546e2bd3bb58d9980eceb1fa99b19687ac999d..328c8bee8bba65f05d27543e986832a8ac314778 100644 (file)
@@ -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);
+}
index c623a3c0b97aab5d6b90bc493ec7154dee339744..4ba87a32af9452b9b43ddcd51dc017aeef21312d 100644 (file)
@@ -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);;
 
index d4088d4b699c5ce4907b99d300eab26fcee4e88a..46b0e72014c7f87b1d3ad99438224128124184b2 100644 (file)
@@ -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. */
index 266dee9d314ab7e7079b77b1e8176b3e52d98b9b..db70c119fa3ff441113f83963bd15c13cf9bbf48 100644 (file)
@@ -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;
+}
index 748b4c358c5a2ac1146d8eded3dab4c3fc71729a..09862c77511d1bec24214cc6acf0448b905f2ca2 100644 (file)
@@ -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;
+}
index b8bfb3592eaf0123e7ac0b23f59555b7ad1357aa..b04fe011159f21f770dea1a18f610c1e20e2d774 100644 (file)
@@ -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;
+}
index 3d093af5c77bc79f11e63d2d7b08f5601b4c91f7..095a945f6eab45ba6425f46c2822e48a7cce00ee 100644 (file)
@@ -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)