diff options
author | jsing <> | 2022-07-24 14:28:16 +0000 |
---|---|---|
committer | jsing <> | 2022-07-24 14:28:16 +0000 |
commit | f7f7655b1951f8dd9a8166cb6203a780f911d0bc (patch) | |
tree | f814f798e3d47e53e29dfd4db0eece8481fc97ad /src/lib/libssl/tls13_record_layer.c | |
parent | c804d574e337158da589e90dc9cbb13d6ffde44f (diff) | |
download | openbsd-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_record_layer.c')
-rw-r--r-- | src/lib/libssl/tls13_record_layer.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/lib/libssl/tls13_record_layer.c b/src/lib/libssl/tls13_record_layer.c index c92fd8d193..ac5b83bd34 100644 --- a/src/lib/libssl/tls13_record_layer.c +++ b/src/lib/libssl/tls13_record_layer.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls13_record_layer.c,v 1.69 2022/07/24 14:16:29 jsing Exp $ */ | 1 | /* $OpenBSD: tls13_record_layer.c,v 1.70 2022/07/24 14:28:16 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -146,8 +146,8 @@ tls13_record_layer_new(const struct tls13_record_layer_callbacks *callbacks, | |||
146 | goto err; | 146 | goto err; |
147 | 147 | ||
148 | rl->legacy_version = TLS1_2_VERSION; | 148 | rl->legacy_version = TLS1_2_VERSION; |
149 | rl->cb = *callbacks; | 149 | |
150 | rl->cb_arg = cb_arg; | 150 | tls13_record_layer_set_callbacks(rl, callbacks, cb_arg); |
151 | 151 | ||
152 | return rl; | 152 | return rl; |
153 | 153 | ||
@@ -178,6 +178,14 @@ tls13_record_layer_free(struct tls13_record_layer *rl) | |||
178 | } | 178 | } |
179 | 179 | ||
180 | void | 180 | void |
181 | tls13_record_layer_set_callbacks(struct tls13_record_layer *rl, | ||
182 | const struct tls13_record_layer_callbacks *callbacks, void *cb_arg) | ||
183 | { | ||
184 | rl->cb = *callbacks; | ||
185 | rl->cb_arg = cb_arg; | ||
186 | } | ||
187 | |||
188 | void | ||
181 | tls13_record_layer_rcontent(struct tls13_record_layer *rl, CBS *cbs) | 189 | tls13_record_layer_rcontent(struct tls13_record_layer *rl, CBS *cbs) |
182 | { | 190 | { |
183 | CBS_dup(tls_content_cbs(rl->rcontent), cbs); | 191 | CBS_dup(tls_content_cbs(rl->rcontent), cbs); |
@@ -489,6 +497,10 @@ int | |||
489 | tls13_record_layer_set_read_traffic_key(struct tls13_record_layer *rl, | 497 | tls13_record_layer_set_read_traffic_key(struct tls13_record_layer *rl, |
490 | struct tls13_secret *read_key, enum ssl_encryption_level_t read_level) | 498 | struct tls13_secret *read_key, enum ssl_encryption_level_t read_level) |
491 | { | 499 | { |
500 | if (rl->cb.set_read_traffic_key != NULL) | ||
501 | return rl->cb.set_read_traffic_key(read_key, read_level, | ||
502 | rl->cb_arg); | ||
503 | |||
492 | return tls13_record_layer_set_traffic_key(rl->aead, rl->hash, | 504 | return tls13_record_layer_set_traffic_key(rl->aead, rl->hash, |
493 | rl->read, read_key); | 505 | rl->read, read_key); |
494 | } | 506 | } |
@@ -497,6 +509,10 @@ int | |||
497 | tls13_record_layer_set_write_traffic_key(struct tls13_record_layer *rl, | 509 | tls13_record_layer_set_write_traffic_key(struct tls13_record_layer *rl, |
498 | struct tls13_secret *write_key, enum ssl_encryption_level_t write_level) | 510 | struct tls13_secret *write_key, enum ssl_encryption_level_t write_level) |
499 | { | 511 | { |
512 | if (rl->cb.set_write_traffic_key != NULL) | ||
513 | return rl->cb.set_write_traffic_key(write_key, write_level, | ||
514 | rl->cb_arg); | ||
515 | |||
500 | return tls13_record_layer_set_traffic_key(rl->aead, rl->hash, | 516 | return tls13_record_layer_set_traffic_key(rl->aead, rl->hash, |
501 | rl->write, write_key); | 517 | rl->write, write_key); |
502 | } | 518 | } |
@@ -1128,6 +1144,9 @@ tls13_send_dummy_ccs(struct tls13_record_layer *rl) | |||
1128 | ssize_t | 1144 | ssize_t |
1129 | tls13_read_handshake_data(struct tls13_record_layer *rl, uint8_t *buf, size_t n) | 1145 | tls13_read_handshake_data(struct tls13_record_layer *rl, uint8_t *buf, size_t n) |
1130 | { | 1146 | { |
1147 | if (rl->cb.handshake_read != NULL) | ||
1148 | return rl->cb.handshake_read(buf, n, rl->cb_arg); | ||
1149 | |||
1131 | return tls13_record_layer_read(rl, SSL3_RT_HANDSHAKE, buf, n); | 1150 | return tls13_record_layer_read(rl, SSL3_RT_HANDSHAKE, buf, n); |
1132 | } | 1151 | } |
1133 | 1152 | ||
@@ -1135,6 +1154,9 @@ ssize_t | |||
1135 | tls13_write_handshake_data(struct tls13_record_layer *rl, const uint8_t *buf, | 1154 | tls13_write_handshake_data(struct tls13_record_layer *rl, const uint8_t *buf, |
1136 | size_t n) | 1155 | size_t n) |
1137 | { | 1156 | { |
1157 | if (rl->cb.handshake_write != NULL) | ||
1158 | return rl->cb.handshake_write(buf, n, rl->cb_arg); | ||
1159 | |||
1138 | return tls13_record_layer_write(rl, SSL3_RT_HANDSHAKE, buf, n); | 1160 | return tls13_record_layer_write(rl, SSL3_RT_HANDSHAKE, buf, n); |
1139 | } | 1161 | } |
1140 | 1162 | ||
@@ -1181,6 +1203,9 @@ tls13_send_alert(struct tls13_record_layer *rl, uint8_t alert_desc) | |||
1181 | uint8_t alert_level = TLS13_ALERT_LEVEL_FATAL; | 1203 | uint8_t alert_level = TLS13_ALERT_LEVEL_FATAL; |
1182 | ssize_t ret; | 1204 | ssize_t ret; |
1183 | 1205 | ||
1206 | if (rl->cb.alert_send != NULL) | ||
1207 | return rl->cb.alert_send(alert_desc, rl->cb_arg); | ||
1208 | |||
1184 | if (alert_desc == TLS13_ALERT_CLOSE_NOTIFY || | 1209 | if (alert_desc == TLS13_ALERT_CLOSE_NOTIFY || |
1185 | alert_desc == TLS13_ALERT_USER_CANCELED) | 1210 | alert_desc == TLS13_ALERT_USER_CANCELED) |
1186 | alert_level = TLS13_ALERT_LEVEL_WARNING; | 1211 | alert_level = TLS13_ALERT_LEVEL_WARNING; |