From: Hugo Landau Date: Mon, 29 Apr 2024 11:36:21 +0000 (+0100) Subject: QUIC RADIX: Test domain functions as well X-Git-Tag: openssl-3.5.0-alpha1~363 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ccbf3f6ecb0050704653af486670a81edb66f70b;p=thirdparty%2Fopenssl.git QUIC RADIX: Test domain functions as well Reviewed-by: Matt Caswell Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/24971) --- diff --git a/test/radix/quic_bindings.c b/test/radix/quic_bindings.c index e752cd7a7a8..ab501a21251 100644 --- a/test/radix/quic_bindings.c +++ b/test/radix/quic_bindings.c @@ -788,5 +788,26 @@ err: return ok; } +DEF_FUNC(hf_clear) +{ + RADIX_THREAD *rt = RT(); + size_t i; + + ossl_crypto_mutex_lock(RP()->gm); + + lh_RADIX_OBJ_doall(RP()->objs, cleanup_one); + lh_RADIX_OBJ_flush(RP()->objs); + + for (i = 0; i < NUM_SLOTS; ++i) { + rt->slot[i] = NULL; + rt->ssl[i] = NULL; + } + + ossl_crypto_mutex_unlock(RP()->gm); + return 1; +} + #define OP_SPAWN_THREAD(script_name) \ (OP_PUSH_P(SCRIPT(script_name)), OP_FUNC(hf_spawn_thread)) +#define OP_CLEAR() \ + (OP_FUNC(hf_clear)) diff --git a/test/radix/quic_ops.c b/test/radix/quic_ops.c index 79398b8122b..89b2a4e22c7 100644 --- a/test/radix/quic_ops.c +++ b/test/radix/quic_ops.c @@ -139,11 +139,13 @@ DEF_FUNC(hf_new_ssl) const SSL_METHOD *method; SSL *ssl; uint64_t flags; - int is_server; + int is_server, is_domain; F_POP2(name, flags); - is_server = (flags != 0); + is_domain = ((flags & 2) != 0); + is_server = ((flags & 1) != 0); + method = is_server ? OSSL_QUIC_server_method() : OSSL_QUIC_client_method(); if (!TEST_ptr(ctx = SSL_CTX_new(method))) goto err; @@ -151,7 +153,11 @@ DEF_FUNC(hf_new_ssl) if (!TEST_true(ssl_ctx_configure(ctx, is_server))) goto err; - if (is_server) { + if (is_domain) { + if (!TEST_ptr(ssl = SSL_new_domain(ctx, 0))) + goto err; + + } else if (is_server) { if (!TEST_ptr(ssl = SSL_new_listener(ctx, 0))) goto err; } else { @@ -159,7 +165,7 @@ DEF_FUNC(hf_new_ssl) goto err; } - if (!TEST_true(ssl_attach_bio_dgram(ssl, 0, NULL))) + if (!is_domain && !TEST_true(ssl_attach_bio_dgram(ssl, 0, NULL))) goto err; if (!TEST_true(RADIX_PROCESS_set_ssl(RP(), name, ssl))) { @@ -174,6 +180,37 @@ err: return ok; } +DEF_FUNC(hf_new_ssl_listener_from) +{ + int ok = 0; + SSL *domain, *listener; + const char *listener_name; + uint64_t flags; + + REQUIRE_SSL(domain); + F_POP2(listener_name, flags); + + if (!TEST_ptr_null(RADIX_PROCESS_get_obj(RP(), listener_name))) + goto err; + + if (!TEST_ptr(listener = SSL_new_listener_from(domain, flags))) + goto err; + + if (!TEST_true(ssl_attach_bio_dgram(listener, 0, NULL))) + goto err; + + if (!TEST_true(RADIX_PROCESS_set_ssl(RP(), listener_name, listener))) { + SSL_free(listener); + goto err; + } + + radix_activate_slot(0); + + ok = 1; +err: + return ok; +} + DEF_FUNC(hf_listen) { int ok = 0, r; @@ -185,7 +222,9 @@ DEF_FUNC(hf_listen) if (!TEST_true(r)) goto err; - radix_activate_slot(0); + if (SSL_get0_domain(ssl) == NULL) + radix_activate_slot(0); + ok = 1; err: return ok; @@ -901,10 +940,25 @@ err: OP_PUSH_U64(1), \ OP_FUNC(hf_new_ssl)) +#define OP_NEW_SSL_D(name) \ + (OP_PUSH_PZ(#name), \ + OP_PUSH_U64(3), \ + OP_FUNC(hf_new_ssl)) + #define OP_NEW_SSL_L_LISTEN(name) \ (OP_NEW_SSL_L(name), \ OP_LISTEN(name)) +#define OP_NEW_SSL_L_FROM(domain_name, listener_name, flags) \ + (OP_SELECT_SSL(0, domain_name), \ + OP_PUSH_PZ(#listener_name), \ + OP_PUSH_U64(flags), \ + OP_FUNC(hf_new_ssl_listener_from)) + +#define OP_NEW_SSL_L_FROM_LISTEN(domain_name, listener_name, flags) \ + (OP_NEW_SSL_L_FROM(domain_name, listener_name, flags), \ + OP_LISTEN(listener_name)) + #define OP_SET_PEER_ADDR_FROM(dst_name, src_name) \ (OP_SELECT_SSL(0, dst_name), \ OP_SELECT_SSL(1, src_name), \ @@ -916,6 +970,13 @@ err: OP_SET_PEER_ADDR_FROM(C, L), \ OP_CONNECT_WAIT(C)) +#define OP_SIMPLE_PAIR_CONN_D() \ + (OP_NEW_SSL_D(Ds), \ + OP_NEW_SSL_L_FROM_LISTEN(Ds, L, 0), \ + OP_NEW_SSL_C(C), \ + OP_SET_PEER_ADDR_FROM(C, L), \ + OP_CONNECT_WAIT(C)) + #define OP_NEW_STREAM(conn_name, stream_name, flags) \ (OP_SELECT_SSL(0, conn_name), \ OP_PUSH_PZ(#stream_name), \ diff --git a/test/radix/quic_tests.c b/test/radix/quic_tests.c index 001105a5a76..e8dcef240ec 100644 --- a/test/radix/quic_tests.c +++ b/test/radix/quic_tests.c @@ -14,15 +14,25 @@ DEF_SCRIPT(simple_conn, "simple connection to server") { - OP_SIMPLE_PAIR_CONN(); - OP_WRITE_B(C, "apple"); + size_t i; + + for (i = 0; i < 2; ++i) { + if (i == 0) { + OP_SIMPLE_PAIR_CONN_D(); + } else { + OP_CLEAR(); + OP_SIMPLE_PAIR_CONN(); + } + + OP_WRITE_B(C, "apple"); - OP_ACCEPT_CONN_WAIT(L, La, 0); - OP_ACCEPT_CONN_NONE(L); + OP_ACCEPT_CONN_WAIT(L, La, 0); + OP_ACCEPT_CONN_NONE(L); - OP_READ_EXPECT_B(La, "apple"); - OP_WRITE_B(La, "orange"); - OP_READ_EXPECT_B(C, "orange"); + OP_READ_EXPECT_B(La, "apple"); + OP_WRITE_B(La, "orange"); + OP_READ_EXPECT_B(C, "orange"); + } } DEF_SCRIPT(simple_thread_child,