summaryrefslogtreecommitdiff
path: root/src/lib/libssl/tls13_record_layer.c
diff options
context:
space:
mode:
authorjsing <>2020-01-22 06:23:00 +0000
committerjsing <>2020-01-22 06:23:00 +0000
commit9e9db88c593e9fe3ec46a015b783a8903db297c3 (patch)
treeb500b4cd4fbfdaf1e52f3a0b754eb1e97bd5f92f /src/lib/libssl/tls13_record_layer.c
parent0cbc880fa36f08c10caa253c5b025333c684fa2f (diff)
downloadopenbsd-9e9db88c593e9fe3ec46a015b783a8903db297c3.tar.gz
openbsd-9e9db88c593e9fe3ec46a015b783a8903db297c3.tar.bz2
openbsd-9e9db88c593e9fe3ec46a015b783a8903db297c3.zip
Implement support for SSL_peek() in the TLSv1.3 record layer.
ok beck@ tb@
Diffstat (limited to 'src/lib/libssl/tls13_record_layer.c')
-rw-r--r--src/lib/libssl/tls13_record_layer.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/src/lib/libssl/tls13_record_layer.c b/src/lib/libssl/tls13_record_layer.c
index ef558d52df..4de7340999 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.21 2020/01/22 05:06:23 tb Exp $ */ 1/* $OpenBSD: tls13_record_layer.c,v 1.22 2020/01/22 06:23:00 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 *
@@ -812,8 +812,8 @@ tls13_record_layer_read_record(struct tls13_record_layer *rl)
812} 812}
813 813
814ssize_t 814ssize_t
815tls13_record_layer_read(struct tls13_record_layer *rl, uint8_t content_type, 815tls13_record_layer_read_internal(struct tls13_record_layer *rl,
816 uint8_t *buf, size_t n) 816 uint8_t content_type, uint8_t *buf, size_t n, int peek)
817{ 817{
818 ssize_t ret; 818 ssize_t ret;
819 819
@@ -898,8 +898,11 @@ tls13_record_layer_read(struct tls13_record_layer *rl, uint8_t content_type,
898 898
899 /* XXX - CBS_memcpy? CBS_copy_bytes? */ 899 /* XXX - CBS_memcpy? CBS_copy_bytes? */
900 memcpy(buf, CBS_data(&rl->rbuf_cbs), n); 900 memcpy(buf, CBS_data(&rl->rbuf_cbs), n);
901 if (!CBS_skip(&rl->rbuf_cbs, n)) 901
902 goto err; 902 if (!peek) {
903 if (!CBS_skip(&rl->rbuf_cbs, n))
904 goto err;
905 }
903 906
904 if (CBS_len(&rl->rbuf_cbs) == 0) 907 if (CBS_len(&rl->rbuf_cbs) == 0)
905 tls13_record_layer_rbuf_free(rl); 908 tls13_record_layer_rbuf_free(rl);
@@ -910,6 +913,20 @@ tls13_record_layer_read(struct tls13_record_layer *rl, uint8_t content_type,
910 return TLS13_IO_FAILURE; 913 return TLS13_IO_FAILURE;
911} 914}
912 915
916ssize_t
917tls13_record_layer_peek(struct tls13_record_layer *rl, uint8_t content_type,
918 uint8_t *buf, size_t n)
919{
920 return tls13_record_layer_read_internal(rl, content_type, buf, n, 1);
921}
922
923ssize_t
924tls13_record_layer_read(struct tls13_record_layer *rl, uint8_t content_type,
925 uint8_t *buf, size_t n)
926{
927 return tls13_record_layer_read_internal(rl, content_type, buf, n, 0);
928}
929
913static ssize_t 930static ssize_t
914tls13_record_layer_write_record(struct tls13_record_layer *rl, 931tls13_record_layer_write_record(struct tls13_record_layer *rl,
915 uint8_t content_type, const uint8_t *content, size_t content_len) 932 uint8_t content_type, const uint8_t *content, size_t content_len)
@@ -1006,6 +1023,15 @@ tls13_write_handshake_data(struct tls13_record_layer *rl, const uint8_t *buf,
1006} 1023}
1007 1024
1008ssize_t 1025ssize_t
1026tls13_peek_application_data(struct tls13_record_layer *rl, uint8_t *buf, size_t n)
1027{
1028 if (!rl->handshake_completed)
1029 return TLS13_IO_FAILURE;
1030
1031 return tls13_record_layer_peek(rl, SSL3_RT_APPLICATION_DATA, buf, n);
1032}
1033
1034ssize_t
1009tls13_read_application_data(struct tls13_record_layer *rl, uint8_t *buf, size_t n) 1035tls13_read_application_data(struct tls13_record_layer *rl, uint8_t *buf, size_t n)
1010{ 1036{
1011 if (!rl->handshake_completed) 1037 if (!rl->handshake_completed)