summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2024-01-27 14:23:51 +0000
committerjsing <>2024-01-27 14:23:51 +0000
commit340a6fc865a1f962157425333362f1ccd2f6fc4d (patch)
tree9cbd5fde21560efd1f35dcf0b36726c3ac48b0c5 /src
parentd01a2efdc6e392ca2ff82cecb4ec37c80c960b94 (diff)
downloadopenbsd-340a6fc865a1f962157425333362f1ccd2f6fc4d.tar.gz
openbsd-340a6fc865a1f962157425333362f1ccd2f6fc4d.tar.bz2
openbsd-340a6fc865a1f962157425333362f1ccd2f6fc4d.zip
Add message callbacks for alerts in the TLSv1.3 stack.
This will make it easier to regress test shutdown behaviour in the TLSv1.3 stack. Additionally, `openssl -msg` now shows alerts for TLSv1.3 connections. ok tb@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libssl/tls13_internal.h11
-rw-r--r--src/lib/libssl/tls13_lib.c42
-rw-r--r--src/lib/libssl/tls13_record_layer.c6
3 files changed, 49 insertions, 10 deletions
diff --git a/src/lib/libssl/tls13_internal.h b/src/lib/libssl/tls13_internal.h
index f4b17bdf25..68e695e53a 100644
--- a/src/lib/libssl/tls13_internal.h
+++ b/src/lib/libssl/tls13_internal.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls13_internal.h,v 1.101 2022/07/24 14:28:16 jsing Exp $ */ 1/* $OpenBSD: tls13_internal.h,v 1.102 2024/01/27 14:23:51 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2018 Bob Beck <beck@openbsd.org> 3 * Copyright (c) 2018 Bob Beck <beck@openbsd.org>
4 * Copyright (c) 2018 Theo Buehler <tb@openbsd.org> 4 * Copyright (c) 2018 Theo Buehler <tb@openbsd.org>
@@ -87,7 +87,8 @@ __BEGIN_HIDDEN_DECLS
87#define TLS13_INFO_ACCEPT_EXIT SSL_CB_ACCEPT_EXIT 87#define TLS13_INFO_ACCEPT_EXIT SSL_CB_ACCEPT_EXIT
88#define TLS13_INFO_CONNECT_EXIT SSL_CB_CONNECT_EXIT 88#define TLS13_INFO_CONNECT_EXIT SSL_CB_CONNECT_EXIT
89 89
90typedef void (*tls13_alert_cb)(uint8_t _alert_desc, void *_cb_arg); 90typedef void (*tls13_alert_cb)(uint8_t _alert_level, uint8_t _alert_desc,
91 void *_cb_arg);
91typedef ssize_t (*tls13_phh_recv_cb)(void *_cb_arg); 92typedef ssize_t (*tls13_phh_recv_cb)(void *_cb_arg);
92typedef void (*tls13_phh_sent_cb)(void *_cb_arg); 93typedef void (*tls13_phh_sent_cb)(void *_cb_arg);
93typedef void (*tls13_handshake_message_cb)(void *_cb_arg); 94typedef void (*tls13_handshake_message_cb)(void *_cb_arg);
@@ -291,6 +292,8 @@ struct tls13_ctx {
291 int phh_count; 292 int phh_count;
292 time_t phh_last_seen; 293 time_t phh_last_seen;
293 294
295 tls13_alert_cb alert_sent_cb;
296 tls13_alert_cb alert_recv_cb;
294 tls13_handshake_message_cb handshake_message_sent_cb; 297 tls13_handshake_message_cb handshake_message_sent_cb;
295 tls13_handshake_message_cb handshake_message_recv_cb; 298 tls13_handshake_message_cb handshake_message_recv_cb;
296 tls13_info_cb info_cb; 299 tls13_info_cb info_cb;
@@ -309,8 +312,8 @@ void tls13_ctx_free(struct tls13_ctx *ctx);
309const EVP_AEAD *tls13_cipher_aead(const SSL_CIPHER *cipher); 312const EVP_AEAD *tls13_cipher_aead(const SSL_CIPHER *cipher);
310const EVP_MD *tls13_cipher_hash(const SSL_CIPHER *cipher); 313const EVP_MD *tls13_cipher_hash(const SSL_CIPHER *cipher);
311 314
312void tls13_alert_received_cb(uint8_t alert_desc, void *arg); 315void tls13_alert_received_cb(uint8_t alert_level, uint8_t alert_desc, void *arg);
313void tls13_alert_sent_cb(uint8_t alert_desc, void *arg); 316void tls13_alert_sent_cb(uint8_t alert_level, uint8_t alert_desc, void *arg);
314ssize_t tls13_phh_received_cb(void *cb_arg); 317ssize_t tls13_phh_received_cb(void *cb_arg);
315void tls13_phh_done_cb(void *cb_arg); 318void tls13_phh_done_cb(void *cb_arg);
316 319
diff --git a/src/lib/libssl/tls13_lib.c b/src/lib/libssl/tls13_lib.c
index 05f125adc8..331a3ad1a7 100644
--- a/src/lib/libssl/tls13_lib.c
+++ b/src/lib/libssl/tls13_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls13_lib.c,v 1.76 2022/11/26 16:08:56 tb Exp $ */ 1/* $OpenBSD: tls13_lib.c,v 1.77 2024/01/27 14:23:51 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 * Copyright (c) 2019 Bob Beck <beck@openbsd.org> 4 * Copyright (c) 2019 Bob Beck <beck@openbsd.org>
@@ -110,11 +110,42 @@ tls13_cipher_hash(const SSL_CIPHER *cipher)
110 return NULL; 110 return NULL;
111} 111}
112 112
113static void
114tls13_legacy_alert_cb(int sent, uint8_t alert_level, uint8_t alert_desc,
115 void *arg)
116{
117 uint8_t alert[] = {alert_level, alert_desc};
118 struct tls13_ctx *ctx = arg;
119 SSL *s = ctx->ssl;
120 CBS cbs;
121
122 if (s->msg_callback == NULL)
123 return;
124
125 CBS_init(&cbs, alert, sizeof(alert));
126 ssl_msg_callback_cbs(s, sent, SSL3_RT_ALERT, &cbs);
127}
128
129static void
130tls13_legacy_alert_recv_cb(uint8_t alert_level, uint8_t alert_desc, void *arg)
131{
132 tls13_legacy_alert_cb(0, alert_level, alert_desc, arg);
133}
134
135static void
136tls13_legacy_alert_sent_cb(uint8_t alert_level, uint8_t alert_desc, void *arg)
137{
138 tls13_legacy_alert_cb(1, alert_level, alert_desc, arg);
139}
140
113void 141void
114tls13_alert_received_cb(uint8_t alert_desc, void *arg) 142tls13_alert_received_cb(uint8_t alert_level, uint8_t alert_desc, void *arg)
115{ 143{
116 struct tls13_ctx *ctx = arg; 144 struct tls13_ctx *ctx = arg;
117 145
146 if (ctx->alert_recv_cb != NULL)
147 ctx->alert_recv_cb(alert_level, alert_desc, arg);
148
118 if (alert_desc == TLS13_ALERT_CLOSE_NOTIFY) { 149 if (alert_desc == TLS13_ALERT_CLOSE_NOTIFY) {
119 ctx->close_notify_recv = 1; 150 ctx->close_notify_recv = 1;
120 ctx->ssl->shutdown |= SSL_RECEIVED_SHUTDOWN; 151 ctx->ssl->shutdown |= SSL_RECEIVED_SHUTDOWN;
@@ -140,10 +171,13 @@ tls13_alert_received_cb(uint8_t alert_desc, void *arg)
140} 171}
141 172
142void 173void
143tls13_alert_sent_cb(uint8_t alert_desc, void *arg) 174tls13_alert_sent_cb(uint8_t alert_level, uint8_t alert_desc, void *arg)
144{ 175{
145 struct tls13_ctx *ctx = arg; 176 struct tls13_ctx *ctx = arg;
146 177
178 if (ctx->alert_sent_cb != NULL)
179 ctx->alert_sent_cb(alert_level, alert_desc, arg);
180
147 if (alert_desc == TLS13_ALERT_CLOSE_NOTIFY) { 181 if (alert_desc == TLS13_ALERT_CLOSE_NOTIFY) {
148 ctx->close_notify_sent = 1; 182 ctx->close_notify_sent = 1;
149 return; 183 return;
@@ -514,6 +548,8 @@ tls13_ctx_new(int mode, SSL *ssl)
514 if ((ctx->rl = tls13_record_layer_new(&tls13_rl_callbacks, ctx)) == NULL) 548 if ((ctx->rl = tls13_record_layer_new(&tls13_rl_callbacks, ctx)) == NULL)
515 goto err; 549 goto err;
516 550
551 ctx->alert_sent_cb = tls13_legacy_alert_sent_cb;
552 ctx->alert_recv_cb = tls13_legacy_alert_recv_cb;
517 ctx->handshake_message_sent_cb = tls13_legacy_handshake_message_sent_cb; 553 ctx->handshake_message_sent_cb = tls13_legacy_handshake_message_sent_cb;
518 ctx->handshake_message_recv_cb = tls13_legacy_handshake_message_recv_cb; 554 ctx->handshake_message_recv_cb = tls13_legacy_handshake_message_recv_cb;
519 ctx->info_cb = tls13_legacy_info_cb; 555 ctx->info_cb = tls13_legacy_info_cb;
diff --git a/src/lib/libssl/tls13_record_layer.c b/src/lib/libssl/tls13_record_layer.c
index 4ae4e298eb..5432744cd7 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.72 2022/11/11 17:15:27 jsing Exp $ */ 1/* $OpenBSD: tls13_record_layer.c,v 1.73 2024/01/27 14:23:51 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 *
@@ -327,7 +327,7 @@ tls13_record_layer_process_alert(struct tls13_record_layer *rl)
327 return tls13_send_alert(rl, TLS13_ALERT_ILLEGAL_PARAMETER); 327 return tls13_send_alert(rl, TLS13_ALERT_ILLEGAL_PARAMETER);
328 } 328 }
329 329
330 rl->cb.alert_recv(alert_desc, rl->cb_arg); 330 rl->cb.alert_recv(alert_level, alert_desc, rl->cb_arg);
331 331
332 return ret; 332 return ret;
333} 333}
@@ -361,7 +361,7 @@ tls13_record_layer_send_alert(struct tls13_record_layer *rl)
361 ret = TLS13_IO_ALERT; 361 ret = TLS13_IO_ALERT;
362 } 362 }
363 363
364 rl->cb.alert_sent(rl->alert_desc, rl->cb_arg); 364 rl->cb.alert_sent(rl->alert_level, rl->alert_desc, rl->cb_arg);
365 365
366 return ret; 366 return ret;
367} 367}