summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2020-01-25 13:11:21 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2020-01-25 13:11:21 +0000
commitcdf774ecdacb8016602793e885c3b68205419b5e (patch)
treefdaac4bf15373fa6bb3ee6f5ab4ad9f3a1bd6574 /lib
parente2da1aa234a275dde8b96d5a0288c30a705fa079 (diff)
Support legacy message callbacks. First step for SSL_set_msg_callback(3)
support. Makes openssl s_client -msg work for handshake messages. ok beck jsing
Diffstat (limited to 'lib')
-rw-r--r--lib/libssl/tls13_handshake.c8
-rw-r--r--lib/libssl/tls13_internal.h6
-rw-r--r--lib/libssl/tls13_lib.c29
3 files changed, 40 insertions, 3 deletions
diff --git a/lib/libssl/tls13_handshake.c b/lib/libssl/tls13_handshake.c
index ed70ec1f4b7..1528bd5e2ae 100644
--- a/lib/libssl/tls13_handshake.c
+++ b/lib/libssl/tls13_handshake.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tls13_handshake.c,v 1.45 2020/01/25 06:37:30 beck Exp $ */
+/* $OpenBSD: tls13_handshake.c,v 1.46 2020/01/25 13:11:20 tb Exp $ */
/*
* Copyright (c) 2018-2019 Theo Buehler <tb@openbsd.org>
* Copyright (c) 2019 Joel Sing <jsing@openbsd.org>
@@ -363,6 +363,9 @@ tls13_handshake_send_action(struct tls13_ctx *ctx,
return TLS13_IO_FAILURE;
}
+ if (ctx->handshake_message_sent_cb != NULL)
+ ctx->handshake_message_sent_cb(ctx, &cbs);
+
tls13_handshake_msg_free(ctx->hs_msg);
ctx->hs_msg = NULL;
@@ -399,6 +402,9 @@ tls13_handshake_recv_action(struct tls13_ctx *ctx,
if (!tls1_transcript_record(ctx->ssl, CBS_data(&cbs), CBS_len(&cbs)))
return TLS13_IO_FAILURE;
+ if (ctx->handshake_message_recv_cb != NULL)
+ ctx->handshake_message_recv_cb(ctx, &cbs);
+
/*
* In TLSv1.3 there is no way to know if you're going to receive a
* certificate request message or not, hence we have to special case it
diff --git a/lib/libssl/tls13_internal.h b/lib/libssl/tls13_internal.h
index 9aabc409d8c..278704002e4 100644
--- a/lib/libssl/tls13_internal.h
+++ b/lib/libssl/tls13_internal.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tls13_internal.h,v 1.54 2020/01/25 09:20:56 jsing Exp $ */
+/* $OpenBSD: tls13_internal.h,v 1.55 2020/01/25 13:11:20 tb Exp $ */
/*
* Copyright (c) 2018 Bob Beck <beck@openbsd.org>
* Copyright (c) 2018 Theo Buehler <tb@openbsd.org>
@@ -50,6 +50,7 @@ typedef void (*tls13_phh_sent_cb)(void *_cb_arg);
typedef ssize_t (*tls13_read_cb)(void *_buf, size_t _buflen, void *_cb_arg);
typedef ssize_t (*tls13_write_cb)(const void *_buf, size_t _buflen,
void *_cb_arg);
+typedef void (*tls13_handshake_message_cb)(void *_cb_arg, CBS *_cbs);
struct tls13_buffer;
@@ -205,6 +206,9 @@ struct tls13_ctx {
uint8_t alert;
int phh_count;
time_t phh_last_seen;
+
+ tls13_handshake_message_cb handshake_message_sent_cb;
+ tls13_handshake_message_cb handshake_message_recv_cb;
};
#ifndef TLS13_PHH_LIMIT_TIME
#define TLS13_PHH_LIMIT_TIME 3600
diff --git a/lib/libssl/tls13_lib.c b/lib/libssl/tls13_lib.c
index f17f2ff0de3..950b5a4019c 100644
--- a/lib/libssl/tls13_lib.c
+++ b/lib/libssl/tls13_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tls13_lib.c,v 1.29 2020/01/24 05:11:34 beck Exp $ */
+/* $OpenBSD: tls13_lib.c,v 1.30 2020/01/25 13:11:20 tb Exp $ */
/*
* Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org>
* Copyright (c) 2019 Bob Beck <beck@openbsd.org>
@@ -105,6 +105,30 @@ tls13_alert_received_cb(uint8_t alert_desc, void *arg)
SSL_CTX_remove_session(s->ctx, s->session);
}
+static void
+tls13_legacy_handshake_message_recv_cb(void *arg, CBS *cbs)
+{
+ struct tls13_ctx *ctx = arg;
+ SSL *s = ctx->ssl;
+
+ if (s->internal->msg_callback != NULL)
+ s->internal->msg_callback(0, TLS1_3_VERSION, SSL3_RT_HANDSHAKE,
+ CBS_data(cbs), CBS_len(cbs), s,
+ s->internal->msg_callback_arg);
+}
+
+static void
+tls13_legacy_handshake_message_sent_cb(void *arg, CBS *cbs)
+{
+ struct tls13_ctx *ctx = arg;
+ SSL *s = ctx->ssl;
+
+ if (s->internal->msg_callback != NULL)
+ s->internal->msg_callback(1, TLS1_3_VERSION, SSL3_RT_HANDSHAKE,
+ CBS_data(cbs), CBS_len(cbs), s,
+ s->internal->msg_callback_arg);
+}
+
static int
tls13_phh_update_local_traffic_secret(struct tls13_ctx *ctx)
{
@@ -263,6 +287,9 @@ tls13_ctx_new(int mode)
tls13_phh_received_cb, tls13_phh_done_cb, ctx)) == NULL)
goto err;
+ ctx->handshake_message_sent_cb = tls13_legacy_handshake_message_sent_cb;
+ ctx->handshake_message_recv_cb = tls13_legacy_handshake_message_recv_cb;
+
return ctx;
err: