diff options
author | jsing <> | 2019-01-20 09:12:05 +0000 |
---|---|---|
committer | jsing <> | 2019-01-20 09:12:05 +0000 |
commit | 7edeeab42abe6a4ac98592eaeb95ef15308aa99e (patch) | |
tree | 257e0bb03cf9a5f9921b66d81038d5791e9f8377 | |
parent | 64b3f74c4f83388e7209fc3cfcb421829ed07533 (diff) | |
download | openbsd-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.c | 24 | ||||
-rw-r--r-- | src/lib/libssl/tls13_record.h | 16 |
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 | ||
65 | int | ||
66 | tls13_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 | |||
65 | uint8_t | 76 | uint8_t |
66 | tls13_record_content_type(struct tls13_record *rec) | 77 | tls13_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 | ||
92 | void | 103 | int |
93 | tls13_record_set_data(struct tls13_record *rec, uint8_t *data, size_t data_len) | 104 | tls13_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 | ||
101 | ssize_t | 117 | ssize_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 | ||
44 | struct tls13_record *tls13_record_new(void); | 49 | struct tls13_record *tls13_record_new(void); |
45 | void tls13_record_free(struct tls13_record *_rec); | 50 | void tls13_record_free(struct tls13_record *_rec); |
51 | int tls13_record_header(struct tls13_record *_rec, CBS *_cbs); | ||
46 | uint8_t tls13_record_content_type(struct tls13_record *_rec); | 52 | uint8_t tls13_record_content_type(struct tls13_record *_rec); |
47 | int tls13_record_content(struct tls13_record *_rec, CBS *_cbs); | 53 | int tls13_record_content(struct tls13_record *_rec, CBS *_cbs); |
48 | void tls13_record_data(struct tls13_record *_rec, CBS *_cbs); | 54 | void tls13_record_data(struct tls13_record *_rec, CBS *_cbs); |
49 | void tls13_record_set_data(struct tls13_record *_rec, uint8_t *_data, | 55 | int tls13_record_set_data(struct tls13_record *_rec, uint8_t *_data, |
50 | size_t _data_len); | 56 | size_t _data_len); |
51 | ssize_t tls13_record_recv(struct tls13_record *_rec, tls13_read_cb _wire_read, | 57 | ssize_t tls13_record_recv(struct tls13_record *_rec, tls13_read_cb _wire_read, |
52 | void *_wire_arg); | 58 | void *_wire_arg); |