diff options
author | tb <> | 2020-03-16 15:11:35 +0000 |
---|---|---|
committer | tb <> | 2020-03-16 15:11:35 +0000 |
commit | 108f8702aed150676e48a7a8233559c84c82b07f (patch) | |
tree | 6a053ff9c6b2a4df1c707c9d61c1f161618cff0c /src | |
parent | 96cf222f202447895d0d051a4c795f157e301e07 (diff) | |
download | openbsd-108f8702aed150676e48a7a8233559c84c82b07f.tar.gz openbsd-108f8702aed150676e48a7a8233559c84c82b07f.tar.bz2 openbsd-108f8702aed150676e48a7a8233559c84c82b07f.zip |
The RFC is clear (section 5.3) that sequence number should never wrap.
We currently throw an error on overflow, but still wrap. Check up front
if we would need to wrap and only increment if that case is excluded.
This simplifies the increment loop and makes the returns in this function
less magic.
ok jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libssl/tls13_record_layer.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/lib/libssl/tls13_record_layer.c b/src/lib/libssl/tls13_record_layer.c index 341bceeabc..7664feffc0 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.29 2020/03/13 16:03:27 jsing Exp $ */ | 1 | /* $OpenBSD: tls13_record_layer.c,v 1.30 2020/03/16 15:11:35 tb 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 | * |
@@ -166,18 +166,25 @@ tls13_record_layer_rbuf(struct tls13_record_layer *rl, CBS *cbs) | |||
166 | CBS_dup(&rl->rbuf_cbs, cbs); | 166 | CBS_dup(&rl->rbuf_cbs, cbs); |
167 | } | 167 | } |
168 | 168 | ||
169 | uint8_t tls13_max_seq_num[TLS13_RECORD_SEQ_NUM_LEN] = { | ||
170 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
171 | }; | ||
172 | |||
169 | int | 173 | int |
170 | tls13_record_layer_inc_seq_num(uint8_t *seq_num) | 174 | tls13_record_layer_inc_seq_num(uint8_t *seq_num) |
171 | { | 175 | { |
172 | size_t i; | 176 | int i; |
173 | 177 | ||
174 | for (i = TLS13_RECORD_SEQ_NUM_LEN - 1; i > 0; i--) { | 178 | /* RFC 8446 section 5.3 - sequence numbers must not wrap. */ |
179 | if (memcmp(seq_num, tls13_max_seq_num, TLS13_RECORD_SEQ_NUM_LEN) == 0) | ||
180 | return 0; | ||
181 | |||
182 | for (i = TLS13_RECORD_SEQ_NUM_LEN - 1; i >= 0; i--) { | ||
175 | if (++seq_num[i] != 0) | 183 | if (++seq_num[i] != 0) |
176 | break; | 184 | break; |
177 | } | 185 | } |
178 | 186 | ||
179 | /* RFC 8446 section 5.3 - sequence numbers must not wrap. */ | 187 | return 1; |
180 | return (i != 0 || ++seq_num[0] != 0); | ||
181 | } | 188 | } |
182 | 189 | ||
183 | static int | 190 | static int |