Fix test cases using NEW_CONNECTION_ID frame
authorTomas Mraz <tomas@openssl.org>
Fri, 5 May 2023 15:40:55 +0000 (17:40 +0200)
committerHugo Landau <hlandau@openssl.org>
Wed, 17 May 2023 13:04:18 +0000 (14:04 +0100)
seq_id must be >= retire_prior_to.

Add negative testcase.

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20892)

test/quic_txp_test.c
test/quic_wire_test.c

index e01156d1564f71e46e9f6f47ceb78997cbd8a042..3c9804d2ab347ab1f243ebf8d1a6c97d22526275 100644 (file)
@@ -394,8 +394,8 @@ static int schedule_cfq_new_conn_id(struct helper *h)
     size_t l = 0;
     OSSL_QUIC_FRAME_NEW_CONN_ID ncid = {0};
 
-    ncid.seq_num         = 1234;
-    ncid.retire_prior_to = 2345;
+    ncid.seq_num         = 2345;
+    ncid.retire_prior_to = 1234;
     ncid.conn_id         = cid_1;
     memcpy(ncid.stateless_reset_token, reset_token_1, sizeof(reset_token_1));
 
@@ -432,8 +432,8 @@ err:
 
 static int check_cfq_new_conn_id(struct helper *h)
 {
-    if (!TEST_uint64_t_eq(h->frame.new_conn_id.seq_num, 1234)
-        || !TEST_uint64_t_eq(h->frame.new_conn_id.retire_prior_to, 2345)
+    if (!TEST_uint64_t_eq(h->frame.new_conn_id.seq_num, 2345)
+        || !TEST_uint64_t_eq(h->frame.new_conn_id.retire_prior_to, 1234)
         || !TEST_mem_eq(&h->frame.new_conn_id.conn_id, sizeof(cid_1),
                         &cid_1, sizeof(cid_1))
         || !TEST_mem_eq(&h->frame.new_conn_id.stateless_reset_token,
index ceb273e7b6d13bd510f3a9f22e9bdab51a159419..d6eef296a3423f3f743db6be6a48ea887eb32809 100644 (file)
@@ -714,8 +714,8 @@ static const unsigned char encode_case_16_conn_id[] = {
 };
 
 static const OSSL_QUIC_FRAME_NEW_CONN_ID encode_case_16_f = {
-    0x1234,
     0x9781,
+    0x1234,
     {
         0x4,
         {0x33, 0x44, 0x55, 0x66}
@@ -745,10 +745,10 @@ static int encode_case_16_dec(PACKET *pkt, ossl_ssize_t fail)
     if (fail >= 0)
         return 1;
 
-    if (!TEST_uint64_t_eq(f.seq_num, 0x1234))
+    if (!TEST_uint64_t_eq(f.seq_num, 0x9781))
         return 0;
 
-    if (!TEST_uint64_t_eq(f.retire_prior_to, 0x9781))
+    if (!TEST_uint64_t_eq(f.retire_prior_to, 0x1234))
         return 0;
 
     if (!TEST_uint64_t_eq(f.conn_id.id_len, sizeof(encode_case_16_conn_id)))
@@ -768,6 +768,52 @@ static int encode_case_16_dec(PACKET *pkt, ossl_ssize_t fail)
 }
 
 static const unsigned char encode_case_16_expect[] = {
+    0x18,                           /* Type */
+    0x80, 0x00, 0x97, 0x81,         /* Sequence Number */
+    0x52, 0x34,                     /* Retire Prior To */
+    0x04,                           /* Connection ID Length */
+    0x33, 0x44, 0x55, 0x66,         /* Connection ID */
+    0xde, 0x06, 0xcb, 0x76, 0x5d, 0xb1, 0xa7, 0x71, /* Stateless Reset Token */
+    0x78, 0x09, 0xbb, 0xe8, 0x50, 0x19, 0x12, 0x9a
+};
+
+/* 16b. NEW_CONNECTION_ID seq_num < retire_prior_to */
+static const OSSL_QUIC_FRAME_NEW_CONN_ID encode_case_16b_f = {
+    0x1234,
+    0x9781,
+    {
+        0x4,
+        {0x33, 0x44, 0x55, 0x66}
+    },
+    {
+        0xde, 0x06, 0xcb, 0x76, 0x5d, 0xb1, 0xa7, 0x71,
+        0x78, 0x09, 0xbb, 0xe8, 0x50, 0x19, 0x12, 0x9a
+    }
+};
+
+static int encode_case_16b_enc(WPACKET *pkt)
+{
+    if (!TEST_int_eq(ossl_quic_wire_encode_frame_new_conn_id(pkt,
+                                                             &encode_case_16b_f), 1))
+        return 0;
+
+    return 1;
+}
+
+static int encode_case_16b_dec(PACKET *pkt, ossl_ssize_t fail)
+{
+    OSSL_QUIC_FRAME_NEW_CONN_ID f = {0};
+
+    if (!TEST_int_eq(ossl_quic_wire_decode_frame_new_conn_id(pkt, &f), 0))
+        return 0;
+
+    if (!TEST_true(PACKET_forward(pkt, PACKET_remaining(pkt))))
+        return 0;
+
+    return 1;
+}
+
+static const unsigned char encode_case_16b_expect[] = {
     0x18,                           /* Type */
     0x52, 0x34,                     /* Sequence Number */
     0x80, 0x00, 0x97, 0x81,         /* Retire Prior To */
@@ -1137,6 +1183,7 @@ static const struct encode_test_case encode_cases[] = {
     ENCODE_CASE(14)
     ENCODE_CASE(15)
     ENCODE_CASE(16)
+    ENCODE_CASE(16b)
     ENCODE_CASE(17)
     ENCODE_CASE(18)
     ENCODE_CASE(19)