Skip to content

Commit

Permalink
quic_tserver: Add possibility to change the connection id
Browse files Browse the repository at this point in the history
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #20892)
  • Loading branch information
t8m authored and hlandau committed May 17, 2023
1 parent c301149 commit bbc9754
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
4 changes: 4 additions & 0 deletions include/internal/quic_channel.h
Expand Up @@ -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
5 changes: 5 additions & 0 deletions include/internal/quic_tserver.h
Expand Up @@ -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
27 changes: 22 additions & 5 deletions ssl/quic/quic_channel.c
Expand Up @@ -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. */
Expand Down Expand Up @@ -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. */
Expand All @@ -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. */
Expand All @@ -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. */
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion ssl/quic/quic_channel_local.h
Expand Up @@ -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;
Expand Down

0 comments on commit bbc9754

Please sign in to comment.