Skip to content

Commit

Permalink
QUIC Conformance: Frame Handling Tests
Browse files Browse the repository at this point in the history
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #21135)
  • Loading branch information
hlandau authored and paulidale committed Jul 16, 2023
1 parent 3ffb7d1 commit e26dc8e
Show file tree
Hide file tree
Showing 7 changed files with 791 additions and 33 deletions.
1 change: 0 additions & 1 deletion ssl/quic/quic_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -2629,7 +2629,6 @@ void ossl_quic_channel_on_new_conn_id(QUIC_CHANNEL *ch,
return;

/* We allow only two active connection ids; first check some constraints */

if (ch->cur_remote_dcid.id_len == 0) {
/* Changing from 0 length connection id is disallowed */
ossl_quic_channel_raise_protocol_error(ch,
Expand Down
15 changes: 0 additions & 15 deletions ssl/quic/quic_rx_depack.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,21 +515,6 @@ static int depack_do_frame_stream(PACKET *pkt, QUIC_CHANNEL *ch,
return 0;
}

/*
* RFC 9000 s. 19.8: "The largest offset delivered on a stream -- the sum of
* the offset and data length -- cannot exceed 2**62 - 1, as it is not
* possible to provide flow control credit for that data. Receipt of a frame
* that exceeds this limit MUST be treated as a connection error of type
* FRAME_ENCODING_ERROR or FLOW_CONTROL_ERROR."
*/
if (frame_data.offset + frame_data.len > (((uint64_t)1) << 62) - 1) {
ossl_quic_channel_raise_protocol_error(ch,
QUIC_ERR_FRAME_ENCODING_ERROR,
frame_type,
"oversize stream");
return 0;
}

switch (stream->recv_state) {
case QUIC_RSTREAM_STATE_RECV:
case QUIC_RSTREAM_STATE_SIZE_KNOWN:
Expand Down
12 changes: 11 additions & 1 deletion ssl/quic/quic_wire.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ int ossl_quic_wire_encode_frame_streams_blocked(WPACKET *pkt,
int ossl_quic_wire_encode_frame_new_conn_id(WPACKET *pkt,
const OSSL_QUIC_FRAME_NEW_CONN_ID *f)
{
if (f->conn_id.id_len > QUIC_MAX_CONN_ID_LEN)
if (f->conn_id.id_len < 1
|| f->conn_id.id_len > QUIC_MAX_CONN_ID_LEN)
return 0;

if (!encode_frame_hdr(pkt, OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID)
Expand Down Expand Up @@ -683,6 +684,14 @@ int ossl_quic_wire_decode_frame_stream(PACKET *pkt,
f->len = PACKET_remaining(pkt);
}

/*
* RFC 9000 s. 19.8: "The largest offset delivered on a stream -- the sum of
* the offset and data length -- cannot exceed 2**62 - 1, as it is not
* possible to provide flow control credit for that data."
*/
if (f->offset + f->len > (((uint64_t)1) << 62) - 1)
return 0;

if (nodata) {
f->data = NULL;
} else {
Expand Down Expand Up @@ -774,6 +783,7 @@ int ossl_quic_wire_decode_frame_new_conn_id(PACKET *pkt,
|| !PACKET_get_quic_vlint(pkt, &f->retire_prior_to)
|| f->seq_num < f->retire_prior_to
|| !PACKET_get_1(pkt, &len)
|| len < 1
|| len > QUIC_MAX_CONN_ID_LEN)
return 0;

Expand Down
2 changes: 1 addition & 1 deletion test/build.info
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ IF[{- !$disabled{tests} -}]
INCLUDE[quic_client_test]=../include ../apps/include
DEPEND[quic_client_test]=../libcrypto.a ../libssl.a libtestutil.a

SOURCE[quic_multistream_test]=quic_multistream_test.c
SOURCE[quic_multistream_test]=quic_multistream_test.c helpers/ssltestlib.c helpers/quictestlib.c
INCLUDE[quic_multistream_test]=../include ../apps/include
DEPEND[quic_multistream_test]=../libcrypto.a ../libssl.a libtestutil.a

Expand Down
21 changes: 16 additions & 5 deletions test/helpers/quictestlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ struct qtest_fault {
static void packet_plain_finish(void *arg);
static void handshake_finish(void *arg);

static BIO_METHOD *get_bio_method(void);

static OSSL_TIME fake_now;

static OSSL_TIME fake_now_cb(void *arg)
Expand Down Expand Up @@ -155,7 +153,7 @@ int qtest_create_quic_objects(OSSL_LIB_CTX *libctx, SSL_CTX *clientctx,
goto err;
}

fisbio = BIO_new(get_bio_method());
fisbio = BIO_new(qtest_get_bio_method());
if (!TEST_ptr(fisbio))
goto err;

Expand Down Expand Up @@ -206,6 +204,19 @@ void qtest_add_time(uint64_t millis)
fake_now = ossl_time_add(fake_now, ossl_ms2time(millis));
}

QTEST_FAULT *qtest_create_injector(QUIC_TSERVER *ts)
{
QTEST_FAULT *f;

f = OPENSSL_zalloc(sizeof(*f));
if (f == NULL)
return NULL;

f->qtserv = ts;
return f;

}

int qtest_supports_blocking(void)
{
#if !defined(OPENSSL_NO_POSIX_IO) && defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG)
Expand Down Expand Up @@ -487,7 +498,7 @@ int qtest_fault_resize_plain_packet(QTEST_FAULT *fault, size_t newlen)
* Prepend frame data into a packet. To be called from a packet_plain_listener
* callback
*/
int qtest_fault_prepend_frame(QTEST_FAULT *fault, unsigned char *frame,
int qtest_fault_prepend_frame(QTEST_FAULT *fault, const unsigned char *frame,
size_t frame_len)
{
unsigned char *buf;
Expand Down Expand Up @@ -819,7 +830,7 @@ static long pcipher_ctrl(BIO *b, int cmd, long larg, void *parg)
return BIO_ctrl(next, cmd, larg, parg);
}

static BIO_METHOD *get_bio_method(void)
BIO_METHOD *qtest_get_bio_method(void)
{
BIO_METHOD *tmp;

Expand Down
6 changes: 5 additions & 1 deletion test/helpers/quictestlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ int qtest_create_quic_objects(OSSL_LIB_CTX *libctx, SSL_CTX *clientctx,
/* Where QTEST_FLAG_FAKE_TIME is used, add millis to the current time */
void qtest_add_time(uint64_t millis);

QTEST_FAULT *qtest_create_injector(QUIC_TSERVER *ts);

BIO_METHOD *qtest_get_bio_method(void);

/*
* Free up a Fault Injector instance
*/
Expand Down Expand Up @@ -108,7 +112,7 @@ int qtest_fault_resize_plain_packet(QTEST_FAULT *fault, size_t newlen);
* Prepend frame data into a packet. To be called from a packet_plain_listener
* callback
*/
int qtest_fault_prepend_frame(QTEST_FAULT *fault, unsigned char *frame,
int qtest_fault_prepend_frame(QTEST_FAULT *fault, const unsigned char *frame,
size_t frame_len);

/*
Expand Down

0 comments on commit e26dc8e

Please sign in to comment.