summaryrefslogtreecommitdiff
path: root/src/lib/libssl/d1_pkt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libssl/d1_pkt.c')
-rw-r--r--src/lib/libssl/d1_pkt.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/lib/libssl/d1_pkt.c b/src/lib/libssl/d1_pkt.c
index 6963e58ed3..4f0678f0b8 100644
--- a/src/lib/libssl/d1_pkt.c
+++ b/src/lib/libssl/d1_pkt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: d1_pkt.c,v 1.105 2021/07/31 09:31:04 jsing Exp $ */ 1/* $OpenBSD: d1_pkt.c,v 1.106 2021/08/30 19:12:25 jsing Exp $ */
2/* 2/*
3 * DTLS implementation written by Nagendra Modadugu 3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. 4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -273,12 +273,14 @@ static int
273dtls1_process_buffered_record(SSL *s) 273dtls1_process_buffered_record(SSL *s)
274{ 274{
275 /* Check if epoch is current. */ 275 /* Check if epoch is current. */
276 if (D1I(s)->unprocessed_rcds.epoch != D1I(s)->r_epoch) 276 if (D1I(s)->unprocessed_rcds.epoch !=
277 tls12_record_layer_read_epoch(s->internal->rl))
277 return (0); 278 return (0);
278 279
279 /* Update epoch once all unprocessed records have been processed. */ 280 /* Update epoch once all unprocessed records have been processed. */
280 if (pqueue_peek(D1I(s)->unprocessed_rcds.q) == NULL) { 281 if (pqueue_peek(D1I(s)->unprocessed_rcds.q) == NULL) {
281 D1I(s)->unprocessed_rcds.epoch = D1I(s)->r_epoch + 1; 282 D1I(s)->unprocessed_rcds.epoch =
283 tls12_record_layer_read_epoch(s->internal->rl) + 1;
282 return (0); 284 return (0);
283 } 285 }
284 286
@@ -858,7 +860,7 @@ dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
858 /* this may just be a stale retransmit */ 860 /* this may just be a stale retransmit */
859 if (!dtls1_get_message_header(rr->data, &msg_hdr)) 861 if (!dtls1_get_message_header(rr->data, &msg_hdr))
860 return -1; 862 return -1;
861 if (rr->epoch != D1I(s)->r_epoch) { 863 if (rr->epoch != tls12_record_layer_read_epoch(s->internal->rl)) {
862 rr->length = 0; 864 rr->length = 0;
863 goto start; 865 goto start;
864 } 866 }
@@ -1136,17 +1138,20 @@ dtls1_record_bitmap_update(SSL *s, DTLS1_BITMAP *bitmap,
1136static DTLS1_BITMAP * 1138static DTLS1_BITMAP *
1137dtls1_get_bitmap(SSL *s, SSL3_RECORD_INTERNAL *rr, unsigned int *is_next_epoch) 1139dtls1_get_bitmap(SSL *s, SSL3_RECORD_INTERNAL *rr, unsigned int *is_next_epoch)
1138{ 1140{
1139 uint16_t next_epoch = D1I(s)->r_epoch + 1; 1141 uint16_t read_epoch, read_epoch_next;
1140 1142
1141 *is_next_epoch = 0; 1143 *is_next_epoch = 0;
1142 1144
1145 read_epoch = tls12_record_layer_read_epoch(s->internal->rl);
1146 read_epoch_next = read_epoch + 1;
1147
1143 /* In current epoch, accept HM, CCS, DATA, & ALERT */ 1148 /* In current epoch, accept HM, CCS, DATA, & ALERT */
1144 if (rr->epoch == D1I(s)->r_epoch) 1149 if (rr->epoch == read_epoch)
1145 return &D1I(s)->bitmap; 1150 return &D1I(s)->bitmap;
1146 1151
1147 /* Only HM and ALERT messages can be from the next epoch */ 1152 /* Only HM and ALERT messages can be from the next epoch */
1148 else if (rr->epoch == next_epoch && 1153 if (rr->epoch == read_epoch_next &&
1149 (rr->type == SSL3_RT_HANDSHAKE || rr->type == SSL3_RT_ALERT)) { 1154 (rr->type == SSL3_RT_HANDSHAKE || rr->type == SSL3_RT_ALERT)) {
1150 *is_next_epoch = 1; 1155 *is_next_epoch = 1;
1151 return &D1I(s)->next_bitmap; 1156 return &D1I(s)->next_bitmap;
1152 } 1157 }
@@ -1157,7 +1162,6 @@ dtls1_get_bitmap(SSL *s, SSL3_RECORD_INTERNAL *rr, unsigned int *is_next_epoch)
1157void 1162void
1158dtls1_reset_read_seq_numbers(SSL *s) 1163dtls1_reset_read_seq_numbers(SSL *s)
1159{ 1164{
1160 D1I(s)->r_epoch++;
1161 memcpy(&(D1I(s)->bitmap), &(D1I(s)->next_bitmap), sizeof(DTLS1_BITMAP)); 1165 memcpy(&(D1I(s)->bitmap), &(D1I(s)->next_bitmap), sizeof(DTLS1_BITMAP));
1162 memset(&(D1I(s)->next_bitmap), 0, sizeof(DTLS1_BITMAP)); 1166 memset(&(D1I(s)->next_bitmap), 0, sizeof(DTLS1_BITMAP));
1163} 1167}