|
19 | 19 |
|
20 | 20 | #define XQC_TEST_SHORT_HEADER_PACKET_A "\x40\xAB\x3f\x12\x0a\xcd\xef\x00\x89" |
21 | 21 | #define XQC_TEST_LONG_HEADER_PACKET_B "\xC0\x00\x00\x00\x01\x08\xAB\x3f\x12\x0a\xcd\xef\x00\x89\x08\xAB\x3f\x12\x0a\xcd\xef\x00\x89" |
| 22 | +#define XQC_TEST_ZERO_RTT_PACKET \ |
| 23 | + "\xD0\x00\x00\x00\x01\x08\xAB\x3f\x12\x0a\xcd\xef\x00\x89" \ |
| 24 | + "\x08\xAB\x3f\x12\x0a\xcd\xef\x00\x89\x01\x00" |
22 | 25 |
|
23 | 26 | #define XQC_TEST_CHECK_CID "ab3f120acdef0089" |
24 | 27 |
|
@@ -67,6 +70,59 @@ xqc_test_long_header_packet_parse_cid() |
67 | 70 | } |
68 | 71 |
|
69 | 72 |
|
| 73 | +void |
| 74 | +xqc_test_client_discards_received_zero_rtt(void) |
| 75 | +{ |
| 76 | + xqc_connection_t *conn = test_engine_connect(); |
| 77 | + xqc_packet_in_t packet_in; |
| 78 | + xqc_int_t ret; |
| 79 | + |
| 80 | + CU_ASSERT_PTR_NOT_NULL_FATAL(conn); |
| 81 | + CU_ASSERT_EQUAL_FATAL(conn->conn_type, XQC_CONN_TYPE_CLIENT); |
| 82 | + |
| 83 | + xqc_packet_in_init(&packet_in, |
| 84 | + (unsigned char *)XQC_TEST_ZERO_RTT_PACKET, |
| 85 | + sizeof(XQC_TEST_ZERO_RTT_PACKET) - 1, NULL, 0, 0); |
| 86 | + |
| 87 | + ret = xqc_packet_process_single(conn, &packet_in); |
| 88 | + |
| 89 | + /* |
| 90 | + * RFC 9001 Section 5.6 requires discard before decryption. The receive |
| 91 | + * path must not retain the packet or mark client-side 0-RTT state. |
| 92 | + */ |
| 93 | + CU_ASSERT_EQUAL(ret, -XQC_EIGNORE_PKT); |
| 94 | + CU_ASSERT_EQUAL(conn->undecrypt_count[XQC_ENC_LEV_0RTT], 0); |
| 95 | + CU_ASSERT_FALSE(conn->conn_flag & XQC_CONN_FLAG_HAS_0RTT); |
| 96 | + |
| 97 | + xqc_engine_destroy(conn->engine); |
| 98 | +} |
| 99 | + |
| 100 | + |
| 101 | +void |
| 102 | +xqc_test_server_buffers_received_zero_rtt(void) |
| 103 | +{ |
| 104 | + xqc_connection_t *conn = test_engine_connect(); |
| 105 | + xqc_packet_in_t packet_in; |
| 106 | + xqc_int_t ret; |
| 107 | + |
| 108 | + CU_ASSERT_PTR_NOT_NULL_FATAL(conn); |
| 109 | + conn->conn_type = XQC_CONN_TYPE_SERVER; |
| 110 | + |
| 111 | + xqc_packet_in_init(&packet_in, |
| 112 | + (unsigned char *)XQC_TEST_ZERO_RTT_PACKET, |
| 113 | + sizeof(XQC_TEST_ZERO_RTT_PACKET) - 1, NULL, 0, 0); |
| 114 | + |
| 115 | + ret = xqc_packet_process_single(conn, &packet_in); |
| 116 | + |
| 117 | + CU_ASSERT_EQUAL(ret, -XQC_EWAITING); |
| 118 | + CU_ASSERT_EQUAL(conn->undecrypt_count[XQC_ENC_LEV_0RTT], 1); |
| 119 | + CU_ASSERT_TRUE(conn->conn_flag & XQC_CONN_FLAG_HAS_0RTT); |
| 120 | + |
| 121 | + conn->conn_type = XQC_CONN_TYPE_CLIENT; |
| 122 | + xqc_engine_destroy(conn->engine); |
| 123 | +} |
| 124 | + |
| 125 | + |
70 | 126 |
|
71 | 127 |
|
72 | 128 |
|
|
0 commit comments