diff options
author | jsing <> | 2021-08-30 19:12:25 +0000 |
---|---|---|
committer | jsing <> | 2021-08-30 19:12:25 +0000 |
commit | cedbde20c0ecfb870c00ce4fe4401f89a9397b6d (patch) | |
tree | 2d39ac8fc8532fdfcf26841981b52bd4c01b1e0f /src | |
parent | abf6f6607dda2d28fb254cd45e519fec1091fc0d (diff) | |
download | openbsd-cedbde20c0ecfb870c00ce4fe4401f89a9397b6d.tar.gz openbsd-cedbde20c0ecfb870c00ce4fe4401f89a9397b6d.tar.bz2 openbsd-cedbde20c0ecfb870c00ce4fe4401f89a9397b6d.zip |
Replace DTLS r_epoch with the read epoch from the TLSv1.2 record layer.
ok inoguchi@ tb@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libssl/d1_lib.c | 8 | ||||
-rw-r--r-- | src/lib/libssl/d1_pkt.c | 22 | ||||
-rw-r--r-- | src/lib/libssl/dtls_locl.h | 9 | ||||
-rw-r--r-- | src/lib/libssl/ssl_locl.h | 4 | ||||
-rw-r--r-- | src/lib/libssl/tls12_record_layer.c | 10 |
5 files changed, 26 insertions, 27 deletions
diff --git a/src/lib/libssl/d1_lib.c b/src/lib/libssl/d1_lib.c index 3db5629e23..d4280a277c 100644 --- a/src/lib/libssl/d1_lib.c +++ b/src/lib/libssl/d1_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: d1_lib.c,v 1.58 2021/07/21 08:42:14 jsing Exp $ */ | 1 | /* $OpenBSD: d1_lib.c,v 1.59 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. |
@@ -191,10 +191,8 @@ dtls1_clear(SSL *s) | |||
191 | memset(s->d1, 0, sizeof(*s->d1)); | 191 | memset(s->d1, 0, sizeof(*s->d1)); |
192 | s->d1->internal = internal; | 192 | s->d1->internal = internal; |
193 | 193 | ||
194 | D1I(s)->r_epoch = | 194 | D1I(s)->unprocessed_rcds.epoch = |
195 | tls12_record_layer_initial_epoch(s->internal->rl); | 195 | tls12_record_layer_read_epoch(s->internal->rl) + 1; |
196 | |||
197 | D1I(s)->unprocessed_rcds.epoch = D1I(s)->r_epoch + 1; | ||
198 | 196 | ||
199 | if (s->server) { | 197 | if (s->server) { |
200 | D1I(s)->cookie_len = sizeof(D1I(s)->cookie); | 198 | D1I(s)->cookie_len = sizeof(D1I(s)->cookie); |
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 | |||
273 | dtls1_process_buffered_record(SSL *s) | 273 | dtls1_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, | |||
1136 | static DTLS1_BITMAP * | 1138 | static DTLS1_BITMAP * |
1137 | dtls1_get_bitmap(SSL *s, SSL3_RECORD_INTERNAL *rr, unsigned int *is_next_epoch) | 1139 | dtls1_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) | |||
1157 | void | 1162 | void |
1158 | dtls1_reset_read_seq_numbers(SSL *s) | 1163 | dtls1_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 | } |
diff --git a/src/lib/libssl/dtls_locl.h b/src/lib/libssl/dtls_locl.h index 97f05b26bd..83fb9e0e10 100644 --- a/src/lib/libssl/dtls_locl.h +++ b/src/lib/libssl/dtls_locl.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: dtls_locl.h,v 1.4 2021/07/26 03:17:38 jsing Exp $ */ | 1 | /* $OpenBSD: dtls_locl.h,v 1.5 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. |
@@ -132,13 +132,6 @@ typedef struct dtls1_state_internal_st { | |||
132 | unsigned char rcvd_cookie[DTLS1_COOKIE_LENGTH]; | 132 | unsigned char rcvd_cookie[DTLS1_COOKIE_LENGTH]; |
133 | unsigned int cookie_len; | 133 | unsigned int cookie_len; |
134 | 134 | ||
135 | /* | ||
136 | * The current data and handshake epoch. This is initially | ||
137 | * undefined, and starts at zero once the initial handshake is | ||
138 | * completed | ||
139 | */ | ||
140 | unsigned short r_epoch; | ||
141 | |||
142 | /* records being received in the current epoch */ | 135 | /* records being received in the current epoch */ |
143 | DTLS1_BITMAP bitmap; | 136 | DTLS1_BITMAP bitmap; |
144 | 137 | ||
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h index f3650f238e..d25ac1a1a6 100644 --- a/src/lib/libssl/ssl_locl.h +++ b/src/lib/libssl/ssl_locl.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_locl.h,v 1.356 2021/07/26 03:17:38 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_locl.h,v 1.357 2021/08/30 19:12:25 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -641,7 +641,7 @@ void tls12_record_layer_set_version(struct tls12_record_layer *rl, | |||
641 | uint16_t version); | 641 | uint16_t version); |
642 | void tls12_record_layer_set_initial_epoch(struct tls12_record_layer *rl, | 642 | void tls12_record_layer_set_initial_epoch(struct tls12_record_layer *rl, |
643 | uint16_t epoch); | 643 | uint16_t epoch); |
644 | uint16_t tls12_record_layer_initial_epoch(struct tls12_record_layer *rl); | 644 | uint16_t tls12_record_layer_read_epoch(struct tls12_record_layer *rl); |
645 | uint16_t tls12_record_layer_write_epoch(struct tls12_record_layer *rl); | 645 | uint16_t tls12_record_layer_write_epoch(struct tls12_record_layer *rl); |
646 | int tls12_record_layer_use_write_epoch(struct tls12_record_layer *rl, | 646 | int tls12_record_layer_use_write_epoch(struct tls12_record_layer *rl, |
647 | uint16_t epoch); | 647 | uint16_t epoch); |
diff --git a/src/lib/libssl/tls12_record_layer.c b/src/lib/libssl/tls12_record_layer.c index f59364bb67..6d7d8696eb 100644 --- a/src/lib/libssl/tls12_record_layer.c +++ b/src/lib/libssl/tls12_record_layer.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls12_record_layer.c,v 1.33 2021/08/30 19:00:49 jsing Exp $ */ | 1 | /* $OpenBSD: tls12_record_layer.c,v 1.34 2021/08/30 19:12:25 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2020 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2020 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -296,9 +296,9 @@ tls12_record_layer_set_initial_epoch(struct tls12_record_layer *rl, | |||
296 | } | 296 | } |
297 | 297 | ||
298 | uint16_t | 298 | uint16_t |
299 | tls12_record_layer_initial_epoch(struct tls12_record_layer *rl) | 299 | tls12_record_layer_read_epoch(struct tls12_record_layer *rl) |
300 | { | 300 | { |
301 | return rl->initial_epoch; | 301 | return rl->read->epoch; |
302 | } | 302 | } |
303 | 303 | ||
304 | uint16_t | 304 | uint16_t |
@@ -580,6 +580,10 @@ tls12_record_layer_change_read_cipher_state(struct tls12_record_layer *rl, | |||
580 | 580 | ||
581 | /* Read sequence number gets reset to zero. */ | 581 | /* Read sequence number gets reset to zero. */ |
582 | 582 | ||
583 | /* DTLS epoch is incremented and is permitted to wrap. */ | ||
584 | if (rl->dtls) | ||
585 | read_new->epoch = rl->read_current->epoch + 1; | ||
586 | |||
583 | if (!tls12_record_layer_change_cipher_state(rl, read_new, 0, | 587 | if (!tls12_record_layer_change_cipher_state(rl, read_new, 0, |
584 | mac_key, key, iv)) | 588 | mac_key, key, iv)) |
585 | goto err; | 589 | goto err; |