summaryrefslogtreecommitdiff
path: root/src/lib/libssl/tls13_quic.c
diff options
context:
space:
mode:
authorjsing <>2022-07-24 14:28:16 +0000
committerjsing <>2022-07-24 14:28:16 +0000
commitf7f7655b1951f8dd9a8166cb6203a780f911d0bc (patch)
treef814f798e3d47e53e29dfd4db0eece8481fc97ad /src/lib/libssl/tls13_quic.c
parentc804d574e337158da589e90dc9cbb13d6ffde44f (diff)
downloadopenbsd-f7f7655b1951f8dd9a8166cb6203a780f911d0bc.tar.gz
openbsd-f7f7655b1951f8dd9a8166cb6203a780f911d0bc.tar.bz2
openbsd-f7f7655b1951f8dd9a8166cb6203a780f911d0bc.zip
Provide record layer callbacks for QUIC.
QUIC uses TLS to complete the handshake, however unlike normal TLS it does not use the TLS record layer, rather it provides its own transport. This means that we need to intercept all communication between the TLS handshake and the record layer. This allows TLS handshake message writes to be directed to QUIC, likewise for TLS handshake message reads. Alerts also need to be sent via QUIC, plus it needs to be provided with the traffic keys that are derived by TLS. ok tb@
Diffstat (limited to 'src/lib/libssl/tls13_quic.c')
-rw-r--r--src/lib/libssl/tls13_quic.c135
1 files changed, 135 insertions, 0 deletions
diff --git a/src/lib/libssl/tls13_quic.c b/src/lib/libssl/tls13_quic.c
new file mode 100644
index 0000000000..3f814188a7
--- /dev/null
+++ b/src/lib/libssl/tls13_quic.c
@@ -0,0 +1,135 @@
1/* $OpenBSD: tls13_quic.c,v 1.1 2022/07/24 14:28:16 jsing Exp $ */
2/*
3 * Copyright (c) 2022 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <ssl_locl.h>
19
20#include "tls13_internal.h"
21
22static ssize_t
23tls13_quic_wire_read_cb(void *buf, size_t n, void *arg)
24{
25 struct tls13_ctx *ctx = arg;
26 SSL *ssl = ctx->ssl;
27
28 SSLerror(ssl, ERR_R_INTERNAL_ERROR);
29 return TLS13_IO_FAILURE;
30}
31
32static ssize_t
33tls13_quic_wire_write_cb(const void *buf, size_t n, void *arg)
34{
35 struct tls13_ctx *ctx = arg;
36 SSL *ssl = ctx->ssl;
37
38 SSLerror(ssl, ERR_R_INTERNAL_ERROR);
39 return TLS13_IO_FAILURE;
40}
41
42static ssize_t
43tls13_quic_wire_flush_cb(void *arg)
44{
45 struct tls13_ctx *ctx = arg;
46 SSL *ssl = ctx->ssl;
47
48 /* XXX - call flush_flight. */
49 SSLerror(ssl, ERR_R_INTERNAL_ERROR);
50 return TLS13_IO_FAILURE;
51}
52
53static ssize_t
54tls13_quic_handshake_read_cb(void *buf, size_t n, void *arg)
55{
56 /* XXX - read handshake data. */
57 return TLS13_IO_FAILURE;
58}
59
60static ssize_t
61tls13_quic_handshake_write_cb(const void *buf, size_t n, void *arg)
62{
63 struct tls13_ctx *ctx = arg;
64 SSL *ssl = ctx->ssl;
65
66 /* XXX - call add_handshake_data. */
67 SSLerror(ssl, ERR_R_INTERNAL_ERROR);
68 return TLS13_IO_FAILURE;
69}
70
71static int
72tls13_quic_set_read_traffic_key(struct tls13_secret *read_key,
73 enum ssl_encryption_level_t read_level, void *arg)
74{
75 struct tls13_ctx *ctx = arg;
76 SSL *ssl = ctx->ssl;
77
78 ctx->hs->tls13.quic_read_level = read_level;
79
80 /* XXX - call set_read_secret. */
81 SSLerror(ssl, ERR_R_INTERNAL_ERROR);
82 return 0;
83}
84
85static int
86tls13_quic_set_write_traffic_key(struct tls13_secret *write_key,
87 enum ssl_encryption_level_t write_level, void *arg)
88{
89 struct tls13_ctx *ctx = arg;
90 SSL *ssl = ctx->ssl;
91
92 ctx->hs->tls13.quic_write_level = write_level;
93
94 /* XXX - call set_write_secret. */
95 SSLerror(ssl, ERR_R_INTERNAL_ERROR);
96 return 0;
97}
98
99static int
100tls13_quic_alert_send_cb(int alert_desc, void *arg)
101{
102 struct tls13_ctx *ctx = arg;
103 SSL *ssl = ctx->ssl;
104
105 /* XXX - call send_alert. */
106 SSLerror(ssl, ERR_R_INTERNAL_ERROR);
107 return TLS13_IO_FAILURE;
108}
109
110static const struct tls13_record_layer_callbacks quic_rl_callbacks = {
111 .wire_read = tls13_quic_wire_read_cb,
112 .wire_write = tls13_quic_wire_write_cb,
113 .wire_flush = tls13_quic_wire_flush_cb,
114
115 .handshake_read = tls13_quic_handshake_read_cb,
116 .handshake_write = tls13_quic_handshake_write_cb,
117 .set_read_traffic_key = tls13_quic_set_read_traffic_key,
118 .set_write_traffic_key = tls13_quic_set_write_traffic_key,
119 .alert_send = tls13_quic_alert_send_cb,
120
121 .alert_recv = tls13_alert_received_cb,
122 .alert_sent = tls13_alert_sent_cb,
123 .phh_recv = tls13_phh_received_cb,
124 .phh_sent = tls13_phh_done_cb,
125};
126
127int
128tls13_quic_init(struct tls13_ctx *ctx)
129{
130 tls13_record_layer_set_callbacks(ctx->rl, &quic_rl_callbacks, ctx);
131
132 ctx->middlebox_compat = 0;
133
134 return 1;
135}