]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
quic_tserver: Add possibility to change the connection id
authorTomas Mraz <tomas@openssl.org>
Thu, 11 May 2023 11:49:51 +0000 (13:49 +0200)
committerHugo Landau <hlandau@openssl.org>
Wed, 17 May 2023 13:04:18 +0000 (14:04 +0100)
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20892)

include/internal/quic_channel.h
include/internal/quic_tserver.h
ssl/quic/quic_channel.c
ssl/quic/quic_channel_local.h

index d1a231fcc8868a62748f1a761e3bf70eff48a9a5..6dbf08665de8b21e81d5df19feab85ad5ea0d103 100644 (file)
@@ -319,6 +319,10 @@ void ossl_quic_channel_set_incoming_stream_auto_reject(QUIC_CHANNEL *ch,
  */
 void ossl_quic_channel_reject_stream(QUIC_CHANNEL *ch, QUIC_STREAM *qs);
 
+/* Replace local connection ID in TXP and DEMUX for testing purposes. */
+int ossl_quic_channel_replace_local_cid(QUIC_CHANNEL *ch,
+                                        const QUIC_CONN_ID *conn_id);
+
 # endif
 
 #endif
index a42bbaa6847d38cc655d2b494d0bddb96b540a11..744c34472e7a6c15d59e2ac7f065f73e18ed9076 100644 (file)
@@ -145,6 +145,11 @@ int ossl_quic_tserver_stream_has_peer_reset_stream(QUIC_TSERVER *srv,
                                                    uint64_t stream_id,
                                                    uint64_t *app_error_code);
 
+/*
+ * Replaces existing local connection ID in the underlying QUIC_CHANNEL.
+ */
+int ossl_quic_tserver_set_new_local_cid(QUIC_TSERVER *srv,
+                                        const QUIC_CONN_ID *conn_id);
 # endif
 
 #endif
index 4b378bf40a64e39e43a49932614dcffcf08602d7..6e0af8676066cba7be0f9e882df5ae6172c3787b 100644 (file)
@@ -1194,7 +1194,7 @@ static int ch_generate_transport_params(QUIC_CHANNEL *ch)
             goto err;
 
         if (!ossl_quic_wire_encode_transport_param_cid(&wpkt, QUIC_TPARAM_INITIAL_SCID,
-                                                       &ch->cur_local_dcid))
+                                                       &ch->cur_local_cid))
             goto err;
     } else {
         /* Client always uses an empty SCID. */
@@ -2291,7 +2291,7 @@ static int ch_server_on_new_conn(QUIC_CHANNEL *ch, const BIO_ADDR *peer,
 
     /* Generate a SCID we will use for the connection. */
     if (!gen_rand_conn_id(ch->libctx, INIT_DCID_LEN,
-                          &ch->cur_local_dcid))
+                          &ch->cur_local_cid))
         return 0;
 
     /* Note our newly learnt peer address and CIDs. */
@@ -2307,7 +2307,7 @@ static int ch_server_on_new_conn(QUIC_CHANNEL *ch, const BIO_ADDR *peer,
     if (!ossl_quic_tx_packetiser_set_cur_dcid(ch->txp, &ch->cur_remote_dcid))
         return 0;
 
-    if (!ossl_quic_tx_packetiser_set_cur_scid(ch->txp, &ch->cur_local_dcid))
+    if (!ossl_quic_tx_packetiser_set_cur_scid(ch->txp, &ch->cur_local_cid))
         return 0;
 
     /* Plug in secrets for the Initial EL. */
@@ -2318,8 +2318,8 @@ static int ch_server_on_new_conn(QUIC_CHANNEL *ch, const BIO_ADDR *peer,
                                           ch->qrx, ch->qtx))
         return 0;
 
-    /* Register our local DCID in the DEMUX. */
-    if (!ossl_qrx_add_dst_conn_id(ch->qrx, &ch->cur_local_dcid))
+    /* Register our local CID in the DEMUX. */
+    if (!ossl_qrx_add_dst_conn_id(ch->qrx, &ch->cur_local_cid))
         return 0;
 
     /* Change state. */
@@ -2491,3 +2491,20 @@ void ossl_quic_channel_reject_stream(QUIC_CHANNEL *ch, QUIC_STREAM *qs)
 
     ossl_quic_stream_map_update_state(&ch->qsm, qs);
 }
+
+/* Replace local connection ID in TXP and DEMUX for testing purposes. */
+int ossl_quic_channel_replace_local_cid(QUIC_CHANNEL *ch,
+                                        const QUIC_CONN_ID *conn_id)
+{
+    /* Remove the current local CID from the DEMUX. */
+    if (!ossl_qrx_remove_dst_conn_id(ch->qrx, &ch->cur_local_cid))
+        return 0;
+    ch->cur_local_cid = *conn_id;
+    /* Set in the TXP, used only for long header packets. */
+    if (!ossl_quic_tx_packetiser_set_cur_scid(ch->txp, &ch->cur_local_cid))
+        return 0;
+    /* Register our new local CID in the DEMUX. */
+    if (!ossl_qrx_add_dst_conn_id(ch->qrx, &ch->cur_local_cid))
+        return 0;
+    return 1;
+}
index 0eb47f3f13c28c887a4c12d87f52b8685583d5f9..99fbb1db68e640f4cef0282dffd8ae8883878893 100644 (file)
@@ -127,7 +127,7 @@ struct quic_channel_st {
     uint64_t                        cur_remote_seq_num;
     uint64_t                        cur_retire_prior_to;
     /* Server only: The DCID we currently expect the peer to use to talk to us. */
-    QUIC_CONN_ID                    cur_local_dcid;
+    QUIC_CONN_ID                    cur_local_cid;
 
     /* Transport parameter values we send to our peer. */
     uint64_t                        tx_init_max_stream_data_bidi_local;