From f3053a044b26a9a6c7c7edb6783003483d758112 Mon Sep 17 00:00:00 2001 From: beck <> Date: Wed, 20 Nov 2019 16:21:20 +0000 Subject: Add accessors to change the buffer in a handshake message. Needed for doing TLS 1.3 Post Handshake Handshake messages. ok jsing@ --- src/lib/libssl/tls13_buffer.c | 11 ++++++++++- src/lib/libssl/tls13_handshake_msg.c | 8 +++++++- src/lib/libssl/tls13_internal.h | 4 +++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/lib/libssl/tls13_buffer.c b/src/lib/libssl/tls13_buffer.c index 1b490c8b46..8990327bb6 100644 --- a/src/lib/libssl/tls13_buffer.c +++ b/src/lib/libssl/tls13_buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls13_buffer.c,v 1.1 2019/01/17 06:32:12 jsing Exp $ */ +/* $OpenBSD: tls13_buffer.c,v 1.2 2019/11/20 16:21:20 beck Exp $ */ /* * Copyright (c) 2018, 2019 Joel Sing * @@ -75,6 +75,15 @@ tls13_buffer_resize(struct tls13_buffer *buf, size_t capacity) return 1; } +int +tls13_buffer_set_data(struct tls13_buffer *buf, CBS *data) +{ + if (!tls13_buffer_resize(buf, CBS_len(data))) + return 0; + memcpy(buf->data, CBS_data(data), CBS_len(data)); + return 1; +} + ssize_t tls13_buffer_extend(struct tls13_buffer *buf, size_t len, tls13_read_cb read_cb, void *cb_arg) diff --git a/src/lib/libssl/tls13_handshake_msg.c b/src/lib/libssl/tls13_handshake_msg.c index f85271a537..21932fc4ee 100644 --- a/src/lib/libssl/tls13_handshake_msg.c +++ b/src/lib/libssl/tls13_handshake_msg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls13_handshake_msg.c,v 1.1 2019/01/20 12:27:34 jsing Exp $ */ +/* $OpenBSD: tls13_handshake_msg.c,v 1.2 2019/11/20 16:21:20 beck Exp $ */ /* * Copyright (c) 2018, 2019 Joel Sing * @@ -72,6 +72,12 @@ tls13_handshake_msg_data(struct tls13_handshake_msg *msg, CBS *cbs) CBS_init(cbs, msg->data, msg->data_len); } +int +tls13_handshake_msg_set_buffer(struct tls13_handshake_msg *msg, CBS *cbs) +{ + return tls13_buffer_set_data(msg->buf, cbs); +} + uint8_t tls13_handshake_msg_type(struct tls13_handshake_msg *msg) { diff --git a/src/lib/libssl/tls13_internal.h b/src/lib/libssl/tls13_internal.h index 03e75933a1..859030747f 100644 --- a/src/lib/libssl/tls13_internal.h +++ b/src/lib/libssl/tls13_internal.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tls13_internal.h,v 1.34 2019/11/18 15:25:59 beck Exp $ */ +/* $OpenBSD: tls13_internal.h,v 1.35 2019/11/20 16:21:20 beck Exp $ */ /* * Copyright (c) 2018 Bob Beck * Copyright (c) 2018 Theo Buehler @@ -47,6 +47,7 @@ typedef ssize_t (*tls13_write_cb)(const void *_buf, size_t _buflen, struct tls13_buffer; struct tls13_buffer *tls13_buffer_new(size_t init_size); +int tls13_buffer_set_data(struct tls13_buffer *buf, CBS *data); void tls13_buffer_free(struct tls13_buffer *buf); ssize_t tls13_buffer_extend(struct tls13_buffer *buf, size_t len, tls13_read_cb read_cb, void *cb_arg); @@ -141,6 +142,7 @@ struct tls13_handshake_msg; struct tls13_handshake_msg *tls13_handshake_msg_new(void); void tls13_handshake_msg_free(struct tls13_handshake_msg *msg); void tls13_handshake_msg_data(struct tls13_handshake_msg *msg, CBS *cbs); +int tls13_handshake_msg_set_buffer(struct tls13_handshake_msg *msg, CBS *cbs); uint8_t tls13_handshake_msg_type(struct tls13_handshake_msg *msg); int tls13_handshake_msg_content(struct tls13_handshake_msg *msg, CBS *cbs); int tls13_handshake_msg_start(struct tls13_handshake_msg *msg, CBB *body, -- cgit v1.2.3-55-g6feb