Coverage Report

Created: 2025-08-28 07:07

/src/openssl35/ssl/quic/quic_obj.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2024-2025 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
#include "quic_obj_local.h"
11
#include "quic_local.h"
12
#include "internal/ssl_unwrap.h"
13
14
static int obj_update_cache(QUIC_OBJ *obj);
15
16
int ossl_quic_obj_init(QUIC_OBJ *obj,
17
                       SSL_CTX *ctx,
18
                       int type,
19
                       SSL *parent_obj,
20
                       QUIC_ENGINE *engine,
21
                       QUIC_PORT *port)
22
23.8k
{
23
23.8k
    int is_event_leader = (engine != NULL);
24
23.8k
    int is_port_leader  = (port != NULL);
25
26
23.8k
    if (!ossl_assert(obj != NULL && !obj->init_done && SSL_TYPE_IS_QUIC(type)
27
23.8k
                     && (parent_obj == NULL || IS_QUIC(parent_obj))))
28
0
        return 0;
29
30
    /* Event leader is always the root object. */
31
23.8k
    if (!ossl_assert(!is_event_leader || parent_obj == NULL))
32
0
        return 0;
33
34
23.8k
    if (!ossl_ssl_init(&obj->ssl, ctx, ctx->method, type))
35
0
        goto err;
36
37
23.8k
    obj->domain_flags       = ctx->domain_flags;
38
23.8k
    obj->parent_obj         = (QUIC_OBJ *)parent_obj;
39
23.8k
    obj->is_event_leader    = is_event_leader;
40
23.8k
    obj->is_port_leader     = is_port_leader;
41
23.8k
    obj->engine             = engine;
42
23.8k
    obj->port               = port;
43
23.8k
    obj->req_blocking_mode  = QUIC_BLOCKING_MODE_INHERIT;
44
23.8k
    if (!obj_update_cache(obj))
45
0
        goto err;
46
47
23.8k
    obj->init_done          = 1;
48
23.8k
    return 1;
49
50
0
err:
51
0
    obj->is_event_leader = 0;
52
0
    obj->is_port_leader  = 0;
53
0
    return 0;
54
23.8k
}
55
56
static int obj_update_cache(QUIC_OBJ *obj)
57
23.8k
{
58
23.8k
    QUIC_OBJ *p;
59
60
28.4k
    for (p = obj; p != NULL && !p->is_event_leader;
61
23.8k
         p = p->parent_obj)
62
4.61k
        if (!ossl_assert(p == obj || p->init_done))
63
0
            return 0;
64
65
23.8k
    if (!ossl_assert(p != NULL))
66
0
        return 0;
67
68
    /*
69
     * Offset of ->ssl is guaranteed to be 0 but the NULL check makes ubsan
70
     * happy.
71
     */
72
23.8k
    obj->cached_event_leader    = p;
73
23.8k
    obj->engine                 = p->engine;
74
75
28.4k
    for (p = obj; p != NULL && !p->is_port_leader;
76
23.8k
         p = p->parent_obj);
77
78
23.8k
    obj->cached_port_leader     = p;
79
23.8k
    obj->port                   = (p != NULL) ? p->port : NULL;
80
23.8k
    return 1;
81
23.8k
}
82
83
SSL_CONNECTION *ossl_quic_obj_get0_handshake_layer(QUIC_OBJ *obj)
84
45.1M
{
85
45.1M
    assert(obj != NULL && obj->init_done);
86
87
45.1M
    if (obj->ssl.type != SSL_TYPE_QUIC_CONNECTION)
88
5.47M
        return NULL;
89
90
39.6M
    return SSL_CONNECTION_FROM_SSL_ONLY(((QUIC_CONNECTION *)obj)->tls);
91
45.1M
}
92
93
/* (Returns a cached result.) */
94
int ossl_quic_obj_can_support_blocking(const QUIC_OBJ *obj)
95
36.1M
{
96
36.1M
    QUIC_REACTOR *rtor;
97
98
36.1M
    assert(obj != NULL);
99
36.1M
    rtor = ossl_quic_obj_get0_reactor(obj);
100
101
36.1M
    if ((obj->domain_flags
102
36.1M
            & (SSL_DOMAIN_FLAG_LEGACY_BLOCKING | SSL_DOMAIN_FLAG_BLOCKING)) == 0)
103
0
        return 0;
104
105
36.1M
    return ossl_quic_reactor_can_poll_r(rtor)
106
36.1M
        || ossl_quic_reactor_can_poll_w(rtor);
107
36.1M
}
108
109
int ossl_quic_obj_desires_blocking(const QUIC_OBJ *obj)
110
50.5M
{
111
50.5M
    unsigned int req_blocking_mode;
112
113
50.5M
    assert(obj != NULL);
114
53.2M
    for (; (req_blocking_mode = obj->req_blocking_mode) == QUIC_BLOCKING_MODE_INHERIT
115
53.2M
           && obj->parent_obj != NULL; obj = obj->parent_obj);
116
117
50.5M
    return req_blocking_mode != QUIC_BLOCKING_MODE_NONBLOCKING;
118
50.5M
}
119
120
int ossl_quic_obj_blocking(const QUIC_OBJ *obj)
121
36.1M
{
122
36.1M
    assert(obj != NULL);
123
124
36.1M
    if (!ossl_quic_obj_desires_blocking(obj))
125
0
        return 0;
126
127
36.1M
    ossl_quic_engine_update_poll_descriptors(ossl_quic_obj_get0_engine(obj),
128
36.1M
                                             /*force=*/0);
129
36.1M
    return ossl_quic_obj_can_support_blocking(obj);
130
36.1M
}
131
132
void ossl_quic_obj_set_blocking_mode(QUIC_OBJ *obj, unsigned int mode)
133
0
{
134
0
    assert(obj != NULL);
135
136
0
    obj->req_blocking_mode = mode;
137
0
}