Skip to content

Commit

Permalink
QUIC APL: Introduce the QUIC_OBJ base type and infrastructure
Browse files Browse the repository at this point in the history
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from #23334)
  • Loading branch information
hlandau committed Apr 19, 2024
1 parent 762d5bf commit ace3825
Show file tree
Hide file tree
Showing 7 changed files with 388 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/internal/quic_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ void ossl_quic_engine_set_inhibit_tick(QUIC_ENGINE *qeng, int inhibit);
/* Gets the reactor which can be used to tick/poll on the port. */
QUIC_REACTOR *ossl_quic_engine_get0_reactor(QUIC_ENGINE *qeng);

OSSL_LIB_CTX *ossl_quic_engine_get0_libctx(QUIC_ENGINE *qeng);
const char *ossl_quic_engine_get0_propq(QUIC_ENGINE *qeng);

# endif

#endif
1 change: 1 addition & 0 deletions include/internal/quic_predef.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ typedef struct quic_srtm_st QUIC_SRTM;
typedef struct quic_lcidm_st QUIC_LCIDM;
typedef struct quic_urxe_st QUIC_URXE;
typedef struct quic_engine_st QUIC_ENGINE;
typedef struct quic_obj_st QUIC_OBJ;

# endif

Expand Down
1 change: 1 addition & 0 deletions ssl/quic/build.info
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ IF[{- !$disabled{qlog} -}]
SOURCE[$LIBSSL]=json_enc.c qlog.c
SHARED_SOURCE[$LIBSSL]=../../crypto/getenv.c ../../crypto/ctype.c
ENDIF
SOURCE[$LIBSSL]=quic_obj.c
10 changes: 10 additions & 0 deletions ssl/quic/quic_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ void ossl_quic_engine_set_inhibit_tick(QUIC_ENGINE *qeng, int inhibit)
qeng->inhibit_tick = (inhibit != 0);
}

OSSL_LIB_CTX *ossl_quic_engine_get0_libctx(QUIC_ENGINE *qeng)
{
return qeng->libctx;
}

const char *ossl_quic_engine_get0_propq(QUIC_ENGINE *qeng)
{
return qeng->propq;
}

/*
* QUIC Engine: Child Object Lifecycle Management
* ==============================================
Expand Down
1 change: 1 addition & 0 deletions ssl/quic/quic_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# include "internal/quic_reactor.h"
# include "internal/quic_thread_assist.h"
# include "../ssl_local.h"
# include "quic_obj_local.h"

# ifndef OPENSSL_NO_QUIC

Expand Down
98 changes: 98 additions & 0 deletions ssl/quic/quic_obj.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright 2024 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/

#include "quic_obj_local.h"
#include "quic_local.h"

static int obj_update_cache(QUIC_OBJ *obj);

int ossl_quic_obj_init(QUIC_OBJ *obj,
SSL_CTX *ctx,
int type,
SSL *parent_obj,
QUIC_ENGINE *engine,
QUIC_PORT *port)
{
int is_event_leader = (engine != NULL);
int is_port_leader = (port != NULL);

if (!ossl_assert(!obj->init_done && obj != NULL && SSL_TYPE_IS_QUIC(type)
&& (parent_obj == NULL || IS_QUIC(parent_obj))))
return 0;

/* Event leader is always the root object. */
if (!ossl_assert(!is_event_leader || parent_obj == NULL))
return 0;

if (!ossl_ssl_init(&obj->ssl, ctx, ctx->method, type))
goto err;

obj->parent_obj = parent_obj;
obj->is_event_leader = is_event_leader;
obj->is_port_leader = is_port_leader;
if (!obj_update_cache(obj))
goto err;

obj->engine = engine;
obj->port = port;
obj->init_done = 1;
return 1;

err:
obj->is_event_leader = 0;
obj->is_port_leader = 0;
return 0;
}

static ossl_inline QUIC_OBJ *
ssl_to_obj(SSL *ssl)
{
if (ssl == NULL)
return NULL;

assert(IS_QUIC(ssl));
return (QUIC_OBJ *)ssl;
}

static int obj_update_cache(QUIC_OBJ *obj)
{
QUIC_OBJ *p;

for (p = obj; p != NULL && !p->is_event_leader;
p = ssl_to_obj(p->parent_obj))
if (!ossl_assert(p == obj || p->init_done))
return 0;

if (!ossl_assert(p != NULL))
return 0;

/*
* Offset of ->ssl is guaranteed to be 0 but the NULL check makes ubsan
* happy.
*/
obj->cached_event_leader = (p != NULL) ? &p->ssl : NULL;
obj->engine = p->engine;

for (p = obj; p != NULL && !p->is_port_leader;
p = ssl_to_obj(p->parent_obj));

obj->cached_port_leader = (p != NULL) ? &p->ssl : NULL;
obj->port = (p != NULL) ? p->port : NULL;
return 1;
}

SSL_CONNECTION *ossl_quic_obj_get0_handshake_layer(QUIC_OBJ *obj)
{
assert(obj->init_done);

if (obj == NULL || obj->ssl.type != SSL_TYPE_QUIC_CONNECTION)
return NULL;

return SSL_CONNECTION_FROM_SSL_ONLY(((QUIC_CONNECTION *)obj)->tls);
}

0 comments on commit ace3825

Please sign in to comment.