summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2019-01-20 09:12:05 +0000
committerjsing <>2019-01-20 09:12:05 +0000
commit7edeeab42abe6a4ac98592eaeb95ef15308aa99e (patch)
tree257e0bb03cf9a5f9921b66d81038d5791e9f8377
parent64b3f74c4f83388e7209fc3cfcb421829ed07533 (diff)
downloadopenbsd-7edeeab42abe6a4ac98592eaeb95ef15308aa99e.tar.gz
openbsd-7edeeab42abe6a4ac98592eaeb95ef15308aa99e.tar.bz2
openbsd-7edeeab42abe6a4ac98592eaeb95ef15308aa99e.zip
Provide a way to get just the record header.
Also check record size limits when reading records and setting data. ok tb@
-rw-r--r--src/lib/libssl/tls13_record.c24
-rw-r--r--src/lib/libssl/tls13_record.h16
2 files changed, 33 insertions, 7 deletions
diff --git a/src/lib/libssl/tls13_record.c b/src/lib/libssl/tls13_record.c
index 857d3bee49..1a4e22ee47 100644
--- a/src/lib/libssl/tls13_record.c
+++ b/src/lib/libssl/tls13_record.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls13_record.c,v 1.1 2019/01/19 02:53:54 jsing Exp $ */ 1/* $OpenBSD: tls13_record.c,v 1.2 2019/01/20 09:12:05 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 *
@@ -62,6 +62,17 @@ tls13_record_free(struct tls13_record *rec)
62 freezero(rec, sizeof(struct tls13_record)); 62 freezero(rec, sizeof(struct tls13_record));
63} 63}
64 64
65int
66tls13_record_header(struct tls13_record *rec, CBS *cbs)
67{
68 if (rec->data_len < TLS13_RECORD_HEADER_LEN)
69 return 0;
70
71 CBS_init(cbs, rec->data, TLS13_RECORD_HEADER_LEN);
72
73 return 1;
74}
75
65uint8_t 76uint8_t
66tls13_record_content_type(struct tls13_record *rec) 77tls13_record_content_type(struct tls13_record *rec)
67{ 78{
@@ -89,13 +100,18 @@ tls13_record_data(struct tls13_record *rec, CBS *cbs)
89 CBS_init(cbs, rec->data, rec->data_len); 100 CBS_init(cbs, rec->data, rec->data_len);
90} 101}
91 102
92void 103int
93tls13_record_set_data(struct tls13_record *rec, uint8_t *data, size_t data_len) 104tls13_record_set_data(struct tls13_record *rec, uint8_t *data, size_t data_len)
94{ 105{
106 if (data_len > TLS13_RECORD_MAX_LEN)
107 return 0;
108
95 freezero(rec->data, rec->data_len); 109 freezero(rec->data, rec->data_len);
96 rec->data = data; 110 rec->data = data;
97 rec->data_len = data_len; 111 rec->data_len = data_len;
98 CBS_init(&rec->cbs, rec->data, rec->data_len); 112 CBS_init(&rec->cbs, rec->data, rec->data_len);
113
114 return 1;
99} 115}
100 116
101ssize_t 117ssize_t
@@ -124,6 +140,10 @@ tls13_record_recv(struct tls13_record *rec, tls13_read_cb wire_read,
124 if (!CBS_get_u16(&cbs, &rec_len)) 140 if (!CBS_get_u16(&cbs, &rec_len))
125 return TLS13_IO_FAILURE; 141 return TLS13_IO_FAILURE;
126 142
143 /* XXX - record overflow alert. */
144 if (rec_len > TLS13_RECORD_MAX_CIPHERTEXT_LEN)
145 return TLS13_IO_FAILURE;
146
127 rec->content_type = content_type; 147 rec->content_type = content_type;
128 rec->rec_len = rec_len; 148 rec->rec_len = rec_len;
129 } 149 }
diff --git a/src/lib/libssl/tls13_record.h b/src/lib/libssl/tls13_record.h
index ca7a63f99c..72350d5d49 100644
--- a/src/lib/libssl/tls13_record.h
+++ b/src/lib/libssl/tls13_record.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls13_record.h,v 1.1 2019/01/19 02:53:54 jsing Exp $ */ 1/* $OpenBSD: tls13_record.h,v 1.2 2019/01/20 09:12:05 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2019 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2019 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -24,7 +24,7 @@
24__BEGIN_HIDDEN_DECLS 24__BEGIN_HIDDEN_DECLS
25 25
26/* 26/*
27 * TLSv1.3 - RFC 8446 section 5. 27 * TLSv1.3 Record Protocol - RFC 8446 section 5.
28 * 28 *
29 * The maximum plaintext is 2^14, however for inner plaintext an additional 29 * The maximum plaintext is 2^14, however for inner plaintext an additional
30 * byte is allowed for the content type. A maximum AEAD overhead of 255-bytes 30 * byte is allowed for the content type. A maximum AEAD overhead of 255-bytes
@@ -36,17 +36,23 @@ __BEGIN_HIDDEN_DECLS
36#define TLS13_RECORD_MAX_PLAINTEXT_LEN 16384 36#define TLS13_RECORD_MAX_PLAINTEXT_LEN 16384
37#define TLS13_RECORD_MAX_INNER_PLAINTEXT_LEN \ 37#define TLS13_RECORD_MAX_INNER_PLAINTEXT_LEN \
38 (TLS13_RECORD_MAX_PLAINTEXT_LEN + 1) 38 (TLS13_RECORD_MAX_PLAINTEXT_LEN + 1)
39#define TLS13_RECORD_MAX_CIPHERTEXT \ 39#define TLS13_RECORD_MAX_CIPHERTEXT_LEN \
40 (TLS13_RECORD_MAX_INNER_PLAINTEXT_LEN + TLS13_RECORD_MAX_AEAD_OVERHEAD) 40 (TLS13_RECORD_MAX_INNER_PLAINTEXT_LEN + TLS13_RECORD_MAX_AEAD_OVERHEAD)
41#define TLS13_RECORD_MAX_LEN \ 41#define TLS13_RECORD_MAX_LEN \
42 (TLS13_RECORD_HEADER_LEN + TLS13_RECORD_MAX_CIPHERTEXT) 42 (TLS13_RECORD_HEADER_LEN + TLS13_RECORD_MAX_CIPHERTEXT_LEN)
43
44/*
45 * TLSv1.3 Per-Record Nonces and Sequence Numbers - RFC 8446 section 5.3.
46 */
47#define TLS13_RECORD_SEQ_NUM_LEN 8
43 48
44struct tls13_record *tls13_record_new(void); 49struct tls13_record *tls13_record_new(void);
45void tls13_record_free(struct tls13_record *_rec); 50void tls13_record_free(struct tls13_record *_rec);
51int tls13_record_header(struct tls13_record *_rec, CBS *_cbs);
46uint8_t tls13_record_content_type(struct tls13_record *_rec); 52uint8_t tls13_record_content_type(struct tls13_record *_rec);
47int tls13_record_content(struct tls13_record *_rec, CBS *_cbs); 53int tls13_record_content(struct tls13_record *_rec, CBS *_cbs);
48void tls13_record_data(struct tls13_record *_rec, CBS *_cbs); 54void tls13_record_data(struct tls13_record *_rec, CBS *_cbs);
49void tls13_record_set_data(struct tls13_record *_rec, uint8_t *_data, 55int tls13_record_set_data(struct tls13_record *_rec, uint8_t *_data,
50 size_t _data_len); 56 size_t _data_len);
51ssize_t tls13_record_recv(struct tls13_record *_rec, tls13_read_cb _wire_read, 57ssize_t tls13_record_recv(struct tls13_record *_rec, tls13_read_cb _wire_read,
52 void *_wire_arg); 58 void *_wire_arg);