1 1.1 christos /* 2 1.1 christos * Copyright 2023-2025 The OpenSSL Project Authors. All Rights Reserved. 3 1.1 christos * 4 1.1 christos * Licensed under the Apache License 2.0 (the "License"). You may not use 5 1.1 christos * this file except in compliance with the License. You can obtain a copy 6 1.1 christos * in the file LICENSE in the source distribution or at 7 1.1 christos * https://www.openssl.org/source/license.html 8 1.1 christos */ 9 1.1 christos #include <openssl/ssl.h> 10 1.1 christos #include <openssl/quic.h> 11 1.1 christos #include <openssl/bio.h> 12 1.1 christos #include <openssl/lhash.h> 13 1.1 christos #include <openssl/rand.h> 14 1.1 christos #include "internal/quic_tserver.h" 15 1.1 christos #include "internal/quic_ssl.h" 16 1.1 christos #include "internal/quic_error.h" 17 1.1 christos #include "internal/quic_stream_map.h" 18 1.1 christos #include "internal/quic_engine.h" 19 1.1 christos #include "testutil.h" 20 1.1 christos #include "helpers/quictestlib.h" 21 1.1 christos #if defined(OPENSSL_THREADS) 22 1.1.1.2 christos #include "internal/thread_arch.h" 23 1.1 christos #endif 24 1.1.1.2 christos #include "internal/numbers.h" /* UINT64_C */ 25 1.1 christos 26 1.1 christos static const char *certfile, *keyfile; 27 1.1 christos 28 1.1 christos #if defined(_AIX) 29 1.1 christos /* 30 1.1 christos * Some versions of AIX define macros for events and revents for use when 31 1.1 christos * accessing pollfd structures (see Github issue #24236). That interferes 32 1.1 christos * with our use of these names here. We simply undef them. 33 1.1 christos */ 34 1.1.1.2 christos #undef revents 35 1.1.1.2 christos #undef events 36 1.1 christos #endif 37 1.1 christos 38 1.1 christos #if defined(OPENSSL_THREADS) 39 1.1 christos struct child_thread_args { 40 1.1 christos struct helper *h; 41 1.1 christos const struct script_op *script; 42 1.1 christos const char *script_name; 43 1.1 christos int thread_idx; 44 1.1 christos 45 1.1 christos CRYPTO_THREAD *t; 46 1.1 christos CRYPTO_MUTEX *m; 47 1.1 christos int testresult; 48 1.1 christos int done; 49 1.1 christos int s_checked_out; 50 1.1 christos }; 51 1.1 christos #endif 52 1.1 christos 53 1.1 christos typedef struct stream_info { 54 1.1.1.2 christos const char *name; 55 1.1.1.2 christos SSL *c_stream; 56 1.1.1.2 christos uint64_t s_stream_id; 57 1.1 christos } STREAM_INFO; 58 1.1 christos 59 1.1 christos DEFINE_LHASH_OF_EX(STREAM_INFO); 60 1.1 christos 61 1.1 christos struct helper { 62 1.1.1.2 christos int s_fd; 63 1.1.1.2 christos BIO *s_net_bio, *s_net_bio_own, *s_qtf_wbio, *s_qtf_wbio_own; 64 1.1 christos /* The BIO_ADDR used for BIO_bind() */ 65 1.1.1.2 christos BIO_ADDR *s_net_bio_orig_addr; 66 1.1 christos /* The resulting address, which is the one to connect to */ 67 1.1.1.2 christos BIO_ADDR *s_net_bio_addr; 68 1.1 christos 69 1.1 christos /* 70 1.1 christos * When doing a blocking mode test run, s_priv always points to the TSERVER 71 1.1 christos * and s is NULL when the main thread should not be touching s_priv. 72 1.1 christos */ 73 1.1.1.2 christos QUIC_TSERVER *s, *s_priv; 74 1.1.1.2 christos LHASH_OF(STREAM_INFO) *s_streams; 75 1.1 christos 76 1.1.1.2 christos int c_fd; 77 1.1.1.2 christos BIO *c_net_bio, *c_net_bio_own; 78 1.1.1.2 christos SSL_CTX *c_ctx; 79 1.1.1.2 christos SSL *c_conn; 80 1.1.1.2 christos LHASH_OF(STREAM_INFO) *c_streams; 81 1.1 christos 82 1.1 christos #if defined(OPENSSL_THREADS) 83 1.1.1.2 christos struct child_thread_args *threads; 84 1.1.1.2 christos size_t num_threads; 85 1.1.1.2 christos CRYPTO_MUTEX *misc_m; 86 1.1.1.2 christos CRYPTO_CONDVAR *misc_cv; 87 1.1 christos #endif 88 1.1 christos 89 1.1.1.2 christos OSSL_TIME start_time; 90 1.1 christos 91 1.1 christos /* 92 1.1 christos * This is a duration recording the amount of time we have skipped forwards 93 1.1 christos * for testing purposes relative to the real ossl_time_now() clock. We add 94 1.1 christos * a quantity of time to this every time we skip some time. 95 1.1 christos */ 96 1.1.1.2 christos CRYPTO_RWLOCK *time_lock; 97 1.1.1.2 christos OSSL_TIME time_slip; /* protected by time_lock */ 98 1.1 christos 99 1.1.1.2 christos QTEST_FAULT *qtf; 100 1.1 christos 101 1.1.1.2 christos int init, blocking, check_spin_again; 102 1.1.1.2 christos int free_order, need_injector; 103 1.1 christos 104 1.1 christos int (*qtf_packet_plain_cb)(struct helper *h, QUIC_PKT_HDR *hdr, 105 1.1.1.2 christos unsigned char *buf, size_t buf_len); 106 1.1 christos int (*qtf_handshake_cb)(struct helper *h, 107 1.1.1.2 christos unsigned char *buf, size_t buf_len); 108 1.1 christos int (*qtf_datagram_cb)(struct helper *h, 109 1.1.1.2 christos BIO_MSG *m, size_t stride); 110 1.1 christos uint64_t inject_word0, inject_word1; 111 1.1 christos uint64_t scratch0, scratch1, fail_count; 112 1.1 christos #if defined(OPENSSL_THREADS) 113 1.1 christos struct { 114 1.1.1.2 christos CRYPTO_THREAD *t; 115 1.1.1.2 christos CRYPTO_MUTEX *m; 116 1.1.1.2 christos CRYPTO_CONDVAR *c; 117 1.1.1.2 christos int ready, stop; 118 1.1 christos } server_thread; 119 1.1 christos int s_checked_out; 120 1.1 christos #endif 121 1.1 christos }; 122 1.1 christos 123 1.1 christos struct helper_local { 124 1.1.1.2 christos struct helper *h; 125 1.1.1.2 christos LHASH_OF(STREAM_INFO) *c_streams; 126 1.1.1.2 christos int thread_idx; 127 1.1.1.2 christos const struct script_op *check_op; 128 1.1.1.2 christos int explicit_event_handling; 129 1.1 christos }; 130 1.1 christos 131 1.1 christos struct script_op { 132 1.1.1.2 christos uint32_t op; 133 1.1.1.2 christos const void *arg0; 134 1.1.1.2 christos size_t arg1; 135 1.1.1.2 christos int (*check_func)(struct helper *h, struct helper_local *hl); 136 1.1.1.2 christos const char *stream_name; 137 1.1.1.2 christos uint64_t arg2; 138 1.1.1.2 christos int (*qtf_packet_plain_cb)(struct helper *h, QUIC_PKT_HDR *hdr, 139 1.1.1.2 christos unsigned char *buf, size_t buf_len); 140 1.1.1.2 christos int (*qtf_handshake_cb)(struct helper *h, 141 1.1.1.2 christos unsigned char *buf, size_t buf_len); 142 1.1.1.2 christos int (*qtf_datagram_cb)(struct helper *h, 143 1.1.1.2 christos BIO_MSG *m, size_t stride); 144 1.1.1.2 christos }; 145 1.1.1.2 christos 146 1.1.1.2 christos #define OPK_END 0 147 1.1.1.2 christos #define OPK_CHECK 1 148 1.1.1.2 christos #define OPK_C_SET_ALPN 2 149 1.1.1.2 christos #define OPK_C_CONNECT_WAIT 3 150 1.1.1.2 christos #define OPK_C_WRITE 4 151 1.1.1.2 christos #define OPK_S_WRITE 5 152 1.1.1.2 christos #define OPK_C_READ_EXPECT 6 153 1.1.1.2 christos #define OPK_S_READ_EXPECT 7 154 1.1.1.2 christos #define OPK_C_EXPECT_FIN 8 155 1.1.1.2 christos #define OPK_S_EXPECT_FIN 9 156 1.1.1.2 christos #define OPK_C_CONCLUDE 10 157 1.1.1.2 christos #define OPK_S_CONCLUDE 11 158 1.1.1.2 christos #define OPK_C_DETACH 12 159 1.1.1.2 christos #define OPK_C_ATTACH 13 160 1.1.1.2 christos #define OPK_C_NEW_STREAM 14 161 1.1.1.2 christos #define OPK_S_NEW_STREAM 15 162 1.1.1.2 christos #define OPK_C_ACCEPT_STREAM_WAIT 16 163 1.1.1.2 christos #define OPK_C_ACCEPT_STREAM_NONE 17 164 1.1.1.2 christos #define OPK_C_FREE_STREAM 18 165 1.1.1.2 christos #define OPK_C_SET_DEFAULT_STREAM_MODE 19 166 1.1.1.2 christos #define OPK_C_SET_INCOMING_STREAM_POLICY 20 167 1.1.1.2 christos #define OPK_C_SHUTDOWN_WAIT 21 168 1.1.1.2 christos #define OPK_C_EXPECT_CONN_CLOSE_INFO 22 169 1.1.1.2 christos #define OPK_S_EXPECT_CONN_CLOSE_INFO 23 170 1.1.1.2 christos #define OPK_S_BIND_STREAM_ID 24 171 1.1.1.2 christos #define OPK_C_WAIT_FOR_DATA 25 172 1.1.1.2 christos #define OPK_C_WRITE_FAIL 26 173 1.1.1.2 christos #define OPK_S_WRITE_FAIL 27 174 1.1.1.2 christos #define OPK_C_READ_FAIL 28 175 1.1.1.2 christos #define OPK_C_STREAM_RESET 29 176 1.1.1.2 christos #define OPK_S_ACCEPT_STREAM_WAIT 30 177 1.1.1.2 christos #define OPK_NEW_THREAD 31 178 1.1.1.2 christos #define OPK_BEGIN_REPEAT 32 179 1.1.1.2 christos #define OPK_END_REPEAT 33 180 1.1.1.2 christos #define OPK_S_UNBIND_STREAM_ID 34 181 1.1.1.2 christos #define OPK_C_READ_FAIL_WAIT 35 182 1.1.1.2 christos #define OPK_C_CLOSE_SOCKET 36 183 1.1.1.2 christos #define OPK_C_EXPECT_SSL_ERR 37 184 1.1.1.2 christos #define OPK_EXPECT_ERR_REASON 38 185 1.1.1.2 christos #define OPK_EXPECT_ERR_LIB 39 186 1.1.1.2 christos #define OPK_SLEEP 40 187 1.1.1.2 christos #define OPK_S_READ_FAIL 41 188 1.1.1.2 christos #define OPK_S_SET_INJECT_PLAIN 42 189 1.1.1.2 christos #define OPK_SET_INJECT_WORD 43 190 1.1.1.2 christos #define OPK_C_INHIBIT_TICK 44 191 1.1.1.2 christos #define OPK_C_SET_WRITE_BUF_SIZE 45 192 1.1.1.2 christos #define OPK_S_SET_INJECT_HANDSHAKE 46 193 1.1.1.2 christos #define OPK_S_NEW_TICKET 47 194 1.1.1.2 christos #define OPK_C_SKIP_IF_UNBOUND 48 195 1.1.1.2 christos #define OPK_S_SET_INJECT_DATAGRAM 49 196 1.1.1.2 christos #define OPK_S_SHUTDOWN 50 197 1.1.1.2 christos #define OPK_POP_ERR 51 198 1.1.1.2 christos #define OPK_C_WRITE_EX2 52 199 1.1.1.2 christos #define OPK_SKIP_IF_BLOCKING 53 200 1.1.1.2 christos #define OPK_C_STREAM_RESET_FAIL 54 201 1.1 christos 202 1.1.1.2 christos #define EXPECT_CONN_CLOSE_APP (1U << 0) 203 1.1.1.2 christos #define EXPECT_CONN_CLOSE_REMOTE (1U << 1) 204 1.1 christos 205 1.1 christos /* OPK_C_NEW_STREAM */ 206 1.1 christos #define ALLOW_FAIL (1U << 16) 207 1.1 christos 208 1.1 christos #define C_BIDI_ID(ordinal) \ 209 1.1 christos (((ordinal) << 2) | QUIC_STREAM_INITIATOR_CLIENT | QUIC_STREAM_DIR_BIDI) 210 1.1 christos #define S_BIDI_ID(ordinal) \ 211 1.1 christos (((ordinal) << 2) | QUIC_STREAM_INITIATOR_SERVER | QUIC_STREAM_DIR_BIDI) 212 1.1 christos #define C_UNI_ID(ordinal) \ 213 1.1 christos (((ordinal) << 2) | QUIC_STREAM_INITIATOR_CLIENT | QUIC_STREAM_DIR_UNI) 214 1.1 christos #define S_UNI_ID(ordinal) \ 215 1.1 christos (((ordinal) << 2) | QUIC_STREAM_INITIATOR_SERVER | QUIC_STREAM_DIR_UNI) 216 1.1 christos 217 1.1 christos #define ANY_ID UINT64_MAX 218 1.1 christos 219 1.1.1.2 christos #define OP_END \ 220 1.1.1.2 christos { OPK_END } 221 1.1.1.2 christos #define OP_CHECK(func, arg2) \ 222 1.1.1.2 christos { OPK_CHECK, NULL, 0, (func), NULL, (arg2) }, 223 1.1 christos #define OP_C_SET_ALPN(alpn) \ 224 1.1.1.2 christos { OPK_C_SET_ALPN, (alpn), 0, NULL, NULL }, 225 1.1 christos #define OP_C_CONNECT_WAIT() \ 226 1.1.1.2 christos { OPK_C_CONNECT_WAIT, NULL, 0, NULL, NULL }, 227 1.1 christos #define OP_C_CONNECT_WAIT_OR_FAIL() \ 228 1.1.1.2 christos { OPK_C_CONNECT_WAIT, NULL, 1, NULL, NULL }, 229 1.1.1.2 christos #define OP_C_WRITE(stream_name, buf, buf_len) \ 230 1.1.1.2 christos { OPK_C_WRITE, (buf), (buf_len), NULL, #stream_name }, 231 1.1.1.2 christos #define OP_S_WRITE(stream_name, buf, buf_len) \ 232 1.1.1.2 christos { OPK_S_WRITE, (buf), (buf_len), NULL, #stream_name }, 233 1.1.1.2 christos #define OP_C_READ_EXPECT(stream_name, buf, buf_len) \ 234 1.1.1.2 christos { OPK_C_READ_EXPECT, (buf), (buf_len), NULL, #stream_name }, 235 1.1.1.2 christos #define OP_S_READ_EXPECT(stream_name, buf, buf_len) \ 236 1.1.1.2 christos { OPK_S_READ_EXPECT, (buf), (buf_len), NULL, #stream_name }, 237 1.1 christos #define OP_C_EXPECT_FIN(stream_name) \ 238 1.1.1.2 christos { OPK_C_EXPECT_FIN, NULL, 0, NULL, #stream_name }, 239 1.1 christos #define OP_S_EXPECT_FIN(stream_name) \ 240 1.1.1.2 christos { OPK_S_EXPECT_FIN, NULL, 0, NULL, #stream_name }, 241 1.1 christos #define OP_C_CONCLUDE(stream_name) \ 242 1.1.1.2 christos { OPK_C_CONCLUDE, NULL, 0, NULL, #stream_name }, 243 1.1 christos #define OP_S_CONCLUDE(stream_name) \ 244 1.1.1.2 christos { OPK_S_CONCLUDE, NULL, 0, NULL, #stream_name }, 245 1.1 christos #define OP_C_DETACH(stream_name) \ 246 1.1.1.2 christos { OPK_C_DETACH, NULL, 0, NULL, #stream_name }, 247 1.1 christos #define OP_C_ATTACH(stream_name) \ 248 1.1.1.2 christos { OPK_C_ATTACH, NULL, 0, NULL, #stream_name }, 249 1.1 christos #define OP_C_NEW_STREAM_BIDI(stream_name, expect_id) \ 250 1.1.1.2 christos { OPK_C_NEW_STREAM, NULL, 0, NULL, #stream_name, (expect_id) }, 251 1.1 christos #define OP_C_NEW_STREAM_BIDI_EX(stream_name, expect_id, flags) \ 252 1.1.1.2 christos { OPK_C_NEW_STREAM, NULL, (flags), NULL, #stream_name, (expect_id) }, 253 1.1 christos #define OP_C_NEW_STREAM_UNI(stream_name, expect_id) \ 254 1.1.1.2 christos { OPK_C_NEW_STREAM, NULL, SSL_STREAM_FLAG_UNI, \ 255 1.1.1.2 christos NULL, #stream_name, (expect_id) }, 256 1.1 christos #define OP_C_NEW_STREAM_UNI_EX(stream_name, expect_id, flags) \ 257 1.1.1.2 christos { OPK_C_NEW_STREAM, NULL, (flags) | SSL_STREAM_FLAG_UNI, \ 258 1.1.1.2 christos NULL, #stream_name, (expect_id) }, 259 1.1 christos #define OP_S_NEW_STREAM_BIDI(stream_name, expect_id) \ 260 1.1.1.2 christos { OPK_S_NEW_STREAM, NULL, 0, NULL, #stream_name, (expect_id) }, 261 1.1 christos #define OP_S_NEW_STREAM_UNI(stream_name, expect_id) \ 262 1.1.1.2 christos { OPK_S_NEW_STREAM, NULL, 1, NULL, #stream_name, (expect_id) }, 263 1.1 christos #define OP_C_ACCEPT_STREAM_WAIT(stream_name) \ 264 1.1.1.2 christos { OPK_C_ACCEPT_STREAM_WAIT, NULL, 0, NULL, #stream_name }, 265 1.1 christos #define OP_C_ACCEPT_STREAM_NONE() \ 266 1.1.1.2 christos { OPK_C_ACCEPT_STREAM_NONE, NULL, 0, NULL, NULL }, 267 1.1 christos #define OP_C_FREE_STREAM(stream_name) \ 268 1.1.1.2 christos { OPK_C_FREE_STREAM, NULL, 0, NULL, #stream_name }, 269 1.1 christos #define OP_C_SET_DEFAULT_STREAM_MODE(mode) \ 270 1.1.1.2 christos { OPK_C_SET_DEFAULT_STREAM_MODE, NULL, (mode), NULL, NULL }, 271 1.1 christos #define OP_C_SET_INCOMING_STREAM_POLICY(policy) \ 272 1.1.1.2 christos { OPK_C_SET_INCOMING_STREAM_POLICY, NULL, (policy), NULL, NULL }, 273 1.1 christos #define OP_C_SHUTDOWN_WAIT(reason, flags) \ 274 1.1.1.2 christos { OPK_C_SHUTDOWN_WAIT, (reason), (flags), NULL, NULL }, 275 1.1.1.2 christos #define OP_C_EXPECT_CONN_CLOSE_INFO(ec, app, remote) \ 276 1.1.1.2 christos { OPK_C_EXPECT_CONN_CLOSE_INFO, NULL, \ 277 1.1.1.2 christos ((app) ? EXPECT_CONN_CLOSE_APP : 0) | ((remote) ? EXPECT_CONN_CLOSE_REMOTE : 0), \ 278 1.1.1.2 christos NULL, NULL, (ec) }, 279 1.1.1.2 christos #define OP_S_EXPECT_CONN_CLOSE_INFO(ec, app, remote) \ 280 1.1.1.2 christos { OPK_S_EXPECT_CONN_CLOSE_INFO, NULL, \ 281 1.1.1.2 christos ((app) ? EXPECT_CONN_CLOSE_APP : 0) | ((remote) ? EXPECT_CONN_CLOSE_REMOTE : 0), \ 282 1.1.1.2 christos NULL, NULL, (ec) }, 283 1.1 christos #define OP_S_BIND_STREAM_ID(stream_name, stream_id) \ 284 1.1.1.2 christos { OPK_S_BIND_STREAM_ID, NULL, 0, NULL, #stream_name, (stream_id) }, 285 1.1 christos #define OP_C_WAIT_FOR_DATA(stream_name) \ 286 1.1.1.2 christos { OPK_C_WAIT_FOR_DATA, NULL, 0, NULL, #stream_name }, 287 1.1.1.2 christos #define OP_C_WRITE_FAIL(stream_name) \ 288 1.1.1.2 christos { OPK_C_WRITE_FAIL, NULL, 0, NULL, #stream_name }, 289 1.1.1.2 christos #define OP_S_WRITE_FAIL(stream_name) \ 290 1.1.1.2 christos { OPK_S_WRITE_FAIL, NULL, 0, NULL, #stream_name }, 291 1.1.1.2 christos #define OP_C_READ_FAIL(stream_name) \ 292 1.1.1.2 christos { OPK_C_READ_FAIL, NULL, 0, NULL, #stream_name }, 293 1.1.1.2 christos #define OP_S_READ_FAIL(stream_name, allow_zero_len) \ 294 1.1.1.2 christos { OPK_S_READ_FAIL, NULL, (allow_zero_len), NULL, #stream_name }, 295 1.1.1.2 christos #define OP_C_STREAM_RESET(stream_name, aec) \ 296 1.1.1.2 christos { OPK_C_STREAM_RESET, NULL, 0, NULL, #stream_name, (aec) }, 297 1.1.1.2 christos #define OP_C_STREAM_RESET_FAIL(stream_name, aec) \ 298 1.1.1.2 christos { OPK_C_STREAM_RESET_FAIL, NULL, 0, NULL, #stream_name, (aec) }, 299 1.1.1.2 christos #define OP_S_ACCEPT_STREAM_WAIT(stream_name) \ 300 1.1.1.2 christos { OPK_S_ACCEPT_STREAM_WAIT, NULL, 0, NULL, #stream_name }, 301 1.1 christos #define OP_NEW_THREAD(num_threads, script) \ 302 1.1.1.2 christos { OPK_NEW_THREAD, (script), (num_threads), NULL, NULL, 0 }, 303 1.1.1.2 christos #define OP_BEGIN_REPEAT(n) \ 304 1.1.1.2 christos { OPK_BEGIN_REPEAT, NULL, (n) }, 305 1.1 christos #define OP_END_REPEAT() \ 306 1.1.1.2 christos { OPK_END_REPEAT }, 307 1.1 christos #define OP_S_UNBIND_STREAM_ID(stream_name) \ 308 1.1.1.2 christos { OPK_S_UNBIND_STREAM_ID, NULL, 0, NULL, #stream_name }, 309 1.1 christos #define OP_C_READ_FAIL_WAIT(stream_name) \ 310 1.1.1.2 christos { OPK_C_READ_FAIL_WAIT, NULL, 0, NULL, #stream_name }, 311 1.1 christos #define OP_C_CLOSE_SOCKET() \ 312 1.1.1.2 christos { OPK_C_CLOSE_SOCKET }, 313 1.1 christos #define OP_C_EXPECT_SSL_ERR(stream_name, err) \ 314 1.1.1.2 christos { OPK_C_EXPECT_SSL_ERR, NULL, (err), NULL, #stream_name }, 315 1.1 christos #define OP_EXPECT_ERR_REASON(err) \ 316 1.1.1.2 christos { OPK_EXPECT_ERR_REASON, NULL, (err) }, 317 1.1 christos #define OP_EXPECT_ERR_LIB(lib) \ 318 1.1.1.2 christos { OPK_EXPECT_ERR_LIB, NULL, (lib) }, 319 1.1 christos #define OP_SLEEP(ms) \ 320 1.1.1.2 christos { OPK_SLEEP, NULL, 0, NULL, NULL, (ms) }, 321 1.1 christos #define OP_S_SET_INJECT_PLAIN(f) \ 322 1.1.1.2 christos { OPK_S_SET_INJECT_PLAIN, NULL, 0, NULL, NULL, 0, (f) }, 323 1.1 christos #define OP_SET_INJECT_WORD(w0, w1) \ 324 1.1.1.2 christos { OPK_SET_INJECT_WORD, NULL, (w0), NULL, NULL, (w1), NULL }, 325 1.1 christos #define OP_C_INHIBIT_TICK(inhibit) \ 326 1.1.1.2 christos { OPK_C_INHIBIT_TICK, NULL, (inhibit), NULL, NULL, 0, NULL }, 327 1.1 christos #define OP_C_SET_WRITE_BUF_SIZE(stream_name, size) \ 328 1.1.1.2 christos { OPK_C_SET_WRITE_BUF_SIZE, NULL, (size), NULL, #stream_name }, 329 1.1 christos #define OP_S_SET_INJECT_HANDSHAKE(f) \ 330 1.1.1.2 christos { OPK_S_SET_INJECT_HANDSHAKE, NULL, 0, NULL, NULL, 0, NULL, (f) }, 331 1.1 christos #define OP_S_NEW_TICKET() \ 332 1.1.1.2 christos { OPK_S_NEW_TICKET }, 333 1.1 christos #define OP_C_SKIP_IF_UNBOUND(stream_name, n) \ 334 1.1.1.2 christos { OPK_C_SKIP_IF_UNBOUND, NULL, (n), NULL, #stream_name }, 335 1.1 christos #define OP_S_SET_INJECT_DATAGRAM(f) \ 336 1.1.1.2 christos { OPK_S_SET_INJECT_DATAGRAM, NULL, 0, NULL, NULL, 0, NULL, NULL, (f) }, 337 1.1 christos #define OP_S_SHUTDOWN(error_code) \ 338 1.1.1.2 christos { OPK_S_SHUTDOWN, NULL, (error_code) }, 339 1.1 christos #define OP_POP_ERR() \ 340 1.1.1.2 christos { OPK_POP_ERR }, 341 1.1 christos #define OP_C_WRITE_EX2(stream_name, buf, buf_len, flags) \ 342 1.1.1.2 christos { OPK_C_WRITE_EX2, (buf), (buf_len), NULL, #stream_name, (flags) }, 343 1.1 christos #define OP_CHECK2(func, arg1, arg2) \ 344 1.1.1.2 christos { OPK_CHECK, NULL, (arg1), (func), NULL, (arg2) }, 345 1.1 christos #define OP_SKIP_IF_BLOCKING(n) \ 346 1.1.1.2 christos { OPK_SKIP_IF_BLOCKING, NULL, (n), NULL, 0 }, 347 1.1 christos 348 1.1 christos static OSSL_TIME get_time(void *arg) 349 1.1 christos { 350 1.1 christos struct helper *h = arg; 351 1.1 christos OSSL_TIME t; 352 1.1 christos 353 1.1 christos if (!TEST_true(CRYPTO_THREAD_read_lock(h->time_lock))) 354 1.1 christos return ossl_time_zero(); 355 1.1 christos 356 1.1 christos t = ossl_time_add(ossl_time_now(), h->time_slip); 357 1.1 christos 358 1.1 christos CRYPTO_THREAD_unlock(h->time_lock); 359 1.1 christos return t; 360 1.1 christos } 361 1.1 christos 362 1.1 christos static int skip_time_ms(struct helper *h, struct helper_local *hl) 363 1.1 christos { 364 1.1 christos if (!TEST_true(CRYPTO_THREAD_write_lock(h->time_lock))) 365 1.1 christos return 0; 366 1.1 christos 367 1.1 christos h->time_slip = ossl_time_add(h->time_slip, ossl_ms2time(hl->check_op->arg2)); 368 1.1 christos 369 1.1 christos CRYPTO_THREAD_unlock(h->time_lock); 370 1.1 christos return 1; 371 1.1 christos } 372 1.1 christos 373 1.1 christos static QUIC_TSERVER *s_lock(struct helper *h, struct helper_local *hl); 374 1.1 christos static void s_unlock(struct helper *h, struct helper_local *hl); 375 1.1 christos 376 1.1 christos #define ACQUIRE_S() s_lock(h, hl) 377 1.1 christos #define ACQUIRE_S_NOHL() s_lock(h, NULL) 378 1.1 christos 379 1.1 christos static int check_rejected(struct helper *h, struct helper_local *hl) 380 1.1 christos { 381 1.1 christos uint64_t stream_id = hl->check_op->arg2; 382 1.1 christos 383 1.1 christos if (!ossl_quic_tserver_stream_has_peer_stop_sending(ACQUIRE_S(), stream_id, NULL) 384 1.1 christos || !ossl_quic_tserver_stream_has_peer_reset_stream(ACQUIRE_S(), stream_id, NULL)) { 385 1.1 christos h->check_spin_again = 1; 386 1.1 christos return 0; 387 1.1 christos } 388 1.1 christos 389 1.1 christos return 1; 390 1.1 christos } 391 1.1 christos 392 1.1 christos static int check_stream_reset(struct helper *h, struct helper_local *hl) 393 1.1 christos { 394 1.1 christos uint64_t stream_id = hl->check_op->arg2, aec = 0; 395 1.1 christos 396 1.1 christos if (!ossl_quic_tserver_stream_has_peer_reset_stream(ACQUIRE_S(), stream_id, &aec)) { 397 1.1 christos h->check_spin_again = 1; 398 1.1 christos return 0; 399 1.1 christos } 400 1.1 christos 401 1.1 christos return TEST_uint64_t_eq(aec, 42); 402 1.1 christos } 403 1.1 christos 404 1.1 christos static int check_stream_stopped(struct helper *h, struct helper_local *hl) 405 1.1 christos { 406 1.1 christos uint64_t stream_id = hl->check_op->arg2; 407 1.1 christos 408 1.1 christos if (!ossl_quic_tserver_stream_has_peer_stop_sending(ACQUIRE_S(), stream_id, NULL)) { 409 1.1 christos h->check_spin_again = 1; 410 1.1 christos return 0; 411 1.1 christos } 412 1.1 christos 413 1.1 christos return 1; 414 1.1 christos } 415 1.1 christos 416 1.1 christos static int override_key_update(struct helper *h, struct helper_local *hl) 417 1.1 christos { 418 1.1 christos QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn); 419 1.1 christos 420 1.1 christos ossl_quic_channel_set_txku_threshold_override(ch, hl->check_op->arg2); 421 1.1 christos return 1; 422 1.1 christos } 423 1.1 christos 424 1.1 christos static int trigger_key_update(struct helper *h, struct helper_local *hl) 425 1.1 christos { 426 1.1 christos if (!TEST_true(SSL_key_update(h->c_conn, SSL_KEY_UPDATE_REQUESTED))) 427 1.1 christos return 0; 428 1.1 christos 429 1.1 christos return 1; 430 1.1 christos } 431 1.1 christos 432 1.1 christos static int check_key_update_ge(struct helper *h, struct helper_local *hl) 433 1.1 christos { 434 1.1 christos QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn); 435 1.1 christos int64_t txke = (int64_t)ossl_quic_channel_get_tx_key_epoch(ch); 436 1.1 christos int64_t rxke = (int64_t)ossl_quic_channel_get_rx_key_epoch(ch); 437 1.1 christos int64_t diff = txke - rxke; 438 1.1 christos 439 1.1 christos /* 440 1.1 christos * TXKE must always be equal to or ahead of RXKE. 441 1.1 christos * It can be ahead of RXKE by at most 1. 442 1.1 christos */ 443 1.1 christos if (!TEST_int64_t_ge(diff, 0) || !TEST_int64_t_le(diff, 1)) 444 1.1 christos return 0; 445 1.1 christos 446 1.1 christos /* Caller specifies a minimum number of RXKEs which must have happened. */ 447 1.1 christos if (!TEST_uint64_t_ge((uint64_t)rxke, hl->check_op->arg2)) 448 1.1 christos return 0; 449 1.1 christos 450 1.1 christos return 1; 451 1.1 christos } 452 1.1 christos 453 1.1 christos static int check_key_update_lt(struct helper *h, struct helper_local *hl) 454 1.1 christos { 455 1.1 christos QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn); 456 1.1 christos uint64_t txke = ossl_quic_channel_get_tx_key_epoch(ch); 457 1.1 christos 458 1.1 christos /* Caller specifies a maximum number of TXKEs which must have happened. */ 459 1.1 christos if (!TEST_uint64_t_lt(txke, hl->check_op->arg2)) 460 1.1 christos return 0; 461 1.1 christos 462 1.1 christos return 1; 463 1.1 christos } 464 1.1 christos 465 1.1 christos static unsigned long stream_info_hash(const STREAM_INFO *info) 466 1.1 christos { 467 1.1 christos return OPENSSL_LH_strhash(info->name); 468 1.1 christos } 469 1.1 christos 470 1.1 christos static int stream_info_cmp(const STREAM_INFO *a, const STREAM_INFO *b) 471 1.1 christos { 472 1.1 christos return strcmp(a->name, b->name); 473 1.1 christos } 474 1.1 christos 475 1.1 christos static void cleanup_stream(STREAM_INFO *info) 476 1.1 christos { 477 1.1 christos SSL_free(info->c_stream); 478 1.1 christos OPENSSL_free(info); 479 1.1 christos } 480 1.1 christos 481 1.1 christos static void helper_cleanup_streams(LHASH_OF(STREAM_INFO) **lh) 482 1.1 christos { 483 1.1 christos if (*lh == NULL) 484 1.1 christos return; 485 1.1 christos 486 1.1 christos lh_STREAM_INFO_doall(*lh, cleanup_stream); 487 1.1 christos lh_STREAM_INFO_free(*lh); 488 1.1 christos *lh = NULL; 489 1.1 christos } 490 1.1 christos 491 1.1 christos #if defined(OPENSSL_THREADS) 492 1.1 christos static CRYPTO_THREAD_RETVAL run_script_child_thread(void *arg); 493 1.1 christos 494 1.1 christos static int join_threads(struct child_thread_args *threads, size_t num_threads) 495 1.1 christos { 496 1.1 christos int ok = 1; 497 1.1 christos size_t i; 498 1.1 christos CRYPTO_THREAD_RETVAL rv; 499 1.1 christos 500 1.1 christos for (i = 0; i < num_threads; ++i) { 501 1.1 christos if (threads[i].t != NULL) { 502 1.1 christos ossl_crypto_thread_native_join(threads[i].t, &rv); 503 1.1 christos 504 1.1 christos if (!threads[i].testresult) 505 1.1 christos /* Do not log failure here, worker will do it. */ 506 1.1 christos ok = 0; 507 1.1 christos 508 1.1 christos ossl_crypto_thread_native_clean(threads[i].t); 509 1.1 christos threads[i].t = NULL; 510 1.1 christos } 511 1.1 christos 512 1.1 christos ossl_crypto_mutex_free(&threads[i].m); 513 1.1 christos } 514 1.1 christos 515 1.1 christos return ok; 516 1.1 christos } 517 1.1 christos 518 1.1 christos static int join_server_thread(struct helper *h) 519 1.1 christos { 520 1.1 christos CRYPTO_THREAD_RETVAL rv; 521 1.1 christos 522 1.1 christos if (h->server_thread.t == NULL) 523 1.1 christos return 1; 524 1.1 christos 525 1.1 christos ossl_crypto_mutex_lock(h->server_thread.m); 526 1.1 christos h->server_thread.stop = 1; 527 1.1 christos ossl_crypto_condvar_signal(h->server_thread.c); 528 1.1 christos ossl_crypto_mutex_unlock(h->server_thread.m); 529 1.1 christos 530 1.1 christos ossl_crypto_thread_native_join(h->server_thread.t, &rv); 531 1.1 christos ossl_crypto_thread_native_clean(h->server_thread.t); 532 1.1 christos h->server_thread.t = NULL; 533 1.1 christos return 1; 534 1.1 christos } 535 1.1 christos 536 1.1 christos /* Ensure the server-state lock is currently held. Idempotent. */ 537 1.1 christos static int *s_checked_out_p(struct helper *h, int thread_idx) 538 1.1 christos { 539 1.1 christos return (thread_idx < 0) ? &h->s_checked_out 540 1.1.1.2 christos : &h->threads[thread_idx].s_checked_out; 541 1.1 christos } 542 1.1 christos 543 1.1 christos static QUIC_TSERVER *s_lock(struct helper *h, struct helper_local *hl) 544 1.1 christos { 545 1.1 christos int *p_checked_out = s_checked_out_p(h, hl == NULL ? -1 : hl->thread_idx); 546 1.1 christos 547 1.1 christos if (h->server_thread.m == NULL || *p_checked_out) 548 1.1 christos return h->s; 549 1.1 christos 550 1.1 christos ossl_crypto_mutex_lock(h->server_thread.m); 551 1.1 christos h->s = h->s_priv; 552 1.1 christos *p_checked_out = 1; 553 1.1 christos return h->s; 554 1.1 christos } 555 1.1 christos 556 1.1 christos /* Ensure the server-state lock is currently not held. Idempotent. */ 557 1.1 christos static void s_unlock(struct helper *h, struct helper_local *hl) 558 1.1 christos { 559 1.1 christos int *p_checked_out = s_checked_out_p(h, hl->thread_idx); 560 1.1 christos 561 1.1 christos if (h->server_thread.m == NULL || !*p_checked_out) 562 1.1 christos return; 563 1.1 christos 564 1.1 christos *p_checked_out = 0; 565 1.1 christos h->s = NULL; 566 1.1 christos ossl_crypto_mutex_unlock(h->server_thread.m); 567 1.1 christos } 568 1.1 christos 569 1.1 christos static unsigned int server_helper_thread(void *arg) 570 1.1 christos { 571 1.1 christos struct helper *h = arg; 572 1.1 christos 573 1.1 christos ossl_crypto_mutex_lock(h->server_thread.m); 574 1.1 christos 575 1.1 christos for (;;) { 576 1.1 christos int ready, stop; 577 1.1 christos 578 1.1.1.2 christos ready = h->server_thread.ready; 579 1.1.1.2 christos stop = h->server_thread.stop; 580 1.1 christos 581 1.1 christos if (stop) 582 1.1 christos break; 583 1.1 christos 584 1.1 christos if (!ready) { 585 1.1 christos ossl_crypto_condvar_wait(h->server_thread.c, h->server_thread.m); 586 1.1 christos continue; 587 1.1 christos } 588 1.1 christos 589 1.1 christos ossl_quic_tserver_tick(h->s_priv); 590 1.1 christos ossl_crypto_mutex_unlock(h->server_thread.m); 591 1.1 christos /* 592 1.1 christos * Give the main thread an opportunity to get the mutex, which is 593 1.1 christos * sometimes necessary in some script operations. 594 1.1 christos */ 595 1.1 christos OSSL_sleep(1); 596 1.1 christos ossl_crypto_mutex_lock(h->server_thread.m); 597 1.1 christos } 598 1.1 christos 599 1.1 christos ossl_crypto_mutex_unlock(h->server_thread.m); 600 1.1 christos return 1; 601 1.1 christos } 602 1.1 christos 603 1.1 christos #else 604 1.1 christos 605 1.1 christos static QUIC_TSERVER *s_lock(struct helper *h, struct helper_local *hl) 606 1.1 christos { 607 1.1 christos return h->s; 608 1.1 christos } 609 1.1 christos 610 1.1 christos static void s_unlock(struct helper *h, struct helper_local *hl) 611 1.1.1.2 christos { 612 1.1.1.2 christos } 613 1.1 christos 614 1.1 christos #endif 615 1.1 christos 616 1.1 christos static void helper_cleanup(struct helper *h) 617 1.1 christos { 618 1.1 christos #if defined(OPENSSL_THREADS) 619 1.1 christos join_threads(h->threads, h->num_threads); 620 1.1 christos join_server_thread(h); 621 1.1 christos OPENSSL_free(h->threads); 622 1.1 christos h->threads = NULL; 623 1.1 christos h->num_threads = 0; 624 1.1 christos #endif 625 1.1 christos 626 1.1 christos if (h->free_order == 0) { 627 1.1 christos /* order 0: streams, then conn */ 628 1.1 christos helper_cleanup_streams(&h->c_streams); 629 1.1 christos 630 1.1 christos SSL_free(h->c_conn); 631 1.1 christos h->c_conn = NULL; 632 1.1 christos } else { 633 1.1 christos /* order 1: conn, then streams */ 634 1.1 christos SSL_free(h->c_conn); 635 1.1 christos h->c_conn = NULL; 636 1.1 christos 637 1.1 christos helper_cleanup_streams(&h->c_streams); 638 1.1 christos } 639 1.1 christos 640 1.1 christos helper_cleanup_streams(&h->s_streams); 641 1.1 christos ossl_quic_tserver_free(h->s_priv); 642 1.1 christos h->s_priv = h->s = NULL; 643 1.1 christos 644 1.1 christos BIO_free(h->s_net_bio_own); 645 1.1 christos h->s_net_bio_own = NULL; 646 1.1 christos 647 1.1 christos BIO_free(h->c_net_bio_own); 648 1.1 christos h->c_net_bio_own = NULL; 649 1.1 christos 650 1.1 christos BIO_free(h->s_qtf_wbio_own); 651 1.1 christos h->s_qtf_wbio_own = NULL; 652 1.1 christos 653 1.1 christos qtest_fault_free(h->qtf); 654 1.1 christos h->qtf = NULL; 655 1.1 christos 656 1.1 christos if (h->s_fd >= 0) { 657 1.1 christos BIO_closesocket(h->s_fd); 658 1.1 christos h->s_fd = -1; 659 1.1 christos } 660 1.1 christos 661 1.1 christos if (h->c_fd >= 0) { 662 1.1 christos BIO_closesocket(h->c_fd); 663 1.1 christos h->c_fd = -1; 664 1.1 christos } 665 1.1 christos 666 1.1 christos BIO_ADDR_free(h->s_net_bio_addr); 667 1.1 christos h->s_net_bio_addr = NULL; 668 1.1 christos BIO_ADDR_free(h->s_net_bio_orig_addr); 669 1.1 christos h->s_net_bio_orig_addr = NULL; 670 1.1 christos 671 1.1 christos SSL_CTX_free(h->c_ctx); 672 1.1 christos h->c_ctx = NULL; 673 1.1 christos 674 1.1 christos CRYPTO_THREAD_lock_free(h->time_lock); 675 1.1 christos h->time_lock = NULL; 676 1.1 christos 677 1.1 christos #if defined(OPENSSL_THREADS) 678 1.1 christos ossl_crypto_mutex_free(&h->misc_m); 679 1.1 christos ossl_crypto_condvar_free(&h->misc_cv); 680 1.1 christos ossl_crypto_mutex_free(&h->server_thread.m); 681 1.1 christos ossl_crypto_condvar_free(&h->server_thread.c); 682 1.1 christos #endif 683 1.1 christos } 684 1.1 christos 685 1.1 christos static int helper_init(struct helper *h, const char *script_name, 686 1.1.1.2 christos int free_order, int blocking, 687 1.1.1.2 christos int need_injector) 688 1.1 christos { 689 1.1.1.2 christos struct in_addr ina = { 0 }; 690 1.1.1.2 christos QUIC_TSERVER_ARGS s_args = { 0 }; 691 1.1 christos union BIO_sock_info_u info; 692 1.1 christos char title[128]; 693 1.1 christos QTEST_DATA *bdata = NULL; 694 1.1 christos 695 1.1 christos memset(h, 0, sizeof(*h)); 696 1.1 christos h->c_fd = -1; 697 1.1 christos h->s_fd = -1; 698 1.1 christos h->free_order = free_order; 699 1.1 christos h->blocking = blocking; 700 1.1 christos h->need_injector = need_injector; 701 1.1 christos h->time_slip = ossl_time_zero(); 702 1.1 christos 703 1.1 christos bdata = OPENSSL_zalloc(sizeof(QTEST_DATA)); 704 1.1 christos if (bdata == NULL) 705 1.1 christos goto err; 706 1.1 christos 707 1.1 christos if (!TEST_ptr(h->time_lock = CRYPTO_THREAD_lock_new())) 708 1.1 christos goto err; 709 1.1 christos 710 1.1 christos if (!TEST_ptr(h->s_streams = lh_STREAM_INFO_new(stream_info_hash, 711 1.1.1.2 christos stream_info_cmp))) 712 1.1 christos goto err; 713 1.1 christos 714 1.1 christos if (!TEST_ptr(h->c_streams = lh_STREAM_INFO_new(stream_info_hash, 715 1.1.1.2 christos stream_info_cmp))) 716 1.1 christos goto err; 717 1.1 christos 718 1.1 christos ina.s_addr = htonl(0x7f000001UL); 719 1.1 christos 720 1.1 christos h->s_fd = BIO_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0); 721 1.1 christos if (!TEST_int_ge(h->s_fd, 0)) 722 1.1 christos goto err; 723 1.1 christos 724 1.1 christos if (!TEST_true(BIO_socket_nbio(h->s_fd, 1))) 725 1.1 christos goto err; 726 1.1 christos 727 1.1 christos if (!TEST_ptr(h->s_net_bio_orig_addr = BIO_ADDR_new()) 728 1.1 christos || !TEST_ptr(h->s_net_bio_addr = BIO_ADDR_new())) 729 1.1 christos goto err; 730 1.1 christos 731 1.1 christos if (!TEST_true(BIO_ADDR_rawmake(h->s_net_bio_orig_addr, AF_INET, 732 1.1.1.2 christos &ina, sizeof(ina), 0))) 733 1.1 christos goto err; 734 1.1 christos 735 1.1 christos if (!TEST_true(BIO_bind(h->s_fd, h->s_net_bio_orig_addr, 0))) 736 1.1 christos goto err; 737 1.1 christos 738 1.1 christos info.addr = h->s_net_bio_addr; 739 1.1 christos if (!TEST_true(BIO_sock_info(h->s_fd, BIO_SOCK_INFO_ADDRESS, &info))) 740 1.1 christos goto err; 741 1.1 christos 742 1.1 christos if (!TEST_int_gt(BIO_ADDR_rawport(h->s_net_bio_addr), 0)) 743 1.1 christos goto err; 744 1.1 christos 745 1.1.1.2 christos if (!TEST_ptr(h->s_net_bio = h->s_net_bio_own = BIO_new_dgram(h->s_fd, 0))) 746 1.1 christos goto err; 747 1.1 christos 748 1.1 christos if (!BIO_up_ref(h->s_net_bio)) 749 1.1 christos goto err; 750 1.1 christos 751 1.1 christos if (need_injector) { 752 1.1 christos h->s_qtf_wbio = h->s_qtf_wbio_own = BIO_new(qtest_get_bio_method()); 753 1.1 christos if (!TEST_ptr(h->s_qtf_wbio)) 754 1.1 christos goto err; 755 1.1 christos 756 1.1 christos if (!TEST_ptr(BIO_push(h->s_qtf_wbio, h->s_net_bio))) 757 1.1 christos goto err; 758 1.1 christos 759 1.1 christos s_args.net_wbio = h->s_qtf_wbio; 760 1.1 christos } else { 761 1.1 christos s_args.net_wbio = h->s_net_bio; 762 1.1 christos } 763 1.1 christos 764 1.1.1.2 christos s_args.net_rbio = h->s_net_bio; 765 1.1.1.2 christos s_args.alpn = NULL; 766 1.1.1.2 christos s_args.now_cb = get_time; 767 1.1.1.2 christos s_args.now_cb_arg = h; 768 1.1.1.2 christos s_args.ctx = NULL; 769 1.1 christos 770 1.1 christos if (!TEST_ptr(h->s_priv = ossl_quic_tserver_new(&s_args, certfile, keyfile))) 771 1.1 christos goto err; 772 1.1 christos 773 1.1 christos if (!blocking) 774 1.1 christos h->s = h->s_priv; 775 1.1 christos 776 1.1 christos if (need_injector) { 777 1.1 christos h->qtf = qtest_create_injector(h->s_priv); 778 1.1 christos if (!TEST_ptr(h->qtf)) 779 1.1 christos goto err; 780 1.1 christos bdata->fault = h->qtf; 781 1.1 christos BIO_set_data(h->s_qtf_wbio, bdata); 782 1.1 christos } 783 1.1 christos 784 1.1 christos h->s_net_bio_own = NULL; 785 1.1 christos h->s_qtf_wbio_own = NULL; 786 1.1 christos 787 1.1 christos h->c_fd = BIO_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0); 788 1.1 christos if (!TEST_int_ge(h->c_fd, 0)) 789 1.1 christos goto err; 790 1.1 christos 791 1.1 christos if (!TEST_true(BIO_socket_nbio(h->c_fd, 1))) 792 1.1 christos goto err; 793 1.1 christos 794 1.1 christos if (!TEST_ptr(h->c_net_bio = h->c_net_bio_own = BIO_new_dgram(h->c_fd, 0))) 795 1.1 christos goto err; 796 1.1 christos 797 1.1 christos if (!TEST_true(BIO_dgram_set_peer(h->c_net_bio, h->s_net_bio_addr))) 798 1.1 christos goto err; 799 1.1 christos 800 1.1 christos if (!TEST_ptr(h->c_ctx = SSL_CTX_new(OSSL_QUIC_client_method()))) 801 1.1 christos goto err; 802 1.1 christos 803 1.1 christos /* Set title for qlog purposes. */ 804 1.1 christos BIO_snprintf(title, sizeof(title), "quic_multistream_test: %s", script_name); 805 1.1 christos if (!TEST_true(ossl_quic_set_diag_title(h->c_ctx, title))) 806 1.1 christos goto err; 807 1.1 christos 808 1.1 christos if (!TEST_ptr(h->c_conn = SSL_new(h->c_ctx))) 809 1.1 christos goto err; 810 1.1 christos 811 1.1 christos /* Use custom time function for virtual time skip. */ 812 1.1 christos if (!TEST_true(ossl_quic_set_override_now_cb(h->c_conn, get_time, h))) 813 1.1 christos goto err; 814 1.1 christos 815 1.1 christos /* Takes ownership of our reference to the BIO. */ 816 1.1 christos SSL_set0_rbio(h->c_conn, h->c_net_bio); 817 1.1 christos h->c_net_bio_own = NULL; 818 1.1 christos 819 1.1 christos if (!TEST_true(BIO_up_ref(h->c_net_bio))) 820 1.1 christos goto err; 821 1.1 christos 822 1.1 christos SSL_set0_wbio(h->c_conn, h->c_net_bio); 823 1.1 christos 824 1.1 christos if (!TEST_true(SSL_set_blocking_mode(h->c_conn, h->blocking))) 825 1.1 christos goto err; 826 1.1 christos 827 1.1 christos #if defined(OPENSSL_THREADS) 828 1.1 christos if (!TEST_ptr(h->misc_m = ossl_crypto_mutex_new())) 829 1.1.1.2 christos goto err; 830 1.1 christos if (!TEST_ptr(h->misc_cv = ossl_crypto_condvar_new())) 831 1.1.1.2 christos goto err; 832 1.1 christos #endif 833 1.1 christos 834 1.1 christos if (h->blocking) { 835 1.1 christos #if defined(OPENSSL_THREADS) 836 1.1 christos if (!TEST_ptr(h->server_thread.m = ossl_crypto_mutex_new())) 837 1.1 christos goto err; 838 1.1 christos 839 1.1 christos if (!TEST_ptr(h->server_thread.c = ossl_crypto_condvar_new())) 840 1.1 christos goto err; 841 1.1 christos 842 1.1 christos h->server_thread.t 843 1.1 christos = ossl_crypto_thread_native_start(server_helper_thread, h, 1); 844 1.1 christos if (!TEST_ptr(h->server_thread.t)) 845 1.1 christos goto err; 846 1.1 christos #else 847 1.1 christos TEST_error("cannot support blocking mode without threads"); 848 1.1 christos goto err; 849 1.1 christos #endif 850 1.1 christos } 851 1.1 christos 852 1.1.1.2 christos h->start_time = ossl_time_now(); 853 1.1.1.2 christos h->init = 1; 854 1.1 christos return 1; 855 1.1 christos 856 1.1 christos err: 857 1.1 christos helper_cleanup(h); 858 1.1 christos return 0; 859 1.1 christos } 860 1.1 christos 861 1.1 christos static int helper_local_init(struct helper_local *hl, struct helper *h, 862 1.1.1.2 christos int thread_idx) 863 1.1 christos { 864 1.1.1.2 christos hl->h = h; 865 1.1.1.2 christos hl->c_streams = NULL; 866 1.1.1.2 christos hl->thread_idx = thread_idx; 867 1.1 christos hl->explicit_event_handling = 0; 868 1.1 christos 869 1.1 christos if (!TEST_ptr(h)) 870 1.1 christos return 0; 871 1.1 christos 872 1.1 christos if (thread_idx < 0) { 873 1.1 christos hl->c_streams = h->c_streams; 874 1.1 christos } else { 875 1.1 christos if (!TEST_ptr(hl->c_streams = lh_STREAM_INFO_new(stream_info_hash, 876 1.1.1.2 christos stream_info_cmp))) 877 1.1 christos return 0; 878 1.1 christos } 879 1.1 christos 880 1.1 christos return 1; 881 1.1 christos } 882 1.1 christos 883 1.1 christos static void helper_local_cleanup(struct helper_local *hl) 884 1.1 christos { 885 1.1 christos if (hl->h == NULL) 886 1.1 christos return; 887 1.1 christos 888 1.1 christos if (hl->thread_idx >= 0) 889 1.1 christos helper_cleanup_streams(&hl->c_streams); 890 1.1 christos 891 1.1 christos hl->h = NULL; 892 1.1 christos } 893 1.1 christos 894 1.1 christos static STREAM_INFO *get_stream_info(LHASH_OF(STREAM_INFO) *lh, 895 1.1.1.2 christos const char *stream_name) 896 1.1 christos { 897 1.1 christos STREAM_INFO key, *info; 898 1.1 christos 899 1.1 christos if (!TEST_ptr(stream_name)) 900 1.1 christos return NULL; 901 1.1 christos 902 1.1 christos if (!strcmp(stream_name, "DEFAULT")) 903 1.1 christos return NULL; 904 1.1 christos 905 1.1 christos key.name = stream_name; 906 1.1 christos info = lh_STREAM_INFO_retrieve(lh, &key); 907 1.1 christos if (info == NULL) { 908 1.1 christos info = OPENSSL_zalloc(sizeof(*info)); 909 1.1 christos if (info == NULL) 910 1.1 christos return NULL; 911 1.1 christos 912 1.1.1.2 christos info->name = stream_name; 913 1.1.1.2 christos info->s_stream_id = UINT64_MAX; 914 1.1 christos lh_STREAM_INFO_insert(lh, info); 915 1.1 christos } 916 1.1 christos 917 1.1 christos return info; 918 1.1 christos } 919 1.1 christos 920 1.1 christos static int helper_local_set_c_stream(struct helper_local *hl, 921 1.1.1.2 christos const char *stream_name, 922 1.1.1.2 christos SSL *c_stream) 923 1.1 christos { 924 1.1 christos STREAM_INFO *info = get_stream_info(hl->c_streams, stream_name); 925 1.1 christos 926 1.1 christos if (info == NULL) 927 1.1 christos return 0; 928 1.1 christos 929 1.1.1.2 christos info->c_stream = c_stream; 930 1.1.1.2 christos info->s_stream_id = UINT64_MAX; 931 1.1 christos return 1; 932 1.1 christos } 933 1.1 christos 934 1.1 christos static SSL *helper_local_get_c_stream(struct helper_local *hl, 935 1.1.1.2 christos const char *stream_name) 936 1.1 christos { 937 1.1 christos STREAM_INFO *info; 938 1.1 christos 939 1.1 christos if (!strcmp(stream_name, "DEFAULT")) 940 1.1 christos return hl->h->c_conn; 941 1.1 christos 942 1.1 christos info = get_stream_info(hl->c_streams, stream_name); 943 1.1 christos if (info == NULL) 944 1.1 christos return NULL; 945 1.1 christos 946 1.1 christos return info->c_stream; 947 1.1 christos } 948 1.1 christos 949 1.1 christos static int 950 1.1 christos helper_set_s_stream(struct helper *h, const char *stream_name, 951 1.1.1.2 christos uint64_t s_stream_id) 952 1.1 christos { 953 1.1 christos STREAM_INFO *info; 954 1.1 christos 955 1.1 christos if (!strcmp(stream_name, "DEFAULT")) 956 1.1 christos return 0; 957 1.1 christos 958 1.1 christos info = get_stream_info(h->s_streams, stream_name); 959 1.1 christos if (info == NULL) 960 1.1 christos return 0; 961 1.1 christos 962 1.1.1.2 christos info->c_stream = NULL; 963 1.1.1.2 christos info->s_stream_id = s_stream_id; 964 1.1 christos return 1; 965 1.1 christos } 966 1.1 christos 967 1.1 christos static uint64_t helper_get_s_stream(struct helper *h, const char *stream_name) 968 1.1 christos { 969 1.1 christos STREAM_INFO *info; 970 1.1 christos 971 1.1 christos if (!strcmp(stream_name, "DEFAULT")) 972 1.1 christos return UINT64_MAX; 973 1.1 christos 974 1.1 christos info = get_stream_info(h->s_streams, stream_name); 975 1.1 christos if (info == NULL) 976 1.1 christos return UINT64_MAX; 977 1.1 christos 978 1.1 christos return info->s_stream_id; 979 1.1 christos } 980 1.1 christos 981 1.1 christos static int helper_packet_plain_listener(QTEST_FAULT *qtf, QUIC_PKT_HDR *hdr, 982 1.1.1.2 christos unsigned char *buf, size_t buf_len, 983 1.1.1.2 christos void *arg) 984 1.1 christos { 985 1.1 christos struct helper *h = arg; 986 1.1 christos 987 1.1 christos return h->qtf_packet_plain_cb(h, hdr, buf, buf_len); 988 1.1 christos } 989 1.1 christos 990 1.1 christos static int helper_handshake_listener(QTEST_FAULT *fault, 991 1.1.1.2 christos unsigned char *buf, size_t buf_len, 992 1.1.1.2 christos void *arg) 993 1.1 christos { 994 1.1 christos struct helper *h = arg; 995 1.1 christos 996 1.1 christos return h->qtf_handshake_cb(h, buf, buf_len); 997 1.1 christos } 998 1.1 christos 999 1.1 christos static int helper_datagram_listener(QTEST_FAULT *fault, 1000 1.1.1.2 christos BIO_MSG *msg, size_t stride, 1001 1.1.1.2 christos void *arg) 1002 1.1 christos { 1003 1.1 christos struct helper *h = arg; 1004 1.1 christos 1005 1.1 christos return h->qtf_datagram_cb(h, msg, stride); 1006 1.1 christos } 1007 1.1 christos 1008 1.1 christos static int is_want(SSL *s, int ret) 1009 1.1 christos { 1010 1.1 christos int ec = SSL_get_error(s, ret); 1011 1.1 christos 1012 1.1 christos return ec == SSL_ERROR_WANT_READ || ec == SSL_ERROR_WANT_WRITE; 1013 1.1 christos } 1014 1.1 christos 1015 1.1 christos static int check_consistent_want(SSL *s, int ret) 1016 1.1 christos { 1017 1.1 christos int ec = SSL_get_error(s, ret); 1018 1.1 christos int w = SSL_want(s); 1019 1.1 christos 1020 1.1 christos int ok = TEST_true( 1021 1.1.1.2 christos (ec == SSL_ERROR_NONE && w == SSL_NOTHING) 1022 1.1.1.2 christos || (ec == SSL_ERROR_ZERO_RETURN && w == SSL_NOTHING) 1023 1.1.1.2 christos || (ec == SSL_ERROR_SSL && w == SSL_NOTHING) 1024 1.1.1.2 christos || (ec == SSL_ERROR_SYSCALL && w == SSL_NOTHING) 1025 1.1.1.2 christos || (ec == SSL_ERROR_WANT_READ && w == SSL_READING) 1026 1.1.1.2 christos || (ec == SSL_ERROR_WANT_WRITE && w == SSL_WRITING) 1027 1.1.1.2 christos || (ec == SSL_ERROR_WANT_CLIENT_HELLO_CB && w == SSL_CLIENT_HELLO_CB) 1028 1.1.1.2 christos || (ec == SSL_ERROR_WANT_X509_LOOKUP && w == SSL_X509_LOOKUP) 1029 1.1.1.2 christos || (ec == SSL_ERROR_WANT_RETRY_VERIFY && w == SSL_RETRY_VERIFY)); 1030 1.1 christos 1031 1.1 christos if (!ok) 1032 1.1 christos TEST_error("got error=%d, want=%d", ec, w); 1033 1.1 christos 1034 1.1 christos return ok; 1035 1.1 christos } 1036 1.1 christos 1037 1.1 christos static int run_script_worker(struct helper *h, const struct script_op *script, 1038 1.1.1.2 christos const char *script_name, 1039 1.1.1.2 christos int thread_idx) 1040 1.1 christos { 1041 1.1 christos int testresult = 0; 1042 1.1 christos unsigned char *tmp_buf = NULL; 1043 1.1 christos int connect_started = 0; 1044 1.1 christos size_t offset = 0; 1045 1.1 christos size_t op_idx = 0; 1046 1.1 christos const struct script_op *op = NULL; 1047 1.1 christos int no_advance = 0, first = 1; 1048 1.1 christos #if defined(OPENSSL_THREADS) 1049 1.1 christos int end_wait_warning = 0; 1050 1.1 christos #endif 1051 1.1 christos OSSL_TIME op_start_time = ossl_time_zero(), op_deadline = ossl_time_zero(); 1052 1.1 christos struct helper_local hl_, *hl = &hl_; 1053 1.1 christos #define REPEAT_SLOTS 8 1054 1.1 christos size_t repeat_stack_idx[REPEAT_SLOTS], repeat_stack_done[REPEAT_SLOTS]; 1055 1.1 christos size_t repeat_stack_limit[REPEAT_SLOTS]; 1056 1.1 christos size_t repeat_stack_len = 0; 1057 1.1 christos 1058 1.1 christos if (!TEST_true(helper_local_init(hl, h, thread_idx))) 1059 1.1 christos goto out; 1060 1.1 christos 1061 1.1.1.2 christos #define COMMON_SPIN_AGAIN() \ 1062 1.1.1.2 christos { \ 1063 1.1.1.2 christos no_advance = 1; \ 1064 1.1.1.2 christos continue; \ 1065 1.1 christos } 1066 1.1.1.2 christos #define S_SPIN_AGAIN() \ 1067 1.1.1.2 christos { \ 1068 1.1.1.2 christos s_lock(h, hl); \ 1069 1.1.1.2 christos ossl_quic_tserver_tick(h->s); \ 1070 1.1.1.2 christos COMMON_SPIN_AGAIN(); \ 1071 1.1 christos } 1072 1.1.1.2 christos #define C_SPIN_AGAIN() \ 1073 1.1.1.2 christos { \ 1074 1.1.1.2 christos if (h->blocking) { \ 1075 1.1.1.2 christos TEST_error("spin again in blocking mode"); \ 1076 1.1.1.2 christos goto out; \ 1077 1.1.1.2 christos } \ 1078 1.1.1.2 christos COMMON_SPIN_AGAIN(); \ 1079 1.1 christos } 1080 1.1 christos 1081 1.1 christos for (;;) { 1082 1.1.1.2 christos SSL *c_tgt = h->c_conn; 1083 1.1.1.2 christos uint64_t s_stream_id = UINT64_MAX; 1084 1.1 christos 1085 1.1 christos s_unlock(h, hl); 1086 1.1 christos 1087 1.1 christos if (no_advance) { 1088 1.1 christos no_advance = 0; 1089 1.1 christos } else { 1090 1.1 christos if (!first) 1091 1.1 christos ++op_idx; 1092 1.1 christos 1093 1.1.1.2 christos first = 0; 1094 1.1.1.2 christos offset = 0; 1095 1.1.1.2 christos op_start_time = ossl_time_now(); 1096 1.1.1.2 christos op_deadline = ossl_time_add(op_start_time, ossl_ms2time(60000)); 1097 1.1 christos } 1098 1.1 christos 1099 1.1 christos if (!TEST_int_le(ossl_time_compare(ossl_time_now(), op_deadline), 0)) { 1100 1.1 christos TEST_error("op %zu timed out on thread %d", op_idx + 1, thread_idx); 1101 1.1 christos goto out; 1102 1.1 christos } 1103 1.1 christos 1104 1.1 christos op = &script[op_idx]; 1105 1.1 christos 1106 1.1 christos if (op->stream_name != NULL) { 1107 1.1 christos c_tgt = helper_local_get_c_stream(hl, op->stream_name); 1108 1.1 christos if (thread_idx < 0) 1109 1.1 christos s_stream_id = helper_get_s_stream(h, op->stream_name); 1110 1.1 christos else 1111 1.1 christos s_stream_id = UINT64_MAX; 1112 1.1 christos } 1113 1.1 christos 1114 1.1 christos if (thread_idx < 0) { 1115 1.1 christos if (!h->blocking) { 1116 1.1 christos ossl_quic_tserver_tick(h->s); 1117 1.1 christos } 1118 1.1 christos #if defined(OPENSSL_THREADS) 1119 1.1 christos else if (h->blocking && !h->server_thread.ready) { 1120 1.1 christos ossl_crypto_mutex_lock(h->server_thread.m); 1121 1.1 christos h->server_thread.ready = 1; 1122 1.1 christos ossl_crypto_condvar_signal(h->server_thread.c); 1123 1.1 christos ossl_crypto_mutex_unlock(h->server_thread.m); 1124 1.1 christos } 1125 1.1 christos if (h->blocking) 1126 1.1 christos assert(h->s == NULL); 1127 1.1 christos #endif 1128 1.1 christos } 1129 1.1 christos 1130 1.1 christos if (!hl->explicit_event_handling 1131 1.1 christos && (thread_idx >= 0 || connect_started)) 1132 1.1 christos SSL_handle_events(h->c_conn); 1133 1.1 christos 1134 1.1 christos if (thread_idx >= 0) { 1135 1.1 christos /* Only allow certain opcodes on child threads. */ 1136 1.1 christos switch (op->op) { 1137 1.1.1.2 christos case OPK_END: 1138 1.1.1.2 christos case OPK_CHECK: 1139 1.1.1.2 christos case OPK_C_ACCEPT_STREAM_WAIT: 1140 1.1.1.2 christos case OPK_C_NEW_STREAM: 1141 1.1.1.2 christos case OPK_C_READ_EXPECT: 1142 1.1.1.2 christos case OPK_C_EXPECT_FIN: 1143 1.1.1.2 christos case OPK_C_WRITE: 1144 1.1.1.2 christos case OPK_C_WRITE_EX2: 1145 1.1.1.2 christos case OPK_C_CONCLUDE: 1146 1.1.1.2 christos case OPK_C_FREE_STREAM: 1147 1.1.1.2 christos case OPK_BEGIN_REPEAT: 1148 1.1.1.2 christos case OPK_END_REPEAT: 1149 1.1.1.2 christos case OPK_C_READ_FAIL_WAIT: 1150 1.1.1.2 christos case OPK_C_EXPECT_SSL_ERR: 1151 1.1.1.2 christos case OPK_EXPECT_ERR_REASON: 1152 1.1.1.2 christos case OPK_EXPECT_ERR_LIB: 1153 1.1.1.2 christos case OPK_POP_ERR: 1154 1.1.1.2 christos case OPK_SLEEP: 1155 1.1.1.2 christos break; 1156 1.1.1.2 christos 1157 1.1.1.2 christos default: 1158 1.1.1.2 christos TEST_error("opcode %lu not allowed on child thread", 1159 1.1.1.2 christos (unsigned long)op->op); 1160 1.1.1.2 christos goto out; 1161 1.1 christos } 1162 1.1 christos } 1163 1.1 christos 1164 1.1 christos switch (op->op) { 1165 1.1 christos case OPK_END: 1166 1.1 christos if (!TEST_size_t_eq(repeat_stack_len, 0)) 1167 1.1 christos goto out; 1168 1.1 christos 1169 1.1 christos #if defined(OPENSSL_THREADS) 1170 1.1 christos if (thread_idx < 0) { 1171 1.1 christos int done; 1172 1.1 christos size_t i; 1173 1.1 christos 1174 1.1 christos for (i = 0; i < h->num_threads; ++i) { 1175 1.1 christos if (h->threads[i].m == NULL) 1176 1.1 christos continue; 1177 1.1 christos 1178 1.1 christos ossl_crypto_mutex_lock(h->threads[i].m); 1179 1.1 christos done = h->threads[i].done; 1180 1.1 christos ossl_crypto_mutex_unlock(h->threads[i].m); 1181 1.1 christos 1182 1.1 christos if (!done) { 1183 1.1 christos if (!end_wait_warning) { 1184 1.1 christos TEST_info("still waiting for other threads to finish (%zu)", i); 1185 1.1 christos end_wait_warning = 1; 1186 1.1 christos } 1187 1.1 christos 1188 1.1 christos S_SPIN_AGAIN(); 1189 1.1 christos } 1190 1.1 christos } 1191 1.1 christos } 1192 1.1 christos #endif 1193 1.1 christos 1194 1.1 christos TEST_info("script \"%s\" finished on thread %d", script_name, thread_idx); 1195 1.1 christos testresult = 1; 1196 1.1 christos goto out; 1197 1.1 christos 1198 1.1 christos case OPK_BEGIN_REPEAT: 1199 1.1 christos if (!TEST_size_t_lt(repeat_stack_len, OSSL_NELEM(repeat_stack_idx))) 1200 1.1 christos goto out; 1201 1.1 christos 1202 1.1 christos if (!TEST_size_t_gt(op->arg1, 0)) 1203 1.1 christos goto out; 1204 1.1 christos 1205 1.1 christos repeat_stack_idx[repeat_stack_len] = op_idx + 1; 1206 1.1 christos repeat_stack_done[repeat_stack_len] = 0; 1207 1.1 christos repeat_stack_limit[repeat_stack_len] = op->arg1; 1208 1.1 christos ++repeat_stack_len; 1209 1.1 christos break; 1210 1.1 christos 1211 1.1 christos case OPK_C_SKIP_IF_UNBOUND: 1212 1.1 christos if (c_tgt != NULL) 1213 1.1 christos break; 1214 1.1 christos 1215 1.1 christos op_idx += op->arg1; 1216 1.1 christos break; 1217 1.1 christos 1218 1.1 christos case OPK_SKIP_IF_BLOCKING: 1219 1.1 christos if (!h->blocking) 1220 1.1 christos break; 1221 1.1 christos 1222 1.1 christos op_idx += op->arg1; 1223 1.1 christos break; 1224 1.1 christos 1225 1.1 christos case OPK_END_REPEAT: 1226 1.1 christos if (!TEST_size_t_gt(repeat_stack_len, 0)) 1227 1.1 christos goto out; 1228 1.1 christos 1229 1.1 christos if (++repeat_stack_done[repeat_stack_len - 1] 1230 1.1 christos == repeat_stack_limit[repeat_stack_len - 1]) { 1231 1.1 christos --repeat_stack_len; 1232 1.1 christos } else { 1233 1.1 christos op_idx = repeat_stack_idx[repeat_stack_len - 1]; 1234 1.1 christos no_advance = 1; 1235 1.1 christos continue; 1236 1.1 christos } 1237 1.1 christos 1238 1.1 christos break; 1239 1.1 christos 1240 1.1.1.2 christos case OPK_CHECK: { 1241 1.1.1.2 christos int ok; 1242 1.1 christos 1243 1.1.1.2 christos hl->check_op = op; 1244 1.1.1.2 christos ok = op->check_func(h, hl); 1245 1.1.1.2 christos hl->check_op = NULL; 1246 1.1 christos 1247 1.1.1.2 christos if (thread_idx < 0 && h->check_spin_again) { 1248 1.1.1.2 christos h->check_spin_again = 0; 1249 1.1.1.2 christos S_SPIN_AGAIN(); 1250 1.1.1.2 christos } 1251 1.1 christos 1252 1.1.1.2 christos if (!TEST_true(ok)) 1253 1.1.1.2 christos goto out; 1254 1.1.1.2 christos } break; 1255 1.1 christos 1256 1.1.1.2 christos case OPK_C_SET_ALPN: { 1257 1.1.1.2 christos const char *alpn = op->arg0; 1258 1.1.1.2 christos size_t alpn_len = strlen(alpn); 1259 1.1 christos 1260 1.1.1.2 christos if (!TEST_size_t_le(alpn_len, UINT8_MAX) 1261 1.1.1.2 christos || !TEST_ptr(tmp_buf = (unsigned char *)OPENSSL_malloc(alpn_len + 1))) 1262 1.1.1.2 christos goto out; 1263 1.1 christos 1264 1.1.1.2 christos memcpy(tmp_buf + 1, alpn, alpn_len); 1265 1.1.1.2 christos tmp_buf[0] = (unsigned char)alpn_len; 1266 1.1 christos 1267 1.1.1.2 christos /* 0 is the success case for SSL_set_alpn_protos(). */ 1268 1.1.1.2 christos if (!TEST_false(SSL_set_alpn_protos(h->c_conn, tmp_buf, 1269 1.1.1.2 christos alpn_len + 1))) 1270 1.1.1.2 christos goto out; 1271 1.1 christos 1272 1.1.1.2 christos OPENSSL_free(tmp_buf); 1273 1.1.1.2 christos tmp_buf = NULL; 1274 1.1.1.2 christos } break; 1275 1.1 christos 1276 1.1.1.2 christos case OPK_C_CONNECT_WAIT: { 1277 1.1.1.2 christos int ret; 1278 1.1 christos 1279 1.1.1.2 christos connect_started = 1; 1280 1.1 christos 1281 1.1.1.2 christos ret = SSL_connect(h->c_conn); 1282 1.1.1.2 christos if (!check_consistent_want(c_tgt, ret)) 1283 1.1.1.2 christos goto out; 1284 1.1.1.2 christos if (ret != 1) { 1285 1.1.1.2 christos if (!h->blocking && is_want(h->c_conn, ret)) 1286 1.1.1.2 christos C_SPIN_AGAIN(); 1287 1.1 christos 1288 1.1.1.2 christos if (op->arg1 == 0 && !TEST_int_eq(ret, 1)) 1289 1.1 christos goto out; 1290 1.1 christos } 1291 1.1.1.2 christos } break; 1292 1.1 christos 1293 1.1.1.2 christos case OPK_C_WRITE: { 1294 1.1.1.2 christos size_t bytes_written = 0; 1295 1.1.1.2 christos int r; 1296 1.1 christos 1297 1.1.1.2 christos if (!TEST_ptr(c_tgt)) 1298 1.1.1.2 christos goto out; 1299 1.1 christos 1300 1.1.1.2 christos r = SSL_write_ex(c_tgt, op->arg0, op->arg1, &bytes_written); 1301 1.1.1.2 christos if (!TEST_true(r) 1302 1.1.1.2 christos || !check_consistent_want(c_tgt, r) 1303 1.1.1.2 christos || !TEST_size_t_eq(bytes_written, op->arg1)) 1304 1.1.1.2 christos goto out; 1305 1.1.1.2 christos } break; 1306 1.1 christos 1307 1.1.1.2 christos case OPK_C_WRITE_EX2: { 1308 1.1.1.2 christos size_t bytes_written = 0; 1309 1.1.1.2 christos int r; 1310 1.1 christos 1311 1.1.1.2 christos if (!TEST_ptr(c_tgt)) 1312 1.1.1.2 christos goto out; 1313 1.1 christos 1314 1.1.1.2 christos r = SSL_write_ex2(c_tgt, op->arg0, op->arg1, op->arg2, 1315 1.1.1.2 christos &bytes_written); 1316 1.1.1.2 christos if (!TEST_true(r) 1317 1.1.1.2 christos || !check_consistent_want(c_tgt, r) 1318 1.1.1.2 christos || !TEST_size_t_eq(bytes_written, op->arg1)) 1319 1.1.1.2 christos goto out; 1320 1.1.1.2 christos } break; 1321 1.1 christos 1322 1.1.1.2 christos case OPK_S_WRITE: { 1323 1.1.1.2 christos size_t bytes_written = 0; 1324 1.1 christos 1325 1.1.1.2 christos if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) 1326 1.1.1.2 christos goto out; 1327 1.1 christos 1328 1.1.1.2 christos if (!TEST_true(ossl_quic_tserver_write(ACQUIRE_S(), s_stream_id, 1329 1.1.1.2 christos op->arg0, op->arg1, 1330 1.1.1.2 christos &bytes_written)) 1331 1.1.1.2 christos || !TEST_size_t_eq(bytes_written, op->arg1)) 1332 1.1.1.2 christos goto out; 1333 1.1.1.2 christos } break; 1334 1.1 christos 1335 1.1.1.2 christos case OPK_C_CONCLUDE: { 1336 1.1.1.2 christos if (!TEST_true(SSL_stream_conclude(c_tgt, 0))) 1337 1.1.1.2 christos goto out; 1338 1.1.1.2 christos } break; 1339 1.1 christos 1340 1.1.1.2 christos case OPK_S_CONCLUDE: { 1341 1.1.1.2 christos if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) 1342 1.1.1.2 christos goto out; 1343 1.1 christos 1344 1.1.1.2 christos ossl_quic_tserver_conclude(ACQUIRE_S(), s_stream_id); 1345 1.1.1.2 christos } break; 1346 1.1 christos 1347 1.1.1.2 christos case OPK_C_WAIT_FOR_DATA: { 1348 1.1.1.2 christos char buf[1]; 1349 1.1.1.2 christos size_t bytes_read = 0; 1350 1.1 christos 1351 1.1.1.2 christos if (!TEST_ptr(c_tgt)) 1352 1.1.1.2 christos goto out; 1353 1.1 christos 1354 1.1.1.2 christos if (!SSL_peek_ex(c_tgt, buf, sizeof(buf), &bytes_read) 1355 1.1.1.2 christos || bytes_read == 0) 1356 1.1.1.2 christos C_SPIN_AGAIN(); 1357 1.1.1.2 christos } break; 1358 1.1.1.2 christos 1359 1.1.1.2 christos case OPK_C_READ_EXPECT: { 1360 1.1.1.2 christos size_t bytes_read = 0; 1361 1.1.1.2 christos int r; 1362 1.1 christos 1363 1.1.1.2 christos if (op->arg1 > 0 && tmp_buf == NULL 1364 1.1.1.2 christos && !TEST_ptr(tmp_buf = OPENSSL_malloc(op->arg1))) 1365 1.1.1.2 christos goto out; 1366 1.1 christos 1367 1.1.1.2 christos r = SSL_read_ex(c_tgt, tmp_buf + offset, op->arg1 - offset, 1368 1.1.1.2 christos &bytes_read); 1369 1.1.1.2 christos if (!check_consistent_want(c_tgt, r)) 1370 1.1.1.2 christos goto out; 1371 1.1 christos 1372 1.1.1.2 christos if (!r) 1373 1.1.1.2 christos C_SPIN_AGAIN(); 1374 1.1 christos 1375 1.1.1.2 christos if (bytes_read + offset != op->arg1) { 1376 1.1.1.2 christos offset += bytes_read; 1377 1.1.1.2 christos C_SPIN_AGAIN(); 1378 1.1 christos } 1379 1.1 christos 1380 1.1.1.2 christos if (op->arg1 > 0 1381 1.1.1.2 christos && !TEST_mem_eq(tmp_buf, op->arg1, op->arg0, op->arg1)) 1382 1.1.1.2 christos goto out; 1383 1.1 christos 1384 1.1.1.2 christos OPENSSL_free(tmp_buf); 1385 1.1.1.2 christos tmp_buf = NULL; 1386 1.1.1.2 christos } break; 1387 1.1 christos 1388 1.1.1.2 christos case OPK_S_READ_EXPECT: { 1389 1.1.1.2 christos size_t bytes_read = 0; 1390 1.1 christos 1391 1.1.1.2 christos if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) 1392 1.1.1.2 christos goto out; 1393 1.1 christos 1394 1.1.1.2 christos if (op->arg1 > 0 && tmp_buf == NULL 1395 1.1.1.2 christos && !TEST_ptr(tmp_buf = OPENSSL_malloc(op->arg1))) 1396 1.1.1.2 christos goto out; 1397 1.1 christos 1398 1.1.1.2 christos if (!TEST_true(ossl_quic_tserver_read(ACQUIRE_S(), s_stream_id, 1399 1.1.1.2 christos tmp_buf + offset, 1400 1.1.1.2 christos op->arg1 - offset, 1401 1.1.1.2 christos &bytes_read))) 1402 1.1.1.2 christos goto out; 1403 1.1 christos 1404 1.1.1.2 christos if (bytes_read + offset != op->arg1) { 1405 1.1.1.2 christos offset += bytes_read; 1406 1.1.1.2 christos S_SPIN_AGAIN(); 1407 1.1 christos } 1408 1.1 christos 1409 1.1.1.2 christos if (op->arg1 > 0 1410 1.1.1.2 christos && !TEST_mem_eq(tmp_buf, op->arg1, op->arg0, op->arg1)) 1411 1.1.1.2 christos goto out; 1412 1.1 christos 1413 1.1.1.2 christos OPENSSL_free(tmp_buf); 1414 1.1.1.2 christos tmp_buf = NULL; 1415 1.1.1.2 christos } break; 1416 1.1.1.2 christos 1417 1.1.1.2 christos case OPK_C_EXPECT_FIN: { 1418 1.1.1.2 christos char buf[1]; 1419 1.1.1.2 christos size_t bytes_read = 0; 1420 1.1.1.2 christos int r; 1421 1.1.1.2 christos 1422 1.1.1.2 christos r = SSL_read_ex(c_tgt, buf, sizeof(buf), &bytes_read); 1423 1.1.1.2 christos if (!check_consistent_want(c_tgt, r) 1424 1.1.1.2 christos || !TEST_false(r) 1425 1.1.1.2 christos || !TEST_size_t_eq(bytes_read, 0)) 1426 1.1.1.2 christos goto out; 1427 1.1 christos 1428 1.1.1.2 christos if (is_want(c_tgt, 0)) 1429 1.1.1.2 christos C_SPIN_AGAIN(); 1430 1.1 christos 1431 1.1.1.2 christos if (!TEST_int_eq(SSL_get_error(c_tgt, 0), 1432 1.1.1.2 christos SSL_ERROR_ZERO_RETURN)) 1433 1.1.1.2 christos goto out; 1434 1.1 christos 1435 1.1.1.2 christos if (!TEST_int_eq(SSL_want(c_tgt), SSL_NOTHING)) 1436 1.1.1.2 christos goto out; 1437 1.1.1.2 christos } break; 1438 1.1 christos 1439 1.1.1.2 christos case OPK_S_EXPECT_FIN: { 1440 1.1.1.2 christos if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) 1441 1.1.1.2 christos goto out; 1442 1.1 christos 1443 1.1.1.2 christos if (!ossl_quic_tserver_has_read_ended(ACQUIRE_S(), s_stream_id)) 1444 1.1.1.2 christos S_SPIN_AGAIN(); 1445 1.1.1.2 christos } break; 1446 1.1 christos 1447 1.1.1.2 christos case OPK_C_DETACH: { 1448 1.1.1.2 christos SSL *c_stream; 1449 1.1 christos 1450 1.1.1.2 christos if (!TEST_ptr_null(c_tgt)) 1451 1.1.1.2 christos goto out; /* don't overwrite existing stream with same name */ 1452 1.1 christos 1453 1.1.1.2 christos if (!TEST_ptr(op->stream_name)) 1454 1.1.1.2 christos goto out; 1455 1.1 christos 1456 1.1.1.2 christos if (!TEST_ptr(c_stream = ossl_quic_detach_stream(h->c_conn))) 1457 1.1.1.2 christos goto out; 1458 1.1 christos 1459 1.1.1.2 christos if (!TEST_true(helper_local_set_c_stream(hl, op->stream_name, c_stream))) 1460 1.1.1.2 christos goto out; 1461 1.1.1.2 christos } break; 1462 1.1 christos 1463 1.1.1.2 christos case OPK_C_ATTACH: { 1464 1.1.1.2 christos if (!TEST_ptr(c_tgt)) 1465 1.1.1.2 christos goto out; 1466 1.1 christos 1467 1.1.1.2 christos if (!TEST_ptr(op->stream_name)) 1468 1.1.1.2 christos goto out; 1469 1.1 christos 1470 1.1.1.2 christos if (!TEST_true(ossl_quic_attach_stream(h->c_conn, c_tgt))) 1471 1.1.1.2 christos goto out; 1472 1.1 christos 1473 1.1.1.2 christos if (!TEST_true(helper_local_set_c_stream(hl, op->stream_name, NULL))) 1474 1.1.1.2 christos goto out; 1475 1.1.1.2 christos } break; 1476 1.1 christos 1477 1.1.1.2 christos case OPK_C_NEW_STREAM: { 1478 1.1.1.2 christos SSL *c_stream; 1479 1.1.1.2 christos uint64_t flags = op->arg1; 1480 1.1.1.2 christos int allow_fail = ((flags & ALLOW_FAIL) != 0); 1481 1.1 christos 1482 1.1.1.2 christos flags &= ~(uint64_t)ALLOW_FAIL; 1483 1.1 christos 1484 1.1.1.2 christos if (!TEST_ptr_null(c_tgt)) 1485 1.1.1.2 christos goto out; /* don't overwrite existing stream with same name */ 1486 1.1 christos 1487 1.1.1.2 christos if (!TEST_ptr(op->stream_name)) 1488 1.1.1.2 christos goto out; 1489 1.1 christos 1490 1.1.1.2 christos c_stream = SSL_new_stream(h->c_conn, flags); 1491 1.1.1.2 christos if (!allow_fail && !TEST_ptr(c_stream)) 1492 1.1.1.2 christos goto out; 1493 1.1 christos 1494 1.1.1.2 christos if (allow_fail && c_stream == NULL) { 1495 1.1.1.2 christos if (!TEST_size_t_eq(ERR_GET_REASON(ERR_get_error()), 1496 1.1.1.2 christos SSL_R_STREAM_COUNT_LIMITED)) 1497 1.1 christos goto out; 1498 1.1 christos 1499 1.1.1.2 christos ++h->fail_count; 1500 1.1.1.2 christos break; 1501 1.1 christos } 1502 1.1 christos 1503 1.1.1.2 christos if (op->arg2 != UINT64_MAX 1504 1.1.1.2 christos && !TEST_uint64_t_eq(SSL_get_stream_id(c_stream), 1505 1.1.1.2 christos op->arg2)) 1506 1.1.1.2 christos goto out; 1507 1.1 christos 1508 1.1.1.2 christos if (!TEST_true(helper_local_set_c_stream(hl, op->stream_name, c_stream))) 1509 1.1.1.2 christos goto out; 1510 1.1.1.2 christos } break; 1511 1.1 christos 1512 1.1.1.2 christos case OPK_S_NEW_STREAM: { 1513 1.1.1.2 christos uint64_t stream_id = UINT64_MAX; 1514 1.1 christos 1515 1.1.1.2 christos if (!TEST_uint64_t_eq(s_stream_id, UINT64_MAX)) 1516 1.1.1.2 christos goto out; /* don't overwrite existing stream with same name */ 1517 1.1 christos 1518 1.1.1.2 christos if (!TEST_ptr(op->stream_name)) 1519 1.1.1.2 christos goto out; 1520 1.1 christos 1521 1.1.1.2 christos if (!TEST_true(ossl_quic_tserver_stream_new(ACQUIRE_S(), 1522 1.1.1.2 christos op->arg1 > 0, 1523 1.1.1.2 christos &stream_id))) 1524 1.1.1.2 christos goto out; 1525 1.1 christos 1526 1.1.1.2 christos if (op->arg2 != UINT64_MAX 1527 1.1.1.2 christos && !TEST_uint64_t_eq(stream_id, op->arg2)) 1528 1.1.1.2 christos goto out; 1529 1.1 christos 1530 1.1.1.2 christos if (!TEST_true(helper_set_s_stream(h, op->stream_name, 1531 1.1.1.2 christos stream_id))) 1532 1.1.1.2 christos goto out; 1533 1.1.1.2 christos } break; 1534 1.1 christos 1535 1.1.1.2 christos case OPK_C_ACCEPT_STREAM_WAIT: { 1536 1.1.1.2 christos SSL *c_stream; 1537 1.1 christos 1538 1.1.1.2 christos if (!TEST_ptr_null(c_tgt)) 1539 1.1.1.2 christos goto out; /* don't overwrite existing stream with same name */ 1540 1.1 christos 1541 1.1.1.2 christos if (!TEST_ptr(op->stream_name)) 1542 1.1.1.2 christos goto out; 1543 1.1 christos 1544 1.1.1.2 christos if ((c_stream = SSL_accept_stream(h->c_conn, 0)) == NULL) 1545 1.1.1.2 christos C_SPIN_AGAIN(); 1546 1.1 christos 1547 1.1.1.2 christos if (!TEST_true(helper_local_set_c_stream(hl, op->stream_name, 1548 1.1.1.2 christos c_stream))) 1549 1.1.1.2 christos goto out; 1550 1.1.1.2 christos } break; 1551 1.1 christos 1552 1.1.1.2 christos case OPK_S_ACCEPT_STREAM_WAIT: { 1553 1.1.1.2 christos uint64_t new_stream_id; 1554 1.1 christos 1555 1.1.1.2 christos if (!TEST_uint64_t_eq(s_stream_id, UINT64_MAX)) 1556 1.1.1.2 christos goto out; 1557 1.1 christos 1558 1.1.1.2 christos if (!TEST_ptr(op->stream_name)) 1559 1.1.1.2 christos goto out; 1560 1.1 christos 1561 1.1.1.2 christos new_stream_id = ossl_quic_tserver_pop_incoming_stream(ACQUIRE_S()); 1562 1.1.1.2 christos if (new_stream_id == UINT64_MAX) 1563 1.1.1.2 christos S_SPIN_AGAIN(); 1564 1.1 christos 1565 1.1.1.2 christos if (!TEST_true(helper_set_s_stream(h, op->stream_name, new_stream_id))) 1566 1.1.1.2 christos goto out; 1567 1.1.1.2 christos } break; 1568 1.1 christos 1569 1.1.1.2 christos case OPK_C_ACCEPT_STREAM_NONE: { 1570 1.1.1.2 christos SSL *c_stream; 1571 1.1 christos 1572 1.1.1.2 christos if (!TEST_ptr_null(c_stream = SSL_accept_stream(h->c_conn, 1573 1.1.1.2 christos SSL_ACCEPT_STREAM_NO_BLOCK))) { 1574 1.1.1.2 christos SSL_free(c_stream); 1575 1.1.1.2 christos goto out; 1576 1.1 christos } 1577 1.1.1.2 christos } break; 1578 1.1 christos 1579 1.1.1.2 christos case OPK_C_FREE_STREAM: { 1580 1.1.1.2 christos if (!TEST_ptr(c_tgt) 1581 1.1.1.2 christos || !TEST_true(!SSL_is_connection(c_tgt))) 1582 1.1.1.2 christos goto out; 1583 1.1 christos 1584 1.1.1.2 christos if (!TEST_ptr(op->stream_name)) 1585 1.1.1.2 christos goto out; 1586 1.1 christos 1587 1.1.1.2 christos if (!TEST_true(helper_local_set_c_stream(hl, op->stream_name, NULL))) 1588 1.1.1.2 christos goto out; 1589 1.1 christos 1590 1.1.1.2 christos SSL_free(c_tgt); 1591 1.1.1.2 christos c_tgt = NULL; 1592 1.1.1.2 christos } break; 1593 1.1 christos 1594 1.1.1.2 christos case OPK_C_SET_DEFAULT_STREAM_MODE: { 1595 1.1.1.2 christos if (!TEST_ptr(c_tgt)) 1596 1.1.1.2 christos goto out; 1597 1.1 christos 1598 1.1.1.2 christos if (!TEST_true(SSL_set_default_stream_mode(c_tgt, op->arg1))) 1599 1.1.1.2 christos goto out; 1600 1.1.1.2 christos } break; 1601 1.1 christos 1602 1.1.1.2 christos case OPK_C_SET_INCOMING_STREAM_POLICY: { 1603 1.1.1.2 christos if (!TEST_ptr(c_tgt)) 1604 1.1.1.2 christos goto out; 1605 1.1 christos 1606 1.1.1.2 christos if (!TEST_true(SSL_set_incoming_stream_policy(c_tgt, 1607 1.1.1.2 christos op->arg1, 0))) 1608 1.1.1.2 christos goto out; 1609 1.1.1.2 christos } break; 1610 1.1 christos 1611 1.1.1.2 christos case OPK_C_SHUTDOWN_WAIT: { 1612 1.1.1.2 christos int ret; 1613 1.1.1.2 christos QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn); 1614 1.1.1.2 christos SSL_SHUTDOWN_EX_ARGS args = { 0 }; 1615 1.1 christos 1616 1.1.1.2 christos ossl_quic_engine_set_inhibit_tick(ossl_quic_channel_get0_engine(ch), 0); 1617 1.1 christos 1618 1.1.1.2 christos if (!TEST_ptr(c_tgt)) 1619 1.1.1.2 christos goto out; 1620 1.1 christos 1621 1.1.1.2 christos args.quic_reason = (const char *)op->arg0; 1622 1.1 christos 1623 1.1.1.2 christos ret = SSL_shutdown_ex(c_tgt, op->arg1, &args, sizeof(args)); 1624 1.1.1.2 christos if (!TEST_int_ge(ret, 0)) 1625 1.1.1.2 christos goto out; 1626 1.1 christos 1627 1.1.1.2 christos if (ret == 0) 1628 1.1.1.2 christos C_SPIN_AGAIN(); 1629 1.1.1.2 christos } break; 1630 1.1.1.2 christos 1631 1.1.1.2 christos case OPK_S_SHUTDOWN: { 1632 1.1.1.2 christos ossl_quic_tserver_shutdown(ACQUIRE_S(), op->arg1); 1633 1.1.1.2 christos } break; 1634 1.1.1.2 christos 1635 1.1.1.2 christos case OPK_C_EXPECT_CONN_CLOSE_INFO: { 1636 1.1.1.2 christos SSL_CONN_CLOSE_INFO cc_info = { 0 }; 1637 1.1.1.2 christos int expect_app = (op->arg1 & EXPECT_CONN_CLOSE_APP) != 0; 1638 1.1.1.2 christos int expect_remote = (op->arg1 & EXPECT_CONN_CLOSE_REMOTE) != 0; 1639 1.1.1.2 christos uint64_t error_code = op->arg2; 1640 1.1 christos 1641 1.1.1.2 christos if (!TEST_ptr(c_tgt)) 1642 1.1.1.2 christos goto out; 1643 1.1 christos 1644 1.1.1.2 christos if (h->blocking 1645 1.1.1.2 christos && !TEST_true(SSL_shutdown_ex(c_tgt, 1646 1.1.1.2 christos SSL_SHUTDOWN_FLAG_WAIT_PEER, 1647 1.1.1.2 christos NULL, 0))) 1648 1.1.1.2 christos goto out; 1649 1.1 christos 1650 1.1.1.2 christos if (!SSL_get_conn_close_info(c_tgt, &cc_info, sizeof(cc_info))) 1651 1.1.1.2 christos C_SPIN_AGAIN(); 1652 1.1 christos 1653 1.1.1.2 christos if (!TEST_int_eq(expect_app, 1654 1.1.1.2 christos (cc_info.flags 1655 1.1.1.2 christos & SSL_CONN_CLOSE_FLAG_TRANSPORT) 1656 1.1.1.2 christos == 0) 1657 1.1.1.2 christos || !TEST_int_eq(expect_remote, 1658 1.1.1.2 christos (cc_info.flags 1659 1.1.1.2 christos & SSL_CONN_CLOSE_FLAG_LOCAL) 1660 1.1.1.2 christos == 0) 1661 1.1.1.2 christos || !TEST_uint64_t_eq(error_code, cc_info.error_code)) { 1662 1.1.1.2 christos TEST_info("Connection close reason: %s", cc_info.reason); 1663 1.1.1.2 christos goto out; 1664 1.1.1.2 christos } 1665 1.1.1.2 christos } break; 1666 1.1 christos 1667 1.1.1.2 christos case OPK_S_EXPECT_CONN_CLOSE_INFO: { 1668 1.1.1.2 christos const QUIC_TERMINATE_CAUSE *tc; 1669 1.1.1.2 christos int expect_app = (op->arg1 & EXPECT_CONN_CLOSE_APP) != 0; 1670 1.1.1.2 christos int expect_remote = (op->arg1 & EXPECT_CONN_CLOSE_REMOTE) != 0; 1671 1.1.1.2 christos uint64_t error_code = op->arg2; 1672 1.1.1.2 christos 1673 1.1.1.2 christos if (!ossl_quic_tserver_is_term_any(ACQUIRE_S())) { 1674 1.1.1.2 christos ossl_quic_tserver_ping(ACQUIRE_S()); 1675 1.1.1.2 christos S_SPIN_AGAIN(); 1676 1.1 christos } 1677 1.1 christos 1678 1.1.1.2 christos if (!TEST_ptr(tc = ossl_quic_tserver_get_terminate_cause(ACQUIRE_S()))) 1679 1.1.1.2 christos goto out; 1680 1.1 christos 1681 1.1.1.2 christos if (!TEST_uint64_t_eq(error_code, tc->error_code) 1682 1.1.1.2 christos || !TEST_int_eq(expect_app, tc->app) 1683 1.1.1.2 christos || !TEST_int_eq(expect_remote, tc->remote)) 1684 1.1.1.2 christos goto out; 1685 1.1.1.2 christos } break; 1686 1.1 christos 1687 1.1.1.2 christos case OPK_S_BIND_STREAM_ID: { 1688 1.1.1.2 christos if (!TEST_uint64_t_eq(s_stream_id, UINT64_MAX)) 1689 1.1.1.2 christos goto out; 1690 1.1 christos 1691 1.1.1.2 christos if (!TEST_ptr(op->stream_name)) 1692 1.1.1.2 christos goto out; 1693 1.1 christos 1694 1.1.1.2 christos if (!TEST_true(helper_set_s_stream(h, op->stream_name, op->arg2))) 1695 1.1.1.2 christos goto out; 1696 1.1.1.2 christos } break; 1697 1.1 christos 1698 1.1.1.2 christos case OPK_S_UNBIND_STREAM_ID: { 1699 1.1.1.2 christos if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) 1700 1.1.1.2 christos goto out; 1701 1.1 christos 1702 1.1.1.2 christos if (!TEST_ptr(op->stream_name)) 1703 1.1.1.2 christos goto out; 1704 1.1 christos 1705 1.1.1.2 christos if (!TEST_true(helper_set_s_stream(h, op->stream_name, UINT64_MAX))) 1706 1.1.1.2 christos goto out; 1707 1.1.1.2 christos } break; 1708 1.1 christos 1709 1.1.1.2 christos case OPK_C_WRITE_FAIL: { 1710 1.1.1.2 christos size_t bytes_written = 0; 1711 1.1.1.2 christos int r; 1712 1.1 christos 1713 1.1.1.2 christos if (!TEST_ptr(c_tgt)) 1714 1.1.1.2 christos goto out; 1715 1.1 christos 1716 1.1.1.2 christos r = SSL_write_ex(c_tgt, "apple", 5, &bytes_written); 1717 1.1.1.2 christos if (!TEST_false(r) 1718 1.1.1.2 christos || !check_consistent_want(c_tgt, r)) 1719 1.1.1.2 christos goto out; 1720 1.1.1.2 christos } break; 1721 1.1 christos 1722 1.1.1.2 christos case OPK_S_WRITE_FAIL: { 1723 1.1.1.2 christos size_t bytes_written = 0; 1724 1.1 christos 1725 1.1.1.2 christos if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) 1726 1.1.1.2 christos goto out; 1727 1.1 christos 1728 1.1.1.2 christos if (!TEST_false(ossl_quic_tserver_write(ACQUIRE_S(), s_stream_id, 1729 1.1.1.2 christos (const unsigned char *)"apple", 5, 1730 1.1.1.2 christos &bytes_written))) 1731 1.1.1.2 christos goto out; 1732 1.1.1.2 christos } break; 1733 1.1 christos 1734 1.1.1.2 christos case OPK_C_READ_FAIL: { 1735 1.1.1.2 christos size_t bytes_read = 0; 1736 1.1.1.2 christos char buf[1]; 1737 1.1.1.2 christos int r; 1738 1.1 christos 1739 1.1.1.2 christos if (!TEST_ptr(c_tgt)) 1740 1.1.1.2 christos goto out; 1741 1.1 christos 1742 1.1.1.2 christos r = SSL_read_ex(c_tgt, buf, sizeof(buf), &bytes_read); 1743 1.1.1.2 christos if (!TEST_false(r)) 1744 1.1.1.2 christos goto out; 1745 1.1.1.2 christos if (!check_consistent_want(c_tgt, r)) 1746 1.1.1.2 christos goto out; 1747 1.1.1.2 christos } break; 1748 1.1 christos 1749 1.1.1.2 christos case OPK_C_READ_FAIL_WAIT: { 1750 1.1.1.2 christos size_t bytes_read = 0; 1751 1.1.1.2 christos char buf[1]; 1752 1.1.1.2 christos int r; 1753 1.1 christos 1754 1.1.1.2 christos if (!TEST_ptr(c_tgt)) 1755 1.1.1.2 christos goto out; 1756 1.1.1.2 christos 1757 1.1.1.2 christos r = SSL_read_ex(c_tgt, buf, sizeof(buf), &bytes_read); 1758 1.1.1.2 christos if (!TEST_false(r)) 1759 1.1.1.2 christos goto out; 1760 1.1.1.2 christos if (!check_consistent_want(c_tgt, r)) 1761 1.1.1.2 christos goto out; 1762 1.1 christos 1763 1.1.1.2 christos if (is_want(c_tgt, 0)) 1764 1.1.1.2 christos C_SPIN_AGAIN(); 1765 1.1.1.2 christos } break; 1766 1.1.1.2 christos 1767 1.1.1.2 christos case OPK_S_READ_FAIL: { 1768 1.1.1.2 christos int ret; 1769 1.1.1.2 christos size_t bytes_read = 0; 1770 1.1.1.2 christos unsigned char buf[1]; 1771 1.1 christos 1772 1.1.1.2 christos if (!TEST_uint64_t_ne(s_stream_id, UINT64_MAX)) 1773 1.1.1.2 christos goto out; 1774 1.1 christos 1775 1.1.1.2 christos ret = ossl_quic_tserver_read(ACQUIRE_S(), s_stream_id, 1776 1.1.1.2 christos buf, sizeof(buf), 1777 1.1.1.2 christos &bytes_read); 1778 1.1.1.2 christos if (!TEST_true(ret == 0 || (op->arg1 && bytes_read == 0))) 1779 1.1.1.2 christos goto out; 1780 1.1.1.2 christos } break; 1781 1.1 christos 1782 1.1 christos case OPK_C_STREAM_RESET: 1783 1.1.1.2 christos case OPK_C_STREAM_RESET_FAIL: { 1784 1.1.1.2 christos SSL_STREAM_RESET_ARGS args = { 0 }; 1785 1.1 christos 1786 1.1.1.2 christos if (!TEST_ptr(c_tgt)) 1787 1.1.1.2 christos goto out; 1788 1.1 christos 1789 1.1.1.2 christos args.quic_error_code = op->arg2; 1790 1.1.1.2 christos if (op->op == OPK_C_STREAM_RESET) { 1791 1.1.1.2 christos if (!TEST_true(SSL_stream_reset(c_tgt, &args, sizeof(args)))) 1792 1.1.1.2 christos goto out; 1793 1.1.1.2 christos } else { 1794 1.1.1.2 christos if (!TEST_false(SSL_stream_reset(c_tgt, &args, sizeof(args)))) 1795 1.1.1.2 christos goto out; 1796 1.1 christos } 1797 1.1.1.2 christos } break; 1798 1.1 christos 1799 1.1.1.2 christos case OPK_NEW_THREAD: { 1800 1.1 christos #if !defined(OPENSSL_THREADS) 1801 1.1.1.2 christos /* 1802 1.1.1.2 christos * If this test script requires threading and we do not have 1803 1.1.1.2 christos * support for it, skip the rest of it. 1804 1.1.1.2 christos */ 1805 1.1.1.2 christos TEST_skip("threading not supported, skipping"); 1806 1.1.1.2 christos testresult = 1; 1807 1.1.1.2 christos goto out; 1808 1.1 christos #else 1809 1.1.1.2 christos size_t i; 1810 1.1 christos 1811 1.1.1.2 christos if (!TEST_ptr_null(h->threads)) { 1812 1.1.1.2 christos TEST_error("max one NEW_THREAD operation per script"); 1813 1.1.1.2 christos goto out; 1814 1.1.1.2 christos } 1815 1.1 christos 1816 1.1.1.2 christos h->threads = OPENSSL_zalloc(op->arg1 * sizeof(struct child_thread_args)); 1817 1.1.1.2 christos if (!TEST_ptr(h->threads)) 1818 1.1.1.2 christos goto out; 1819 1.1 christos 1820 1.1.1.2 christos h->num_threads = op->arg1; 1821 1.1 christos 1822 1.1.1.2 christos for (i = 0; i < op->arg1; ++i) { 1823 1.1.1.2 christos h->threads[i].h = h; 1824 1.1.1.2 christos h->threads[i].script = op->arg0; 1825 1.1.1.2 christos h->threads[i].script_name = script_name; 1826 1.1.1.2 christos h->threads[i].thread_idx = i; 1827 1.1.1.2 christos 1828 1.1.1.2 christos h->threads[i].m = ossl_crypto_mutex_new(); 1829 1.1.1.2 christos if (!TEST_ptr(h->threads[i].m)) 1830 1.1.1.2 christos goto out; 1831 1.1.1.2 christos 1832 1.1.1.2 christos h->threads[i].t 1833 1.1.1.2 christos = ossl_crypto_thread_native_start(run_script_child_thread, 1834 1.1.1.2 christos &h->threads[i], 1); 1835 1.1.1.2 christos if (!TEST_ptr(h->threads[i].t)) 1836 1.1.1.2 christos goto out; 1837 1.1 christos } 1838 1.1.1.2 christos #endif 1839 1.1.1.2 christos } break; 1840 1.1 christos 1841 1.1.1.2 christos case OPK_C_CLOSE_SOCKET: { 1842 1.1.1.2 christos BIO_closesocket(h->c_fd); 1843 1.1.1.2 christos h->c_fd = -1; 1844 1.1.1.2 christos } break; 1845 1.1 christos 1846 1.1.1.2 christos case OPK_C_EXPECT_SSL_ERR: { 1847 1.1.1.2 christos if (!TEST_size_t_eq((size_t)SSL_get_error(c_tgt, 0), op->arg1)) 1848 1.1.1.2 christos goto out; 1849 1.1.1.2 christos if (!TEST_int_eq(SSL_want(c_tgt), SSL_NOTHING)) 1850 1.1.1.2 christos goto out; 1851 1.1.1.2 christos } break; 1852 1.1 christos 1853 1.1.1.2 christos case OPK_EXPECT_ERR_REASON: { 1854 1.1.1.2 christos if (!TEST_size_t_eq((size_t)ERR_GET_REASON(ERR_peek_last_error()), op->arg1)) 1855 1.1.1.2 christos goto out; 1856 1.1.1.2 christos } break; 1857 1.1 christos 1858 1.1.1.2 christos case OPK_EXPECT_ERR_LIB: { 1859 1.1.1.2 christos if (!TEST_size_t_eq((size_t)ERR_GET_LIB(ERR_peek_last_error()), op->arg1)) 1860 1.1.1.2 christos goto out; 1861 1.1.1.2 christos } break; 1862 1.1 christos 1863 1.1 christos case OPK_POP_ERR: 1864 1.1 christos ERR_pop(); 1865 1.1 christos break; 1866 1.1 christos 1867 1.1.1.2 christos case OPK_SLEEP: { 1868 1.1.1.2 christos OSSL_sleep(op->arg2); 1869 1.1.1.2 christos } break; 1870 1.1 christos 1871 1.1 christos case OPK_S_SET_INJECT_PLAIN: 1872 1.1 christos h->qtf_packet_plain_cb = op->qtf_packet_plain_cb; 1873 1.1 christos 1874 1.1 christos if (!TEST_true(qtest_fault_set_packet_plain_listener(h->qtf, 1875 1.1.1.2 christos h->qtf_packet_plain_cb != NULL ? helper_packet_plain_listener : NULL, 1876 1.1.1.2 christos h))) 1877 1.1 christos goto out; 1878 1.1 christos 1879 1.1 christos break; 1880 1.1 christos 1881 1.1 christos case OPK_S_SET_INJECT_HANDSHAKE: 1882 1.1 christos h->qtf_handshake_cb = op->qtf_handshake_cb; 1883 1.1 christos 1884 1.1 christos if (!TEST_true(qtest_fault_set_handshake_listener(h->qtf, 1885 1.1.1.2 christos h->qtf_handshake_cb != NULL ? helper_handshake_listener : NULL, 1886 1.1.1.2 christos h))) 1887 1.1 christos goto out; 1888 1.1 christos 1889 1.1 christos break; 1890 1.1 christos 1891 1.1 christos case OPK_S_SET_INJECT_DATAGRAM: 1892 1.1 christos h->qtf_datagram_cb = op->qtf_datagram_cb; 1893 1.1 christos 1894 1.1 christos if (!TEST_true(qtest_fault_set_datagram_listener(h->qtf, 1895 1.1.1.2 christos h->qtf_datagram_cb != NULL ? helper_datagram_listener : NULL, 1896 1.1.1.2 christos h))) 1897 1.1 christos goto out; 1898 1.1 christos 1899 1.1 christos break; 1900 1.1 christos 1901 1.1 christos case OPK_SET_INJECT_WORD: 1902 1.1 christos /* 1903 1.1 christos * Must hold server tick lock - callbacks can be called from other 1904 1.1 christos * thread when running test in blocking mode (tsan). 1905 1.1 christos */ 1906 1.1 christos ACQUIRE_S(); 1907 1.1 christos h->inject_word0 = op->arg1; 1908 1.1 christos h->inject_word1 = op->arg2; 1909 1.1 christos break; 1910 1.1 christos 1911 1.1.1.2 christos case OPK_C_INHIBIT_TICK: { 1912 1.1.1.2 christos QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn); 1913 1.1 christos 1914 1.1.1.2 christos ossl_quic_engine_set_inhibit_tick(ossl_quic_channel_get0_engine(ch), 1915 1.1.1.2 christos op->arg1); 1916 1.1.1.2 christos } break; 1917 1.1 christos 1918 1.1 christos case OPK_C_SET_WRITE_BUF_SIZE: 1919 1.1 christos if (!TEST_ptr(c_tgt)) 1920 1.1 christos goto out; 1921 1.1 christos 1922 1.1 christos if (!TEST_true(ossl_quic_set_write_buffer_size(c_tgt, op->arg1))) 1923 1.1 christos goto out; 1924 1.1 christos 1925 1.1 christos break; 1926 1.1 christos 1927 1.1 christos case OPK_S_NEW_TICKET: 1928 1.1 christos if (!TEST_true(ossl_quic_tserver_new_ticket(ACQUIRE_S()))) 1929 1.1 christos goto out; 1930 1.1 christos break; 1931 1.1 christos 1932 1.1 christos default: 1933 1.1 christos TEST_error("unknown op"); 1934 1.1 christos goto out; 1935 1.1 christos } 1936 1.1 christos } 1937 1.1 christos 1938 1.1 christos out: 1939 1.1 christos s_unlock(h, hl); /* idempotent */ 1940 1.1 christos if (!testresult) { 1941 1.1 christos size_t i; 1942 1.1 christos const QUIC_TERMINATE_CAUSE *tcause; 1943 1.1 christos const char *e_str, *f_str; 1944 1.1 christos 1945 1.1 christos TEST_error("failed in script \"%s\" at op %zu, thread %d\n", 1946 1.1.1.2 christos script_name, op_idx + 1, thread_idx); 1947 1.1 christos 1948 1.1 christos for (i = 0; i < repeat_stack_len; ++i) 1949 1.1 christos TEST_info("while repeating, iteration %zu of %zu, starting at script op %zu", 1950 1.1.1.2 christos repeat_stack_done[i], 1951 1.1.1.2 christos repeat_stack_limit[i], 1952 1.1.1.2 christos repeat_stack_idx[i]); 1953 1.1 christos 1954 1.1 christos ERR_print_errors_fp(stderr); 1955 1.1 christos 1956 1.1 christos if (h->c_conn != NULL) { 1957 1.1.1.2 christos SSL_CONN_CLOSE_INFO cc_info = { 0 }; 1958 1.1 christos 1959 1.1 christos if (SSL_get_conn_close_info(h->c_conn, &cc_info, sizeof(cc_info))) { 1960 1.1 christos e_str = ossl_quic_err_to_string(cc_info.error_code); 1961 1.1 christos f_str = ossl_quic_frame_type_to_string(cc_info.frame_type); 1962 1.1 christos 1963 1.1 christos if (e_str == NULL) 1964 1.1 christos e_str = "?"; 1965 1.1 christos if (f_str == NULL) 1966 1.1 christos f_str = "?"; 1967 1.1 christos 1968 1.1 christos TEST_info("client side is closed: %llu(%s)/%llu(%s), " 1969 1.1 christos "%s, %s, reason: \"%s\"", 1970 1.1.1.2 christos (unsigned long long)cc_info.error_code, 1971 1.1.1.2 christos e_str, 1972 1.1.1.2 christos (unsigned long long)cc_info.frame_type, 1973 1.1.1.2 christos f_str, 1974 1.1.1.2 christos (cc_info.flags & SSL_CONN_CLOSE_FLAG_LOCAL) != 0 1975 1.1.1.2 christos ? "local" 1976 1.1.1.2 christos : "remote", 1977 1.1.1.2 christos (cc_info.flags & SSL_CONN_CLOSE_FLAG_TRANSPORT) != 0 1978 1.1.1.2 christos ? "transport" 1979 1.1.1.2 christos : "app", 1980 1.1.1.2 christos cc_info.reason != NULL ? cc_info.reason : "-"); 1981 1.1 christos } 1982 1.1 christos } 1983 1.1 christos 1984 1.1 christos tcause = (h->s != NULL 1985 1.1.1.2 christos ? ossl_quic_tserver_get_terminate_cause(h->s) 1986 1.1.1.2 christos : NULL); 1987 1.1 christos if (tcause != NULL) { 1988 1.1 christos e_str = ossl_quic_err_to_string(tcause->error_code); 1989 1.1 christos f_str = ossl_quic_frame_type_to_string(tcause->frame_type); 1990 1.1 christos 1991 1.1 christos if (e_str == NULL) 1992 1.1 christos e_str = "?"; 1993 1.1 christos if (f_str == NULL) 1994 1.1 christos f_str = "?"; 1995 1.1 christos 1996 1.1 christos TEST_info("server side is closed: %llu(%s)/%llu(%s), " 1997 1.1.1.2 christos "%s, %s, reason: \"%s\"", 1998 1.1.1.2 christos (unsigned long long)tcause->error_code, 1999 1.1.1.2 christos e_str, 2000 1.1.1.2 christos (unsigned long long)tcause->frame_type, 2001 1.1.1.2 christos f_str, 2002 1.1.1.2 christos tcause->remote ? "remote" : "local", 2003 1.1.1.2 christos tcause->app ? "app" : "transport", 2004 1.1.1.2 christos tcause->reason != NULL ? tcause->reason : "-"); 2005 1.1 christos } 2006 1.1 christos } 2007 1.1 christos 2008 1.1 christos OPENSSL_free(tmp_buf); 2009 1.1 christos helper_local_cleanup(hl); 2010 1.1 christos return testresult; 2011 1.1 christos } 2012 1.1 christos 2013 1.1 christos static int run_script(const struct script_op *script, 2014 1.1.1.2 christos const char *script_name, 2015 1.1.1.2 christos int free_order, 2016 1.1.1.2 christos int blocking) 2017 1.1 christos { 2018 1.1 christos int testresult = 0; 2019 1.1 christos struct helper h; 2020 1.1 christos 2021 1.1 christos if (!TEST_true(helper_init(&h, script_name, 2022 1.1.1.2 christos free_order, blocking, 1))) 2023 1.1 christos goto out; 2024 1.1 christos 2025 1.1 christos if (!TEST_true(run_script_worker(&h, script, script_name, -1))) 2026 1.1 christos goto out; 2027 1.1 christos 2028 1.1 christos #if defined(OPENSSL_THREADS) 2029 1.1 christos if (!TEST_true(join_threads(h.threads, h.num_threads))) 2030 1.1 christos goto out; 2031 1.1 christos #endif 2032 1.1 christos 2033 1.1 christos testresult = 1; 2034 1.1 christos out: 2035 1.1 christos helper_cleanup(&h); 2036 1.1 christos return testresult; 2037 1.1 christos } 2038 1.1 christos 2039 1.1 christos #if defined(OPENSSL_THREADS) 2040 1.1 christos static CRYPTO_THREAD_RETVAL run_script_child_thread(void *arg) 2041 1.1 christos { 2042 1.1 christos int testresult; 2043 1.1 christos struct child_thread_args *args = arg; 2044 1.1 christos 2045 1.1 christos testresult = run_script_worker(args->h, args->script, 2046 1.1.1.2 christos args->script_name, 2047 1.1.1.2 christos args->thread_idx); 2048 1.1 christos 2049 1.1 christos ossl_crypto_mutex_lock(args->m); 2050 1.1.1.2 christos args->testresult = testresult; 2051 1.1.1.2 christos args->done = 1; 2052 1.1 christos ossl_crypto_mutex_unlock(args->m); 2053 1.1 christos return 1; 2054 1.1 christos } 2055 1.1 christos #endif 2056 1.1 christos 2057 1.1 christos /* 1. Simple single-stream test */ 2058 1.1 christos static const struct script_op script_1[] = { 2059 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2060 1.1.1.2 christos OP_C_CONNECT_WAIT() 2061 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 2062 1.1.1.2 christos OP_C_CONCLUDE(DEFAULT) 2063 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 2064 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 2065 1.1.1.2 christos OP_S_EXPECT_FIN(a) 2066 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 2067 1.1.1.2 christos OP_S_CONCLUDE(a) 2068 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "orange", 6) 2069 1.1.1.2 christos OP_C_EXPECT_FIN(DEFAULT) 2070 1.1.1.2 christos OP_END 2071 1.1 christos }; 2072 1.1 christos 2073 1.1 christos /* 2. Multi-stream test */ 2074 1.1 christos static const struct script_op script_2[] = { 2075 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2076 1.1.1.2 christos OP_C_CONNECT_WAIT() 2077 1.1.1.2 christos OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_ACCEPT) 2078 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 2079 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 2080 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 2081 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 2082 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "orange", 6) 2083 1.1.1.2 christos 2084 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(b, C_BIDI_ID(1)) 2085 1.1.1.2 christos OP_C_WRITE(b, "flamingo", 8) 2086 1.1.1.2 christos OP_C_CONCLUDE(b) 2087 1.1.1.2 christos OP_S_BIND_STREAM_ID(b, C_BIDI_ID(1)) 2088 1.1.1.2 christos OP_S_READ_EXPECT(b, "flamingo", 8) 2089 1.1.1.2 christos OP_S_EXPECT_FIN(b) 2090 1.1.1.2 christos OP_S_WRITE(b, "gargoyle", 8) 2091 1.1.1.2 christos OP_S_CONCLUDE(b) 2092 1.1.1.2 christos OP_C_READ_EXPECT(b, "gargoyle", 8) 2093 1.1.1.2 christos OP_C_EXPECT_FIN(b) 2094 1.1.1.2 christos 2095 1.1.1.2 christos OP_C_NEW_STREAM_UNI(c, C_UNI_ID(0)) 2096 1.1.1.2 christos OP_C_WRITE(c, "elephant", 8) 2097 1.1.1.2 christos OP_C_CONCLUDE(c) 2098 1.1.1.2 christos OP_S_BIND_STREAM_ID(c, C_UNI_ID(0)) 2099 1.1.1.2 christos OP_S_READ_EXPECT(c, "elephant", 8) 2100 1.1.1.2 christos OP_S_EXPECT_FIN(c) 2101 1.1.1.2 christos OP_S_WRITE_FAIL(c) 2102 1.1.1.2 christos 2103 1.1.1.2 christos OP_C_ACCEPT_STREAM_NONE() 2104 1.1.1.2 christos 2105 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(d, S_BIDI_ID(0)) 2106 1.1.1.2 christos OP_S_WRITE(d, "frog", 4) 2107 1.1.1.2 christos OP_S_CONCLUDE(d) 2108 1.1.1.2 christos 2109 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(d) 2110 1.1.1.2 christos OP_C_ACCEPT_STREAM_NONE() 2111 1.1.1.2 christos OP_C_READ_EXPECT(d, "frog", 4) 2112 1.1.1.2 christos OP_C_EXPECT_FIN(d) 2113 1.1.1.2 christos 2114 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(e, S_BIDI_ID(1)) 2115 1.1.1.2 christos OP_S_WRITE(e, "mixture", 7) 2116 1.1.1.2 christos OP_S_CONCLUDE(e) 2117 1.1.1.2 christos 2118 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(e) 2119 1.1.1.2 christos OP_C_READ_EXPECT(e, "mixture", 7) 2120 1.1.1.2 christos OP_C_EXPECT_FIN(e) 2121 1.1.1.2 christos OP_C_WRITE(e, "ramble", 6) 2122 1.1.1.2 christos OP_S_READ_EXPECT(e, "ramble", 6) 2123 1.1.1.2 christos OP_C_CONCLUDE(e) 2124 1.1.1.2 christos OP_S_EXPECT_FIN(e) 2125 1.1.1.2 christos 2126 1.1.1.2 christos OP_S_NEW_STREAM_UNI(f, S_UNI_ID(0)) 2127 1.1.1.2 christos OP_S_WRITE(f, "yonder", 6) 2128 1.1.1.2 christos OP_S_CONCLUDE(f) 2129 1.1.1.2 christos 2130 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(f) 2131 1.1.1.2 christos OP_C_ACCEPT_STREAM_NONE() 2132 1.1.1.2 christos OP_C_READ_EXPECT(f, "yonder", 6) 2133 1.1.1.2 christos OP_C_EXPECT_FIN(f) 2134 1.1.1.2 christos OP_C_WRITE_FAIL(f) 2135 1.1.1.2 christos 2136 1.1.1.2 christos OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_REJECT) 2137 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(g, S_BIDI_ID(2)) 2138 1.1.1.2 christos OP_S_WRITE(g, "unseen", 6) 2139 1.1.1.2 christos OP_S_CONCLUDE(g) 2140 1.1.1.2 christos 2141 1.1.1.2 christos OP_C_ACCEPT_STREAM_NONE() 2142 1.1.1.2 christos 2143 1.1.1.2 christos OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_AUTO) 2144 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(h, S_BIDI_ID(3)) 2145 1.1.1.2 christos OP_S_WRITE(h, "UNSEEN", 6) 2146 1.1.1.2 christos OP_S_CONCLUDE(h) 2147 1.1 christos 2148 1.1.1.2 christos OP_C_ACCEPT_STREAM_NONE() 2149 1.1 christos 2150 1.1 christos /* 2151 1.1 christos * Streams g, h should have been rejected, so server should have got 2152 1.1 christos * STOP_SENDING/RESET_STREAM. 2153 1.1 christos */ 2154 1.1.1.2 christos OP_CHECK(check_rejected, S_BIDI_ID(2)) 2155 1.1.1.2 christos OP_CHECK(check_rejected, S_BIDI_ID(3)) 2156 1.1 christos 2157 1.1.1.2 christos OP_END 2158 1.1 christos }; 2159 1.1 christos 2160 1.1 christos /* 3. Default stream detach/reattach test */ 2161 1.1 christos static const struct script_op script_3[] = { 2162 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2163 1.1.1.2 christos OP_C_CONNECT_WAIT() 2164 1.1 christos 2165 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 2166 1.1.1.2 christos OP_C_DETACH(a) /* DEFAULT becomes stream 'a' */ 2167 1.1.1.2 christos OP_C_WRITE_FAIL(DEFAULT) 2168 1.1 christos 2169 1.1.1.2 christos OP_C_WRITE(a, "by", 2) 2170 1.1 christos 2171 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 2172 1.1.1.2 christos OP_S_READ_EXPECT(a, "appleby", 7) 2173 1.1 christos 2174 1.1.1.2 christos OP_S_WRITE(a, "hello", 5) 2175 1.1.1.2 christos OP_C_READ_EXPECT(a, "hello", 5) 2176 1.1 christos 2177 1.1.1.2 christos OP_C_WRITE_FAIL(DEFAULT) 2178 1.1.1.2 christos OP_C_ATTACH(a) 2179 1.1.1.2 christos OP_C_WRITE(DEFAULT, "is here", 7) 2180 1.1.1.2 christos OP_S_READ_EXPECT(a, "is here", 7) 2181 1.1 christos 2182 1.1.1.2 christos OP_C_DETACH(a) 2183 1.1.1.2 christos OP_C_CONCLUDE(a) 2184 1.1.1.2 christos OP_S_EXPECT_FIN(a) 2185 1.1 christos 2186 1.1.1.2 christos OP_END 2187 1.1 christos }; 2188 1.1 christos 2189 1.1 christos /* 4. Default stream mode test */ 2190 1.1 christos static const struct script_op script_4[] = { 2191 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2192 1.1.1.2 christos OP_C_CONNECT_WAIT() 2193 1.1 christos 2194 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 2195 1.1.1.2 christos OP_C_WRITE_FAIL(DEFAULT) 2196 1.1 christos 2197 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(a, S_BIDI_ID(0)) 2198 1.1.1.2 christos OP_S_WRITE(a, "apple", 5) 2199 1.1 christos 2200 1.1.1.2 christos OP_C_READ_FAIL(DEFAULT) 2201 1.1 christos 2202 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(a) 2203 1.1.1.2 christos OP_C_READ_EXPECT(a, "apple", 5) 2204 1.1 christos 2205 1.1.1.2 christos OP_C_ATTACH(a) 2206 1.1.1.2 christos OP_C_WRITE(DEFAULT, "orange", 6) 2207 1.1.1.2 christos OP_S_READ_EXPECT(a, "orange", 6) 2208 1.1 christos 2209 1.1.1.2 christos OP_END 2210 1.1 christos }; 2211 1.1 christos 2212 1.1 christos /* 5. Test stream reset functionality */ 2213 1.1 christos static const struct script_op script_5[] = { 2214 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2215 1.1.1.2 christos OP_C_CONNECT_WAIT() 2216 1.1 christos 2217 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 2218 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 2219 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(b, C_BIDI_ID(1)) 2220 1.1 christos 2221 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 2222 1.1.1.2 christos OP_C_STREAM_RESET(a, 42) 2223 1.1 christos 2224 1.1.1.2 christos OP_C_WRITE(b, "strawberry", 10) 2225 1.1 christos 2226 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 2227 1.1.1.2 christos OP_S_BIND_STREAM_ID(b, C_BIDI_ID(1)) 2228 1.1.1.2 christos OP_S_READ_EXPECT(b, "strawberry", 10) 2229 1.1 christos /* Reset disrupts read of already sent data */ 2230 1.1.1.2 christos OP_S_READ_FAIL(a, 0) 2231 1.1.1.2 christos OP_CHECK(check_stream_reset, C_BIDI_ID(0)) 2232 1.1 christos 2233 1.1.1.2 christos OP_END 2234 1.1 christos }; 2235 1.1 christos 2236 1.1 christos /* 6. Test STOP_SENDING functionality */ 2237 1.1 christos static const struct script_op script_6[] = { 2238 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2239 1.1.1.2 christos OP_C_CONNECT_WAIT() 2240 1.1 christos 2241 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 2242 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(a, S_BIDI_ID(0)) 2243 1.1.1.2 christos OP_S_WRITE(a, "apple", 5) 2244 1.1 christos 2245 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(a) 2246 1.1.1.2 christos OP_C_FREE_STREAM(a) 2247 1.1.1.2 christos OP_C_ACCEPT_STREAM_NONE() 2248 1.1 christos 2249 1.1.1.2 christos OP_CHECK(check_stream_stopped, S_BIDI_ID(0)) 2250 1.1 christos 2251 1.1.1.2 christos OP_END 2252 1.1 christos }; 2253 1.1 christos 2254 1.1 christos /* 7. Unidirectional default stream mode test (client sends first) */ 2255 1.1 christos static const struct script_op script_7[] = { 2256 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2257 1.1.1.2 christos OP_C_CONNECT_WAIT() 2258 1.1 christos 2259 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI) 2260 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 2261 1.1 christos 2262 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_UNI_ID(0)) 2263 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 2264 1.1.1.2 christos OP_S_WRITE_FAIL(a) 2265 1.1 christos 2266 1.1.1.2 christos OP_END 2267 1.1 christos }; 2268 1.1 christos 2269 1.1 christos /* 8. Unidirectional default stream mode test (server sends first) */ 2270 1.1 christos static const struct script_op script_8[] = { 2271 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2272 1.1.1.2 christos OP_C_CONNECT_WAIT() 2273 1.1 christos 2274 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI) 2275 1.1.1.2 christos OP_S_NEW_STREAM_UNI(a, S_UNI_ID(0)) 2276 1.1.1.2 christos OP_S_WRITE(a, "apple", 5) 2277 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "apple", 5) 2278 1.1.1.2 christos OP_C_WRITE_FAIL(DEFAULT) 2279 1.1 christos 2280 1.1.1.2 christos OP_END 2281 1.1 christos }; 2282 1.1 christos 2283 1.1 christos /* 9. Unidirectional default stream mode test (server sends first on bidi) */ 2284 1.1 christos static const struct script_op script_9[] = { 2285 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2286 1.1.1.2 christos OP_C_CONNECT_WAIT() 2287 1.1 christos 2288 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_AUTO_UNI) 2289 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(a, S_BIDI_ID(0)) 2290 1.1.1.2 christos OP_S_WRITE(a, "apple", 5) 2291 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "apple", 5) 2292 1.1.1.2 christos OP_C_WRITE(DEFAULT, "orange", 6) 2293 1.1.1.2 christos OP_S_READ_EXPECT(a, "orange", 6) 2294 1.1 christos 2295 1.1.1.2 christos OP_END 2296 1.1 christos }; 2297 1.1 christos 2298 1.1 christos /* 10. Shutdown */ 2299 1.1 christos static const struct script_op script_10[] = { 2300 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2301 1.1.1.2 christos OP_C_CONNECT_WAIT() 2302 1.1 christos 2303 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 2304 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 2305 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 2306 1.1.1.2 christos 2307 1.1.1.2 christos OP_C_SHUTDOWN_WAIT(NULL, 0) 2308 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(0, 1, 0) 2309 1.1.1.2 christos OP_S_EXPECT_CONN_CLOSE_INFO(0, 1, 1) 2310 1.1 christos 2311 1.1.1.2 christos OP_END 2312 1.1 christos }; 2313 1.1 christos 2314 1.1 christos /* 11. Many threads accepted on the same client connection */ 2315 1.1 christos static const struct script_op script_11_child[] = { 2316 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(a) 2317 1.1.1.2 christos OP_C_READ_EXPECT(a, "foo", 3) 2318 1.1.1.2 christos OP_SLEEP(10) 2319 1.1.1.2 christos OP_C_EXPECT_FIN(a) 2320 1.1 christos 2321 1.1.1.2 christos OP_END 2322 1.1 christos }; 2323 1.1 christos 2324 1.1 christos static const struct script_op script_11[] = { 2325 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2326 1.1.1.2 christos OP_C_CONNECT_WAIT() 2327 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 2328 1.1 christos 2329 1.1.1.2 christos OP_NEW_THREAD(5, script_11_child) 2330 1.1 christos 2331 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(a, ANY_ID) 2332 1.1.1.2 christos OP_S_WRITE(a, "foo", 3) 2333 1.1.1.2 christos OP_S_CONCLUDE(a) 2334 1.1 christos 2335 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(b, ANY_ID) 2336 1.1.1.2 christos OP_S_WRITE(b, "foo", 3) 2337 1.1.1.2 christos OP_S_CONCLUDE(b) 2338 1.1 christos 2339 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(c, ANY_ID) 2340 1.1.1.2 christos OP_S_WRITE(c, "foo", 3) 2341 1.1.1.2 christos OP_S_CONCLUDE(c) 2342 1.1 christos 2343 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(d, ANY_ID) 2344 1.1.1.2 christos OP_S_WRITE(d, "foo", 3) 2345 1.1.1.2 christos OP_S_CONCLUDE(d) 2346 1.1 christos 2347 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(e, ANY_ID) 2348 1.1.1.2 christos OP_S_WRITE(e, "foo", 3) 2349 1.1.1.2 christos OP_S_CONCLUDE(e) 2350 1.1 christos 2351 1.1.1.2 christos OP_END 2352 1.1 christos }; 2353 1.1 christos 2354 1.1 christos /* 12. Many threads initiated on the same client connection */ 2355 1.1 christos static const struct script_op script_12_child[] = { 2356 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, ANY_ID) 2357 1.1.1.2 christos OP_C_WRITE(a, "foo", 3) 2358 1.1.1.2 christos OP_C_CONCLUDE(a) 2359 1.1.1.2 christos OP_C_FREE_STREAM(a) 2360 1.1 christos 2361 1.1.1.2 christos OP_END 2362 1.1 christos }; 2363 1.1 christos 2364 1.1 christos static const struct script_op script_12[] = { 2365 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2366 1.1.1.2 christos OP_C_CONNECT_WAIT() 2367 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 2368 1.1.1.2 christos 2369 1.1.1.2 christos OP_NEW_THREAD(5, script_12_child) 2370 1.1.1.2 christos 2371 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 2372 1.1.1.2 christos OP_S_READ_EXPECT(a, "foo", 3) 2373 1.1.1.2 christos OP_S_EXPECT_FIN(a) 2374 1.1.1.2 christos OP_S_BIND_STREAM_ID(b, C_BIDI_ID(1)) 2375 1.1.1.2 christos OP_S_READ_EXPECT(b, "foo", 3) 2376 1.1.1.2 christos OP_S_EXPECT_FIN(b) 2377 1.1.1.2 christos OP_S_BIND_STREAM_ID(c, C_BIDI_ID(2)) 2378 1.1.1.2 christos OP_S_READ_EXPECT(c, "foo", 3) 2379 1.1.1.2 christos OP_S_EXPECT_FIN(c) 2380 1.1.1.2 christos OP_S_BIND_STREAM_ID(d, C_BIDI_ID(3)) 2381 1.1.1.2 christos OP_S_READ_EXPECT(d, "foo", 3) 2382 1.1.1.2 christos OP_S_EXPECT_FIN(d) 2383 1.1.1.2 christos OP_S_BIND_STREAM_ID(e, C_BIDI_ID(4)) 2384 1.1.1.2 christos OP_S_READ_EXPECT(e, "foo", 3) 2385 1.1.1.2 christos OP_S_EXPECT_FIN(e) 2386 1.1 christos 2387 1.1.1.2 christos OP_END 2388 1.1 christos }; 2389 1.1 christos 2390 1.1 christos /* 13. Many threads accepted on the same client connection (stress test) */ 2391 1.1 christos static const struct script_op script_13_child[] = { 2392 1.1.1.2 christos OP_BEGIN_REPEAT(10) 2393 1.1 christos 2394 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(a) 2395 1.1.1.2 christos OP_C_READ_EXPECT(a, "foo", 3) 2396 1.1.1.2 christos OP_C_EXPECT_FIN(a) 2397 1.1.1.2 christos OP_C_FREE_STREAM(a) 2398 1.1 christos 2399 1.1.1.2 christos OP_END_REPEAT() 2400 1.1 christos 2401 1.1.1.2 christos OP_END 2402 1.1 christos }; 2403 1.1 christos 2404 1.1 christos static const struct script_op script_13[] = { 2405 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2406 1.1.1.2 christos OP_C_CONNECT_WAIT() 2407 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 2408 1.1 christos 2409 1.1.1.2 christos OP_NEW_THREAD(5, script_13_child) 2410 1.1 christos 2411 1.1.1.2 christos OP_BEGIN_REPEAT(50) 2412 1.1 christos 2413 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(a, ANY_ID) 2414 1.1.1.2 christos OP_S_WRITE(a, "foo", 3) 2415 1.1.1.2 christos OP_S_CONCLUDE(a) 2416 1.1.1.2 christos OP_S_UNBIND_STREAM_ID(a) 2417 1.1 christos 2418 1.1.1.2 christos OP_END_REPEAT() 2419 1.1 christos 2420 1.1.1.2 christos OP_END 2421 1.1 christos }; 2422 1.1 christos 2423 1.1 christos /* 14. Many threads initiating on the same client connection (stress test) */ 2424 1.1 christos static const struct script_op script_14_child[] = { 2425 1.1.1.2 christos OP_BEGIN_REPEAT(10) 2426 1.1 christos 2427 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, ANY_ID) 2428 1.1.1.2 christos OP_C_WRITE(a, "foo", 3) 2429 1.1.1.2 christos OP_C_CONCLUDE(a) 2430 1.1.1.2 christos OP_C_FREE_STREAM(a) 2431 1.1 christos 2432 1.1.1.2 christos OP_END_REPEAT() 2433 1.1 christos 2434 1.1.1.2 christos OP_END 2435 1.1 christos }; 2436 1.1 christos 2437 1.1 christos static const struct script_op script_14[] = { 2438 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2439 1.1.1.2 christos OP_C_CONNECT_WAIT() 2440 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 2441 1.1 christos 2442 1.1.1.2 christos OP_NEW_THREAD(5, script_14_child) 2443 1.1 christos 2444 1.1.1.2 christos OP_BEGIN_REPEAT(50) 2445 1.1 christos 2446 1.1.1.2 christos OP_S_ACCEPT_STREAM_WAIT(a) 2447 1.1.1.2 christos OP_S_READ_EXPECT(a, "foo", 3) 2448 1.1.1.2 christos OP_S_EXPECT_FIN(a) 2449 1.1.1.2 christos OP_S_UNBIND_STREAM_ID(a) 2450 1.1 christos 2451 1.1.1.2 christos OP_END_REPEAT() 2452 1.1 christos 2453 1.1.1.2 christos OP_END 2454 1.1 christos }; 2455 1.1 christos 2456 1.1 christos /* 15. Client sending large number of streams, MAX_STREAMS test */ 2457 1.1 christos static const struct script_op script_15[] = { 2458 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2459 1.1.1.2 christos OP_C_CONNECT_WAIT() 2460 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 2461 1.1 christos 2462 1.1 christos /* 2463 1.1 christos * This will cause a protocol violation to be raised by the server if we are 2464 1.1 christos * not handling the stream limit correctly on the TX side. 2465 1.1 christos */ 2466 1.1.1.2 christos OP_BEGIN_REPEAT(200) 2467 1.1 christos 2468 1.1.1.2 christos OP_C_NEW_STREAM_BIDI_EX(a, ANY_ID, SSL_STREAM_FLAG_ADVANCE) 2469 1.1.1.2 christos OP_C_WRITE(a, "foo", 3) 2470 1.1.1.2 christos OP_C_CONCLUDE(a) 2471 1.1.1.2 christos OP_C_FREE_STREAM(a) 2472 1.1 christos 2473 1.1.1.2 christos OP_END_REPEAT() 2474 1.1 christos 2475 1.1 christos /* Prove the connection is still good. */ 2476 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(a, S_BIDI_ID(0)) 2477 1.1.1.2 christos OP_S_WRITE(a, "bar", 3) 2478 1.1.1.2 christos OP_S_CONCLUDE(a) 2479 1.1.1.2 christos 2480 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(a) 2481 1.1.1.2 christos OP_C_READ_EXPECT(a, "bar", 3) 2482 1.1.1.2 christos OP_C_EXPECT_FIN(a) 2483 1.1 christos 2484 1.1 christos /* 2485 1.1 christos * Drain the queue of incoming streams. We should be able to get all 200 2486 1.1 christos * even though only 100 can be initiated at a time. 2487 1.1 christos */ 2488 1.1.1.2 christos OP_BEGIN_REPEAT(200) 2489 1.1 christos 2490 1.1.1.2 christos OP_S_ACCEPT_STREAM_WAIT(b) 2491 1.1.1.2 christos OP_S_READ_EXPECT(b, "foo", 3) 2492 1.1.1.2 christos OP_S_EXPECT_FIN(b) 2493 1.1.1.2 christos OP_S_UNBIND_STREAM_ID(b) 2494 1.1 christos 2495 1.1.1.2 christos OP_END_REPEAT() 2496 1.1 christos 2497 1.1.1.2 christos OP_END 2498 1.1 christos }; 2499 1.1 christos 2500 1.1 christos /* 16. Server sending large number of streams, MAX_STREAMS test */ 2501 1.1 christos static const struct script_op script_16[] = { 2502 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2503 1.1.1.2 christos OP_C_CONNECT_WAIT() 2504 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 2505 1.1 christos 2506 1.1 christos /* 2507 1.1 christos * This will cause a protocol violation to be raised by the client if we are 2508 1.1 christos * not handling the stream limit correctly on the TX side. 2509 1.1 christos */ 2510 1.1.1.2 christos OP_BEGIN_REPEAT(200) 2511 1.1 christos 2512 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(a, ANY_ID) 2513 1.1.1.2 christos OP_S_WRITE(a, "foo", 3) 2514 1.1.1.2 christos OP_S_CONCLUDE(a) 2515 1.1.1.2 christos OP_S_UNBIND_STREAM_ID(a) 2516 1.1 christos 2517 1.1.1.2 christos OP_END_REPEAT() 2518 1.1 christos 2519 1.1 christos /* Prove that the connection is still good. */ 2520 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, ANY_ID) 2521 1.1.1.2 christos OP_C_WRITE(a, "bar", 3) 2522 1.1.1.2 christos OP_C_CONCLUDE(a) 2523 1.1.1.2 christos 2524 1.1.1.2 christos OP_S_ACCEPT_STREAM_WAIT(b) 2525 1.1.1.2 christos OP_S_READ_EXPECT(b, "bar", 3) 2526 1.1.1.2 christos OP_S_EXPECT_FIN(b) 2527 1.1 christos 2528 1.1 christos /* Drain the queue of incoming streams. */ 2529 1.1.1.2 christos OP_BEGIN_REPEAT(200) 2530 1.1 christos 2531 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(b) 2532 1.1.1.2 christos OP_C_READ_EXPECT(b, "foo", 3) 2533 1.1.1.2 christos OP_C_EXPECT_FIN(b) 2534 1.1.1.2 christos OP_C_FREE_STREAM(b) 2535 1.1 christos 2536 1.1.1.2 christos OP_END_REPEAT() 2537 1.1 christos 2538 1.1.1.2 christos OP_END 2539 1.1 christos }; 2540 1.1 christos 2541 1.1 christos /* 17. Key update test - unlimited */ 2542 1.1 christos static const struct script_op script_17[] = { 2543 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2544 1.1.1.2 christos OP_C_CONNECT_WAIT() 2545 1.1 christos 2546 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 2547 1.1 christos 2548 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 2549 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 2550 1.1 christos 2551 1.1.1.2 christos OP_CHECK(override_key_update, 1) 2552 1.1 christos 2553 1.1.1.2 christos OP_BEGIN_REPEAT(200) 2554 1.1 christos 2555 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 2556 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 2557 1.1 christos 2558 1.1 christos /* 2559 1.1 christos * TXKU frequency is bounded by RTT because a previous TXKU needs to be 2560 1.1 christos * acknowledged by the peer first before another one can be begin. By 2561 1.1 christos * waiting this long, we eliminate any such concern and ensure as many key 2562 1.1 christos * updates as possible can occur for the purposes of this test. 2563 1.1 christos */ 2564 1.1.1.2 christos OP_CHECK(skip_time_ms, 100) 2565 1.1 christos 2566 1.1.1.2 christos OP_END_REPEAT() 2567 1.1 christos 2568 1.1 christos /* At least 5 RXKUs detected */ 2569 1.1.1.2 christos OP_CHECK(check_key_update_ge, 5) 2570 1.1 christos 2571 1.1 christos /* 2572 1.1 christos * Prove the connection is still healthy by sending something in both 2573 1.1 christos * directions. 2574 1.1 christos */ 2575 1.1.1.2 christos OP_C_WRITE(DEFAULT, "xyzzy", 5) 2576 1.1.1.2 christos OP_S_READ_EXPECT(a, "xyzzy", 5) 2577 1.1 christos 2578 1.1.1.2 christos OP_S_WRITE(a, "plugh", 5) 2579 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "plugh", 5) 2580 1.1 christos 2581 1.1.1.2 christos OP_END 2582 1.1 christos }; 2583 1.1 christos 2584 1.1 christos /* 18. Key update test - RTT-bounded */ 2585 1.1 christos static const struct script_op script_18[] = { 2586 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2587 1.1.1.2 christos OP_C_CONNECT_WAIT() 2588 1.1 christos 2589 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 2590 1.1 christos 2591 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 2592 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 2593 1.1 christos 2594 1.1.1.2 christos OP_CHECK(override_key_update, 1) 2595 1.1 christos 2596 1.1.1.2 christos OP_BEGIN_REPEAT(200) 2597 1.1 christos 2598 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 2599 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 2600 1.1.1.2 christos OP_CHECK(skip_time_ms, 8) 2601 1.1 christos 2602 1.1.1.2 christos OP_END_REPEAT() 2603 1.1 christos 2604 1.1 christos /* 2605 1.1 christos * This time we simulate far less time passing between writes, so there are 2606 1.1 christos * fewer opportunities to initiate TXKUs. Note that we ask for a TXKU every 2607 1.1 christos * 1 packet above, which is absurd; thus this ensures we only actually 2608 1.1 christos * generate TXKUs when we are allowed to. 2609 1.1 christos */ 2610 1.1.1.2 christos OP_CHECK(check_key_update_lt, 240) 2611 1.1 christos 2612 1.1 christos /* 2613 1.1 christos * Prove the connection is still healthy by sending something in both 2614 1.1 christos * directions. 2615 1.1 christos */ 2616 1.1.1.2 christos OP_C_WRITE(DEFAULT, "xyzzy", 5) 2617 1.1.1.2 christos OP_S_READ_EXPECT(a, "xyzzy", 5) 2618 1.1 christos 2619 1.1.1.2 christos OP_S_WRITE(a, "plugh", 5) 2620 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "plugh", 5) 2621 1.1 christos 2622 1.1.1.2 christos OP_END 2623 1.1 christos }; 2624 1.1 christos 2625 1.1 christos /* 19. Key update test - artificially triggered */ 2626 1.1 christos static const struct script_op script_19[] = { 2627 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2628 1.1.1.2 christos OP_C_CONNECT_WAIT() 2629 1.1 christos 2630 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 2631 1.1 christos 2632 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 2633 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 2634 1.1 christos 2635 1.1.1.2 christos OP_C_WRITE(DEFAULT, "orange", 6) 2636 1.1.1.2 christos OP_S_READ_EXPECT(a, "orange", 6) 2637 1.1 christos 2638 1.1.1.2 christos OP_S_WRITE(a, "strawberry", 10) 2639 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "strawberry", 10) 2640 1.1 christos 2641 1.1.1.2 christos OP_CHECK(check_key_update_lt, 1) 2642 1.1.1.2 christos OP_CHECK(trigger_key_update, 0) 2643 1.1 christos 2644 1.1.1.2 christos OP_C_WRITE(DEFAULT, "orange", 6) 2645 1.1.1.2 christos OP_S_READ_EXPECT(a, "orange", 6) 2646 1.1.1.2 christos OP_S_WRITE(a, "ok", 2) 2647 1.1 christos 2648 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "ok", 2) 2649 1.1.1.2 christos OP_CHECK(check_key_update_ge, 1) 2650 1.1 christos 2651 1.1.1.2 christos OP_END 2652 1.1 christos }; 2653 1.1 christos 2654 1.1 christos /* 20. Multiple threads accept stream with socket forcibly closed (error test) */ 2655 1.1 christos static int script_20_trigger(struct helper *h, volatile uint64_t *counter) 2656 1.1 christos { 2657 1.1 christos #if defined(OPENSSL_THREADS) 2658 1.1 christos ossl_crypto_mutex_lock(h->misc_m); 2659 1.1 christos ++*counter; 2660 1.1 christos ossl_crypto_condvar_broadcast(h->misc_cv); 2661 1.1 christos ossl_crypto_mutex_unlock(h->misc_m); 2662 1.1 christos #endif 2663 1.1 christos return 1; 2664 1.1 christos } 2665 1.1 christos 2666 1.1 christos static int script_20_wait(struct helper *h, volatile uint64_t *counter, uint64_t threshold) 2667 1.1 christos { 2668 1.1 christos #if defined(OPENSSL_THREADS) 2669 1.1 christos int stop = 0; 2670 1.1 christos 2671 1.1 christos ossl_crypto_mutex_lock(h->misc_m); 2672 1.1 christos while (!stop) { 2673 1.1 christos stop = (*counter >= threshold); 2674 1.1 christos if (stop) 2675 1.1 christos break; 2676 1.1 christos 2677 1.1 christos ossl_crypto_condvar_wait(h->misc_cv, h->misc_m); 2678 1.1 christos } 2679 1.1 christos 2680 1.1 christos ossl_crypto_mutex_unlock(h->misc_m); 2681 1.1 christos #endif 2682 1.1 christos return 1; 2683 1.1 christos } 2684 1.1 christos 2685 1.1 christos static int script_20_trigger1(struct helper *h, struct helper_local *hl) 2686 1.1 christos { 2687 1.1 christos return script_20_trigger(h, &h->scratch0); 2688 1.1 christos } 2689 1.1 christos 2690 1.1 christos static int script_20_wait1(struct helper *h, struct helper_local *hl) 2691 1.1 christos { 2692 1.1 christos return script_20_wait(h, &h->scratch0, hl->check_op->arg2); 2693 1.1 christos } 2694 1.1 christos 2695 1.1 christos static int script_20_trigger2(struct helper *h, struct helper_local *hl) 2696 1.1 christos { 2697 1.1 christos return script_20_trigger(h, &h->scratch1); 2698 1.1 christos } 2699 1.1 christos 2700 1.1 christos static int script_20_wait2(struct helper *h, struct helper_local *hl) 2701 1.1 christos { 2702 1.1 christos return script_20_wait(h, &h->scratch1, hl->check_op->arg2); 2703 1.1 christos } 2704 1.1 christos 2705 1.1 christos static const struct script_op script_20_child[] = { 2706 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(a) 2707 1.1.1.2 christos OP_C_READ_EXPECT(a, "foo", 3) 2708 1.1 christos 2709 1.1.1.2 christos OP_CHECK(script_20_trigger1, 0) 2710 1.1.1.2 christos OP_CHECK(script_20_wait2, 1) 2711 1.1 christos 2712 1.1.1.2 christos OP_C_READ_FAIL_WAIT(a) 2713 1.1.1.2 christos OP_C_EXPECT_SSL_ERR(a, SSL_ERROR_SYSCALL) 2714 1.1 christos 2715 1.1.1.2 christos OP_EXPECT_ERR_LIB(ERR_LIB_SSL) 2716 1.1.1.2 christos OP_EXPECT_ERR_REASON(SSL_R_PROTOCOL_IS_SHUTDOWN) 2717 1.1 christos 2718 1.1.1.2 christos OP_POP_ERR() 2719 1.1.1.2 christos OP_EXPECT_ERR_LIB(ERR_LIB_SSL) 2720 1.1.1.2 christos OP_EXPECT_ERR_REASON(SSL_R_QUIC_NETWORK_ERROR) 2721 1.1 christos 2722 1.1.1.2 christos OP_C_FREE_STREAM(a) 2723 1.1 christos 2724 1.1.1.2 christos OP_END 2725 1.1 christos }; 2726 1.1 christos 2727 1.1 christos static const struct script_op script_20[] = { 2728 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2729 1.1.1.2 christos OP_C_CONNECT_WAIT() 2730 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 2731 1.1 christos 2732 1.1.1.2 christos OP_NEW_THREAD(5, script_20_child) 2733 1.1 christos 2734 1.1.1.2 christos OP_BEGIN_REPEAT(5) 2735 1.1 christos 2736 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(a, ANY_ID) 2737 1.1.1.2 christos OP_S_WRITE(a, "foo", 3) 2738 1.1.1.2 christos OP_S_UNBIND_STREAM_ID(a) 2739 1.1 christos 2740 1.1.1.2 christos OP_END_REPEAT() 2741 1.1 christos 2742 1.1.1.2 christos OP_CHECK(script_20_wait1, 5) 2743 1.1 christos 2744 1.1.1.2 christos OP_C_CLOSE_SOCKET() 2745 1.1.1.2 christos OP_CHECK(script_20_trigger2, 0) 2746 1.1 christos 2747 1.1.1.2 christos OP_END 2748 1.1 christos }; 2749 1.1 christos 2750 1.1 christos /* 21. Fault injection - unknown frame in 1-RTT packet */ 2751 1.1 christos static int script_21_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, 2752 1.1.1.2 christos unsigned char *buf, size_t len) 2753 1.1 christos { 2754 1.1 christos int ok = 0; 2755 1.1 christos WPACKET wpkt; 2756 1.1 christos unsigned char frame_buf[21]; 2757 1.1 christos size_t written; 2758 1.1 christos 2759 1.1 christos if (h->inject_word0 == 0 || hdr->type != h->inject_word0) 2760 1.1 christos return 1; 2761 1.1 christos 2762 1.1 christos if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, 2763 1.1.1.2 christos sizeof(frame_buf), 0))) 2764 1.1 christos return 0; 2765 1.1 christos 2766 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1))) 2767 1.1 christos goto err; 2768 1.1 christos 2769 1.1 christos switch (h->inject_word1) { 2770 1.1 christos case OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE: 2771 1.1 christos case OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE: 2772 1.1 christos case OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID: 2773 1.1 christos /* 2774 1.1 christos * These cases to be formatted properly need a single uint64_t 2775 1.1 christos */ 2776 1.1 christos if (!TEST_true(WPACKET_put_bytes_u64(&wpkt, (uint64_t)0))) 2777 1.1 christos goto err; 2778 1.1 christos break; 2779 1.1 christos case OSSL_QUIC_FRAME_TYPE_MAX_DATA: 2780 1.1 christos case OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI: 2781 1.1 christos case OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI: 2782 1.1 christos case OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI: 2783 1.1 christos case OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI: 2784 1.1 christos case OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED: 2785 1.1 christos /* 2786 1.1 christos * These cases require a single vlint 2787 1.1 christos */ 2788 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, (uint64_t)0))) 2789 1.1 christos goto err; 2790 1.1 christos break; 2791 1.1 christos case OSSL_QUIC_FRAME_TYPE_STOP_SENDING: 2792 1.1 christos case OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA: 2793 1.1 christos case OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED: 2794 1.1 christos /* 2795 1.1 christos * These cases require 2 variable integers 2796 1.1 christos */ 2797 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, (uint64_t)0))) 2798 1.1 christos goto err; 2799 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, (uint64_t)0))) 2800 1.1 christos goto err; 2801 1.1 christos break; 2802 1.1 christos case OSSL_QUIC_FRAME_TYPE_STREAM: 2803 1.1 christos case OSSL_QUIC_FRAME_TYPE_RESET_STREAM: 2804 1.1 christos case OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_APP: 2805 1.1 christos /* 2806 1.1 christos * These cases require 3 variable integers 2807 1.1 christos */ 2808 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, (uint64_t)0))) 2809 1.1 christos goto err; 2810 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, (uint64_t)0))) 2811 1.1 christos goto err; 2812 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, (uint64_t)0))) 2813 1.1 christos goto err; 2814 1.1 christos break; 2815 1.1 christos case OSSL_QUIC_FRAME_TYPE_NEW_TOKEN: 2816 1.1 christos /* 2817 1.1 christos * Special case for new token 2818 1.1 christos */ 2819 1.1 christos 2820 1.1 christos /* New token length, cannot be zero */ 2821 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, (uint64_t)1))) 2822 1.1 christos goto err; 2823 1.1 christos 2824 1.1 christos /* 1 bytes of token data, to match the above length */ 2825 1.1 christos if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, (uint8_t)0))) 2826 1.1 christos goto err; 2827 1.1 christos break; 2828 1.1 christos case OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID: 2829 1.1 christos /* 2830 1.1 christos * Special case for New Connection ids, has a combination 2831 1.1 christos * of vlints and fixed width values 2832 1.1 christos */ 2833 1.1 christos 2834 1.1 christos /* seq number */ 2835 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, (uint64_t)0))) 2836 1.1 christos goto err; 2837 1.1 christos 2838 1.1 christos /* retire prior to */ 2839 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, (uint64_t)0))) 2840 1.1 christos goto err; 2841 1.1 christos 2842 1.1 christos /* Connection id length, arbitrary at 1 bytes */ 2843 1.1 christos if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, (uint8_t)1))) 2844 1.1 christos goto err; 2845 1.1 christos 2846 1.1 christos /* The connection id, to match the above length */ 2847 1.1 christos if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, (uint8_t)0))) 2848 1.1 christos goto err; 2849 1.1 christos 2850 1.1 christos /* 16 bytes total for the SRT */ 2851 1.1 christos if (!TEST_true(WPACKET_memset(&wpkt, 0, 16))) 2852 1.1 christos goto err; 2853 1.1 christos 2854 1.1 christos break; 2855 1.1 christos } 2856 1.1 christos 2857 1.1 christos if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) 2858 1.1 christos goto err; 2859 1.1 christos 2860 1.1 christos if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) 2861 1.1 christos goto err; 2862 1.1 christos 2863 1.1 christos ok = 1; 2864 1.1 christos err: 2865 1.1 christos if (ok) 2866 1.1 christos WPACKET_finish(&wpkt); 2867 1.1 christos else 2868 1.1 christos WPACKET_cleanup(&wpkt); 2869 1.1 christos return ok; 2870 1.1 christos } 2871 1.1 christos 2872 1.1 christos static const struct script_op script_21[] = { 2873 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_21_inject_plain) 2874 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2875 1.1.1.2 christos OP_C_CONNECT_WAIT() 2876 1.1 christos 2877 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 2878 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 2879 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 2880 1.1 christos 2881 1.1.1.2 christos OP_SET_INJECT_WORD(QUIC_PKT_TYPE_1RTT, OSSL_QUIC_VLINT_MAX) 2882 1.1 christos 2883 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 2884 1.1 christos 2885 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_FRAME_ENCODING_ERROR, 0, 0) 2886 1.1 christos 2887 1.1.1.2 christos OP_END 2888 1.1 christos }; 2889 1.1 christos 2890 1.1 christos /* 22. Fault injection - non-zero packet header reserved bits */ 2891 1.1 christos static int script_22_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, 2892 1.1.1.2 christos unsigned char *buf, size_t len) 2893 1.1 christos { 2894 1.1 christos if (h->inject_word0 == 0) 2895 1.1 christos return 1; 2896 1.1 christos 2897 1.1 christos hdr->reserved = 1; 2898 1.1 christos return 1; 2899 1.1 christos } 2900 1.1 christos 2901 1.1 christos static const struct script_op script_22[] = { 2902 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_22_inject_plain) 2903 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2904 1.1.1.2 christos OP_C_CONNECT_WAIT() 2905 1.1 christos 2906 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 2907 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 2908 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 2909 1.1 christos 2910 1.1.1.2 christos OP_SET_INJECT_WORD(1, 0) 2911 1.1 christos 2912 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 2913 1.1 christos 2914 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_PROTOCOL_VIOLATION, 0, 0) 2915 1.1 christos 2916 1.1.1.2 christos OP_END 2917 1.1 christos }; 2918 1.1 christos 2919 1.1 christos /* 23. Fault injection - empty NEW_TOKEN */ 2920 1.1 christos static int script_23_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, 2921 1.1.1.2 christos unsigned char *buf, size_t len) 2922 1.1 christos { 2923 1.1 christos int ok = 0; 2924 1.1 christos WPACKET wpkt; 2925 1.1 christos unsigned char frame_buf[16]; 2926 1.1 christos size_t written; 2927 1.1 christos 2928 1.1 christos if (h->inject_word0 == 0 || hdr->type != QUIC_PKT_TYPE_1RTT) 2929 1.1 christos return 1; 2930 1.1 christos 2931 1.1 christos if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, 2932 1.1.1.2 christos sizeof(frame_buf), 0))) 2933 1.1 christos return 0; 2934 1.1 christos 2935 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_FRAME_TYPE_NEW_TOKEN)) 2936 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 0))) 2937 1.1 christos goto err; 2938 1.1 christos 2939 1.1 christos if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) 2940 1.1 christos goto err; 2941 1.1 christos 2942 1.1 christos if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) 2943 1.1 christos goto err; 2944 1.1 christos 2945 1.1 christos ok = 1; 2946 1.1 christos err: 2947 1.1 christos if (ok) 2948 1.1 christos WPACKET_finish(&wpkt); 2949 1.1 christos else 2950 1.1 christos WPACKET_cleanup(&wpkt); 2951 1.1 christos return ok; 2952 1.1 christos } 2953 1.1 christos 2954 1.1 christos static const struct script_op script_23[] = { 2955 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_23_inject_plain) 2956 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 2957 1.1.1.2 christos OP_C_CONNECT_WAIT() 2958 1.1 christos 2959 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 2960 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 2961 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 2962 1.1 christos 2963 1.1.1.2 christos OP_SET_INJECT_WORD(1, 0) 2964 1.1 christos 2965 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 2966 1.1 christos 2967 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_FRAME_ENCODING_ERROR, 0, 0) 2968 1.1 christos 2969 1.1.1.2 christos OP_END 2970 1.1 christos }; 2971 1.1 christos 2972 1.1 christos /* 24. Fault injection - excess value of MAX_STREAMS_BIDI */ 2973 1.1 christos static int script_24_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, 2974 1.1.1.2 christos unsigned char *buf, size_t len) 2975 1.1 christos { 2976 1.1 christos int ok = 0; 2977 1.1 christos WPACKET wpkt; 2978 1.1 christos unsigned char frame_buf[16]; 2979 1.1 christos size_t written; 2980 1.1 christos 2981 1.1 christos if (h->inject_word0 == 0 || hdr->type != QUIC_PKT_TYPE_1RTT) 2982 1.1 christos return 1; 2983 1.1 christos 2984 1.1 christos if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, 2985 1.1.1.2 christos sizeof(frame_buf), 0))) 2986 1.1 christos return 0; 2987 1.1 christos 2988 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1)) 2989 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, (((uint64_t)1) << 60) + 1))) 2990 1.1 christos goto err; 2991 1.1 christos 2992 1.1 christos if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) 2993 1.1 christos goto err; 2994 1.1 christos 2995 1.1 christos if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) 2996 1.1 christos goto err; 2997 1.1 christos 2998 1.1 christos ok = 1; 2999 1.1 christos err: 3000 1.1 christos if (ok) 3001 1.1 christos WPACKET_finish(&wpkt); 3002 1.1 christos else 3003 1.1 christos WPACKET_cleanup(&wpkt); 3004 1.1 christos return ok; 3005 1.1 christos } 3006 1.1 christos 3007 1.1 christos static const struct script_op script_24[] = { 3008 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_24_inject_plain) 3009 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3010 1.1.1.2 christos OP_C_CONNECT_WAIT() 3011 1.1 christos 3012 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 3013 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 3014 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 3015 1.1 christos 3016 1.1.1.2 christos OP_SET_INJECT_WORD(1, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI) 3017 1.1 christos 3018 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 3019 1.1 christos 3020 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_FRAME_ENCODING_ERROR, 0, 0) 3021 1.1 christos 3022 1.1.1.2 christos OP_END 3023 1.1 christos }; 3024 1.1 christos 3025 1.1 christos /* 25. Fault injection - excess value of MAX_STREAMS_UNI */ 3026 1.1 christos static const struct script_op script_25[] = { 3027 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_24_inject_plain) 3028 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3029 1.1.1.2 christos OP_C_CONNECT_WAIT() 3030 1.1 christos 3031 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 3032 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 3033 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 3034 1.1 christos 3035 1.1.1.2 christos OP_SET_INJECT_WORD(1, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI) 3036 1.1 christos 3037 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 3038 1.1 christos 3039 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_FRAME_ENCODING_ERROR, 0, 0) 3040 1.1 christos 3041 1.1.1.2 christos OP_END 3042 1.1 christos }; 3043 1.1 christos 3044 1.1 christos /* 26. Fault injection - excess value of STREAMS_BLOCKED_BIDI */ 3045 1.1 christos static const struct script_op script_26[] = { 3046 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_24_inject_plain) 3047 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3048 1.1.1.2 christos OP_C_CONNECT_WAIT() 3049 1.1 christos 3050 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 3051 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 3052 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 3053 1.1 christos 3054 1.1.1.2 christos OP_SET_INJECT_WORD(1, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI) 3055 1.1 christos 3056 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 3057 1.1 christos 3058 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_STREAM_LIMIT_ERROR, 0, 0) 3059 1.1 christos 3060 1.1.1.2 christos OP_END 3061 1.1 christos }; 3062 1.1 christos 3063 1.1 christos /* 27. Fault injection - excess value of STREAMS_BLOCKED_UNI */ 3064 1.1 christos static const struct script_op script_27[] = { 3065 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_24_inject_plain) 3066 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3067 1.1.1.2 christos OP_C_CONNECT_WAIT() 3068 1.1 christos 3069 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 3070 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 3071 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 3072 1.1 christos 3073 1.1.1.2 christos OP_SET_INJECT_WORD(1, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI) 3074 1.1 christos 3075 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 3076 1.1 christos 3077 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_STREAM_LIMIT_ERROR, 0, 0) 3078 1.1 christos 3079 1.1.1.2 christos OP_END 3080 1.1 christos }; 3081 1.1 christos 3082 1.1 christos /* 28. Fault injection - received RESET_STREAM for send-only stream */ 3083 1.1 christos static int script_28_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, 3084 1.1.1.2 christos unsigned char *buf, size_t len) 3085 1.1 christos { 3086 1.1 christos int ok = 0; 3087 1.1 christos WPACKET wpkt; 3088 1.1 christos unsigned char frame_buf[32]; 3089 1.1 christos size_t written; 3090 1.1 christos 3091 1.1 christos if (h->inject_word0 == 0 || hdr->type != QUIC_PKT_TYPE_1RTT) 3092 1.1 christos return 1; 3093 1.1 christos 3094 1.1 christos if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, 3095 1.1.1.2 christos sizeof(frame_buf), 0))) 3096 1.1 christos return 0; 3097 1.1 christos 3098 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1)) 3099 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, /* stream ID */ 3100 1.1.1.2 christos h->inject_word0 - 1)) 3101 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 123)) 3102 1.1 christos || (h->inject_word1 == OSSL_QUIC_FRAME_TYPE_RESET_STREAM 3103 1.1.1.2 christos && !TEST_true(WPACKET_quic_write_vlint(&wpkt, 5)))) /* final size */ 3104 1.1 christos goto err; 3105 1.1 christos 3106 1.1 christos if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) 3107 1.1 christos goto err; 3108 1.1 christos 3109 1.1 christos if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) 3110 1.1 christos goto err; 3111 1.1 christos 3112 1.1 christos ok = 1; 3113 1.1 christos err: 3114 1.1 christos if (ok) 3115 1.1 christos WPACKET_finish(&wpkt); 3116 1.1 christos else 3117 1.1 christos WPACKET_cleanup(&wpkt); 3118 1.1 christos return ok; 3119 1.1 christos } 3120 1.1 christos 3121 1.1 christos static const struct script_op script_28[] = { 3122 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_28_inject_plain) 3123 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3124 1.1.1.2 christos OP_C_CONNECT_WAIT() 3125 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 3126 1.1 christos 3127 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 3128 1.1.1.2 christos OP_C_WRITE(a, "orange", 6) 3129 1.1 christos 3130 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 3131 1.1.1.2 christos OP_S_READ_EXPECT(a, "orange", 6) 3132 1.1 christos 3133 1.1.1.2 christos OP_C_NEW_STREAM_UNI(b, C_UNI_ID(0)) 3134 1.1.1.2 christos OP_C_WRITE(b, "apple", 5) 3135 1.1 christos 3136 1.1.1.2 christos OP_S_BIND_STREAM_ID(b, C_UNI_ID(0)) 3137 1.1.1.2 christos OP_S_READ_EXPECT(b, "apple", 5) 3138 1.1 christos 3139 1.1.1.2 christos OP_SET_INJECT_WORD(C_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_RESET_STREAM) 3140 1.1.1.2 christos OP_S_WRITE(a, "fruit", 5) 3141 1.1 christos 3142 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_STREAM_STATE_ERROR, 0, 0) 3143 1.1 christos 3144 1.1.1.2 christos OP_END 3145 1.1 christos }; 3146 1.1 christos 3147 1.1 christos /* 29. Fault injection - received RESET_STREAM for nonexistent send-only stream */ 3148 1.1 christos static const struct script_op script_29[] = { 3149 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_28_inject_plain) 3150 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3151 1.1.1.2 christos OP_C_CONNECT_WAIT() 3152 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 3153 1.1 christos 3154 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 3155 1.1.1.2 christos OP_C_WRITE(a, "orange", 6) 3156 1.1 christos 3157 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 3158 1.1.1.2 christos OP_S_READ_EXPECT(a, "orange", 6) 3159 1.1 christos 3160 1.1.1.2 christos OP_C_NEW_STREAM_UNI(b, C_UNI_ID(0)) 3161 1.1.1.2 christos OP_C_WRITE(b, "apple", 5) 3162 1.1 christos 3163 1.1.1.2 christos OP_S_BIND_STREAM_ID(b, C_UNI_ID(0)) 3164 1.1.1.2 christos OP_S_READ_EXPECT(b, "apple", 5) 3165 1.1 christos 3166 1.1.1.2 christos OP_SET_INJECT_WORD(C_UNI_ID(1) + 1, OSSL_QUIC_FRAME_TYPE_RESET_STREAM) 3167 1.1.1.2 christos OP_S_WRITE(a, "fruit", 5) 3168 1.1 christos 3169 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_STREAM_STATE_ERROR, 0, 0) 3170 1.1 christos 3171 1.1.1.2 christos OP_END 3172 1.1 christos }; 3173 1.1 christos 3174 1.1 christos /* 30. Fault injection - received STOP_SENDING for receive-only stream */ 3175 1.1 christos static const struct script_op script_30[] = { 3176 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_28_inject_plain) 3177 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3178 1.1.1.2 christos OP_C_CONNECT_WAIT() 3179 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 3180 1.1 christos 3181 1.1.1.2 christos OP_S_NEW_STREAM_UNI(a, S_UNI_ID(0)) 3182 1.1.1.2 christos OP_S_WRITE(a, "apple", 5) 3183 1.1 christos 3184 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(a) 3185 1.1.1.2 christos OP_C_READ_EXPECT(a, "apple", 5) 3186 1.1 christos 3187 1.1.1.2 christos OP_SET_INJECT_WORD(S_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STOP_SENDING) 3188 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 3189 1.1 christos 3190 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_STREAM_STATE_ERROR, 0, 0) 3191 1.1 christos 3192 1.1.1.2 christos OP_END 3193 1.1 christos }; 3194 1.1 christos 3195 1.1 christos /* 31. Fault injection - received STOP_SENDING for nonexistent receive-only stream */ 3196 1.1 christos static const struct script_op script_31[] = { 3197 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_28_inject_plain) 3198 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3199 1.1.1.2 christos OP_C_CONNECT_WAIT() 3200 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 3201 1.1 christos 3202 1.1.1.2 christos OP_S_NEW_STREAM_UNI(a, S_UNI_ID(0)) 3203 1.1.1.2 christos OP_S_WRITE(a, "apple", 5) 3204 1.1 christos 3205 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(a) 3206 1.1.1.2 christos OP_C_READ_EXPECT(a, "apple", 5) 3207 1.1 christos 3208 1.1.1.2 christos OP_SET_INJECT_WORD(C_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STOP_SENDING) 3209 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 3210 1.1 christos 3211 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_STREAM_STATE_ERROR, 0, 0) 3212 1.1 christos 3213 1.1.1.2 christos OP_END 3214 1.1 christos }; 3215 1.1 christos 3216 1.1 christos /* 32. Fault injection - STREAM frame for nonexistent stream */ 3217 1.1 christos static int script_32_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, 3218 1.1.1.2 christos unsigned char *buf, size_t len) 3219 1.1 christos { 3220 1.1 christos int ok = 0; 3221 1.1 christos WPACKET wpkt; 3222 1.1 christos unsigned char frame_buf[64]; 3223 1.1 christos size_t written; 3224 1.1 christos uint64_t type = OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN, offset, flen, i; 3225 1.1 christos 3226 1.1 christos if (hdr->type != QUIC_PKT_TYPE_1RTT) 3227 1.1 christos return 1; 3228 1.1 christos 3229 1.1 christos switch (h->inject_word1) { 3230 1.1 christos default: 3231 1.1 christos return 0; 3232 1.1 christos case 0: 3233 1.1 christos return 1; 3234 1.1 christos case 1: 3235 1.1.1.2 christos offset = 0; 3236 1.1.1.2 christos flen = 0; 3237 1.1 christos break; 3238 1.1 christos case 2: 3239 1.1.1.2 christos offset = (((uint64_t)1) << 62) - 1; 3240 1.1.1.2 christos flen = 5; 3241 1.1 christos break; 3242 1.1 christos case 3: 3243 1.1.1.2 christos offset = 1 * 1024 * 1024 * 1024; /* 1G */ 3244 1.1.1.2 christos flen = 5; 3245 1.1 christos break; 3246 1.1 christos case 4: 3247 1.1.1.2 christos offset = 0; 3248 1.1.1.2 christos flen = 1; 3249 1.1 christos break; 3250 1.1 christos } 3251 1.1 christos 3252 1.1 christos if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, 3253 1.1.1.2 christos sizeof(frame_buf), 0))) 3254 1.1 christos return 0; 3255 1.1 christos 3256 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, type)) 3257 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, /* stream ID */ 3258 1.1.1.2 christos h->inject_word0 - 1)) 3259 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, offset)) 3260 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, flen))) 3261 1.1 christos goto err; 3262 1.1 christos 3263 1.1 christos for (i = 0; i < flen; ++i) 3264 1.1 christos if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x42))) 3265 1.1 christos goto err; 3266 1.1 christos 3267 1.1 christos if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) 3268 1.1 christos goto err; 3269 1.1 christos 3270 1.1 christos if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) 3271 1.1 christos goto err; 3272 1.1 christos 3273 1.1 christos ok = 1; 3274 1.1 christos err: 3275 1.1 christos if (ok) 3276 1.1 christos WPACKET_finish(&wpkt); 3277 1.1 christos else 3278 1.1 christos WPACKET_cleanup(&wpkt); 3279 1.1 christos return ok; 3280 1.1 christos } 3281 1.1 christos 3282 1.1 christos static const struct script_op script_32[] = { 3283 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_32_inject_plain) 3284 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3285 1.1.1.2 christos OP_C_CONNECT_WAIT() 3286 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 3287 1.1 christos 3288 1.1.1.2 christos OP_S_NEW_STREAM_UNI(a, S_UNI_ID(0)) 3289 1.1.1.2 christos OP_S_WRITE(a, "apple", 5) 3290 1.1 christos 3291 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(a) 3292 1.1.1.2 christos OP_C_READ_EXPECT(a, "apple", 5) 3293 1.1 christos 3294 1.1.1.2 christos OP_SET_INJECT_WORD(C_UNI_ID(0) + 1, 1) 3295 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 3296 1.1 christos 3297 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_STREAM_STATE_ERROR, 0, 0) 3298 1.1 christos 3299 1.1.1.2 christos OP_END 3300 1.1 christos }; 3301 1.1 christos 3302 1.1 christos /* 33. Fault injection - STREAM frame with illegal offset */ 3303 1.1 christos static const struct script_op script_33[] = { 3304 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_32_inject_plain) 3305 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3306 1.1.1.2 christos OP_C_CONNECT_WAIT() 3307 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 3308 1.1 christos 3309 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 3310 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 3311 1.1 christos 3312 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 3313 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 3314 1.1 christos 3315 1.1.1.2 christos OP_SET_INJECT_WORD(C_BIDI_ID(0) + 1, 2) 3316 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 3317 1.1 christos 3318 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_FRAME_ENCODING_ERROR, 0, 0) 3319 1.1 christos 3320 1.1.1.2 christos OP_END 3321 1.1 christos }; 3322 1.1 christos 3323 1.1 christos /* 34. Fault injection - STREAM frame which exceeds FC */ 3324 1.1 christos static const struct script_op script_34[] = { 3325 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_32_inject_plain) 3326 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3327 1.1.1.2 christos OP_C_CONNECT_WAIT() 3328 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 3329 1.1 christos 3330 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 3331 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 3332 1.1 christos 3333 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 3334 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 3335 1.1 christos 3336 1.1.1.2 christos OP_SET_INJECT_WORD(C_BIDI_ID(0) + 1, 3) 3337 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 3338 1.1 christos 3339 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_FLOW_CONTROL_ERROR, 0, 0) 3340 1.1 christos 3341 1.1.1.2 christos OP_END 3342 1.1 christos }; 3343 1.1 christos 3344 1.1 christos /* 35. Fault injection - MAX_STREAM_DATA for receive-only stream */ 3345 1.1 christos static const struct script_op script_35[] = { 3346 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_28_inject_plain) 3347 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3348 1.1.1.2 christos OP_C_CONNECT_WAIT() 3349 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 3350 1.1 christos 3351 1.1.1.2 christos OP_S_NEW_STREAM_UNI(a, S_UNI_ID(0)) 3352 1.1.1.2 christos OP_S_WRITE(a, "apple", 5) 3353 1.1 christos 3354 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(a) 3355 1.1.1.2 christos OP_C_READ_EXPECT(a, "apple", 5) 3356 1.1 christos 3357 1.1.1.2 christos OP_SET_INJECT_WORD(S_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA) 3358 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 3359 1.1 christos 3360 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_STREAM_STATE_ERROR, 0, 0) 3361 1.1 christos 3362 1.1.1.2 christos OP_END 3363 1.1 christos }; 3364 1.1 christos 3365 1.1 christos /* 36. Fault injection - MAX_STREAM_DATA for nonexistent stream */ 3366 1.1 christos static const struct script_op script_36[] = { 3367 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_28_inject_plain) 3368 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3369 1.1.1.2 christos OP_C_CONNECT_WAIT() 3370 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 3371 1.1 christos 3372 1.1.1.2 christos OP_S_NEW_STREAM_UNI(a, S_UNI_ID(0)) 3373 1.1.1.2 christos OP_S_WRITE(a, "apple", 5) 3374 1.1 christos 3375 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(a) 3376 1.1.1.2 christos OP_C_READ_EXPECT(a, "apple", 5) 3377 1.1 christos 3378 1.1.1.2 christos OP_SET_INJECT_WORD(C_BIDI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA) 3379 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 3380 1.1 christos 3381 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_STREAM_STATE_ERROR, 0, 0) 3382 1.1 christos 3383 1.1.1.2 christos OP_END 3384 1.1 christos }; 3385 1.1 christos 3386 1.1 christos /* 37. Fault injection - STREAM_DATA_BLOCKED for send-only stream */ 3387 1.1 christos static const struct script_op script_37[] = { 3388 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_28_inject_plain) 3389 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3390 1.1.1.2 christos OP_C_CONNECT_WAIT() 3391 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 3392 1.1 christos 3393 1.1.1.2 christos OP_C_NEW_STREAM_UNI(a, C_UNI_ID(0)) 3394 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 3395 1.1 christos 3396 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_UNI_ID(0)) 3397 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 3398 1.1 christos 3399 1.1.1.2 christos OP_S_NEW_STREAM_UNI(b, S_UNI_ID(0)) 3400 1.1.1.2 christos OP_SET_INJECT_WORD(C_UNI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED) 3401 1.1.1.2 christos OP_S_WRITE(b, "orange", 5) 3402 1.1 christos 3403 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_STREAM_STATE_ERROR, 0, 0) 3404 1.1 christos 3405 1.1.1.2 christos OP_END 3406 1.1 christos }; 3407 1.1 christos 3408 1.1 christos /* 38. Fault injection - STREAM_DATA_BLOCKED for non-existent stream */ 3409 1.1 christos static const struct script_op script_38[] = { 3410 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_28_inject_plain) 3411 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3412 1.1.1.2 christos OP_C_CONNECT_WAIT() 3413 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 3414 1.1 christos 3415 1.1.1.2 christos OP_C_NEW_STREAM_UNI(a, C_UNI_ID(0)) 3416 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 3417 1.1 christos 3418 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_UNI_ID(0)) 3419 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 3420 1.1 christos 3421 1.1.1.2 christos OP_SET_INJECT_WORD(C_BIDI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED) 3422 1.1 christos 3423 1.1.1.2 christos OP_S_NEW_STREAM_UNI(b, S_UNI_ID(0)) 3424 1.1.1.2 christos OP_S_WRITE(b, "orange", 5) 3425 1.1 christos 3426 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_STREAM_STATE_ERROR, 0, 0) 3427 1.1 christos 3428 1.1.1.2 christos OP_END 3429 1.1 christos }; 3430 1.1 christos 3431 1.1 christos /* 39. Fault injection - NEW_CONN_ID with zero-len CID */ 3432 1.1 christos static int script_39_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, 3433 1.1.1.2 christos unsigned char *buf, size_t len) 3434 1.1 christos { 3435 1.1 christos int ok = 0; 3436 1.1 christos WPACKET wpkt; 3437 1.1 christos unsigned char frame_buf[64]; 3438 1.1 christos size_t i, written; 3439 1.1 christos uint64_t seq_no = 0, retire_prior_to = 0; 3440 1.1.1.2 christos QUIC_CONN_ID new_cid = { 0 }; 3441 1.1 christos QUIC_CHANNEL *ch = ossl_quic_tserver_get_channel(h->s_priv); 3442 1.1 christos 3443 1.1 christos if (hdr->type != QUIC_PKT_TYPE_1RTT) 3444 1.1 christos return 1; 3445 1.1 christos 3446 1.1 christos switch (h->inject_word1) { 3447 1.1 christos case 0: 3448 1.1 christos return 1; 3449 1.1 christos case 1: 3450 1.1.1.2 christos new_cid.id_len = 0; 3451 1.1 christos break; 3452 1.1 christos case 2: 3453 1.1.1.2 christos new_cid.id_len = 21; 3454 1.1 christos break; 3455 1.1 christos case 3: 3456 1.1.1.2 christos new_cid.id_len = 1; 3457 1.1.1.2 christos new_cid.id[0] = 0x55; 3458 1.1 christos 3459 1.1.1.2 christos seq_no = 0; 3460 1.1 christos retire_prior_to = 1; 3461 1.1 christos break; 3462 1.1 christos case 4: 3463 1.1 christos /* Use our actual CID so we don't break connectivity. */ 3464 1.1 christos ossl_quic_channel_get_diag_local_cid(ch, &new_cid); 3465 1.1 christos 3466 1.1.1.2 christos seq_no = 2; 3467 1.1 christos retire_prior_to = 2; 3468 1.1 christos break; 3469 1.1 christos case 5: 3470 1.1 christos /* 3471 1.1 christos * Use a bogus CID which will need to be ignored if connectivity is to 3472 1.1 christos * be continued. 3473 1.1 christos */ 3474 1.1.1.2 christos new_cid.id_len = 8; 3475 1.1.1.2 christos new_cid.id[0] = 0x55; 3476 1.1 christos 3477 1.1.1.2 christos seq_no = 1; 3478 1.1 christos retire_prior_to = 1; 3479 1.1 christos break; 3480 1.1 christos } 3481 1.1 christos 3482 1.1 christos if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, 3483 1.1.1.2 christos sizeof(frame_buf), 0))) 3484 1.1 christos return 0; 3485 1.1 christos 3486 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID)) 3487 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, seq_no)) /* seq no */ 3488 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, retire_prior_to)) /* retire prior to */ 3489 1.1 christos || !TEST_true(WPACKET_put_bytes_u8(&wpkt, new_cid.id_len))) /* len */ 3490 1.1 christos goto err; 3491 1.1 christos 3492 1.1 christos for (i = 0; i < new_cid.id_len && i < OSSL_NELEM(new_cid.id); ++i) 3493 1.1 christos if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, new_cid.id[i]))) 3494 1.1 christos goto err; 3495 1.1 christos 3496 1.1 christos for (; i < new_cid.id_len; ++i) 3497 1.1 christos if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x55))) 3498 1.1 christos goto err; 3499 1.1 christos 3500 1.1 christos for (i = 0; i < QUIC_STATELESS_RESET_TOKEN_LEN; ++i) 3501 1.1 christos if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x42))) 3502 1.1 christos goto err; 3503 1.1 christos 3504 1.1 christos if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) 3505 1.1 christos goto err; 3506 1.1 christos 3507 1.1 christos if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) 3508 1.1 christos goto err; 3509 1.1 christos 3510 1.1 christos ok = 1; 3511 1.1 christos err: 3512 1.1 christos if (ok) 3513 1.1 christos WPACKET_finish(&wpkt); 3514 1.1 christos else 3515 1.1 christos WPACKET_cleanup(&wpkt); 3516 1.1 christos return ok; 3517 1.1 christos } 3518 1.1 christos 3519 1.1 christos static const struct script_op script_39[] = { 3520 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_39_inject_plain) 3521 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3522 1.1.1.2 christos OP_C_CONNECT_WAIT() 3523 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 3524 1.1.1.2 christos 3525 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 3526 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 3527 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 3528 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 3529 1.1 christos 3530 1.1.1.2 christos OP_SET_INJECT_WORD(0, 1) 3531 1.1.1.2 christos OP_S_WRITE(a, "orange", 5) 3532 1.1 christos 3533 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_FRAME_ENCODING_ERROR, 0, 0) 3534 1.1 christos 3535 1.1.1.2 christos OP_END 3536 1.1 christos }; 3537 1.1 christos 3538 1.1 christos /* 40. Shutdown flush test */ 3539 1.1 christos static const unsigned char script_40_data[1024] = "strawberry"; 3540 1.1 christos 3541 1.1 christos static const struct script_op script_40[] = { 3542 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3543 1.1.1.2 christos OP_C_CONNECT_WAIT() 3544 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 3545 1.1 christos 3546 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 3547 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 3548 1.1 christos 3549 1.1.1.2 christos OP_C_INHIBIT_TICK(1) 3550 1.1.1.2 christos OP_C_SET_WRITE_BUF_SIZE(a, 1024 * 100 * 3) 3551 1.1 christos 3552 1.1.1.2 christos OP_BEGIN_REPEAT(100) 3553 1.1 christos 3554 1.1.1.2 christos OP_C_WRITE(a, script_40_data, sizeof(script_40_data)) 3555 1.1 christos 3556 1.1.1.2 christos OP_END_REPEAT() 3557 1.1 christos 3558 1.1.1.2 christos OP_C_CONCLUDE(a) 3559 1.1.1.2 christos OP_C_SHUTDOWN_WAIT(NULL, 0) /* disengages tick inhibition */ 3560 1.1 christos 3561 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 3562 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 3563 1.1 christos 3564 1.1.1.2 christos OP_BEGIN_REPEAT(100) 3565 1.1 christos 3566 1.1.1.2 christos OP_S_READ_EXPECT(a, script_40_data, sizeof(script_40_data)) 3567 1.1 christos 3568 1.1.1.2 christos OP_END_REPEAT() 3569 1.1 christos 3570 1.1.1.2 christos OP_S_EXPECT_FIN(a) 3571 1.1 christos 3572 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(0, 1, 0) 3573 1.1.1.2 christos OP_S_EXPECT_CONN_CLOSE_INFO(0, 1, 1) 3574 1.1 christos 3575 1.1.1.2 christos OP_END 3576 1.1 christos }; 3577 1.1 christos 3578 1.1 christos /* 41. Fault injection - PATH_CHALLENGE yields PATH_RESPONSE */ 3579 1.1 christos static const uint64_t path_challenge = UINT64_C(0xbdeb9451169c83aa); 3580 1.1 christos 3581 1.1 christos static int script_41_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, 3582 1.1.1.2 christos unsigned char *buf, size_t len) 3583 1.1 christos { 3584 1.1 christos int ok = 0; 3585 1.1 christos WPACKET wpkt; 3586 1.1 christos unsigned char frame_buf[16]; 3587 1.1 christos size_t written; 3588 1.1 christos 3589 1.1 christos if (h->inject_word0 == 0 || hdr->type != QUIC_PKT_TYPE_1RTT) 3590 1.1 christos return 1; 3591 1.1 christos 3592 1.1 christos if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, 3593 1.1.1.2 christos sizeof(frame_buf), 0))) 3594 1.1 christos return 0; 3595 1.1 christos 3596 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1)) 3597 1.1 christos || !TEST_true(WPACKET_put_bytes_u64(&wpkt, path_challenge))) 3598 1.1 christos goto err; 3599 1.1 christos 3600 1.1 christos if (!TEST_true(WPACKET_get_total_written(&wpkt, &written)) 3601 1.1 christos || !TEST_size_t_eq(written, 9)) 3602 1.1 christos goto err; 3603 1.1 christos 3604 1.1 christos if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) 3605 1.1 christos goto err; 3606 1.1 christos 3607 1.1 christos --h->inject_word0; 3608 1.1 christos ok = 1; 3609 1.1 christos err: 3610 1.1 christos if (ok) 3611 1.1 christos WPACKET_finish(&wpkt); 3612 1.1 christos else 3613 1.1 christos WPACKET_cleanup(&wpkt); 3614 1.1 christos return ok; 3615 1.1 christos } 3616 1.1 christos 3617 1.1 christos static void script_41_trace(int write_p, int version, int content_type, 3618 1.1.1.2 christos const void *buf, size_t len, SSL *ssl, void *arg) 3619 1.1 christos { 3620 1.1 christos uint64_t frame_type, frame_data; 3621 1.1 christos int was_minimal; 3622 1.1 christos struct helper *h = arg; 3623 1.1 christos PACKET pkt; 3624 1.1 christos 3625 1.1 christos if (version != OSSL_QUIC1_VERSION 3626 1.1 christos || content_type != SSL3_RT_QUIC_FRAME_FULL 3627 1.1 christos || len < 1) 3628 1.1 christos return; 3629 1.1 christos 3630 1.1 christos if (!TEST_true(PACKET_buf_init(&pkt, buf, len))) { 3631 1.1 christos ++h->scratch1; 3632 1.1 christos return; 3633 1.1 christos } 3634 1.1 christos 3635 1.1 christos if (!TEST_true(ossl_quic_wire_peek_frame_header(&pkt, &frame_type, 3636 1.1.1.2 christos &was_minimal))) { 3637 1.1 christos ++h->scratch1; 3638 1.1 christos return; 3639 1.1 christos } 3640 1.1 christos 3641 1.1 christos if (frame_type != OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE) 3642 1.1 christos return; 3643 1.1 christos 3644 1.1.1.2 christos if (!TEST_true(ossl_quic_wire_decode_frame_path_response(&pkt, &frame_data)) 3645 1.1.1.2 christos || !TEST_uint64_t_eq(frame_data, path_challenge)) { 3646 1.1.1.2 christos ++h->scratch1; 3647 1.1 christos return; 3648 1.1.1.2 christos } 3649 1.1 christos 3650 1.1.1.2 christos ++h->scratch0; 3651 1.1 christos } 3652 1.1 christos 3653 1.1 christos static int script_41_setup(struct helper *h, struct helper_local *hl) 3654 1.1 christos { 3655 1.1 christos ossl_quic_tserver_set_msg_callback(ACQUIRE_S(), script_41_trace, h); 3656 1.1 christos return 1; 3657 1.1 christos } 3658 1.1 christos 3659 1.1 christos static int script_41_check(struct helper *h, struct helper_local *hl) 3660 1.1 christos { 3661 1.1 christos /* At least one valid challenge/response echo? */ 3662 1.1 christos if (!TEST_uint64_t_gt(h->scratch0, 0)) 3663 1.1 christos return 0; 3664 1.1 christos 3665 1.1 christos /* No failed tests? */ 3666 1.1 christos if (!TEST_uint64_t_eq(h->scratch1, 0)) 3667 1.1 christos return 0; 3668 1.1 christos 3669 1.1 christos return 1; 3670 1.1 christos } 3671 1.1 christos 3672 1.1 christos static const struct script_op script_41[] = { 3673 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_41_inject_plain) 3674 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3675 1.1.1.2 christos OP_C_CONNECT_WAIT() 3676 1.1.1.2 christos OP_CHECK(script_41_setup, 0) 3677 1.1 christos 3678 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 3679 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 3680 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 3681 1.1 christos 3682 1.1.1.2 christos OP_SET_INJECT_WORD(1, OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE) 3683 1.1 christos 3684 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 3685 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "orange", 6) 3686 1.1 christos 3687 1.1.1.2 christos OP_C_WRITE(DEFAULT, "strawberry", 10) 3688 1.1.1.2 christos OP_S_READ_EXPECT(a, "strawberry", 10) 3689 1.1 christos 3690 1.1.1.2 christos OP_CHECK(script_41_check, 0) 3691 1.1.1.2 christos OP_END 3692 1.1 christos }; 3693 1.1 christos 3694 1.1 christos /* 42. Fault injection - CRYPTO frame with illegal offset */ 3695 1.1 christos static int script_42_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, 3696 1.1.1.2 christos unsigned char *buf, size_t len) 3697 1.1 christos { 3698 1.1 christos int ok = 0; 3699 1.1 christos unsigned char frame_buf[64]; 3700 1.1 christos size_t written; 3701 1.1 christos WPACKET wpkt; 3702 1.1 christos 3703 1.1 christos if (h->inject_word0 == 0) 3704 1.1 christos return 1; 3705 1.1 christos 3706 1.1 christos --h->inject_word0; 3707 1.1 christos 3708 1.1 christos if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, 3709 1.1.1.2 christos sizeof(frame_buf), 0))) 3710 1.1 christos return 0; 3711 1.1 christos 3712 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_FRAME_TYPE_CRYPTO)) 3713 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1)) 3714 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 1)) 3715 1.1 christos || !TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x42))) 3716 1.1 christos goto err; 3717 1.1 christos 3718 1.1 christos if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) 3719 1.1 christos goto err; 3720 1.1 christos 3721 1.1 christos if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) 3722 1.1 christos goto err; 3723 1.1 christos 3724 1.1 christos ok = 1; 3725 1.1 christos err: 3726 1.1 christos if (ok) 3727 1.1 christos WPACKET_finish(&wpkt); 3728 1.1 christos else 3729 1.1 christos WPACKET_cleanup(&wpkt); 3730 1.1 christos return ok; 3731 1.1 christos } 3732 1.1 christos 3733 1.1 christos static const struct script_op script_42[] = { 3734 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_42_inject_plain) 3735 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3736 1.1.1.2 christos OP_C_CONNECT_WAIT() 3737 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 3738 1.1 christos 3739 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 3740 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 3741 1.1 christos 3742 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 3743 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 3744 1.1 christos 3745 1.1.1.2 christos OP_SET_INJECT_WORD(1, (((uint64_t)1) << 62) - 1) 3746 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 3747 1.1 christos 3748 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_FRAME_ENCODING_ERROR, 0, 0) 3749 1.1 christos 3750 1.1.1.2 christos OP_END 3751 1.1 christos }; 3752 1.1 christos 3753 1.1 christos /* 43. Fault injection - CRYPTO frame exceeding FC */ 3754 1.1 christos static const struct script_op script_43[] = { 3755 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_42_inject_plain) 3756 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3757 1.1.1.2 christos OP_C_CONNECT_WAIT() 3758 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 3759 1.1 christos 3760 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 3761 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 3762 1.1 christos 3763 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 3764 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 3765 1.1 christos 3766 1.1.1.2 christos OP_SET_INJECT_WORD(1, 0x100000 /* 1 MiB */) 3767 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 3768 1.1 christos 3769 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_CRYPTO_BUFFER_EXCEEDED, 0, 0) 3770 1.1 christos 3771 1.1.1.2 christos OP_END 3772 1.1 christos }; 3773 1.1 christos 3774 1.1 christos /* 44. Fault injection - PADDING */ 3775 1.1 christos static int script_44_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, 3776 1.1.1.2 christos unsigned char *buf, size_t len) 3777 1.1 christos { 3778 1.1 christos int ok = 0; 3779 1.1 christos WPACKET wpkt; 3780 1.1 christos unsigned char frame_buf[16]; 3781 1.1 christos size_t written; 3782 1.1 christos 3783 1.1 christos if (h->inject_word0 == 0 || hdr->type != QUIC_PKT_TYPE_1RTT) 3784 1.1 christos return 1; 3785 1.1 christos 3786 1.1 christos if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, 3787 1.1.1.2 christos sizeof(frame_buf), 0))) 3788 1.1 christos return 0; 3789 1.1 christos 3790 1.1 christos if (!TEST_true(ossl_quic_wire_encode_padding(&wpkt, 1))) 3791 1.1 christos goto err; 3792 1.1 christos 3793 1.1 christos if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) 3794 1.1 christos goto err; 3795 1.1 christos 3796 1.1 christos if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) 3797 1.1 christos goto err; 3798 1.1 christos 3799 1.1 christos ok = 1; 3800 1.1 christos err: 3801 1.1 christos if (ok) 3802 1.1 christos WPACKET_finish(&wpkt); 3803 1.1 christos else 3804 1.1 christos WPACKET_cleanup(&wpkt); 3805 1.1 christos return ok; 3806 1.1 christos } 3807 1.1 christos 3808 1.1 christos static const struct script_op script_44[] = { 3809 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_44_inject_plain) 3810 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3811 1.1.1.2 christos OP_C_CONNECT_WAIT() 3812 1.1 christos 3813 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 3814 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 3815 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 3816 1.1 christos 3817 1.1.1.2 christos OP_SET_INJECT_WORD(1, 0) 3818 1.1 christos 3819 1.1.1.2 christos OP_S_WRITE(a, "Strawberry", 10) 3820 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "Strawberry", 10) 3821 1.1 christos 3822 1.1.1.2 christos OP_END 3823 1.1 christos }; 3824 1.1 christos 3825 1.1 christos /* 45. PING must generate ACK */ 3826 1.1 christos static int force_ping(struct helper *h, struct helper_local *hl) 3827 1.1 christos { 3828 1.1 christos QUIC_CHANNEL *ch = ossl_quic_tserver_get_channel(ACQUIRE_S()); 3829 1.1 christos 3830 1.1 christos h->scratch0 = ossl_quic_channel_get_diag_num_rx_ack(ch); 3831 1.1 christos 3832 1.1 christos if (!TEST_true(ossl_quic_tserver_ping(ACQUIRE_S()))) 3833 1.1 christos return 0; 3834 1.1 christos 3835 1.1 christos return 1; 3836 1.1 christos } 3837 1.1 christos 3838 1.1 christos static int wait_incoming_acks_increased(struct helper *h, struct helper_local *hl) 3839 1.1 christos { 3840 1.1 christos QUIC_CHANNEL *ch = ossl_quic_tserver_get_channel(ACQUIRE_S()); 3841 1.1 christos uint16_t count; 3842 1.1 christos 3843 1.1 christos count = ossl_quic_channel_get_diag_num_rx_ack(ch); 3844 1.1 christos 3845 1.1 christos if (count == h->scratch0) { 3846 1.1 christos h->check_spin_again = 1; 3847 1.1 christos return 0; 3848 1.1 christos } 3849 1.1 christos 3850 1.1 christos return 1; 3851 1.1 christos } 3852 1.1 christos 3853 1.1 christos static const struct script_op script_45[] = { 3854 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3855 1.1.1.2 christos OP_C_CONNECT_WAIT() 3856 1.1 christos 3857 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 3858 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 3859 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 3860 1.1 christos 3861 1.1.1.2 christos OP_BEGIN_REPEAT(2) 3862 1.1 christos 3863 1.1.1.2 christos OP_CHECK(force_ping, 0) 3864 1.1.1.2 christos OP_CHECK(wait_incoming_acks_increased, 0) 3865 1.1 christos 3866 1.1.1.2 christos OP_END_REPEAT() 3867 1.1 christos 3868 1.1.1.2 christos OP_S_WRITE(a, "Strawberry", 10) 3869 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "Strawberry", 10) 3870 1.1 christos 3871 1.1.1.2 christos OP_END 3872 1.1 christos }; 3873 1.1 christos 3874 1.1 christos /* 46. Fault injection - ACK - malformed initial range */ 3875 1.1 christos static int script_46_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, 3876 1.1.1.2 christos unsigned char *buf, size_t len) 3877 1.1 christos { 3878 1.1 christos int ok = 0; 3879 1.1 christos WPACKET wpkt; 3880 1.1 christos unsigned char frame_buf[16]; 3881 1.1 christos size_t written; 3882 1.1 christos uint64_t type = 0, largest_acked = 0, first_range = 0, range_count = 0; 3883 1.1 christos uint64_t agap = 0, alen = 0; 3884 1.1 christos uint64_t ect0 = 0, ect1 = 0, ecnce = 0; 3885 1.1 christos 3886 1.1 christos if (h->inject_word0 == 0) 3887 1.1 christos return 1; 3888 1.1 christos 3889 1.1 christos if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, 3890 1.1.1.2 christos sizeof(frame_buf), 0))) 3891 1.1 christos return 0; 3892 1.1 christos 3893 1.1 christos type = OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN; 3894 1.1 christos 3895 1.1 christos switch (h->inject_word0) { 3896 1.1 christos case 1: 3897 1.1.1.2 christos largest_acked = 100; 3898 1.1.1.2 christos first_range = 101; 3899 1.1.1.2 christos range_count = 0; 3900 1.1 christos break; 3901 1.1 christos case 2: 3902 1.1.1.2 christos largest_acked = 100; 3903 1.1.1.2 christos first_range = 80; 3904 1.1 christos /* [20..100]; [0..18] */ 3905 1.1.1.2 christos range_count = 1; 3906 1.1.1.2 christos agap = 0; 3907 1.1.1.2 christos alen = 19; 3908 1.1 christos break; 3909 1.1 christos case 3: 3910 1.1.1.2 christos largest_acked = 100; 3911 1.1.1.2 christos first_range = 80; 3912 1.1.1.2 christos range_count = 1; 3913 1.1.1.2 christos agap = 18; 3914 1.1.1.2 christos alen = 1; 3915 1.1 christos break; 3916 1.1 christos case 4: 3917 1.1.1.2 christos type = OSSL_QUIC_FRAME_TYPE_ACK_WITH_ECN; 3918 1.1.1.2 christos largest_acked = 100; 3919 1.1.1.2 christos first_range = 1; 3920 1.1.1.2 christos range_count = 0; 3921 1.1 christos break; 3922 1.1 christos case 5: 3923 1.1.1.2 christos type = OSSL_QUIC_FRAME_TYPE_ACK_WITH_ECN; 3924 1.1.1.2 christos largest_acked = 0; 3925 1.1.1.2 christos first_range = 0; 3926 1.1.1.2 christos range_count = 0; 3927 1.1.1.2 christos ect0 = 0; 3928 1.1.1.2 christos ect1 = 50; 3929 1.1.1.2 christos ecnce = 200; 3930 1.1 christos break; 3931 1.1 christos } 3932 1.1 christos 3933 1.1 christos h->inject_word0 = 0; 3934 1.1 christos 3935 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, type)) 3936 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, largest_acked)) 3937 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, /*ack_delay=*/0)) 3938 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, /*ack_range_count=*/range_count)) 3939 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, /*first_ack_range=*/first_range))) 3940 1.1 christos goto err; 3941 1.1 christos 3942 1.1 christos if (range_count > 0) 3943 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, /*range[0].gap=*/agap)) 3944 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, /*range[0].len=*/alen))) 3945 1.1 christos goto err; 3946 1.1 christos 3947 1.1 christos if (type == OSSL_QUIC_FRAME_TYPE_ACK_WITH_ECN) 3948 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, ect0)) 3949 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, ect1)) 3950 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, ecnce))) 3951 1.1 christos goto err; 3952 1.1 christos 3953 1.1 christos if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) 3954 1.1 christos goto err; 3955 1.1 christos 3956 1.1 christos if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) 3957 1.1 christos goto err; 3958 1.1 christos 3959 1.1 christos ok = 1; 3960 1.1 christos err: 3961 1.1 christos if (ok) 3962 1.1 christos WPACKET_finish(&wpkt); 3963 1.1 christos else 3964 1.1 christos WPACKET_cleanup(&wpkt); 3965 1.1 christos return ok; 3966 1.1 christos } 3967 1.1 christos 3968 1.1 christos static const struct script_op script_46[] = { 3969 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_46_inject_plain) 3970 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3971 1.1.1.2 christos OP_C_CONNECT_WAIT() 3972 1.1 christos 3973 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 3974 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 3975 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 3976 1.1 christos 3977 1.1.1.2 christos OP_SET_INJECT_WORD(1, 0) 3978 1.1 christos 3979 1.1.1.2 christos OP_S_WRITE(a, "Strawberry", 10) 3980 1.1 christos 3981 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_FRAME_ENCODING_ERROR, 0, 0) 3982 1.1 christos 3983 1.1.1.2 christos OP_END 3984 1.1 christos }; 3985 1.1 christos 3986 1.1 christos /* 47. Fault injection - ACK - malformed subsequent range */ 3987 1.1 christos static const struct script_op script_47[] = { 3988 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_46_inject_plain) 3989 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 3990 1.1.1.2 christos OP_C_CONNECT_WAIT() 3991 1.1 christos 3992 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 3993 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 3994 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 3995 1.1 christos 3996 1.1.1.2 christos OP_SET_INJECT_WORD(2, 0) 3997 1.1 christos 3998 1.1.1.2 christos OP_S_WRITE(a, "Strawberry", 10) 3999 1.1 christos 4000 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_FRAME_ENCODING_ERROR, 0, 0) 4001 1.1 christos 4002 1.1.1.2 christos OP_END 4003 1.1 christos }; 4004 1.1 christos 4005 1.1 christos /* 48. Fault injection - ACK - malformed subsequent range */ 4006 1.1 christos static const struct script_op script_48[] = { 4007 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_46_inject_plain) 4008 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4009 1.1.1.2 christos OP_C_CONNECT_WAIT() 4010 1.1 christos 4011 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 4012 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4013 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 4014 1.1 christos 4015 1.1.1.2 christos OP_SET_INJECT_WORD(3, 0) 4016 1.1 christos 4017 1.1.1.2 christos OP_S_WRITE(a, "Strawberry", 10) 4018 1.1 christos 4019 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_FRAME_ENCODING_ERROR, 0, 0) 4020 1.1 christos 4021 1.1.1.2 christos OP_END 4022 1.1 christos }; 4023 1.1 christos 4024 1.1 christos /* 49. Fault injection - ACK - fictional PN */ 4025 1.1 christos static const struct script_op script_49[] = { 4026 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_46_inject_plain) 4027 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4028 1.1.1.2 christos OP_C_CONNECT_WAIT() 4029 1.1 christos 4030 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 4031 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4032 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 4033 1.1 christos 4034 1.1.1.2 christos OP_SET_INJECT_WORD(4, 0) 4035 1.1 christos 4036 1.1.1.2 christos OP_S_WRITE(a, "Strawberry", 10) 4037 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "Strawberry", 10) 4038 1.1 christos 4039 1.1.1.2 christos OP_END 4040 1.1 christos }; 4041 1.1 christos 4042 1.1 christos /* 50. Fault injection - ACK - duplicate PN */ 4043 1.1 christos static const struct script_op script_50[] = { 4044 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_46_inject_plain) 4045 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4046 1.1.1.2 christos OP_C_CONNECT_WAIT() 4047 1.1 christos 4048 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 4049 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4050 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 4051 1.1 christos 4052 1.1.1.2 christos OP_BEGIN_REPEAT(2) 4053 1.1 christos 4054 1.1.1.2 christos OP_SET_INJECT_WORD(5, 0) 4055 1.1 christos 4056 1.1.1.2 christos OP_S_WRITE(a, "Strawberry", 10) 4057 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "Strawberry", 10) 4058 1.1 christos 4059 1.1.1.2 christos OP_END_REPEAT() 4060 1.1 christos 4061 1.1.1.2 christos OP_END 4062 1.1 christos }; 4063 1.1 christos 4064 1.1 christos /* 51. Fault injection - PATH_RESPONSE is ignored */ 4065 1.1 christos static const struct script_op script_51[] = { 4066 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_41_inject_plain) 4067 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4068 1.1.1.2 christos OP_C_CONNECT_WAIT() 4069 1.1 christos 4070 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 4071 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4072 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 4073 1.1 christos 4074 1.1.1.2 christos OP_SET_INJECT_WORD(1, OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE) 4075 1.1 christos 4076 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 4077 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "orange", 6) 4078 1.1 christos 4079 1.1.1.2 christos OP_C_WRITE(DEFAULT, "Strawberry", 10) 4080 1.1.1.2 christos OP_S_READ_EXPECT(a, "Strawberry", 10) 4081 1.1 christos 4082 1.1.1.2 christos OP_END 4083 1.1 christos }; 4084 1.1 christos 4085 1.1 christos /* 52. Fault injection - ignore BLOCKED frames with bogus values */ 4086 1.1 christos static int script_52_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, 4087 1.1.1.2 christos unsigned char *buf, size_t len) 4088 1.1 christos { 4089 1.1 christos int ok = 0; 4090 1.1 christos unsigned char frame_buf[64]; 4091 1.1 christos size_t written; 4092 1.1 christos WPACKET wpkt; 4093 1.1 christos uint64_t type = h->inject_word1; 4094 1.1 christos 4095 1.1 christos if (h->inject_word0 == 0 || hdr->type != QUIC_PKT_TYPE_1RTT) 4096 1.1 christos return 1; 4097 1.1 christos 4098 1.1 christos --h->inject_word0; 4099 1.1 christos 4100 1.1 christos if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, 4101 1.1.1.2 christos sizeof(frame_buf), 0))) 4102 1.1 christos return 0; 4103 1.1 christos 4104 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, type))) 4105 1.1 christos goto err; 4106 1.1 christos 4107 1.1 christos if (type == OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED) 4108 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, C_BIDI_ID(0)))) 4109 1.1 christos goto err; 4110 1.1 christos 4111 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, 0xFFFFFF))) 4112 1.1 christos goto err; 4113 1.1 christos 4114 1.1 christos if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) 4115 1.1 christos goto err; 4116 1.1 christos 4117 1.1 christos if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) 4118 1.1 christos goto err; 4119 1.1 christos 4120 1.1 christos ok = 1; 4121 1.1 christos err: 4122 1.1 christos if (ok) 4123 1.1 christos WPACKET_finish(&wpkt); 4124 1.1 christos else 4125 1.1 christos WPACKET_cleanup(&wpkt); 4126 1.1 christos return ok; 4127 1.1 christos } 4128 1.1 christos 4129 1.1 christos static const struct script_op script_52[] = { 4130 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_52_inject_plain) 4131 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4132 1.1.1.2 christos OP_C_CONNECT_WAIT() 4133 1.1 christos 4134 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 4135 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4136 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 4137 1.1 christos 4138 1.1.1.2 christos OP_SET_INJECT_WORD(1, OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED) 4139 1.1 christos 4140 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 4141 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "orange", 6) 4142 1.1 christos 4143 1.1.1.2 christos OP_C_WRITE(DEFAULT, "Strawberry", 10) 4144 1.1.1.2 christos OP_S_READ_EXPECT(a, "Strawberry", 10) 4145 1.1 christos 4146 1.1.1.2 christos OP_SET_INJECT_WORD(1, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED) 4147 1.1 christos 4148 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 4149 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "orange", 6) 4150 1.1 christos 4151 1.1.1.2 christos OP_C_WRITE(DEFAULT, "Strawberry", 10) 4152 1.1.1.2 christos OP_S_READ_EXPECT(a, "Strawberry", 10) 4153 1.1 christos 4154 1.1.1.2 christos OP_SET_INJECT_WORD(1, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI) 4155 1.1 christos 4156 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 4157 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "orange", 6) 4158 1.1 christos 4159 1.1.1.2 christos OP_C_WRITE(DEFAULT, "Strawberry", 10) 4160 1.1.1.2 christos OP_S_READ_EXPECT(a, "Strawberry", 10) 4161 1.1 christos 4162 1.1.1.2 christos OP_SET_INJECT_WORD(1, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI) 4163 1.1 christos 4164 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 4165 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "orange", 6) 4166 1.1 christos 4167 1.1.1.2 christos OP_C_WRITE(DEFAULT, "Strawberry", 10) 4168 1.1.1.2 christos OP_S_READ_EXPECT(a, "Strawberry", 10) 4169 1.1 christos 4170 1.1.1.2 christos OP_END 4171 1.1 christos }; 4172 1.1 christos 4173 1.1 christos /* 53. Fault injection - excess CRYPTO buffer size */ 4174 1.1 christos static int script_53_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, 4175 1.1.1.2 christos unsigned char *buf, size_t len) 4176 1.1 christos { 4177 1.1 christos int ok = 0; 4178 1.1 christos size_t written; 4179 1.1 christos WPACKET wpkt; 4180 1.1 christos uint64_t offset = 0, data_len = 100; 4181 1.1 christos unsigned char *frame_buf = NULL; 4182 1.1 christos size_t frame_len, i; 4183 1.1 christos 4184 1.1 christos if (h->inject_word0 == 0 || hdr->type != QUIC_PKT_TYPE_1RTT) 4185 1.1 christos return 1; 4186 1.1 christos 4187 1.1 christos h->inject_word0 = 0; 4188 1.1 christos 4189 1.1 christos switch (h->inject_word1) { 4190 1.1 christos case 0: 4191 1.1 christos /* 4192 1.1 christos * Far out offset which will not have been reached during handshake. 4193 1.1 christos * This will not be delivered to the QUIC_TLS instance since it will be 4194 1.1 christos * waiting for in-order delivery of previous bytes. This tests our flow 4195 1.1 christos * control on CRYPTO stream buffering. 4196 1.1 christos */ 4197 1.1.1.2 christos offset = 100000; 4198 1.1.1.2 christos data_len = 1; 4199 1.1 christos break; 4200 1.1 christos } 4201 1.1 christos 4202 1.1 christos frame_len = 1 + 8 + 8 + (size_t)data_len; 4203 1.1 christos if (!TEST_ptr(frame_buf = OPENSSL_malloc(frame_len))) 4204 1.1 christos return 0; 4205 1.1 christos 4206 1.1 christos if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, frame_len, 0))) 4207 1.1 christos goto err; 4208 1.1 christos 4209 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_FRAME_TYPE_CRYPTO)) 4210 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, offset)) 4211 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, data_len))) 4212 1.1 christos goto err; 4213 1.1 christos 4214 1.1 christos for (i = 0; i < data_len; ++i) 4215 1.1 christos if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x42))) 4216 1.1 christos goto err; 4217 1.1 christos 4218 1.1 christos if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) 4219 1.1 christos goto err; 4220 1.1 christos 4221 1.1 christos if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) 4222 1.1 christos goto err; 4223 1.1 christos 4224 1.1 christos ok = 1; 4225 1.1 christos err: 4226 1.1 christos if (ok) 4227 1.1 christos WPACKET_finish(&wpkt); 4228 1.1 christos else 4229 1.1 christos WPACKET_cleanup(&wpkt); 4230 1.1 christos OPENSSL_free(frame_buf); 4231 1.1 christos return ok; 4232 1.1 christos } 4233 1.1 christos 4234 1.1 christos static const struct script_op script_53[] = { 4235 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_53_inject_plain) 4236 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4237 1.1.1.2 christos OP_C_CONNECT_WAIT() 4238 1.1 christos 4239 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 4240 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4241 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 4242 1.1 christos 4243 1.1.1.2 christos OP_SET_INJECT_WORD(1, 0) 4244 1.1.1.2 christos OP_S_WRITE(a, "Strawberry", 10) 4245 1.1 christos 4246 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_CRYPTO_BUFFER_EXCEEDED, 0, 0) 4247 1.1 christos 4248 1.1.1.2 christos OP_END 4249 1.1 christos }; 4250 1.1 christos 4251 1.1 christos /* 54. Fault injection - corrupted crypto stream data */ 4252 1.1 christos static int script_54_inject_handshake(struct helper *h, 4253 1.1.1.2 christos unsigned char *buf, size_t buf_len) 4254 1.1 christos { 4255 1.1 christos size_t i; 4256 1.1 christos 4257 1.1 christos for (i = 0; i < buf_len; ++i) 4258 1.1 christos buf[i] ^= 0xff; 4259 1.1 christos 4260 1.1 christos return 1; 4261 1.1 christos } 4262 1.1 christos 4263 1.1 christos static const struct script_op script_54[] = { 4264 1.1 christos OP_S_SET_INJECT_HANDSHAKE(script_54_inject_handshake) 4265 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4266 1.1.1.2 christos OP_C_CONNECT_WAIT_OR_FAIL() 4267 1.1 christos 4268 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_CRYPTO_UNEXPECTED_MESSAGE, 0, 0) 4269 1.1 christos 4270 1.1.1.2 christos OP_END 4271 1.1 christos }; 4272 1.1 christos 4273 1.1 christos /* 55. Fault injection - NEW_CONN_ID with >20 byte CID */ 4274 1.1 christos static const struct script_op script_55[] = { 4275 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_39_inject_plain) 4276 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4277 1.1.1.2 christos OP_C_CONNECT_WAIT() 4278 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 4279 1.1.1.2 christos 4280 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 4281 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 4282 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4283 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 4284 1.1 christos 4285 1.1.1.2 christos OP_SET_INJECT_WORD(0, 2) 4286 1.1.1.2 christos OP_S_WRITE(a, "orange", 5) 4287 1.1 christos 4288 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_FRAME_ENCODING_ERROR, 0, 0) 4289 1.1 christos 4290 1.1.1.2 christos OP_END 4291 1.1 christos }; 4292 1.1 christos 4293 1.1 christos /* 56. Fault injection - NEW_CONN_ID with seq no < retire prior to */ 4294 1.1 christos static const struct script_op script_56[] = { 4295 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_39_inject_plain) 4296 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4297 1.1.1.2 christos OP_C_CONNECT_WAIT() 4298 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 4299 1.1.1.2 christos 4300 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 4301 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 4302 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4303 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 4304 1.1 christos 4305 1.1.1.2 christos OP_SET_INJECT_WORD(0, 3) 4306 1.1.1.2 christos OP_S_WRITE(a, "orange", 5) 4307 1.1 christos 4308 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_FRAME_ENCODING_ERROR, 0, 0) 4309 1.1 christos 4310 1.1.1.2 christos OP_END 4311 1.1 christos }; 4312 1.1 christos 4313 1.1 christos /* 57. Fault injection - NEW_CONN_ID with lower seq so ignored */ 4314 1.1 christos static const struct script_op script_57[] = { 4315 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_39_inject_plain) 4316 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4317 1.1.1.2 christos OP_C_CONNECT_WAIT() 4318 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 4319 1.1.1.2 christos 4320 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 4321 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 4322 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4323 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 4324 1.1.1.2 christos 4325 1.1.1.2 christos OP_SET_INJECT_WORD(0, 4) 4326 1.1.1.2 christos OP_S_WRITE(a, "orange", 5) 4327 1.1.1.2 christos OP_C_READ_EXPECT(a, "orange", 5) 4328 1.1 christos 4329 1.1.1.2 christos OP_C_WRITE(a, "Strawberry", 10) 4330 1.1.1.2 christos OP_S_READ_EXPECT(a, "Strawberry", 10) 4331 1.1 christos 4332 1.1 christos /* 4333 1.1 christos * Now we send a NEW_CONN_ID with a bogus CID. However the sequence number 4334 1.1 christos * is old so it should be ignored and we should still be able to 4335 1.1 christos * communicate. 4336 1.1 christos */ 4337 1.1.1.2 christos OP_SET_INJECT_WORD(0, 5) 4338 1.1.1.2 christos OP_S_WRITE(a, "raspberry", 9) 4339 1.1.1.2 christos OP_C_READ_EXPECT(a, "raspberry", 9) 4340 1.1 christos 4341 1.1.1.2 christos OP_C_WRITE(a, "peach", 5) 4342 1.1.1.2 christos OP_S_READ_EXPECT(a, "peach", 5) 4343 1.1 christos 4344 1.1.1.2 christos OP_END 4345 1.1 christos }; 4346 1.1 christos 4347 1.1 christos /* 58. Fault injection - repeated HANDSHAKE_DONE */ 4348 1.1 christos static int script_58_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, 4349 1.1.1.2 christos unsigned char *buf, size_t len) 4350 1.1 christos { 4351 1.1 christos int ok = 0; 4352 1.1 christos unsigned char frame_buf[64]; 4353 1.1 christos size_t written; 4354 1.1 christos WPACKET wpkt; 4355 1.1 christos 4356 1.1 christos if (h->inject_word0 == 0 || hdr->type != QUIC_PKT_TYPE_1RTT) 4357 1.1 christos return 1; 4358 1.1 christos 4359 1.1 christos if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, 4360 1.1.1.2 christos sizeof(frame_buf), 0))) 4361 1.1 christos return 0; 4362 1.1 christos 4363 1.1 christos if (h->inject_word0 == 1) { 4364 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE))) 4365 1.1 christos goto err; 4366 1.1 christos } else { 4367 1.1 christos /* Needless multi-byte encoding */ 4368 1.1 christos if (!TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x40)) 4369 1.1 christos || !TEST_true(WPACKET_put_bytes_u8(&wpkt, 0x1E))) 4370 1.1 christos goto err; 4371 1.1 christos } 4372 1.1 christos 4373 1.1 christos if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) 4374 1.1 christos goto err; 4375 1.1 christos 4376 1.1 christos if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) 4377 1.1 christos goto err; 4378 1.1 christos 4379 1.1 christos ok = 1; 4380 1.1 christos err: 4381 1.1 christos if (ok) 4382 1.1 christos WPACKET_finish(&wpkt); 4383 1.1 christos else 4384 1.1 christos WPACKET_cleanup(&wpkt); 4385 1.1 christos return ok; 4386 1.1 christos } 4387 1.1 christos 4388 1.1 christos static const struct script_op script_58[] = { 4389 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_58_inject_plain) 4390 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4391 1.1.1.2 christos OP_C_CONNECT_WAIT() 4392 1.1 christos 4393 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 4394 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4395 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 4396 1.1 christos 4397 1.1.1.2 christos OP_SET_INJECT_WORD(1, 0) 4398 1.1 christos 4399 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 4400 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "orange", 6) 4401 1.1 christos 4402 1.1.1.2 christos OP_C_WRITE(DEFAULT, "Strawberry", 10) 4403 1.1.1.2 christos OP_S_READ_EXPECT(a, "Strawberry", 10) 4404 1.1 christos 4405 1.1.1.2 christos OP_END 4406 1.1 christos }; 4407 1.1 christos 4408 1.1 christos /* 59. Fault injection - multi-byte frame encoding */ 4409 1.1 christos static const struct script_op script_59[] = { 4410 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_58_inject_plain) 4411 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4412 1.1.1.2 christos OP_C_CONNECT_WAIT() 4413 1.1 christos 4414 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 4415 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4416 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 4417 1.1 christos 4418 1.1.1.2 christos OP_SET_INJECT_WORD(2, 0) 4419 1.1 christos 4420 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 4421 1.1 christos 4422 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_PROTOCOL_VIOLATION, 0, 0) 4423 1.1 christos 4424 1.1.1.2 christos OP_END 4425 1.1 christos }; 4426 1.1 christos 4427 1.1 christos /* 60. Connection close reason truncation */ 4428 1.1 christos static char long_reason[2048]; 4429 1.1 christos 4430 1.1 christos static int init_reason(struct helper *h, struct helper_local *hl) 4431 1.1 christos { 4432 1.1 christos memset(long_reason, '~', sizeof(long_reason)); 4433 1.1 christos memcpy(long_reason, "This is a long reason string.", 29); 4434 1.1 christos long_reason[OSSL_NELEM(long_reason) - 1] = '\0'; 4435 1.1 christos return 1; 4436 1.1 christos } 4437 1.1 christos 4438 1.1 christos static int check_shutdown_reason(struct helper *h, struct helper_local *hl) 4439 1.1 christos { 4440 1.1 christos const QUIC_TERMINATE_CAUSE *tc = ossl_quic_tserver_get_terminate_cause(ACQUIRE_S()); 4441 1.1 christos 4442 1.1 christos if (tc == NULL) { 4443 1.1 christos h->check_spin_again = 1; 4444 1.1 christos return 0; 4445 1.1 christos } 4446 1.1 christos 4447 1.1 christos if (!TEST_size_t_ge(tc->reason_len, 50) 4448 1.1 christos || !TEST_mem_eq(long_reason, tc->reason_len, 4449 1.1.1.2 christos tc->reason, tc->reason_len)) 4450 1.1 christos return 0; 4451 1.1 christos 4452 1.1 christos return 1; 4453 1.1 christos } 4454 1.1 christos 4455 1.1 christos static const struct script_op script_60[] = { 4456 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4457 1.1.1.2 christos OP_C_CONNECT_WAIT() 4458 1.1 christos 4459 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 4460 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4461 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 4462 1.1.1.2 christos 4463 1.1.1.2 christos OP_CHECK(init_reason, 0) 4464 1.1.1.2 christos OP_C_SHUTDOWN_WAIT(long_reason, 0) 4465 1.1.1.2 christos OP_CHECK(check_shutdown_reason, 0) 4466 1.1 christos 4467 1.1.1.2 christos OP_END 4468 1.1 christos }; 4469 1.1 christos 4470 1.1 christos /* 61. Fault injection - RESET_STREAM exceeding stream count FC */ 4471 1.1 christos static int script_61_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, 4472 1.1.1.2 christos unsigned char *buf, size_t len) 4473 1.1 christos { 4474 1.1 christos int ok = 0; 4475 1.1 christos WPACKET wpkt; 4476 1.1 christos unsigned char frame_buf[32]; 4477 1.1 christos size_t written; 4478 1.1 christos 4479 1.1 christos if (h->inject_word0 == 0 || hdr->type != QUIC_PKT_TYPE_1RTT) 4480 1.1 christos return 1; 4481 1.1 christos 4482 1.1 christos if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, 4483 1.1.1.2 christos sizeof(frame_buf), 0))) 4484 1.1 christos return 0; 4485 1.1 christos 4486 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word0)) 4487 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, /* stream ID */ 4488 1.1.1.2 christos h->inject_word1)) 4489 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 123)) 4490 1.1 christos || (h->inject_word0 == OSSL_QUIC_FRAME_TYPE_RESET_STREAM 4491 1.1.1.2 christos && !TEST_true(WPACKET_quic_write_vlint(&wpkt, 0)))) /* final size */ 4492 1.1 christos goto err; 4493 1.1 christos 4494 1.1 christos if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) 4495 1.1 christos goto err; 4496 1.1 christos 4497 1.1 christos if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) 4498 1.1 christos goto err; 4499 1.1 christos 4500 1.1 christos ok = 1; 4501 1.1 christos err: 4502 1.1 christos if (ok) 4503 1.1 christos WPACKET_finish(&wpkt); 4504 1.1 christos else 4505 1.1 christos WPACKET_cleanup(&wpkt); 4506 1.1 christos return ok; 4507 1.1 christos } 4508 1.1 christos 4509 1.1 christos static const struct script_op script_61[] = { 4510 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_61_inject_plain) 4511 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4512 1.1.1.2 christos OP_C_CONNECT_WAIT() 4513 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 4514 1.1 christos 4515 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 4516 1.1.1.2 christos OP_C_WRITE(a, "orange", 6) 4517 1.1 christos 4518 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4519 1.1.1.2 christos OP_S_READ_EXPECT(a, "orange", 6) 4520 1.1 christos 4521 1.1.1.2 christos OP_SET_INJECT_WORD(OSSL_QUIC_FRAME_TYPE_RESET_STREAM, 4522 1.1.1.2 christos S_BIDI_ID(OSSL_QUIC_VLINT_MAX / 4)) 4523 1.1.1.2 christos OP_S_WRITE(a, "fruit", 5) 4524 1.1 christos 4525 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_STREAM_LIMIT_ERROR, 0, 0) 4526 1.1 christos 4527 1.1.1.2 christos OP_END 4528 1.1 christos }; 4529 1.1 christos 4530 1.1 christos /* 62. Fault injection - STOP_SENDING with high ID */ 4531 1.1 christos static const struct script_op script_62[] = { 4532 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_61_inject_plain) 4533 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4534 1.1.1.2 christos OP_C_CONNECT_WAIT() 4535 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 4536 1.1 christos 4537 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 4538 1.1.1.2 christos OP_C_WRITE(a, "orange", 6) 4539 1.1 christos 4540 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4541 1.1.1.2 christos OP_S_READ_EXPECT(a, "orange", 6) 4542 1.1 christos 4543 1.1.1.2 christos OP_SET_INJECT_WORD(OSSL_QUIC_FRAME_TYPE_STOP_SENDING, 4544 1.1.1.2 christos C_BIDI_ID(OSSL_QUIC_VLINT_MAX / 4)) 4545 1.1.1.2 christos OP_S_WRITE(a, "fruit", 5) 4546 1.1 christos 4547 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_STREAM_STATE_ERROR, 0, 0) 4548 1.1 christos 4549 1.1.1.2 christos OP_END 4550 1.1 christos }; 4551 1.1 christos 4552 1.1 christos /* 63. Fault injection - STREAM frame exceeding stream limit */ 4553 1.1 christos static const struct script_op script_63[] = { 4554 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_32_inject_plain) 4555 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4556 1.1.1.2 christos OP_C_CONNECT_WAIT() 4557 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 4558 1.1 christos 4559 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 4560 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 4561 1.1 christos 4562 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4563 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 4564 1.1 christos 4565 1.1.1.2 christos OP_SET_INJECT_WORD(S_BIDI_ID(5000) + 1, 4) 4566 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 4567 1.1 christos 4568 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_STREAM_LIMIT_ERROR, 0, 0) 4569 1.1 christos 4570 1.1.1.2 christos OP_END 4571 1.1 christos }; 4572 1.1 christos 4573 1.1 christos /* 64. Fault injection - STREAM - zero-length no-FIN is accepted */ 4574 1.1 christos static const struct script_op script_64[] = { 4575 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_32_inject_plain) 4576 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4577 1.1.1.2 christos OP_C_CONNECT_WAIT() 4578 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 4579 1.1.1.2 christos 4580 1.1.1.2 christos OP_S_NEW_STREAM_UNI(a, S_UNI_ID(0)) 4581 1.1.1.2 christos OP_S_WRITE(a, "apple", 5) 4582 1.1.1.2 christos 4583 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(a) 4584 1.1.1.2 christos OP_C_READ_EXPECT(a, "apple", 5) 4585 1.1.1.2 christos 4586 1.1.1.2 christos OP_SET_INJECT_WORD(S_BIDI_ID(20) + 1, 1) 4587 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 4588 1.1.1.2 christos OP_C_READ_EXPECT(a, "orange", 6) 4589 1.1 christos 4590 1.1.1.2 christos OP_END 4591 1.1 christos }; 4592 1.1 christos 4593 1.1 christos /* 65. Fault injection - CRYPTO - zero-length is accepted */ 4594 1.1 christos static int script_65_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, 4595 1.1.1.2 christos unsigned char *buf, size_t len) 4596 1.1 christos { 4597 1.1 christos int ok = 0; 4598 1.1 christos unsigned char frame_buf[64]; 4599 1.1 christos size_t written; 4600 1.1 christos WPACKET wpkt; 4601 1.1 christos 4602 1.1 christos if (h->inject_word0 == 0) 4603 1.1 christos return 1; 4604 1.1 christos 4605 1.1 christos --h->inject_word0; 4606 1.1 christos 4607 1.1 christos if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, 4608 1.1.1.2 christos sizeof(frame_buf), 0))) 4609 1.1 christos return 0; 4610 1.1 christos 4611 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_FRAME_TYPE_CRYPTO)) 4612 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 0)) 4613 1.1 christos || !TEST_true(WPACKET_quic_write_vlint(&wpkt, 0))) 4614 1.1 christos goto err; 4615 1.1 christos 4616 1.1 christos if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) 4617 1.1 christos goto err; 4618 1.1 christos 4619 1.1 christos if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) 4620 1.1 christos goto err; 4621 1.1 christos 4622 1.1 christos ok = 1; 4623 1.1 christos err: 4624 1.1 christos if (ok) 4625 1.1 christos WPACKET_finish(&wpkt); 4626 1.1 christos else 4627 1.1 christos WPACKET_cleanup(&wpkt); 4628 1.1 christos return ok; 4629 1.1 christos } 4630 1.1 christos 4631 1.1 christos static const struct script_op script_65[] = { 4632 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_65_inject_plain) 4633 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4634 1.1.1.2 christos OP_C_CONNECT_WAIT() 4635 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 4636 1.1.1.2 christos 4637 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 4638 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 4639 1.1.1.2 christos 4640 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4641 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 4642 1.1.1.2 christos 4643 1.1.1.2 christos OP_SET_INJECT_WORD(1, 0) 4644 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 4645 1.1.1.2 christos OP_C_READ_EXPECT(a, "orange", 6) 4646 1.1 christos 4647 1.1.1.2 christos OP_END 4648 1.1 christos }; 4649 1.1 christos 4650 1.1 christos /* 66. Fault injection - large MAX_STREAM_DATA */ 4651 1.1 christos static int script_66_inject_plain(struct helper *h, QUIC_PKT_HDR *hdr, 4652 1.1.1.2 christos unsigned char *buf, size_t len) 4653 1.1 christos { 4654 1.1 christos int ok = 0; 4655 1.1 christos WPACKET wpkt; 4656 1.1 christos unsigned char frame_buf[64]; 4657 1.1 christos size_t written; 4658 1.1 christos 4659 1.1 christos if (h->inject_word0 == 0 || hdr->type != QUIC_PKT_TYPE_1RTT) 4660 1.1 christos return 1; 4661 1.1 christos 4662 1.1 christos if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, 4663 1.1.1.2 christos sizeof(frame_buf), 0))) 4664 1.1 christos return 0; 4665 1.1 christos 4666 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, h->inject_word1))) 4667 1.1 christos goto err; 4668 1.1 christos 4669 1.1 christos if (h->inject_word1 == OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA) 4670 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, /* stream ID */ 4671 1.1.1.2 christos h->inject_word0 - 1))) 4672 1.1 christos goto err; 4673 1.1 christos 4674 1.1 christos if (!TEST_true(WPACKET_quic_write_vlint(&wpkt, OSSL_QUIC_VLINT_MAX))) 4675 1.1 christos goto err; 4676 1.1 christos 4677 1.1 christos if (!TEST_true(WPACKET_get_total_written(&wpkt, &written))) 4678 1.1 christos goto err; 4679 1.1 christos 4680 1.1 christos if (!qtest_fault_prepend_frame(h->qtf, frame_buf, written)) 4681 1.1 christos goto err; 4682 1.1 christos 4683 1.1 christos ok = 1; 4684 1.1 christos err: 4685 1.1 christos if (ok) 4686 1.1 christos WPACKET_finish(&wpkt); 4687 1.1 christos else 4688 1.1 christos WPACKET_cleanup(&wpkt); 4689 1.1 christos return ok; 4690 1.1 christos } 4691 1.1 christos 4692 1.1 christos static const struct script_op script_66[] = { 4693 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_66_inject_plain) 4694 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4695 1.1.1.2 christos OP_C_CONNECT_WAIT() 4696 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 4697 1.1.1.2 christos 4698 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(a, S_BIDI_ID(0)) 4699 1.1.1.2 christos OP_S_WRITE(a, "apple", 5) 4700 1.1.1.2 christos 4701 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(a) 4702 1.1.1.2 christos OP_C_READ_EXPECT(a, "apple", 5) 4703 1.1.1.2 christos 4704 1.1.1.2 christos OP_SET_INJECT_WORD(S_BIDI_ID(0) + 1, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA) 4705 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 4706 1.1.1.2 christos OP_C_READ_EXPECT(a, "orange", 6) 4707 1.1.1.2 christos OP_C_WRITE(a, "Strawberry", 10) 4708 1.1.1.2 christos OP_S_READ_EXPECT(a, "Strawberry", 10) 4709 1.1 christos 4710 1.1.1.2 christos OP_END 4711 1.1 christos }; 4712 1.1 christos 4713 1.1 christos /* 67. Fault injection - large MAX_DATA */ 4714 1.1 christos static const struct script_op script_67[] = { 4715 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_66_inject_plain) 4716 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4717 1.1.1.2 christos OP_C_CONNECT_WAIT() 4718 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 4719 1.1.1.2 christos 4720 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(a, S_BIDI_ID(0)) 4721 1.1.1.2 christos OP_S_WRITE(a, "apple", 5) 4722 1.1.1.2 christos 4723 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(a) 4724 1.1.1.2 christos OP_C_READ_EXPECT(a, "apple", 5) 4725 1.1.1.2 christos 4726 1.1.1.2 christos OP_SET_INJECT_WORD(1, OSSL_QUIC_FRAME_TYPE_MAX_DATA) 4727 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 4728 1.1.1.2 christos OP_C_READ_EXPECT(a, "orange", 6) 4729 1.1.1.2 christos OP_C_WRITE(a, "Strawberry", 10) 4730 1.1.1.2 christos OP_S_READ_EXPECT(a, "Strawberry", 10) 4731 1.1 christos 4732 1.1.1.2 christos OP_END 4733 1.1 christos }; 4734 1.1 christos 4735 1.1 christos /* 68. Fault injection - Unexpected TLS messages */ 4736 1.1 christos static int script_68_inject_handshake(struct helper *h, unsigned char *msg, 4737 1.1.1.2 christos size_t msglen) 4738 1.1 christos { 4739 1.1 christos const unsigned char *data; 4740 1.1 christos size_t datalen; 4741 1.1 christos const unsigned char certreq[] = { 4742 1.1.1.2 christos SSL3_MT_CERTIFICATE_REQUEST, /* CertificateRequest message */ 4743 1.1.1.2 christos 0, 0, 12, /* Length of message */ 4744 1.1.1.2 christos 1, 1, /* certificate_request_context */ 4745 1.1.1.2 christos 0, 8, /* Extensions block length */ 4746 1.1 christos 0, TLSEXT_TYPE_signature_algorithms, /* sig_algs extension*/ 4747 1.1.1.2 christos 0, 4, /* 4 bytes of sig algs extension*/ 4748 1.1.1.2 christos 0, 2, /* sigalgs list is 2 bytes long */ 4749 1.1.1.2 christos 8, 4 /* rsa_pss_rsae_sha256 */ 4750 1.1 christos }; 4751 1.1 christos const unsigned char keyupdate[] = { 4752 1.1.1.2 christos SSL3_MT_KEY_UPDATE, /* KeyUpdate message */ 4753 1.1.1.2 christos 0, 0, 1, /* Length of message */ 4754 1.1.1.2 christos SSL_KEY_UPDATE_NOT_REQUESTED /* update_not_requested */ 4755 1.1 christos }; 4756 1.1 christos 4757 1.1 christos /* We transform the NewSessionTicket message into something else */ 4758 1.1.1.2 christos switch (h->inject_word0) { 4759 1.1 christos case 0: 4760 1.1 christos return 1; 4761 1.1 christos 4762 1.1 christos case 1: 4763 1.1 christos /* CertificateRequest message */ 4764 1.1 christos data = certreq; 4765 1.1 christos datalen = sizeof(certreq); 4766 1.1 christos break; 4767 1.1 christos 4768 1.1 christos case 2: 4769 1.1 christos /* KeyUpdate message */ 4770 1.1 christos data = keyupdate; 4771 1.1 christos datalen = sizeof(keyupdate); 4772 1.1 christos break; 4773 1.1 christos 4774 1.1 christos default: 4775 1.1 christos return 0; 4776 1.1 christos } 4777 1.1 christos 4778 1.1 christos if (!TEST_true(qtest_fault_resize_message(h->qtf, 4779 1.1.1.2 christos datalen - SSL3_HM_HEADER_LENGTH))) 4780 1.1 christos return 0; 4781 1.1 christos 4782 1.1 christos memcpy(msg, data, datalen); 4783 1.1 christos 4784 1.1 christos return 1; 4785 1.1 christos } 4786 1.1 christos 4787 1.1 christos /* Send a CerticateRequest message post-handshake */ 4788 1.1 christos static const struct script_op script_68[] = { 4789 1.1 christos OP_S_SET_INJECT_HANDSHAKE(script_68_inject_handshake) 4790 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4791 1.1.1.2 christos OP_C_CONNECT_WAIT() 4792 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 4793 1.1.1.2 christos 4794 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 4795 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 4796 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4797 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 4798 1.1.1.2 christos 4799 1.1.1.2 christos OP_SET_INJECT_WORD(1, 0) 4800 1.1.1.2 christos OP_S_NEW_TICKET() 4801 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 4802 1.1 christos 4803 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_PROTOCOL_VIOLATION, 0, 0) 4804 1.1 christos 4805 1.1.1.2 christos OP_END 4806 1.1 christos }; 4807 1.1 christos 4808 1.1 christos /* 69. Send a TLS KeyUpdate message post-handshake */ 4809 1.1 christos static const struct script_op script_69[] = { 4810 1.1 christos OP_S_SET_INJECT_HANDSHAKE(script_68_inject_handshake) 4811 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4812 1.1.1.2 christos OP_C_CONNECT_WAIT() 4813 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 4814 1.1.1.2 christos 4815 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 4816 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 4817 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4818 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 4819 1.1.1.2 christos 4820 1.1.1.2 christos OP_SET_INJECT_WORD(2, 0) 4821 1.1.1.2 christos OP_S_NEW_TICKET() 4822 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 4823 1.1.1.2 christos 4824 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_CRYPTO_ERR_BEGIN 4825 1.1.1.2 christos + SSL_AD_UNEXPECTED_MESSAGE, 4826 1.1.1.2 christos 0, 0) 4827 1.1 christos 4828 1.1.1.2 christos OP_END 4829 1.1 christos }; 4830 1.1 christos 4831 1.1 christos static int set_max_early_data(struct helper *h, struct helper_local *hl) 4832 1.1 christos { 4833 1.1 christos 4834 1.1 christos if (!TEST_true(ossl_quic_tserver_set_max_early_data(ACQUIRE_S(), 4835 1.1.1.2 christos (uint32_t)hl->check_op->arg2))) 4836 1.1 christos return 0; 4837 1.1 christos 4838 1.1 christos return 1; 4839 1.1 christos } 4840 1.1 christos 4841 1.1 christos /* 70. Send a TLS NewSessionTicket message with invalid max_early_data */ 4842 1.1 christos static const struct script_op script_70[] = { 4843 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4844 1.1.1.2 christos OP_C_CONNECT_WAIT() 4845 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 4846 1.1.1.2 christos 4847 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 4848 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 4849 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4850 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 4851 1.1.1.2 christos 4852 1.1.1.2 christos OP_CHECK(set_max_early_data, 0xfffffffe) 4853 1.1.1.2 christos OP_S_NEW_TICKET() 4854 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 4855 1.1 christos 4856 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_PROTOCOL_VIOLATION, 0, 0) 4857 1.1 christos 4858 1.1.1.2 christos OP_END 4859 1.1 christos }; 4860 1.1 christos 4861 1.1 christos /* 71. Send a TLS NewSessionTicket message with valid max_early_data */ 4862 1.1 christos static const struct script_op script_71[] = { 4863 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4864 1.1.1.2 christos OP_C_CONNECT_WAIT() 4865 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 4866 1.1.1.2 christos 4867 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 4868 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 4869 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 4870 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 4871 1.1.1.2 christos 4872 1.1.1.2 christos OP_CHECK(set_max_early_data, 0xffffffff) 4873 1.1.1.2 christos OP_S_NEW_TICKET() 4874 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 4875 1.1.1.2 christos OP_C_READ_EXPECT(a, "orange", 6) 4876 1.1 christos 4877 1.1.1.2 christos OP_END 4878 1.1 christos }; 4879 1.1 christos 4880 1.1 christos /* 72. Test that APL stops handing out streams after limit reached (bidi) */ 4881 1.1 christos static int script_72_check(struct helper *h, struct helper_local *hl) 4882 1.1 christos { 4883 1.1 christos if (!TEST_uint64_t_ge(h->fail_count, 50)) 4884 1.1 christos return 0; 4885 1.1 christos 4886 1.1 christos return 1; 4887 1.1 christos } 4888 1.1 christos 4889 1.1 christos static const struct script_op script_72[] = { 4890 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4891 1.1.1.2 christos OP_C_CONNECT_WAIT() 4892 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 4893 1.1 christos 4894 1.1 christos /* 4895 1.1 christos * Request more streams than a server will initially hand out and test that 4896 1.1 christos * they fail properly. 4897 1.1 christos */ 4898 1.1.1.2 christos OP_BEGIN_REPEAT(200) 4899 1.1 christos 4900 1.1.1.2 christos OP_C_NEW_STREAM_BIDI_EX(a, ANY_ID, ALLOW_FAIL | SSL_STREAM_FLAG_NO_BLOCK) 4901 1.1.1.2 christos OP_C_SKIP_IF_UNBOUND(a, 2) 4902 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 4903 1.1.1.2 christos OP_C_FREE_STREAM(a) 4904 1.1 christos 4905 1.1.1.2 christos OP_END_REPEAT() 4906 1.1 christos 4907 1.1.1.2 christos OP_CHECK(script_72_check, 0) 4908 1.1 christos 4909 1.1.1.2 christos OP_END 4910 1.1 christos }; 4911 1.1 christos 4912 1.1 christos /* 73. Test that APL stops handing out streams after limit reached (uni) */ 4913 1.1 christos static const struct script_op script_73[] = { 4914 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 4915 1.1.1.2 christos OP_C_CONNECT_WAIT() 4916 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 4917 1.1 christos 4918 1.1 christos /* 4919 1.1 christos * Request more streams than a server will initially hand out and test that 4920 1.1 christos * they fail properly. 4921 1.1 christos */ 4922 1.1.1.2 christos OP_BEGIN_REPEAT(200) 4923 1.1 christos 4924 1.1.1.2 christos OP_C_NEW_STREAM_UNI_EX(a, ANY_ID, ALLOW_FAIL | SSL_STREAM_FLAG_NO_BLOCK) 4925 1.1.1.2 christos OP_C_SKIP_IF_UNBOUND(a, 2) 4926 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 4927 1.1.1.2 christos OP_C_FREE_STREAM(a) 4928 1.1 christos 4929 1.1.1.2 christos OP_END_REPEAT() 4930 1.1 christos 4931 1.1.1.2 christos OP_CHECK(script_72_check, 0) 4932 1.1 christos 4933 1.1.1.2 christos OP_END 4934 1.1 christos }; 4935 1.1 christos 4936 1.1 christos /* 74. Version negotiation: QUIC_VERSION_1 ignored */ 4937 1.1 christos static int generate_version_neg(WPACKET *wpkt, uint32_t version) 4938 1.1 christos { 4939 1.1.1.2 christos QUIC_PKT_HDR hdr = { 0 }; 4940 1.1 christos 4941 1.1.1.2 christos hdr.type = QUIC_PKT_TYPE_VERSION_NEG; 4942 1.1.1.2 christos hdr.version = 0; 4943 1.1.1.2 christos hdr.fixed = 1; 4944 1.1.1.2 christos hdr.dst_conn_id.id_len = 0; 4945 1.1.1.2 christos hdr.src_conn_id.id_len = 8; 4946 1.1 christos memset(hdr.src_conn_id.id, 0x55, 8); 4947 1.1 christos 4948 1.1 christos if (!TEST_true(ossl_quic_wire_encode_pkt_hdr(wpkt, 0, &hdr, NULL))) 4949 1.1 christos return 0; 4950 1.1 christos 4951 1.1 christos if (!TEST_true(WPACKET_put_bytes_u32(wpkt, version))) 4952 1.1 christos return 0; 4953 1.1 christos 4954 1.1 christos return 1; 4955 1.1 christos } 4956 1.1 christos 4957 1.1 christos static int server_gen_version_neg(struct helper *h, BIO_MSG *msg, size_t stride) 4958 1.1 christos { 4959 1.1 christos int rc = 0, have_wpkt = 0; 4960 1.1 christos size_t l; 4961 1.1 christos WPACKET wpkt; 4962 1.1 christos BUF_MEM *buf = NULL; 4963 1.1 christos uint32_t version; 4964 1.1 christos 4965 1.1 christos switch (h->inject_word0) { 4966 1.1 christos case 0: 4967 1.1 christos return 1; 4968 1.1 christos case 1: 4969 1.1 christos version = QUIC_VERSION_1; 4970 1.1 christos break; 4971 1.1 christos default: 4972 1.1 christos version = 0x5432abcd; 4973 1.1 christos break; 4974 1.1 christos } 4975 1.1 christos 4976 1.1 christos if (!TEST_ptr(buf = BUF_MEM_new())) 4977 1.1 christos goto err; 4978 1.1 christos 4979 1.1 christos if (!TEST_true(WPACKET_init(&wpkt, buf))) 4980 1.1 christos goto err; 4981 1.1 christos 4982 1.1 christos have_wpkt = 1; 4983 1.1 christos 4984 1.1 christos generate_version_neg(&wpkt, version); 4985 1.1 christos 4986 1.1 christos if (!TEST_true(WPACKET_get_total_written(&wpkt, &l))) 4987 1.1 christos goto err; 4988 1.1 christos 4989 1.1 christos if (!TEST_true(qtest_fault_resize_datagram(h->qtf, l))) 4990 1.1 christos return 0; 4991 1.1 christos 4992 1.1 christos memcpy(msg->data, buf->data, l); 4993 1.1 christos h->inject_word0 = 0; 4994 1.1 christos 4995 1.1 christos rc = 1; 4996 1.1 christos err: 4997 1.1 christos if (have_wpkt) 4998 1.1 christos WPACKET_finish(&wpkt); 4999 1.1 christos 5000 1.1 christos BUF_MEM_free(buf); 5001 1.1 christos return rc; 5002 1.1 christos } 5003 1.1 christos 5004 1.1 christos static int do_mutation = 0; 5005 1.1 christos static QUIC_PKT_HDR *hdr_to_free = NULL; 5006 1.1 christos 5007 1.1 christos /* 5008 1.1 christos * Check packets to transmit, if we have an initial packet 5009 1.1 christos * Modify the version number to something incorrect 5010 1.1 christos * so that we trigger a version negotiation 5011 1.1 christos * Note, this is a use once function, it will only modify the 5012 1.1 christos * first INITIAL packet it sees, after which it needs to be 5013 1.1 christos * armed again 5014 1.1 christos */ 5015 1.1 christos static int script_74_alter_version(const QUIC_PKT_HDR *hdrin, 5016 1.1.1.2 christos const OSSL_QTX_IOVEC *iovecin, size_t numin, 5017 1.1.1.2 christos QUIC_PKT_HDR **hdrout, 5018 1.1.1.2 christos const OSSL_QTX_IOVEC **iovecout, 5019 1.1.1.2 christos size_t *numout, 5020 1.1.1.2 christos void *arg) 5021 1.1 christos { 5022 1.1 christos *hdrout = OPENSSL_memdup(hdrin, sizeof(QUIC_PKT_HDR)); 5023 1.1 christos *iovecout = iovecin; 5024 1.1 christos *numout = numin; 5025 1.1 christos hdr_to_free = *hdrout; 5026 1.1 christos 5027 1.1 christos if (do_mutation == 0) 5028 1.1 christos return 1; 5029 1.1 christos do_mutation = 0; 5030 1.1 christos 5031 1.1 christos if (hdrin->type == QUIC_PKT_TYPE_INITIAL) 5032 1.1 christos (*hdrout)->version = 0xdeadbeef; 5033 1.1 christos return 1; 5034 1.1 christos } 5035 1.1 christos 5036 1.1 christos static void script_74_finish_mutation(void *arg) 5037 1.1 christos { 5038 1.1 christos OPENSSL_free(hdr_to_free); 5039 1.1 christos } 5040 1.1 christos 5041 1.1 christos /* 5042 1.1 christos * Enable the packet mutator for the client channel 5043 1.1 christos * So that when we send a Initial packet 5044 1.1 christos * We modify the version to be something invalid 5045 1.1 christos * to force a version negotiation 5046 1.1 christos */ 5047 1.1 christos static int script_74_arm_packet_mutator(struct helper *h, 5048 1.1.1.2 christos struct helper_local *hl) 5049 1.1 christos { 5050 1.1 christos QUIC_CHANNEL *ch = ossl_quic_conn_get_channel(h->c_conn); 5051 1.1 christos 5052 1.1 christos do_mutation = 1; 5053 1.1 christos if (!ossl_quic_channel_set_mutator(ch, script_74_alter_version, 5054 1.1.1.2 christos script_74_finish_mutation, 5055 1.1.1.2 christos NULL)) 5056 1.1 christos return 0; 5057 1.1 christos return 1; 5058 1.1 christos } 5059 1.1 christos 5060 1.1 christos static const struct script_op script_74[] = { 5061 1.1.1.2 christos OP_CHECK(script_74_arm_packet_mutator, 0) 5062 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 5063 1.1.1.2 christos OP_C_CONNECT_WAIT() 5064 1.1.1.2 christos 5065 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 5066 1.1.1.2 christos 5067 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 5068 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 5069 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 5070 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 5071 1.1 christos 5072 1.1.1.2 christos OP_END 5073 1.1 christos }; 5074 1.1 christos 5075 1.1 christos /* 75. Version negotiation: Unknown version causes connection abort */ 5076 1.1 christos static const struct script_op script_75[] = { 5077 1.1.1.2 christos OP_S_SET_INJECT_DATAGRAM(server_gen_version_neg) 5078 1.1.1.2 christos OP_SET_INJECT_WORD(2, 0) 5079 1.1 christos 5080 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 5081 1.1.1.2 christos OP_C_CONNECT_WAIT_OR_FAIL() 5082 1.1 christos 5083 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_CONNECTION_REFUSED, 0, 0) 5084 1.1 christos 5085 1.1.1.2 christos OP_END 5086 1.1 christos }; 5087 1.1 christos 5088 1.1 christos /* 76. Test peer-initiated shutdown wait */ 5089 1.1 christos static int script_76_check(struct helper *h, struct helper_local *hl) 5090 1.1 christos { 5091 1.1 christos if (!TEST_false(SSL_shutdown_ex(h->c_conn, 5092 1.1.1.2 christos SSL_SHUTDOWN_FLAG_WAIT_PEER 5093 1.1.1.2 christos | SSL_SHUTDOWN_FLAG_NO_BLOCK, 5094 1.1.1.2 christos NULL, 0))) 5095 1.1 christos return 0; 5096 1.1 christos 5097 1.1 christos return 1; 5098 1.1 christos } 5099 1.1 christos 5100 1.1 christos static const struct script_op script_76[] = { 5101 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 5102 1.1.1.2 christos OP_C_CONNECT_WAIT() 5103 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 5104 1.1 christos 5105 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 5106 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 5107 1.1 christos 5108 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 5109 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 5110 1.1 christos 5111 1.1 christos /* Check a WAIT_PEER call doesn't succeed yet. */ 5112 1.1.1.2 christos OP_CHECK(script_76_check, 0) 5113 1.1.1.2 christos OP_S_SHUTDOWN(42) 5114 1.1 christos 5115 1.1.1.2 christos OP_C_SHUTDOWN_WAIT(NULL, SSL_SHUTDOWN_FLAG_WAIT_PEER) 5116 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(42, 1, 1) 5117 1.1 christos 5118 1.1.1.2 christos OP_END 5119 1.1 christos }; 5120 1.1 christos 5121 1.1 christos /* 77. Ensure default stream popping operates correctly */ 5122 1.1 christos static const struct script_op script_77[] = { 5123 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 5124 1.1.1.2 christos OP_C_CONNECT_WAIT() 5125 1.1 christos 5126 1.1.1.2 christos OP_C_SET_INCOMING_STREAM_POLICY(SSL_INCOMING_STREAM_POLICY_ACCEPT) 5127 1.1 christos 5128 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(a, S_BIDI_ID(0)) 5129 1.1.1.2 christos OP_S_WRITE(a, "Strawberry", 10) 5130 1.1 christos 5131 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "Strawberry", 10) 5132 1.1 christos 5133 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(b, S_BIDI_ID(1)) 5134 1.1.1.2 christos OP_S_WRITE(b, "xyz", 3) 5135 1.1 christos 5136 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(b) 5137 1.1.1.2 christos OP_C_READ_EXPECT(b, "xyz", 3) 5138 1.1 christos 5139 1.1.1.2 christos OP_END 5140 1.1 christos }; 5141 1.1 christos 5142 1.1 christos /* 78. Post-connection session ticket handling */ 5143 1.1 christos static size_t new_session_count; 5144 1.1 christos 5145 1.1 christos static int on_new_session(SSL *s, SSL_SESSION *sess) 5146 1.1 christos { 5147 1.1 christos ++new_session_count; 5148 1.1 christos return 0; /* do not ref session, we aren't keeping it */ 5149 1.1 christos } 5150 1.1 christos 5151 1.1 christos static int setup_session(struct helper *h, struct helper_local *hl) 5152 1.1 christos { 5153 1.1 christos SSL_CTX_set_session_cache_mode(h->c_ctx, SSL_SESS_CACHE_BOTH); 5154 1.1 christos SSL_CTX_sess_set_new_cb(h->c_ctx, on_new_session); 5155 1.1 christos return 1; 5156 1.1 christos } 5157 1.1 christos 5158 1.1 christos static int trigger_late_session_ticket(struct helper *h, struct helper_local *hl) 5159 1.1 christos { 5160 1.1 christos new_session_count = 0; 5161 1.1 christos 5162 1.1 christos if (!TEST_true(ossl_quic_tserver_new_ticket(ACQUIRE_S()))) 5163 1.1 christos return 0; 5164 1.1 christos 5165 1.1 christos return 1; 5166 1.1 christos } 5167 1.1 christos 5168 1.1 christos static int check_got_session_ticket(struct helper *h, struct helper_local *hl) 5169 1.1 christos { 5170 1.1 christos if (!TEST_size_t_gt(new_session_count, 0)) 5171 1.1 christos return 0; 5172 1.1 christos 5173 1.1 christos return 1; 5174 1.1 christos } 5175 1.1 christos 5176 1.1 christos static int check_idle_timeout(struct helper *h, struct helper_local *hl); 5177 1.1 christos 5178 1.1 christos static const struct script_op script_78[] = { 5179 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 5180 1.1.1.2 christos OP_CHECK(setup_session, 0) 5181 1.1.1.2 christos OP_C_CONNECT_WAIT() 5182 1.1 christos 5183 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 5184 1.1 christos 5185 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 5186 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 5187 1.1 christos 5188 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 5189 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 5190 1.1 christos 5191 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 5192 1.1.1.2 christos OP_C_READ_EXPECT(a, "orange", 6) 5193 1.1 christos 5194 1.1.1.2 christos OP_CHECK(trigger_late_session_ticket, 0) 5195 1.1 christos 5196 1.1.1.2 christos OP_S_WRITE(a, "Strawberry", 10) 5197 1.1.1.2 christos OP_C_READ_EXPECT(a, "Strawberry", 10) 5198 1.1 christos 5199 1.1.1.2 christos OP_CHECK(check_got_session_ticket, 0) 5200 1.1.1.2 christos OP_CHECK2(check_idle_timeout, 5201 1.1.1.2 christos SSL_VALUE_CLASS_FEATURE_NEGOTIATED, 30000) 5202 1.1 christos 5203 1.1.1.2 christos OP_END 5204 1.1 christos }; 5205 1.1 christos 5206 1.1 christos /* 79. Optimised FIN test */ 5207 1.1 christos static const struct script_op script_79[] = { 5208 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 5209 1.1.1.2 christos OP_C_CONNECT_WAIT() 5210 1.1.1.2 christos OP_C_WRITE_EX2(DEFAULT, "apple", 5, SSL_WRITE_FLAG_CONCLUDE) 5211 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 5212 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 5213 1.1.1.2 christos OP_S_EXPECT_FIN(a) 5214 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 5215 1.1.1.2 christos OP_S_CONCLUDE(a) 5216 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "orange", 6) 5217 1.1.1.2 christos OP_C_EXPECT_FIN(DEFAULT) 5218 1.1.1.2 christos OP_END 5219 1.1 christos }; 5220 1.1 christos 5221 1.1 christos /* 80. Stateless reset detection test */ 5222 1.1 christos static QUIC_STATELESS_RESET_TOKEN test_reset_token = { 5223 1.1 christos { 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 5224 1.1.1.2 christos 0xde, 0xad, 0xbe, 0xef } 5225 1.1.1.2 christos }; 5226 1.1 christos 5227 1.1 christos /* 5228 1.1 christos * Generate a packet in the following format: 5229 1.1 christos * https://www.rfc-editor.org/rfc/rfc9000.html#name-stateless-reset 5230 1.1 christos * Stateless Reset { 5231 1.1 christos * Fixed Bits (2): 1 5232 1.1 christos * Unpredictable bits (38..) 5233 1.1 christos * Stateless reset token (128) 5234 1.1 christos * } 5235 1.1 christos */ 5236 1.1 christos static int script_80_send_stateless_reset(struct helper *h, QUIC_PKT_HDR *hdr, 5237 1.1.1.2 christos unsigned char *buf, size_t len) 5238 1.1 christos { 5239 1.1 christos unsigned char databuf[64]; 5240 1.1 christos 5241 1.1 christos if (h->inject_word1 == 0) 5242 1.1 christos return 1; 5243 1.1 christos 5244 1.1 christos h->inject_word1 = 0; 5245 1.1 christos 5246 1.1 christos fprintf(stderr, "Sending stateless reset\n"); 5247 1.1 christos 5248 1.1 christos RAND_bytes(databuf, 64); 5249 1.1 christos databuf[0] = 0x40; 5250 1.1 christos memcpy(&databuf[48], test_reset_token.token, 5251 1.1.1.2 christos sizeof(test_reset_token.token)); 5252 1.1 christos 5253 1.1 christos if (!TEST_int_eq(SSL_inject_net_dgram(h->c_conn, databuf, sizeof(databuf), 5254 1.1.1.2 christos NULL, h->s_net_bio_addr), 5255 1.1.1.2 christos 1)) 5256 1.1 christos return 0; 5257 1.1 christos 5258 1.1 christos return 1; 5259 1.1 christos } 5260 1.1 christos 5261 1.1 christos static int script_80_gen_new_conn_id(struct helper *h, QUIC_PKT_HDR *hdr, 5262 1.1.1.2 christos unsigned char *buf, size_t len) 5263 1.1 christos { 5264 1.1 christos int rc = 0; 5265 1.1 christos size_t l; 5266 1.1 christos unsigned char frame_buf[64]; 5267 1.1 christos WPACKET wpkt; 5268 1.1.1.2 christos QUIC_CONN_ID new_cid = { 0 }; 5269 1.1.1.2 christos OSSL_QUIC_FRAME_NEW_CONN_ID ncid = { 0 }; 5270 1.1 christos QUIC_CHANNEL *ch = ossl_quic_tserver_get_channel(ACQUIRE_S_NOHL()); 5271 1.1 christos 5272 1.1 christos if (h->inject_word0 == 0) 5273 1.1 christos return 1; 5274 1.1 christos 5275 1.1 christos h->inject_word0 = 0; 5276 1.1 christos 5277 1.1 christos fprintf(stderr, "sending new conn id\n"); 5278 1.1 christos if (!TEST_true(WPACKET_init_static_len(&wpkt, frame_buf, 5279 1.1.1.2 christos sizeof(frame_buf), 0))) 5280 1.1 christos return 0; 5281 1.1 christos 5282 1.1 christos ossl_quic_channel_get_diag_local_cid(ch, &new_cid); 5283 1.1 christos 5284 1.1 christos ncid.seq_num = 2; 5285 1.1 christos ncid.retire_prior_to = 2; 5286 1.1 christos ncid.conn_id = new_cid; 5287 1.1 christos memcpy(ncid.stateless_reset.token, test_reset_token.token, 5288 1.1.1.2 christos sizeof(test_reset_token.token)); 5289 1.1 christos 5290 1.1 christos if (!TEST_true(ossl_quic_wire_encode_frame_new_conn_id(&wpkt, &ncid))) 5291 1.1 christos goto err; 5292 1.1 christos 5293 1.1 christos if (!TEST_true(WPACKET_get_total_written(&wpkt, &l))) 5294 1.1 christos goto err; 5295 1.1 christos 5296 1.1 christos if (!qtest_fault_prepend_frame(h->qtf, frame_buf, l)) 5297 1.1 christos goto err; 5298 1.1 christos 5299 1.1 christos rc = 1; 5300 1.1 christos err: 5301 1.1 christos if (rc) 5302 1.1 christos WPACKET_finish(&wpkt); 5303 1.1 christos else 5304 1.1 christos WPACKET_cleanup(&wpkt); 5305 1.1 christos 5306 1.1 christos return rc; 5307 1.1 christos } 5308 1.1 christos 5309 1.1 christos static int script_80_inject_pkt(struct helper *h, QUIC_PKT_HDR *hdr, 5310 1.1.1.2 christos unsigned char *buf, size_t len) 5311 1.1 christos { 5312 1.1 christos if (h->inject_word1 == 1) 5313 1.1 christos return script_80_send_stateless_reset(h, hdr, buf, len); 5314 1.1 christos else if (h->inject_word0 == 1) 5315 1.1 christos return script_80_gen_new_conn_id(h, hdr, buf, len); 5316 1.1 christos 5317 1.1 christos return 1; 5318 1.1 christos } 5319 1.1 christos 5320 1.1 christos static const struct script_op script_80[] = { 5321 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_80_inject_pkt) 5322 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 5323 1.1.1.2 christos OP_C_CONNECT_WAIT() 5324 1.1.1.2 christos OP_C_WRITE(DEFAULT, "apple", 5) 5325 1.1.1.2 christos OP_C_CONCLUDE(DEFAULT) 5326 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 5327 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 5328 1.1.1.2 christos OP_SET_INJECT_WORD(1, 0) 5329 1.1.1.2 christos OP_S_WRITE(a, "apple", 5) 5330 1.1.1.2 christos OP_C_READ_EXPECT(DEFAULT, "apple", 5) 5331 1.1.1.2 christos OP_SET_INJECT_WORD(0, 1) 5332 1.1.1.2 christos OP_S_WRITE(a, "apple", 5) 5333 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(0, 0, 1) 5334 1.1.1.2 christos OP_END 5335 1.1 christos }; 5336 1.1 christos 5337 1.1 christos /* 81. Idle timeout configuration */ 5338 1.1 christos static int modify_idle_timeout(struct helper *h, struct helper_local *hl) 5339 1.1 christos { 5340 1.1 christos uint64_t v = 0; 5341 1.1 christos 5342 1.1 christos /* Test bad value is rejected. */ 5343 1.1 christos if (!TEST_false(SSL_set_feature_request_uint(h->c_conn, 5344 1.1.1.2 christos SSL_VALUE_QUIC_IDLE_TIMEOUT, 5345 1.1.1.2 christos (1ULL << 62)))) 5346 1.1 christos return 0; 5347 1.1 christos 5348 1.1 christos /* Set value. */ 5349 1.1 christos if (!TEST_true(SSL_set_feature_request_uint(h->c_conn, 5350 1.1.1.2 christos SSL_VALUE_QUIC_IDLE_TIMEOUT, 5351 1.1.1.2 christos hl->check_op->arg2))) 5352 1.1 christos return 0; 5353 1.1 christos 5354 1.1 christos if (!TEST_true(SSL_get_feature_request_uint(h->c_conn, 5355 1.1.1.2 christos SSL_VALUE_QUIC_IDLE_TIMEOUT, 5356 1.1.1.2 christos &v))) 5357 1.1 christos return 0; 5358 1.1 christos 5359 1.1 christos if (!TEST_uint64_t_eq(v, hl->check_op->arg2)) 5360 1.1 christos return 0; 5361 1.1 christos 5362 1.1 christos return 1; 5363 1.1 christos } 5364 1.1 christos 5365 1.1 christos static int check_idle_timeout(struct helper *h, struct helper_local *hl) 5366 1.1 christos { 5367 1.1 christos uint64_t v = 0; 5368 1.1 christos 5369 1.1 christos if (!TEST_true(SSL_get_value_uint(h->c_conn, hl->check_op->arg1, 5370 1.1.1.2 christos SSL_VALUE_QUIC_IDLE_TIMEOUT, 5371 1.1.1.2 christos &v))) 5372 1.1 christos return 0; 5373 1.1 christos 5374 1.1 christos if (!TEST_uint64_t_eq(v, hl->check_op->arg2)) 5375 1.1 christos return 0; 5376 1.1 christos 5377 1.1 christos return 1; 5378 1.1 christos } 5379 1.1 christos 5380 1.1 christos static const struct script_op script_81[] = { 5381 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 5382 1.1.1.2 christos OP_CHECK(modify_idle_timeout, 25000) 5383 1.1.1.2 christos OP_C_CONNECT_WAIT() 5384 1.1.1.2 christos 5385 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 5386 1.1.1.2 christos 5387 1.1.1.2 christos OP_CHECK2(check_idle_timeout, 5388 1.1.1.2 christos SSL_VALUE_CLASS_FEATURE_PEER_REQUEST, 30000) 5389 1.1.1.2 christos OP_CHECK2(check_idle_timeout, 5390 1.1.1.2 christos SSL_VALUE_CLASS_FEATURE_NEGOTIATED, 25000) 5391 1.1 christos 5392 1.1.1.2 christos OP_END 5393 1.1 christos }; 5394 1.1 christos 5395 1.1 christos /* 82. Negotiated default idle timeout if not configured */ 5396 1.1 christos static const struct script_op script_82[] = { 5397 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 5398 1.1.1.2 christos OP_C_CONNECT_WAIT() 5399 1.1 christos 5400 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 5401 1.1 christos 5402 1.1.1.2 christos OP_CHECK2(check_idle_timeout, 5403 1.1.1.2 christos SSL_VALUE_CLASS_FEATURE_PEER_REQUEST, 30000) 5404 1.1.1.2 christos OP_CHECK2(check_idle_timeout, 5405 1.1.1.2 christos SSL_VALUE_CLASS_FEATURE_NEGOTIATED, 30000) 5406 1.1 christos 5407 1.1.1.2 christos OP_END 5408 1.1 christos }; 5409 1.1 christos 5410 1.1 christos /* 83. No late changes to idle timeout */ 5411 1.1 christos static int cannot_change_idle_timeout(struct helper *h, struct helper_local *hl) 5412 1.1 christos { 5413 1.1 christos uint64_t v = 0; 5414 1.1 christos 5415 1.1 christos if (!TEST_true(SSL_get_feature_request_uint(h->c_conn, 5416 1.1.1.2 christos SSL_VALUE_QUIC_IDLE_TIMEOUT, 5417 1.1.1.2 christos &v))) 5418 1.1 christos return 0; 5419 1.1 christos 5420 1.1 christos if (!TEST_uint64_t_eq(v, 30000)) 5421 1.1 christos return 0; 5422 1.1 christos 5423 1.1 christos if (!TEST_false(SSL_set_feature_request_uint(h->c_conn, 5424 1.1.1.2 christos SSL_VALUE_QUIC_IDLE_TIMEOUT, 5425 1.1.1.2 christos 5000))) 5426 1.1 christos return 0; 5427 1.1 christos 5428 1.1 christos return 1; 5429 1.1 christos } 5430 1.1 christos 5431 1.1 christos static const struct script_op script_83[] = { 5432 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 5433 1.1.1.2 christos OP_C_CONNECT_WAIT() 5434 1.1 christos 5435 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 5436 1.1 christos 5437 1.1.1.2 christos OP_CHECK(cannot_change_idle_timeout, 0) 5438 1.1.1.2 christos OP_CHECK2(check_idle_timeout, 5439 1.1.1.2 christos SSL_VALUE_CLASS_FEATURE_PEER_REQUEST, 30000) 5440 1.1.1.2 christos OP_CHECK2(check_idle_timeout, 5441 1.1.1.2 christos SSL_VALUE_CLASS_FEATURE_NEGOTIATED, 30000) 5442 1.1 christos 5443 1.1.1.2 christos OP_END 5444 1.1 christos }; 5445 1.1 christos 5446 1.1 christos /* 84. Test query of available streams */ 5447 1.1 christos static int check_avail_streams(struct helper *h, struct helper_local *hl) 5448 1.1 christos { 5449 1.1 christos uint64_t v = 0; 5450 1.1 christos 5451 1.1 christos switch (hl->check_op->arg1) { 5452 1.1 christos case 0: 5453 1.1 christos if (!TEST_true(SSL_get_quic_stream_bidi_local_avail(h->c_conn, &v))) 5454 1.1 christos return 0; 5455 1.1 christos break; 5456 1.1 christos case 1: 5457 1.1 christos if (!TEST_true(SSL_get_quic_stream_bidi_remote_avail(h->c_conn, &v))) 5458 1.1 christos return 0; 5459 1.1 christos break; 5460 1.1 christos case 2: 5461 1.1 christos if (!TEST_true(SSL_get_quic_stream_uni_local_avail(h->c_conn, &v))) 5462 1.1 christos return 0; 5463 1.1 christos break; 5464 1.1 christos case 3: 5465 1.1 christos if (!TEST_true(SSL_get_quic_stream_uni_remote_avail(h->c_conn, &v))) 5466 1.1 christos return 0; 5467 1.1 christos break; 5468 1.1 christos default: 5469 1.1 christos return 0; 5470 1.1 christos } 5471 1.1 christos 5472 1.1 christos if (!TEST_uint64_t_eq(v, hl->check_op->arg2)) 5473 1.1 christos return 0; 5474 1.1 christos 5475 1.1 christos return 1; 5476 1.1 christos } 5477 1.1 christos 5478 1.1 christos static int set_event_handling_mode_conn(struct helper *h, struct helper_local *hl); 5479 1.1 christos static int reenable_test_event_handling(struct helper *h, struct helper_local *hl); 5480 1.1 christos 5481 1.1 christos static int check_write_buf_stat(struct helper *h, struct helper_local *hl) 5482 1.1 christos { 5483 1.1 christos SSL *c_a; 5484 1.1 christos uint64_t size, used, avail; 5485 1.1 christos 5486 1.1 christos if (!TEST_ptr(c_a = helper_local_get_c_stream(hl, "a"))) 5487 1.1 christos return 0; 5488 1.1 christos 5489 1.1 christos if (!TEST_true(SSL_get_stream_write_buf_size(c_a, &size)) 5490 1.1 christos || !TEST_true(SSL_get_stream_write_buf_used(c_a, &used)) 5491 1.1 christos || !TEST_true(SSL_get_stream_write_buf_avail(c_a, &avail)) 5492 1.1 christos || !TEST_uint64_t_ge(size, avail) 5493 1.1 christos || !TEST_uint64_t_ge(size, used) 5494 1.1 christos || !TEST_uint64_t_eq(avail + used, size)) 5495 1.1 christos return 0; 5496 1.1 christos 5497 1.1 christos if (!TEST_uint64_t_eq(used, hl->check_op->arg1)) 5498 1.1 christos return 0; 5499 1.1 christos 5500 1.1 christos return 1; 5501 1.1 christos } 5502 1.1 christos 5503 1.1 christos static const struct script_op script_84[] = { 5504 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 5505 1.1.1.2 christos OP_C_CONNECT_WAIT() 5506 1.1 christos 5507 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 5508 1.1 christos 5509 1.1.1.2 christos OP_CHECK2(check_avail_streams, 0, 100) 5510 1.1.1.2 christos OP_CHECK2(check_avail_streams, 1, 100) 5511 1.1.1.2 christos OP_CHECK2(check_avail_streams, 2, 100) 5512 1.1.1.2 christos OP_CHECK2(check_avail_streams, 3, 100) 5513 1.1 christos 5514 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 5515 1.1 christos 5516 1.1.1.2 christos OP_CHECK2(check_avail_streams, 0, 99) 5517 1.1.1.2 christos OP_CHECK2(check_avail_streams, 1, 100) 5518 1.1.1.2 christos OP_CHECK2(check_avail_streams, 2, 100) 5519 1.1.1.2 christos OP_CHECK2(check_avail_streams, 3, 100) 5520 1.1 christos 5521 1.1.1.2 christos OP_C_NEW_STREAM_UNI(b, C_UNI_ID(0)) 5522 1.1 christos 5523 1.1.1.2 christos OP_CHECK2(check_avail_streams, 0, 99) 5524 1.1.1.2 christos OP_CHECK2(check_avail_streams, 1, 100) 5525 1.1.1.2 christos OP_CHECK2(check_avail_streams, 2, 99) 5526 1.1.1.2 christos OP_CHECK2(check_avail_streams, 3, 100) 5527 1.1 christos 5528 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(c, S_BIDI_ID(0)) 5529 1.1.1.2 christos OP_S_WRITE(c, "x", 1) 5530 1.1 christos 5531 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(c) 5532 1.1.1.2 christos OP_C_READ_EXPECT(c, "x", 1) 5533 1.1 christos 5534 1.1.1.2 christos OP_CHECK2(check_avail_streams, 0, 99) 5535 1.1.1.2 christos OP_CHECK2(check_avail_streams, 1, 99) 5536 1.1.1.2 christos OP_CHECK2(check_avail_streams, 2, 99) 5537 1.1.1.2 christos OP_CHECK2(check_avail_streams, 3, 100) 5538 1.1 christos 5539 1.1.1.2 christos OP_S_NEW_STREAM_UNI(d, S_UNI_ID(0)) 5540 1.1.1.2 christos OP_S_WRITE(d, "x", 1) 5541 1.1 christos 5542 1.1.1.2 christos OP_C_ACCEPT_STREAM_WAIT(d) 5543 1.1.1.2 christos OP_C_READ_EXPECT(d, "x", 1) 5544 1.1 christos 5545 1.1.1.2 christos OP_CHECK2(check_avail_streams, 0, 99) 5546 1.1.1.2 christos OP_CHECK2(check_avail_streams, 1, 99) 5547 1.1.1.2 christos OP_CHECK2(check_avail_streams, 2, 99) 5548 1.1.1.2 christos OP_CHECK2(check_avail_streams, 3, 99) 5549 1.1 christos 5550 1.1.1.2 christos OP_CHECK2(check_write_buf_stat, 0, 0) 5551 1.1.1.2 christos OP_CHECK(set_event_handling_mode_conn, 5552 1.1.1.2 christos SSL_VALUE_EVENT_HANDLING_MODE_EXPLICIT) 5553 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 5554 1.1.1.2 christos OP_CHECK2(check_write_buf_stat, 5, 0) 5555 1.1 christos 5556 1.1.1.2 christos OP_CHECK(reenable_test_event_handling, 0) 5557 1.1 christos 5558 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 5559 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 5560 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 5561 1.1.1.2 christos OP_C_READ_EXPECT(a, "orange", 6) 5562 1.1 christos 5563 1.1.1.2 christos OP_END 5564 1.1 christos }; 5565 1.1 christos 5566 1.1 christos /* 85. Test SSL_poll (lite, non-blocking) */ 5567 1.1 christos ossl_unused static int script_85_poll(struct helper *h, struct helper_local *hl) 5568 1.1 christos { 5569 1.1 christos int ok = 1, ret, expected_ret = 1; 5570 1.1.1.2 christos static const struct timeval timeout = { 0 }; 5571 1.1 christos size_t result_count, expected_result_count = 0; 5572 1.1.1.2 christos SSL_POLL_ITEM items[5] = { 0 }, *item = items; 5573 1.1 christos SSL *c_a, *c_b, *c_c, *c_d; 5574 1.1 christos size_t i; 5575 1.1.1.2 christos uint64_t mode, expected_revents[5] = { 0 }; 5576 1.1 christos 5577 1.1 christos if (!TEST_ptr(c_a = helper_local_get_c_stream(hl, "a")) 5578 1.1 christos || !TEST_ptr(c_b = helper_local_get_c_stream(hl, "b")) 5579 1.1 christos || !TEST_ptr(c_c = helper_local_get_c_stream(hl, "c")) 5580 1.1 christos || !TEST_ptr(c_d = helper_local_get_c_stream(hl, "d"))) 5581 1.1 christos return 0; 5582 1.1 christos 5583 1.1.1.2 christos item->desc = SSL_as_poll_descriptor(c_a); 5584 1.1.1.2 christos item->events = UINT64_MAX; 5585 1.1 christos item->revents = UINT64_MAX; 5586 1.1 christos ++item; 5587 1.1 christos 5588 1.1.1.2 christos item->desc = SSL_as_poll_descriptor(c_b); 5589 1.1.1.2 christos item->events = UINT64_MAX; 5590 1.1 christos item->revents = UINT64_MAX; 5591 1.1 christos ++item; 5592 1.1 christos 5593 1.1.1.2 christos item->desc = SSL_as_poll_descriptor(c_c); 5594 1.1.1.2 christos item->events = UINT64_MAX; 5595 1.1 christos item->revents = UINT64_MAX; 5596 1.1 christos ++item; 5597 1.1 christos 5598 1.1.1.2 christos item->desc = SSL_as_poll_descriptor(c_d); 5599 1.1.1.2 christos item->events = UINT64_MAX; 5600 1.1 christos item->revents = UINT64_MAX; 5601 1.1 christos ++item; 5602 1.1 christos 5603 1.1.1.2 christos item->desc = SSL_as_poll_descriptor(h->c_conn); 5604 1.1.1.2 christos item->events = UINT64_MAX; 5605 1.1 christos item->revents = UINT64_MAX; 5606 1.1 christos ++item; 5607 1.1 christos 5608 1.1 christos result_count = SIZE_MAX; 5609 1.1 christos ret = SSL_poll(items, OSSL_NELEM(items), sizeof(SSL_POLL_ITEM), 5610 1.1.1.2 christos &timeout, 0, 5611 1.1.1.2 christos &result_count); 5612 1.1 christos 5613 1.1 christos mode = hl->check_op->arg2; 5614 1.1 christos switch (mode) { 5615 1.1 christos case 0: 5616 1.1 christos /* No incoming data yet */ 5617 1.1.1.2 christos expected_revents[0] = SSL_POLL_EVENT_W; 5618 1.1.1.2 christos expected_revents[1] = SSL_POLL_EVENT_W; 5619 1.1.1.2 christos expected_revents[2] = SSL_POLL_EVENT_W; 5620 1.1.1.2 christos expected_revents[3] = SSL_POLL_EVENT_W; 5621 1.1.1.2 christos expected_revents[4] = SSL_POLL_EVENT_OS; 5622 1.1.1.2 christos expected_result_count = 5; 5623 1.1 christos break; 5624 1.1 christos case 1: 5625 1.1 christos /* Expect more events */ 5626 1.1.1.2 christos expected_revents[0] = SSL_POLL_EVENT_W | SSL_POLL_EVENT_R; 5627 1.1.1.2 christos expected_revents[1] = SSL_POLL_EVENT_W | SSL_POLL_EVENT_ER; 5628 1.1.1.2 christos expected_revents[2] = SSL_POLL_EVENT_EW; 5629 1.1.1.2 christos expected_revents[3] = SSL_POLL_EVENT_W; 5630 1.1.1.2 christos expected_revents[4] = SSL_POLL_EVENT_OS | SSL_POLL_EVENT_ISB; 5631 1.1.1.2 christos expected_result_count = 5; 5632 1.1 christos break; 5633 1.1 christos default: 5634 1.1 christos return 0; 5635 1.1 christos } 5636 1.1 christos 5637 1.1 christos if (!TEST_int_eq(ret, expected_ret) 5638 1.1 christos || !TEST_size_t_eq(result_count, expected_result_count)) 5639 1.1 christos ok = 0; 5640 1.1 christos 5641 1.1 christos for (i = 0; i < OSSL_NELEM(items); ++i) 5642 1.1 christos if (!TEST_uint64_t_eq(items[i].revents, expected_revents[i])) { 5643 1.1 christos TEST_error("mismatch at index %zu in poll results, mode %d", 5644 1.1.1.2 christos i, (int)mode); 5645 1.1 christos ok = 0; 5646 1.1 christos } 5647 1.1 christos 5648 1.1 christos return ok; 5649 1.1 christos } 5650 1.1 christos 5651 1.1 christos static const struct script_op script_85[] = { 5652 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 5653 1.1.1.2 christos OP_C_CONNECT_WAIT() 5654 1.1 christos 5655 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 5656 1.1 christos 5657 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 5658 1.1.1.2 christos OP_C_WRITE(a, "flamingo", 8) 5659 1.1 christos 5660 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(b, C_BIDI_ID(1)) 5661 1.1.1.2 christos OP_C_WRITE(b, "orange", 6) 5662 1.1 christos 5663 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(c, C_BIDI_ID(2)) 5664 1.1.1.2 christos OP_C_WRITE(c, "Strawberry", 10) 5665 1.1 christos 5666 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(d, C_BIDI_ID(3)) 5667 1.1.1.2 christos OP_C_WRITE(d, "sync", 4) 5668 1.1 christos 5669 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 5670 1.1.1.2 christos OP_S_BIND_STREAM_ID(b, C_BIDI_ID(1)) 5671 1.1.1.2 christos OP_S_BIND_STREAM_ID(c, C_BIDI_ID(2)) 5672 1.1.1.2 christos OP_S_BIND_STREAM_ID(d, C_BIDI_ID(3)) 5673 1.1 christos 5674 1.1 christos /* Check nothing readable yet. */ 5675 1.1.1.2 christos OP_CHECK(script_85_poll, 0) 5676 1.1 christos 5677 1.1 christos /* Send something that will make client sockets readable. */ 5678 1.1.1.2 christos OP_S_READ_EXPECT(a, "flamingo", 8) 5679 1.1.1.2 christos OP_S_WRITE(a, "herringbone", 11) 5680 1.1 christos 5681 1.1 christos /* Send something that will make 'b' reset. */ 5682 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_28_inject_plain) 5683 1.1.1.2 christos OP_SET_INJECT_WORD(C_BIDI_ID(1) + 1, OSSL_QUIC_FRAME_TYPE_RESET_STREAM) 5684 1.1 christos 5685 1.1 christos /* Ensure sync. */ 5686 1.1.1.2 christos OP_S_READ_EXPECT(d, "sync", 4) 5687 1.1.1.2 christos OP_S_WRITE(d, "x", 1) 5688 1.1.1.2 christos OP_C_READ_EXPECT(d, "x", 1) 5689 1.1 christos 5690 1.1 christos /* Send something that will make 'c' reset. */ 5691 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_28_inject_plain) 5692 1.1.1.2 christos OP_SET_INJECT_WORD(C_BIDI_ID(2) + 1, OSSL_QUIC_FRAME_TYPE_STOP_SENDING) 5693 1.1 christos 5694 1.1.1.2 christos OP_S_NEW_STREAM_BIDI(z, S_BIDI_ID(0)) 5695 1.1.1.2 christos OP_S_WRITE(z, "z", 1) 5696 1.1 christos 5697 1.1 christos /* Ensure sync. */ 5698 1.1.1.2 christos OP_S_WRITE(d, "x", 1) 5699 1.1.1.2 christos OP_C_READ_EXPECT(d, "x", 1) 5700 1.1 christos 5701 1.1 christos /* Check a is now readable. */ 5702 1.1.1.2 christos OP_CHECK(script_85_poll, 1) 5703 1.1 christos 5704 1.1.1.2 christos OP_END 5705 1.1 christos }; 5706 1.1 christos 5707 1.1 christos /* 86. Event Handling Mode Configuration */ 5708 1.1 christos static int set_event_handling_mode_conn(struct helper *h, struct helper_local *hl) 5709 1.1 christos { 5710 1.1 christos hl->explicit_event_handling = 1; 5711 1.1 christos return SSL_set_event_handling_mode(h->c_conn, hl->check_op->arg2); 5712 1.1 christos } 5713 1.1 christos 5714 1.1 christos static int reenable_test_event_handling(struct helper *h, struct helper_local *hl) 5715 1.1 christos { 5716 1.1 christos hl->explicit_event_handling = 0; 5717 1.1 christos return 1; 5718 1.1 christos } 5719 1.1 christos 5720 1.1 christos static ossl_unused int set_event_handling_mode_stream(struct helper *h, struct helper_local *hl) 5721 1.1 christos { 5722 1.1 christos SSL *ssl = helper_local_get_c_stream(hl, "a"); 5723 1.1 christos 5724 1.1 christos if (!TEST_ptr(ssl)) 5725 1.1 christos return 0; 5726 1.1 christos 5727 1.1 christos return SSL_set_event_handling_mode(ssl, hl->check_op->arg2); 5728 1.1 christos } 5729 1.1 christos 5730 1.1 christos static const struct script_op script_86[] = { 5731 1.1.1.2 christos OP_SKIP_IF_BLOCKING(23) 5732 1.1 christos 5733 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 5734 1.1.1.2 christos OP_C_CONNECT_WAIT() 5735 1.1 christos 5736 1.1.1.2 christos OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE) 5737 1.1 christos 5738 1.1 christos /* Turn on explicit handling mode. */ 5739 1.1.1.2 christos OP_CHECK(set_event_handling_mode_conn, 5740 1.1.1.2 christos SSL_VALUE_EVENT_HANDLING_MODE_EXPLICIT) 5741 1.1 christos 5742 1.1 christos /* 5743 1.1 christos * Create a new stream and write data. This won't get sent 5744 1.1 christos * to the network net because we are in explicit mode 5745 1.1 christos * and we haven't called SSL_handle_events(). 5746 1.1 christos */ 5747 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 5748 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 5749 1.1 christos 5750 1.1 christos /* Put connection back into implicit handling mode. */ 5751 1.1.1.2 christos OP_CHECK(set_event_handling_mode_conn, 5752 1.1.1.2 christos SSL_VALUE_EVENT_HANDLING_MODE_IMPLICIT) 5753 1.1 christos 5754 1.1 christos /* Override at stream level. */ 5755 1.1.1.2 christos OP_CHECK(set_event_handling_mode_stream, 5756 1.1.1.2 christos SSL_VALUE_EVENT_HANDLING_MODE_EXPLICIT) 5757 1.1.1.2 christos OP_C_WRITE(a, "orange", 6) 5758 1.1.1.2 christos OP_C_CONCLUDE(a) 5759 1.1 christos 5760 1.1 christos /* 5761 1.1 christos * Confirm the data isn't going to arrive. OP_SLEEP is always undesirable 5762 1.1 christos * but we have no reasonable way to synchronise on something not arriving 5763 1.1 christos * given all network traffic is essentially stopped and there are no other 5764 1.1 christos * signals arriving from the peer which could be used for synchronisation. 5765 1.1 christos * Slow OSes will pass this anyway (fail-open). 5766 1.1 christos */ 5767 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 5768 1.1 christos 5769 1.1.1.2 christos OP_BEGIN_REPEAT(20) 5770 1.1.1.2 christos OP_S_READ_FAIL(a, 1) 5771 1.1.1.2 christos OP_SLEEP(10) 5772 1.1.1.2 christos OP_END_REPEAT() 5773 1.1 christos 5774 1.1 christos /* Now let the data arrive and confirm it arrives. */ 5775 1.1.1.2 christos OP_CHECK(reenable_test_event_handling, 0) 5776 1.1.1.2 christos OP_S_READ_EXPECT(a, "appleorange", 11) 5777 1.1.1.2 christos OP_S_EXPECT_FIN(a) 5778 1.1 christos 5779 1.1 christos /* Back into explicit mode. */ 5780 1.1.1.2 christos OP_CHECK(set_event_handling_mode_conn, 5781 1.1.1.2 christos SSL_VALUE_EVENT_HANDLING_MODE_EXPLICIT) 5782 1.1.1.2 christos OP_S_WRITE(a, "ok", 2) 5783 1.1.1.2 christos OP_C_READ_FAIL(a) 5784 1.1 christos 5785 1.1 christos /* Works once event handling is done. */ 5786 1.1.1.2 christos OP_CHECK(reenable_test_event_handling, 0) 5787 1.1.1.2 christos OP_C_READ_EXPECT(a, "ok", 2) 5788 1.1 christos 5789 1.1.1.2 christos OP_END 5790 1.1 christos }; 5791 1.1 christos 5792 1.1 christos /* 87. Test stream reset functionality */ 5793 1.1 christos static const struct script_op script_87[] = { 5794 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 5795 1.1.1.2 christos OP_C_CONNECT_WAIT() 5796 1.1.1.2 christos OP_C_NEW_STREAM_BIDI(a, C_BIDI_ID(0)) 5797 1.1.1.2 christos OP_C_WRITE(a, "apple", 5) 5798 1.1.1.2 christos OP_C_CONCLUDE(a) 5799 1.1.1.2 christos OP_S_BIND_STREAM_ID(a, C_BIDI_ID(0)) 5800 1.1.1.2 christos OP_S_READ_EXPECT(a, "apple", 5) 5801 1.1.1.2 christos OP_S_EXPECT_FIN(a) 5802 1.1.1.2 christos OP_S_WRITE(a, "orange", 6) 5803 1.1.1.2 christos OP_C_READ_EXPECT(a, "orange", 6) 5804 1.1.1.2 christos OP_S_CONCLUDE(a) 5805 1.1.1.2 christos OP_C_EXPECT_FIN(a) 5806 1.1.1.2 christos OP_SLEEP(1000) 5807 1.1.1.2 christos OP_C_STREAM_RESET_FAIL(a, 42) 5808 1.1.1.2 christos OP_END 5809 1.1 christos }; 5810 1.1 christos 5811 1.1 christos static const struct script_op *const scripts[] = { 5812 1.1 christos script_1, 5813 1.1 christos script_2, 5814 1.1 christos script_3, 5815 1.1 christos script_4, 5816 1.1 christos script_5, 5817 1.1 christos script_6, 5818 1.1 christos script_7, 5819 1.1 christos script_8, 5820 1.1 christos script_9, 5821 1.1 christos script_10, 5822 1.1 christos script_11, 5823 1.1 christos script_12, 5824 1.1 christos script_13, 5825 1.1 christos script_14, 5826 1.1 christos script_15, 5827 1.1 christos script_16, 5828 1.1 christos script_17, 5829 1.1 christos script_18, 5830 1.1 christos script_19, 5831 1.1 christos script_20, 5832 1.1 christos script_21, 5833 1.1 christos script_22, 5834 1.1 christos script_23, 5835 1.1 christos script_24, 5836 1.1 christos script_25, 5837 1.1 christos script_26, 5838 1.1 christos script_27, 5839 1.1 christos script_28, 5840 1.1 christos script_29, 5841 1.1 christos script_30, 5842 1.1 christos script_31, 5843 1.1 christos script_32, 5844 1.1 christos script_33, 5845 1.1 christos script_34, 5846 1.1 christos script_35, 5847 1.1 christos script_36, 5848 1.1 christos script_37, 5849 1.1 christos script_38, 5850 1.1 christos script_39, 5851 1.1 christos script_40, 5852 1.1 christos script_41, 5853 1.1 christos script_42, 5854 1.1 christos script_43, 5855 1.1 christos script_44, 5856 1.1 christos script_45, 5857 1.1 christos script_46, 5858 1.1 christos script_47, 5859 1.1 christos script_48, 5860 1.1 christos script_49, 5861 1.1 christos script_50, 5862 1.1 christos script_51, 5863 1.1 christos script_52, 5864 1.1 christos script_53, 5865 1.1 christos script_54, 5866 1.1 christos script_55, 5867 1.1 christos script_56, 5868 1.1 christos script_57, 5869 1.1 christos script_58, 5870 1.1 christos script_59, 5871 1.1 christos script_60, 5872 1.1 christos script_61, 5873 1.1 christos script_62, 5874 1.1 christos script_63, 5875 1.1 christos script_64, 5876 1.1 christos script_65, 5877 1.1 christos script_66, 5878 1.1 christos script_67, 5879 1.1 christos script_68, 5880 1.1 christos script_69, 5881 1.1 christos script_70, 5882 1.1 christos script_71, 5883 1.1 christos script_72, 5884 1.1 christos script_73, 5885 1.1 christos script_74, 5886 1.1 christos script_75, 5887 1.1 christos script_76, 5888 1.1 christos script_77, 5889 1.1 christos script_78, 5890 1.1 christos script_79, 5891 1.1 christos script_80, 5892 1.1 christos script_81, 5893 1.1 christos script_82, 5894 1.1 christos script_83, 5895 1.1 christos script_84, 5896 1.1 christos script_85, 5897 1.1 christos script_86, 5898 1.1 christos script_87 5899 1.1 christos }; 5900 1.1 christos 5901 1.1 christos static int test_script(int idx) 5902 1.1 christos { 5903 1.1 christos int script_idx, free_order, blocking; 5904 1.1 christos char script_name[64]; 5905 1.1 christos 5906 1.1 christos free_order = idx % 2; 5907 1.1 christos idx /= 2; 5908 1.1 christos 5909 1.1 christos blocking = idx % 2; 5910 1.1 christos idx /= 2; 5911 1.1 christos 5912 1.1 christos script_idx = idx; 5913 1.1 christos 5914 1.1 christos if (blocking && free_order) 5915 1.1 christos return 1; /* don't need to test free_order twice */ 5916 1.1 christos 5917 1.1 christos #if !defined(OPENSSL_THREADS) 5918 1.1 christos if (blocking) { 5919 1.1 christos TEST_skip("cannot test in blocking mode without threads"); 5920 1.1 christos return 1; 5921 1.1 christos } 5922 1.1 christos #endif 5923 1.1 christos 5924 1.1 christos BIO_snprintf(script_name, sizeof(script_name), "script %d", script_idx + 1); 5925 1.1 christos 5926 1.1 christos TEST_info("Running script %d (order=%d, blocking=%d)", script_idx + 1, 5927 1.1.1.2 christos free_order, blocking); 5928 1.1 christos return run_script(scripts[script_idx], script_name, free_order, blocking); 5929 1.1 christos } 5930 1.1 christos 5931 1.1 christos /* Dynamically generated tests. */ 5932 1.1 christos static struct script_op dyn_frame_types_script[] = { 5933 1.1.1.2 christos OP_S_SET_INJECT_PLAIN(script_21_inject_plain) 5934 1.1.1.2 christos OP_SET_INJECT_WORD(0, 0) /* dynamic */ 5935 1.1 christos 5936 1.1.1.2 christos OP_C_SET_ALPN("ossltest") 5937 1.1.1.2 christos OP_C_CONNECT_WAIT_OR_FAIL() 5938 1.1 christos 5939 1.1.1.2 christos OP_C_EXPECT_CONN_CLOSE_INFO(OSSL_QUIC_ERR_FRAME_ENCODING_ERROR, 0, 0) 5940 1.1 christos 5941 1.1.1.2 christos OP_END 5942 1.1 christos }; 5943 1.1 christos 5944 1.1 christos struct forbidden_frame_type { 5945 1.1 christos uint64_t pkt_type, frame_type, expected_err; 5946 1.1 christos }; 5947 1.1 christos 5948 1.1 christos static const struct forbidden_frame_type forbidden_frame_types[] = { 5949 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_VLINT_MAX, OSSL_QUIC_ERR_FRAME_ENCODING_ERROR }, 5950 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_VLINT_MAX, OSSL_QUIC_ERR_FRAME_ENCODING_ERROR }, 5951 1.1 christos { QUIC_PKT_TYPE_1RTT, OSSL_QUIC_VLINT_MAX, OSSL_QUIC_ERR_FRAME_ENCODING_ERROR }, 5952 1.1 christos 5953 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STREAM, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5954 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_RESET_STREAM, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5955 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STOP_SENDING, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5956 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_NEW_TOKEN, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5957 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_MAX_DATA, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5958 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5959 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5960 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5961 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5962 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5963 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5964 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5965 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5966 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5967 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5968 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5969 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_APP, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5970 1.1 christos { QUIC_PKT_TYPE_INITIAL, OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5971 1.1 christos 5972 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STREAM, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5973 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_RESET_STREAM, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5974 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STOP_SENDING, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5975 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_NEW_TOKEN, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5976 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_MAX_DATA, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5977 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_MAX_STREAM_DATA, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5978 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_BIDI, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5979 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_MAX_STREAMS_UNI, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5980 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_DATA_BLOCKED, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5981 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STREAM_DATA_BLOCKED, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5982 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_BIDI, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5983 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_STREAMS_BLOCKED_UNI, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5984 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5985 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5986 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_PATH_CHALLENGE, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5987 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_PATH_RESPONSE, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5988 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_APP, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5989 1.1 christos { QUIC_PKT_TYPE_HANDSHAKE, OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5990 1.1 christos 5991 1.1 christos /* Client uses a zero-length CID so this is not allowed. */ 5992 1.1 christos { QUIC_PKT_TYPE_1RTT, OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID, OSSL_QUIC_ERR_PROTOCOL_VIOLATION }, 5993 1.1 christos }; 5994 1.1 christos 5995 1.1 christos static ossl_unused int test_dyn_frame_types(int idx) 5996 1.1 christos { 5997 1.1 christos size_t i; 5998 1.1 christos char script_name[64]; 5999 1.1 christos struct script_op *s = dyn_frame_types_script; 6000 1.1 christos 6001 1.1 christos for (i = 0; i < OSSL_NELEM(dyn_frame_types_script); ++i) 6002 1.1 christos if (s[i].op == OPK_SET_INJECT_WORD) { 6003 1.1 christos s[i].arg1 = (size_t)forbidden_frame_types[idx].pkt_type; 6004 1.1 christos s[i].arg2 = forbidden_frame_types[idx].frame_type; 6005 1.1 christos } else if (s[i].op == OPK_C_EXPECT_CONN_CLOSE_INFO) { 6006 1.1 christos s[i].arg2 = forbidden_frame_types[idx].expected_err; 6007 1.1 christos } 6008 1.1 christos 6009 1.1 christos BIO_snprintf(script_name, sizeof(script_name), 6010 1.1.1.2 christos "dyn script %d", idx); 6011 1.1 christos 6012 1.1 christos return run_script(dyn_frame_types_script, script_name, 0, 0); 6013 1.1 christos } 6014 1.1 christos 6015 1.1 christos OPT_TEST_DECLARE_USAGE("certfile privkeyfile\n") 6016 1.1 christos 6017 1.1 christos int setup_tests(void) 6018 1.1 christos { 6019 1.1.1.2 christos #if defined(_PUT_MODEL_) 6020 1.1 christos return TEST_skip("QUIC is not supported by this build"); 6021 1.1 christos #endif 6022 1.1 christos 6023 1.1 christos if (!test_skip_common_options()) { 6024 1.1 christos TEST_error("Error parsing test options\n"); 6025 1.1 christos return 0; 6026 1.1 christos } 6027 1.1 christos 6028 1.1 christos if (!TEST_ptr(certfile = test_get_argument(0)) 6029 1.1 christos || !TEST_ptr(keyfile = test_get_argument(1))) 6030 1.1 christos return 0; 6031 1.1 christos 6032 1.1 christos ADD_ALL_TESTS(test_dyn_frame_types, OSSL_NELEM(forbidden_frame_types)); 6033 1.1 christos ADD_ALL_TESTS(test_script, OSSL_NELEM(scripts) * 2 * 2); 6034 1.1 christos return 1; 6035 1.1 christos } 6036