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 $ */
22/*
33 * DTLS implementation written by Nagendra Modadugu
44 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -273,12 +273,14 @@ static int
273273dtls1_process_buffered_record (SSL * s )
274274{
275275/* 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 ))
277278return (0 );
278279
279280/* Update epoch once all unprocessed records have been processed. */
280281if (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 ;
282284return (0 );
283285}
284286
@@ -858,7 +860,7 @@ dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
858860/* this may just be a stale retransmit */
859861if (!dtls1_get_message_header (rr -> data , & msg_hdr ))
860862return -1 ;
861- if (rr -> epoch != D1I ( s ) -> r_epoch ) {
863+ if (rr -> epoch != tls12_record_layer_read_epoch ( s -> internal -> rl ) ) {
862864rr -> length = 0 ;
863865goto start ;
864866}
@@ -1136,17 +1138,20 @@ dtls1_record_bitmap_update(SSL *s, DTLS1_BITMAP *bitmap,
11361138static DTLS1_BITMAP *
11371139dtls1_get_bitmap (SSL * s , SSL3_RECORD_INTERNAL * rr , unsigned int * is_next_epoch )
11381140{
1139- uint16_t next_epoch = D1I ( s ) -> r_epoch + 1 ;
1141+ uint16_t read_epoch , read_epoch_next ;
11401142
11411143* is_next_epoch = 0 ;
11421144
1145+ read_epoch = tls12_record_layer_read_epoch (s -> internal -> rl );
1146+ read_epoch_next = read_epoch + 1 ;
1147+
11431148/* In current epoch, accept HM, CCS, DATA, & ALERT */
1144- if (rr -> epoch == D1I ( s ) -> r_epoch )
1149+ if (rr -> epoch == read_epoch )
11451150return & D1I (s )-> bitmap ;
11461151
11471152/* Only HM and ALERT messages can be from the next epoch */
1148- else if (rr -> epoch == next_epoch &&
1149- (rr -> type == SSL3_RT_HANDSHAKE || rr -> type == SSL3_RT_ALERT )) {
1153+ if (rr -> epoch == read_epoch_next &&
1154+ (rr -> type == SSL3_RT_HANDSHAKE || rr -> type == SSL3_RT_ALERT )) {
11501155* is_next_epoch = 1 ;
11511156return & D1I (s )-> next_bitmap ;
11521157}
@@ -1157,7 +1162,6 @@ dtls1_get_bitmap(SSL *s, SSL3_RECORD_INTERNAL *rr, unsigned int *is_next_epoch)
11571162void
11581163dtls1_reset_read_seq_numbers (SSL * s )
11591164{
1160- D1I (s )-> r_epoch ++ ;
11611165memcpy (& (D1I (s )-> bitmap ), & (D1I (s )-> next_bitmap ), sizeof (DTLS1_BITMAP ));
11621166memset (& (D1I (s )-> next_bitmap ), 0 , sizeof (DTLS1_BITMAP ));
11631167}
0 commit comments