]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
QUIC APL: Add skeleton listener API
authorHugo Landau <hlandau@openssl.org>
Thu, 11 Jan 2024 09:17:43 +0000 (09:17 +0000)
committerViktor Dukhovni <openssl-users@dukhovni.org>
Wed, 11 Sep 2024 07:32:29 +0000 (17:32 +1000)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23334)

include/internal/quic_ssl.h
include/openssl/ssl.h.in
ssl/quic/quic_impl.c
ssl/quic/quic_local.h
ssl/ssl_lib.c

index 5d1b739725be353559cacb6d0b769f79db51783e..4b8eb83d6f198285a7f30e143acc2e3d29ac8fbb 100644 (file)
@@ -19,6 +19,7 @@
 # ifndef OPENSSL_NO_QUIC
 
 __owur SSL *ossl_quic_new(SSL_CTX *ctx);
+__owur SSL *ossl_quic_new_listener(SSL_CTX *ctx, uint64_t flags);
 __owur int ossl_quic_init(SSL *s);
 void ossl_quic_deinit(SSL *s);
 void ossl_quic_free(SSL *s);
index 4bab2ac767f5589c9077983308618a5c98ec0d3a..575c5b53fc2642ba04fb509adb7cb13cb7df7c41 100644 (file)
@@ -2292,6 +2292,8 @@ __owur int SSL_set1_initial_peer_addr(SSL *s, const BIO_ADDR *peer_addr);
 __owur SSL *SSL_get0_connection(SSL *s);
 __owur int SSL_is_connection(SSL *s);
 
+__owur SSL *SSL_new_listener(SSL_CTX *ctx, uint64_t flags);
+
 #define SSL_STREAM_TYPE_NONE        0
 #define SSL_STREAM_TYPE_READ        (1U << 0)
 #define SSL_STREAM_TYPE_WRITE       (1U << 1)
index a40604352867a16b74c2810bd49ed2e2054a296e..f0e18bc7500369241b5177b92b89dc96a0477843 100644 (file)
@@ -3939,6 +3939,59 @@ int ossl_quic_get_key_update_type(const SSL *s)
     return SSL_KEY_UPDATE_NONE;
 }
 
+/*
+ * QUIC Front-End I/O API: Listeners
+ * =================================
+ */
+
+SSL *ossl_quic_new_listener(SSL_CTX *ctx, uint64_t flags)
+{
+    QUIC_LISTENER *ql = NULL;
+    QUIC_ENGINE_ARGS engine_args = {0};
+    QUIC_PORT_ARGS port_args = {0};
+
+#if defined(OPENSSL_THREADS)
+    if ((ql->mutex = ossl_crypto_mutex_new()) == NULL) {
+        QUIC_RAISE_NON_NORMAL_ERROR(NULL, ERR_R_CRYPTO_LIB, NULL);
+        goto err;
+    }
+#endif
+
+    if ((ql = OPENSSL_zalloc(sizeof(*ql))) == NULL) {
+        QUIC_RAISE_NON_NORMAL_ERROR(NULL, ERR_R_CRYPTO_LIB, NULL);
+        goto err;
+    }
+
+    engine_args.libctx  = ctx->libctx;
+    engine_args.propq   = ctx->propq;
+    engine_args.mutex   = ql->mutex;
+    if ((ql->engine = ossl_quic_engine_new(&engine_args)) == NULL) {
+        QUIC_RAISE_NON_NORMAL_ERROR(NULL, ERR_R_INTERNAL_ERROR, NULL);
+        goto err;
+    }
+
+    port_args.channel_ctx = ctx;
+    ql->port = ossl_quic_engine_create_port(ql->engine, &port_args);
+    if (ql->port == NULL) {
+        QUIC_RAISE_NON_NORMAL_ERROR(NULL, ERR_R_INTERNAL_ERROR, NULL);
+        goto err;
+    }
+
+    /* Initialise the QUIC_LISTENER'S object header. */
+    if (!ossl_quic_obj_init(&ql->obj, ctx, SSL_TYPE_QUIC_LISTENER, NULL,
+                            ql->engine, ql->port))
+        goto err;
+
+    return &ql->obj.ssl;
+
+err:
+    if (ql != NULL)
+        ossl_quic_engine_free(ql->engine);
+
+    OPENSSL_free(ql);
+    return NULL;
+}
+
 /*
  * QUIC Front-End I/O API: SSL_CTX Management
  * ==========================================
index 0fcaf8a14248a1f545892f5727aea7b60ab52c1b..1bf34f35dc0c871000e12589a872e0691a801da5 100644 (file)
@@ -257,6 +257,18 @@ struct quic_conn_st {
 struct quic_listener_st {
     /* QUIC_OBJ common header, including SSL object common header. */
     QUIC_OBJ                        obj;
+
+    /* The QUIC engine representing the QUIC event domain. */
+    QUIC_ENGINE                     *engine;
+
+    /* The QUIC port representing the QUIC listener and socket. */
+    QUIC_PORT                       *port;
+
+    /*
+     * The mutex used to synchronise access to the QUIC_ENGINE. We own this but
+     * provide it to the engine.
+     */
+    CRYPTO_MUTEX                    *mutex;
 };
 
 /* Internal calls to the QUIC CSM which come from various places. */
index eeeaac1a9c4f966eeb3d56d5f7ca0352a3bf4fb3..60ea517235fdda511e92533ac24a2041e71c3e1d 100644 (file)
@@ -7717,6 +7717,18 @@ int SSL_set_value_uint(SSL *s, uint32_t class_, uint32_t id,
     return 0;
 }
 
+SSL *SSL_new_listener(SSL_CTX *ctx, uint64_t flags)
+{
+#ifndef OPENSSL_NO_QUIC
+    if (!IS_QUIC_CTX(ctx))
+        return NULL;
+
+    return ossl_quic_new_listener(ctx, flags);
+#else
+    return NULL;
+#endif
+}
+
 int SSL_add_expected_rpk(SSL *s, EVP_PKEY *rpk)
 {
     unsigned char *data = NULL;