]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
QUIC RADIX: Test domain functions as well
authorHugo Landau <hlandau@openssl.org>
Mon, 29 Apr 2024 11:36:21 +0000 (12:36 +0100)
committerNeil Horman <nhorman@openssl.org>
Mon, 17 Feb 2025 16:27:32 +0000 (11:27 -0500)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24971)

test/radix/quic_bindings.c
test/radix/quic_ops.c
test/radix/quic_tests.c

index e752cd7a7a81611fa9d864b09a5f37b892b5fcf0..ab501a21251b4a9a137dc42da37e93f9796522c8 100644 (file)
@@ -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))
index 79398b8122b3d5dd19fe98012973766c2895ab35..89b2a4e22c7466bdecafd75ef6ee7b05ec30d23e 100644 (file)
@@ -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),                                  \
index 001105a5a76b0bb3c1f9c349ab47b1e8aac9eb97..e8dcef240ec62683e7c093e2babe02890fecfd2e 100644 (file)
 
 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,