mirror of
https://github.com/openssl/openssl.git
synced 2024-12-14 04:24:23 +08:00
QUIC CHANNEL: Allow time source to be overridden
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/20348)
This commit is contained in:
parent
134b79c056
commit
b212d554e7
@ -111,6 +111,13 @@ typedef struct quic_channel_args_st {
|
|||||||
* mutex primitive or using its RW mutex primitive.
|
* mutex primitive or using its RW mutex primitive.
|
||||||
*/
|
*/
|
||||||
CRYPTO_MUTEX *mutex;
|
CRYPTO_MUTEX *mutex;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Optional function pointer to use to retrieve the current time. If NULL,
|
||||||
|
* ossl_time_now() is used.
|
||||||
|
*/
|
||||||
|
OSSL_TIME (*now_cb)(void *arg);
|
||||||
|
void *now_cb_arg;
|
||||||
} QUIC_CHANNEL_ARGS;
|
} QUIC_CHANNEL_ARGS;
|
||||||
|
|
||||||
typedef struct quic_channel_st QUIC_CHANNEL;
|
typedef struct quic_channel_st QUIC_CHANNEL;
|
||||||
|
@ -65,6 +65,14 @@ BIO *ossl_quic_conn_get_net_wbio(const QUIC_CONNECTION *qc);
|
|||||||
__owur int ossl_quic_conn_set_initial_peer_addr(QUIC_CONNECTION *qc,
|
__owur int ossl_quic_conn_set_initial_peer_addr(QUIC_CONNECTION *qc,
|
||||||
const BIO_ADDR *peer_addr);
|
const BIO_ADDR *peer_addr);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Used to override ossl_time_now() for debug purposes. Must be called before
|
||||||
|
* connecting.
|
||||||
|
*/
|
||||||
|
void ossl_quic_conn_set_override_now_cb(SSL *s,
|
||||||
|
OSSL_TIME (*now_cb)(void *arg),
|
||||||
|
void *now_cb_arg);
|
||||||
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -37,6 +37,8 @@ typedef struct quic_tserver_args_st {
|
|||||||
OSSL_LIB_CTX *libctx;
|
OSSL_LIB_CTX *libctx;
|
||||||
const char *propq;
|
const char *propq;
|
||||||
BIO *net_rbio, *net_wbio;
|
BIO *net_rbio, *net_wbio;
|
||||||
|
OSSL_TIME (*now_cb)(void *arg);
|
||||||
|
void *now_cb_arg;
|
||||||
} QUIC_TSERVER_ARGS;
|
} QUIC_TSERVER_ARGS;
|
||||||
|
|
||||||
QUIC_TSERVER *ossl_quic_tserver_new(const QUIC_TSERVER_ARGS *args,
|
QUIC_TSERVER *ossl_quic_tserver_new(const QUIC_TSERVER_ARGS *args,
|
||||||
|
@ -133,7 +133,7 @@ static int ch_init(QUIC_CHANNEL *ch)
|
|||||||
if (!ossl_quic_rxfc_init(&ch->conn_rxfc, NULL,
|
if (!ossl_quic_rxfc_init(&ch->conn_rxfc, NULL,
|
||||||
2 * 1024 * 1024,
|
2 * 1024 * 1024,
|
||||||
10 * 1024 * 1024,
|
10 * 1024 * 1024,
|
||||||
get_time, NULL))
|
get_time, ch))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (!ossl_statm_init(&ch->statm))
|
if (!ossl_statm_init(&ch->statm))
|
||||||
@ -144,7 +144,7 @@ static int ch_init(QUIC_CHANNEL *ch)
|
|||||||
if ((ch->cc_data = ch->cc_method->new(NULL, NULL, NULL)) == NULL)
|
if ((ch->cc_data = ch->cc_method->new(NULL, NULL, NULL)) == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if ((ch->ackm = ossl_ackm_new(get_time, NULL, &ch->statm,
|
if ((ch->ackm = ossl_ackm_new(get_time, ch, &ch->statm,
|
||||||
ch->cc_method, ch->cc_data)) == NULL)
|
ch->cc_method, ch->cc_data)) == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
@ -166,6 +166,7 @@ static int ch_init(QUIC_CHANNEL *ch)
|
|||||||
txp_args.cc_method = ch->cc_method;
|
txp_args.cc_method = ch->cc_method;
|
||||||
txp_args.cc_data = ch->cc_data;
|
txp_args.cc_data = ch->cc_data;
|
||||||
txp_args.now = get_time;
|
txp_args.now = get_time;
|
||||||
|
txp_args.now_arg = ch;
|
||||||
for (pn_space = QUIC_PN_SPACE_INITIAL; pn_space < QUIC_PN_SPACE_NUM; ++pn_space) {
|
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);
|
ch->crypto_send[pn_space] = ossl_quic_sstream_new(INIT_CRYPTO_BUF_LEN);
|
||||||
if (ch->crypto_send[pn_space] == NULL)
|
if (ch->crypto_send[pn_space] == NULL)
|
||||||
@ -180,7 +181,7 @@ static int ch_init(QUIC_CHANNEL *ch)
|
|||||||
|
|
||||||
if ((ch->demux = ossl_quic_demux_new(/*BIO=*/NULL,
|
if ((ch->demux = ossl_quic_demux_new(/*BIO=*/NULL,
|
||||||
/*Short CID Len=*/rx_short_cid_len,
|
/*Short CID Len=*/rx_short_cid_len,
|
||||||
get_time, NULL)) == NULL)
|
get_time, ch)) == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -232,7 +233,7 @@ static int ch_init(QUIC_CHANNEL *ch)
|
|||||||
if (!ossl_quic_rxfc_init(&ch->stream0->rxfc, &ch->conn_rxfc,
|
if (!ossl_quic_rxfc_init(&ch->stream0->rxfc, &ch->conn_rxfc,
|
||||||
1 * 1024 * 1024,
|
1 * 1024 * 1024,
|
||||||
5 * 1024 * 1024,
|
5 * 1024 * 1024,
|
||||||
get_time, NULL))
|
get_time, ch))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
/* Plug in the TLS handshake layer. */
|
/* Plug in the TLS handshake layer. */
|
||||||
@ -332,6 +333,8 @@ QUIC_CHANNEL *ossl_quic_channel_new(const QUIC_CHANNEL_ARGS *args)
|
|||||||
ch->is_server = args->is_server;
|
ch->is_server = args->is_server;
|
||||||
ch->tls = args->tls;
|
ch->tls = args->tls;
|
||||||
ch->mutex = args->mutex;
|
ch->mutex = args->mutex;
|
||||||
|
ch->now_cb = args->now_cb;
|
||||||
|
ch->now_cb_arg = args->now_cb_arg;
|
||||||
|
|
||||||
if (!ch_init(ch)) {
|
if (!ch_init(ch)) {
|
||||||
OPENSSL_free(ch);
|
OPENSSL_free(ch);
|
||||||
@ -457,7 +460,12 @@ CRYPTO_MUTEX *ossl_quic_channel_get_mutex(QUIC_CHANNEL *ch)
|
|||||||
/* Used by various components. */
|
/* Used by various components. */
|
||||||
static OSSL_TIME get_time(void *arg)
|
static OSSL_TIME get_time(void *arg)
|
||||||
{
|
{
|
||||||
return ossl_time_now();
|
QUIC_CHANNEL *ch = arg;
|
||||||
|
|
||||||
|
if (ch->now_cb == NULL)
|
||||||
|
return ossl_time_now();
|
||||||
|
|
||||||
|
return ch->now_cb(ch->now_cb_arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Used by QSM. */
|
/* Used by QSM. */
|
||||||
@ -1237,7 +1245,7 @@ static void ch_tick(QUIC_TICK_RESULT *res, void *arg, uint32_t flags)
|
|||||||
* expired.
|
* expired.
|
||||||
*/
|
*/
|
||||||
if (ossl_quic_channel_is_terminating(ch)) {
|
if (ossl_quic_channel_is_terminating(ch)) {
|
||||||
now = ossl_time_now();
|
now = get_time(ch);
|
||||||
|
|
||||||
if (ossl_time_compare(now, ch->terminate_deadline) >= 0) {
|
if (ossl_time_compare(now, ch->terminate_deadline) >= 0) {
|
||||||
ch_on_terminating_timeout(ch);
|
ch_on_terminating_timeout(ch);
|
||||||
@ -1279,7 +1287,7 @@ static void ch_tick(QUIC_TICK_RESULT *res, void *arg, uint32_t flags)
|
|||||||
* ACKM ACK generation deadline is polled by TXP, so we don't need to handle
|
* ACKM ACK generation deadline is polled by TXP, so we don't need to handle
|
||||||
* it here.
|
* it here.
|
||||||
*/
|
*/
|
||||||
now = ossl_time_now();
|
now = get_time(ch);
|
||||||
if (ossl_time_compare(now, ch->idle_deadline) >= 0) {
|
if (ossl_time_compare(now, ch->idle_deadline) >= 0) {
|
||||||
/*
|
/*
|
||||||
* Idle timeout differs from normal protocol violation because we do not
|
* Idle timeout differs from normal protocol violation because we do not
|
||||||
@ -1934,7 +1942,7 @@ static void ch_start_terminating(QUIC_CHANNEL *ch,
|
|||||||
ch->state = tcause->remote ? QUIC_CHANNEL_STATE_TERMINATING_DRAINING
|
ch->state = tcause->remote ? QUIC_CHANNEL_STATE_TERMINATING_DRAINING
|
||||||
: QUIC_CHANNEL_STATE_TERMINATING_CLOSING;
|
: QUIC_CHANNEL_STATE_TERMINATING_CLOSING;
|
||||||
ch->terminate_deadline
|
ch->terminate_deadline
|
||||||
= ossl_time_add(ossl_time_now(),
|
= ossl_time_add(get_time(ch),
|
||||||
ossl_time_multiply(ossl_ackm_get_pto_duration(ch->ackm),
|
ossl_time_multiply(ossl_ackm_get_pto_duration(ch->ackm),
|
||||||
3));
|
3));
|
||||||
|
|
||||||
@ -2038,7 +2046,7 @@ static void ch_update_idle(QUIC_CHANNEL *ch)
|
|||||||
if (ch->max_idle_timeout == 0)
|
if (ch->max_idle_timeout == 0)
|
||||||
ch->idle_deadline = ossl_time_infinite();
|
ch->idle_deadline = ossl_time_infinite();
|
||||||
else
|
else
|
||||||
ch->idle_deadline = ossl_time_add(ossl_time_now(),
|
ch->idle_deadline = ossl_time_add(get_time(ch),
|
||||||
ossl_ms2time(ch->max_idle_timeout));
|
ossl_ms2time(ch->max_idle_timeout));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,12 @@ struct quic_channel_st {
|
|||||||
*/
|
*/
|
||||||
CRYPTO_RWLOCK *mutex;
|
CRYPTO_RWLOCK *mutex;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Callback used to get the current time.
|
||||||
|
*/
|
||||||
|
OSSL_TIME (*now_cb)(void *arg);
|
||||||
|
void *now_cb_arg;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The associated TLS 1.3 connection data. Used to provide the handshake
|
* The associated TLS 1.3 connection data. Used to provide the handshake
|
||||||
* layer; its 'network' side is plugged into the crypto stream for each EL
|
* layer; its 'network' side is plugged into the crypto stream for each EL
|
||||||
|
@ -246,6 +246,16 @@ int ossl_quic_clear(SSL *s)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ossl_quic_conn_set_override_now_cb(SSL *s,
|
||||||
|
OSSL_TIME (*now_cb)(void *arg),
|
||||||
|
void *now_cb_arg)
|
||||||
|
{
|
||||||
|
QUIC_CONNECTION *qc = QUIC_CONNECTION_FROM_SSL(s);
|
||||||
|
|
||||||
|
qc->override_now_cb = now_cb;
|
||||||
|
qc->override_now_cb_arg = now_cb_arg;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* QUIC Front-End I/O API: Network BIO Configuration
|
* QUIC Front-End I/O API: Network BIO Configuration
|
||||||
* =================================================
|
* =================================================
|
||||||
@ -683,6 +693,8 @@ static int ensure_channel(QUIC_CONNECTION *qc)
|
|||||||
args.is_server = 0;
|
args.is_server = 0;
|
||||||
args.tls = qc->tls;
|
args.tls = qc->tls;
|
||||||
args.mutex = qc->mutex;
|
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);
|
qc->ch = ossl_quic_channel_new(&args);
|
||||||
if (qc->ch == NULL)
|
if (qc->ch == NULL)
|
||||||
|
@ -71,6 +71,10 @@ struct quic_conn_st {
|
|||||||
QUIC_THREAD_ASSIST thread_assist;
|
QUIC_THREAD_ASSIST thread_assist;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* If non-NULL, used instead of ossl_time_now(). Used for testing. */
|
||||||
|
OSSL_TIME (*override_now_cb)(void *arg);
|
||||||
|
void *override_now_cb_arg;
|
||||||
|
|
||||||
/* Have we started? */
|
/* Have we started? */
|
||||||
unsigned int started : 1;
|
unsigned int started : 1;
|
||||||
|
|
||||||
|
@ -94,6 +94,8 @@ QUIC_TSERVER *ossl_quic_tserver_new(const QUIC_TSERVER_ARGS *args,
|
|||||||
ch_args.tls = srv->tls;
|
ch_args.tls = srv->tls;
|
||||||
ch_args.mutex = srv->mutex;
|
ch_args.mutex = srv->mutex;
|
||||||
ch_args.is_server = 1;
|
ch_args.is_server = 1;
|
||||||
|
ch_args.now_cb = srv->args.now_cb;
|
||||||
|
ch_args.now_cb_arg = srv->args.now_cb_arg;
|
||||||
|
|
||||||
if ((srv->ch = ossl_quic_channel_new(&ch_args)) == NULL)
|
if ((srv->ch = ossl_quic_channel_new(&ch_args)) == NULL)
|
||||||
goto err;
|
goto err;
|
||||||
|
Loading…
Reference in New Issue
Block a user