|
|
653b37 |
diff -up openssl-1.0.1e/ssl/d1_both.c.dtls1-dos2 openssl-1.0.1e/ssl/d1_both.c
|
|
|
653b37 |
--- openssl-1.0.1e/ssl/d1_both.c.dtls1-dos2 2016-09-20 15:53:03.748445806 +0200
|
|
|
653b37 |
+++ openssl-1.0.1e/ssl/d1_both.c 2016-09-20 16:12:01.422861505 +0200
|
|
|
653b37 |
@@ -211,7 +211,7 @@ dtls1_hm_fragment_new(unsigned long frag
|
|
|
653b37 |
return frag;
|
|
|
653b37 |
}
|
|
|
653b37 |
|
|
|
653b37 |
-static void
|
|
|
653b37 |
+void
|
|
|
653b37 |
dtls1_hm_fragment_free(hm_fragment *frag)
|
|
|
653b37 |
{
|
|
|
653b37 |
|
|
|
653b37 |
@@ -544,11 +544,26 @@ dtls1_retrieve_buffered_fragment(SSL *s,
|
|
|
653b37 |
int al;
|
|
|
653b37 |
|
|
|
653b37 |
*ok = 0;
|
|
|
653b37 |
- item = pqueue_peek(s->d1->buffered_messages);
|
|
|
653b37 |
- if ( item == NULL)
|
|
|
653b37 |
- return 0;
|
|
|
653b37 |
+ do
|
|
|
653b37 |
+ {
|
|
|
653b37 |
+ item = pqueue_peek(s->d1->buffered_messages);
|
|
|
653b37 |
+ if (item == NULL)
|
|
|
653b37 |
+ return 0;
|
|
|
653b37 |
+
|
|
|
653b37 |
+ frag = (hm_fragment *)item->data;
|
|
|
653b37 |
+
|
|
|
653b37 |
+ if (frag->msg_header.seq < s->d1->handshake_read_seq)
|
|
|
653b37 |
+ {
|
|
|
653b37 |
+ /* This is a stale message that has been buffered so clear it */
|
|
|
653b37 |
+ pqueue_pop(s->d1->buffered_messages);
|
|
|
653b37 |
+ dtls1_hm_fragment_free(frag);
|
|
|
653b37 |
+ pitem_free(item);
|
|
|
653b37 |
+ item = NULL;
|
|
|
653b37 |
+ frag = NULL;
|
|
|
653b37 |
+ }
|
|
|
653b37 |
+ }
|
|
|
653b37 |
+ while (item == NULL);
|
|
|
653b37 |
|
|
|
653b37 |
- frag = (hm_fragment *)item->data;
|
|
|
653b37 |
|
|
|
653b37 |
/* Don't return if reassembly still in progress */
|
|
|
653b37 |
if (frag->reassembly != NULL)
|
|
|
653b37 |
@@ -1339,21 +1354,6 @@ dtls1_retransmit_message(SSL *s, unsigne
|
|
|
653b37 |
return ret;
|
|
|
653b37 |
}
|
|
|
653b37 |
|
|
|
653b37 |
-/* call this function when the buffered messages are no longer needed */
|
|
|
653b37 |
-void
|
|
|
653b37 |
-dtls1_clear_record_buffer(SSL *s)
|
|
|
653b37 |
- {
|
|
|
653b37 |
- pitem *item;
|
|
|
653b37 |
-
|
|
|
653b37 |
- for(item = pqueue_pop(s->d1->sent_messages);
|
|
|
653b37 |
- item != NULL; item = pqueue_pop(s->d1->sent_messages))
|
|
|
653b37 |
- {
|
|
|
653b37 |
- dtls1_hm_fragment_free((hm_fragment *)item->data);
|
|
|
653b37 |
- pitem_free(item);
|
|
|
653b37 |
- }
|
|
|
653b37 |
- }
|
|
|
653b37 |
-
|
|
|
653b37 |
-
|
|
|
653b37 |
unsigned char *
|
|
|
653b37 |
dtls1_set_message_header(SSL *s, unsigned char *p, unsigned char mt,
|
|
|
653b37 |
unsigned long len, unsigned long frag_off, unsigned long frag_len)
|
|
|
653b37 |
diff -up openssl-1.0.1e/ssl/d1_clnt.c.dtls1-dos2 openssl-1.0.1e/ssl/d1_clnt.c
|
|
|
653b37 |
--- openssl-1.0.1e/ssl/d1_clnt.c.dtls1-dos2 2016-09-20 15:53:03.748445806 +0200
|
|
|
653b37 |
+++ openssl-1.0.1e/ssl/d1_clnt.c 2016-09-20 15:58:38.292200957 +0200
|
|
|
653b37 |
@@ -739,6 +739,7 @@ int dtls1_connect(SSL *s)
|
|
|
653b37 |
/* done with handshaking */
|
|
|
653b37 |
s->d1->handshake_read_seq = 0;
|
|
|
653b37 |
s->d1->next_handshake_write_seq = 0;
|
|
|
653b37 |
+ dtls1_clear_received_buffer(s);
|
|
|
653b37 |
goto end;
|
|
|
653b37 |
/* break; */
|
|
|
653b37 |
|
|
|
653b37 |
diff -up openssl-1.0.1e/ssl/d1_lib.c.dtls1-dos2 openssl-1.0.1e/ssl/d1_lib.c
|
|
|
653b37 |
--- openssl-1.0.1e/ssl/d1_lib.c.dtls1-dos2 2016-09-20 15:53:03.749445830 +0200
|
|
|
653b37 |
+++ openssl-1.0.1e/ssl/d1_lib.c 2016-09-20 16:18:10.046443374 +0200
|
|
|
653b37 |
@@ -133,7 +133,6 @@ int dtls1_new(SSL *s)
|
|
|
653b37 |
static void dtls1_clear_queues(SSL *s)
|
|
|
653b37 |
{
|
|
|
653b37 |
pitem *item = NULL;
|
|
|
653b37 |
- hm_fragment *frag = NULL;
|
|
|
653b37 |
DTLS1_RECORD_DATA *rdata;
|
|
|
653b37 |
|
|
|
653b37 |
while( (item = pqueue_pop(s->d1->unprocessed_rcds.q)) != NULL)
|
|
|
653b37 |
@@ -158,32 +157,45 @@ static void dtls1_clear_queues(SSL *s)
|
|
|
653b37 |
pitem_free(item);
|
|
|
653b37 |
}
|
|
|
653b37 |
|
|
|
653b37 |
- while( (item = pqueue_pop(s->d1->buffered_messages)) != NULL)
|
|
|
653b37 |
- {
|
|
|
653b37 |
+ while ((item = pqueue_pop(s->d1->buffered_app_data.q)) != NULL)
|
|
|
653b37 |
+ {
|
|
|
653b37 |
+ rdata = (DTLS1_RECORD_DATA *)item->data;
|
|
|
653b37 |
+ if (rdata->rbuf.buf)
|
|
|
653b37 |
+ {
|
|
|
653b37 |
+ OPENSSL_free(rdata->rbuf.buf);
|
|
|
653b37 |
+ }
|
|
|
653b37 |
+ OPENSSL_free(item->data);
|
|
|
653b37 |
+ pitem_free(item);
|
|
|
653b37 |
+ }
|
|
|
653b37 |
+
|
|
|
653b37 |
+ dtls1_clear_received_buffer(s);
|
|
|
653b37 |
+ dtls1_clear_sent_buffer(s);
|
|
|
653b37 |
+ }
|
|
|
653b37 |
+
|
|
|
653b37 |
+void dtls1_clear_received_buffer(SSL *s)
|
|
|
653b37 |
+ {
|
|
|
653b37 |
+ pitem *item = NULL;
|
|
|
653b37 |
+ hm_fragment *frag = NULL;
|
|
|
653b37 |
+
|
|
|
653b37 |
+ while ((item = pqueue_pop(s->d1->buffered_messages)) != NULL)
|
|
|
653b37 |
+ {
|
|
|
653b37 |
frag = (hm_fragment *)item->data;
|
|
|
653b37 |
- OPENSSL_free(frag->fragment);
|
|
|
653b37 |
- OPENSSL_free(frag);
|
|
|
653b37 |
+ dtls1_hm_fragment_free(frag);
|
|
|
653b37 |
pitem_free(item);
|
|
|
653b37 |
}
|
|
|
653b37 |
+ }
|
|
|
653b37 |
|
|
|
653b37 |
- while ( (item = pqueue_pop(s->d1->sent_messages)) != NULL)
|
|
|
653b37 |
- {
|
|
|
653b37 |
+void dtls1_clear_sent_buffer(SSL *s)
|
|
|
653b37 |
+ {
|
|
|
653b37 |
+ pitem *item = NULL;
|
|
|
653b37 |
+ hm_fragment *frag = NULL;
|
|
|
653b37 |
+
|
|
|
653b37 |
+ while ((item = pqueue_pop(s->d1->sent_messages)) != NULL)
|
|
|
653b37 |
+ {
|
|
|
653b37 |
frag = (hm_fragment *)item->data;
|
|
|
653b37 |
- OPENSSL_free(frag->fragment);
|
|
|
653b37 |
- OPENSSL_free(frag);
|
|
|
653b37 |
+ dtls1_hm_fragment_free(frag);
|
|
|
653b37 |
pitem_free(item);
|
|
|
653b37 |
}
|
|
|
653b37 |
-
|
|
|
653b37 |
- while ( (item = pqueue_pop(s->d1->buffered_app_data.q)) != NULL)
|
|
|
653b37 |
- {
|
|
|
653b37 |
- rdata = (DTLS1_RECORD_DATA *) item->data;
|
|
|
653b37 |
- if (rdata->rbuf.buf)
|
|
|
653b37 |
- {
|
|
|
653b37 |
- OPENSSL_free(rdata->rbuf.buf);
|
|
|
653b37 |
- }
|
|
|
653b37 |
- OPENSSL_free(item->data);
|
|
|
653b37 |
- pitem_free(item);
|
|
|
653b37 |
- }
|
|
|
653b37 |
}
|
|
|
653b37 |
|
|
|
653b37 |
void dtls1_free(SSL *s)
|
|
|
653b37 |
@@ -410,7 +422,7 @@ void dtls1_stop_timer(SSL *s)
|
|
|
653b37 |
s->d1->timeout_duration = 1;
|
|
|
653b37 |
BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0, &(s->d1->next_timeout));
|
|
|
653b37 |
/* Clear retransmission buffer */
|
|
|
653b37 |
- dtls1_clear_record_buffer(s);
|
|
|
653b37 |
+ dtls1_clear_sent_buffer(s);
|
|
|
653b37 |
}
|
|
|
653b37 |
|
|
|
653b37 |
int dtls1_check_timeout_num(SSL *s)
|
|
|
653b37 |
diff -up openssl-1.0.1e/ssl/d1_pkt.c.dtls1-dos2 openssl-1.0.1e/ssl/d1_pkt.c
|
|
|
653b37 |
--- openssl-1.0.1e/ssl/d1_pkt.c.dtls1-dos2 2016-09-20 15:53:17.246758715 +0200
|
|
|
653b37 |
+++ openssl-1.0.1e/ssl/d1_pkt.c 2016-09-20 16:14:33.020390824 +0200
|
|
|
653b37 |
@@ -1900,6 +1900,12 @@ dtls1_reset_seq_numbers(SSL *s, int rw)
|
|
|
653b37 |
s->d1->r_epoch++;
|
|
|
653b37 |
memcpy(&(s->d1->bitmap), &(s->d1->next_bitmap), sizeof(DTLS1_BITMAP));
|
|
|
653b37 |
memset(&(s->d1->next_bitmap), 0x00, sizeof(DTLS1_BITMAP));
|
|
|
653b37 |
+
|
|
|
653b37 |
+ /*
|
|
|
653b37 |
+ * We must not use any buffered messages received from the previous
|
|
|
653b37 |
+ * epoch
|
|
|
653b37 |
+ */
|
|
|
653b37 |
+ dtls1_clear_received_buffer(s);
|
|
|
653b37 |
}
|
|
|
653b37 |
else
|
|
|
653b37 |
{
|
|
|
653b37 |
diff -up openssl-1.0.1e/ssl/d1_srvr.c.dtls1-dos2 openssl-1.0.1e/ssl/d1_srvr.c
|
|
|
653b37 |
--- openssl-1.0.1e/ssl/d1_srvr.c.dtls1-dos2 2016-09-20 15:53:03.750445853 +0200
|
|
|
653b37 |
+++ openssl-1.0.1e/ssl/d1_srvr.c 2016-09-20 16:15:39.699943181 +0200
|
|
|
653b37 |
@@ -276,7 +276,7 @@ int dtls1_accept(SSL *s)
|
|
|
653b37 |
case SSL3_ST_SW_HELLO_REQ_B:
|
|
|
653b37 |
|
|
|
653b37 |
s->shutdown=0;
|
|
|
653b37 |
- dtls1_clear_record_buffer(s);
|
|
|
653b37 |
+ dtls1_clear_sent_buffer(s);
|
|
|
653b37 |
dtls1_start_timer(s);
|
|
|
653b37 |
ret=dtls1_send_hello_request(s);
|
|
|
653b37 |
if (ret <= 0) goto end;
|
|
|
653b37 |
@@ -811,6 +811,7 @@ int dtls1_accept(SSL *s)
|
|
|
653b37 |
/* next message is server hello */
|
|
|
653b37 |
s->d1->handshake_write_seq = 0;
|
|
|
653b37 |
s->d1->next_handshake_write_seq = 0;
|
|
|
653b37 |
+ dtls1_clear_received_buffer(s);
|
|
|
653b37 |
goto end;
|
|
|
653b37 |
/* break; */
|
|
|
653b37 |
|
|
|
653b37 |
diff -up openssl-1.0.1e/ssl/ssl_locl.h.dtls1-dos2 openssl-1.0.1e/ssl/ssl_locl.h
|
|
|
653b37 |
--- openssl-1.0.1e/ssl/ssl_locl.h.dtls1-dos2 2016-09-20 15:53:03.751445876 +0200
|
|
|
653b37 |
+++ openssl-1.0.1e/ssl/ssl_locl.h 2016-09-20 16:11:36.288276350 +0200
|
|
|
653b37 |
@@ -974,7 +974,8 @@ int dtls1_retransmit_message(SSL *s, uns
|
|
|
653b37 |
unsigned long frag_off, int *found);
|
|
|
653b37 |
int dtls1_get_queue_priority(unsigned short seq, int is_ccs);
|
|
|
653b37 |
int dtls1_retransmit_buffered_messages(SSL *s);
|
|
|
653b37 |
-void dtls1_clear_record_buffer(SSL *s);
|
|
|
653b37 |
+void dtls1_clear_received_buffer(SSL *s);
|
|
|
653b37 |
+void dtls1_clear_sent_buffer(SSL *s);
|
|
|
653b37 |
void dtls1_get_message_header(unsigned char *data, struct hm_header_st *msg_hdr);
|
|
|
653b37 |
void dtls1_get_ccs_header(unsigned char *data, struct ccs_header_st *ccs_hdr);
|
|
|
653b37 |
void dtls1_reset_seq_numbers(SSL *s, int rw);
|
|
|
653b37 |
@@ -989,6 +990,7 @@ int dtls1_is_timer_expired(SSL *s);
|
|
|
653b37 |
void dtls1_double_timeout(SSL *s);
|
|
|
653b37 |
int dtls1_send_newsession_ticket(SSL *s);
|
|
|
653b37 |
unsigned int dtls1_min_mtu(void);
|
|
|
653b37 |
+void dtls1_hm_fragment_free(hm_fragment *frag);
|
|
|
653b37 |
|
|
|
653b37 |
/* some client-only functions */
|
|
|
653b37 |
int ssl3_client_hello(SSL *s);
|