Skip to content

Commit

Permalink
QUIC TEST: RESET_STREAM, STOP_SENDING
Browse files Browse the repository at this point in the history
Fixes openssl/project#80

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #21565)
  • Loading branch information
hlandau committed Aug 10, 2023
1 parent d49a163 commit d63b8cb
Showing 1 changed file with 89 additions and 1 deletion.
90 changes: 89 additions & 1 deletion test/quic_multistream_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2898,10 +2898,14 @@ static int script_39_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr,
|| !TEST_true(WPACKET_put_bytes_u8(&wpkt, new_cid.id_len))) /* len */
goto err;

for (i = 0; i < new_cid.id_len; ++i)
for (i = 0; i < new_cid.id_len && i < OSSL_NELEM(new_cid.id); ++i)
if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, new_cid.id[i])))
goto err;

for (; i < new_cid.id_len; ++i)
if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x55)))
goto err;

for (i = 0; i < QUIC_STATELESS_RESET_TOKEN_LEN; ++i)
if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x42)))
goto err;
Expand Down Expand Up @@ -3836,6 +3840,7 @@ static int init_reason(struct helper *h, const struct script_op *op)
{
memset(long_reason, '~', sizeof(long_reason));
memcpy(long_reason, "This is a long reason string.", 29);
long_reason[OSSL_NELEM(long_reason) - 1] = '\0';
return 1;
}

Expand Down Expand Up @@ -3871,6 +3876,87 @@ static const struct script_op script_60[] = {
OP_END
};

/* 61. Fault injection - RESET_STREAM exceeding stream count FC */
static int script_61_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr,
unsigned char *buf, size_t len)
{
int ok = 0;
WPACKET wpkt;
unsigned char frame_buf[32];
size_t written;

if (h->inject_word0 == 0)
return 1;

if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf,
sizeof(frame_buf), 0)))
return 0;

if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word0))
|| !TEST_true(WPACKET_quic_write_vlint(&wpkt, /* stream ID */
h->inject_word1))
|| !TEST_true(WPACKET_quic_write_vlint(&wpkt, 123))
|| (h->inject_word1 == OSSL_QUIC_FRAME_TYPE_RESET_STREAM
&& !TEST_true(WPACKET_quic_write_vlint(&wpkt, 0)))) /* final size */
goto err;

if (!TEST_true(WPACKET_get_total_written(&wpkt, &written)))
goto err;

if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written))
goto err;

ok = 1;
err:
if (ok)
WPACKET_finish(&wpkt);
else
WPACKET_cleanup(&wpkt);
return ok;
}

static const struct script_op script_61[] = {
OP_S_SET_INJECT_PLAIN (script_61_inject_plain)
OP_C_SET_ALPN ("ossltest")
OP_C_CONNECT_WAIT ()
OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)

OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0))
OP_C_WRITE (a, "orange", 6)

OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
OP_S_READ_EXPECT (a, "orange", 6)

OP_SET_INJECT_WORD (OSSL_QUIC_FRAME_TYPE_RESET_STREAM,
S_BIDI_ID(OSSL_QUIC_VLINT_MAX / 4))
OP_S_WRITE (a, "fruit", 5)

OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_LIMIT_ERROR,0,0)

OP_END
};

/* 62. Fault injection - STOP_SENDING with high ID */
static const struct script_op script_62[] = {
OP_S_SET_INJECT_PLAIN (script_61_inject_plain)
OP_C_SET_ALPN ("ossltest")
OP_C_CONNECT_WAIT ()
OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)

OP_C_NEW_STREAM_BIDI (a, C_BIDI_ID(0))
OP_C_WRITE (a, "orange", 6)

OP_S_BIND_STREAM_ID (a, C_BIDI_ID(0))
OP_S_READ_EXPECT (a, "orange", 6)

OP_SET_INJECT_WORD (OSSL_QUIC_FRAME_TYPE_STOP_SENDING,
C_BIDI_ID(OSSL_QUIC_VLINT_MAX / 4))
OP_S_WRITE (a, "fruit", 5)

OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_STREAM_STATE_ERROR,0,0)

OP_END
};

static const struct script_op *const scripts[] = {
script_1,
Expand Down Expand Up @@ -3933,6 +4019,8 @@ static const struct script_op *const scripts[] = {
script_58,
script_59,
script_60,
script_61,
script_62,
};

static int test_script(int idx)
Expand Down

0 comments on commit d63b8cb

Please sign in to comment.