2015-01-22 03:40:55 +00:00
|
|
|
/*
|
2017-11-05 16:46:48 +00:00
|
|
|
* Copyright 2005-2017 The OpenSSL Project Authors. All Rights Reserved.
|
2015-01-22 03:40:55 +00:00
|
|
|
*
|
2016-05-17 18:18:30 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
2005-04-26 16:02:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
2015-02-02 10:38:12 +00:00
|
|
|
#include "../ssl_locl.h"
|
2005-04-26 16:02:40 +00:00
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/buffer.h>
|
2015-02-04 16:02:37 +00:00
|
|
|
#include "record_locl.h"
|
2017-05-15 10:24:24 +00:00
|
|
|
#include "../packet_locl.h"
|
2017-08-02 13:46:31 +00:00
|
|
|
#include "internal/cryptlib.h"
|
2015-02-03 14:54:13 +00:00
|
|
|
|
|
|
|
int DTLS_RECORD_LAYER_new(RECORD_LAYER *rl)
|
|
|
|
{
|
|
|
|
DTLS_RECORD_LAYER *d;
|
2016-06-28 20:51:27 +00:00
|
|
|
|
2015-05-02 03:10:31 +00:00
|
|
|
if ((d = OPENSSL_malloc(sizeof(*d))) == NULL)
|
2017-10-17 14:04:09 +00:00
|
|
|
return 0;
|
2015-02-03 14:54:13 +00:00
|
|
|
|
|
|
|
rl->d = d;
|
2015-02-03 16:11:49 +00:00
|
|
|
|
2015-02-03 16:05:28 +00:00
|
|
|
d->unprocessed_rcds.q = pqueue_new();
|
|
|
|
d->processed_rcds.q = pqueue_new();
|
2015-02-04 10:27:43 +00:00
|
|
|
d->buffered_app_data.q = pqueue_new();
|
2015-02-03 16:05:28 +00:00
|
|
|
|
2015-10-30 10:05:53 +00:00
|
|
|
if (d->unprocessed_rcds.q == NULL || d->processed_rcds.q == NULL
|
|
|
|
|| d->buffered_app_data.q == NULL) {
|
2015-05-01 18:37:16 +00:00
|
|
|
pqueue_free(d->unprocessed_rcds.q);
|
|
|
|
pqueue_free(d->processed_rcds.q);
|
|
|
|
pqueue_free(d->buffered_app_data.q);
|
2015-02-03 16:05:28 +00:00
|
|
|
OPENSSL_free(d);
|
|
|
|
rl->d = NULL;
|
2017-10-17 14:04:09 +00:00
|
|
|
return 0;
|
2015-02-03 16:05:28 +00:00
|
|
|
}
|
2015-02-03 14:54:13 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DTLS_RECORD_LAYER_free(RECORD_LAYER *rl)
|
|
|
|
{
|
2015-02-03 16:05:28 +00:00
|
|
|
DTLS_RECORD_LAYER_clear(rl);
|
|
|
|
pqueue_free(rl->d->unprocessed_rcds.q);
|
|
|
|
pqueue_free(rl->d->processed_rcds.q);
|
2015-02-04 10:27:43 +00:00
|
|
|
pqueue_free(rl->d->buffered_app_data.q);
|
2015-02-03 14:54:13 +00:00
|
|
|
OPENSSL_free(rl->d);
|
|
|
|
rl->d = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DTLS_RECORD_LAYER_clear(RECORD_LAYER *rl)
|
|
|
|
{
|
|
|
|
DTLS_RECORD_LAYER *d;
|
2015-02-03 16:05:28 +00:00
|
|
|
pitem *item = NULL;
|
|
|
|
DTLS1_RECORD_DATA *rdata;
|
2016-01-22 19:54:01 +00:00
|
|
|
pqueue *unprocessed_rcds;
|
|
|
|
pqueue *processed_rcds;
|
|
|
|
pqueue *buffered_app_data;
|
2015-02-03 16:05:28 +00:00
|
|
|
|
2015-02-03 14:54:13 +00:00
|
|
|
d = rl->d;
|
2016-06-28 20:51:27 +00:00
|
|
|
|
2015-02-03 16:05:28 +00:00
|
|
|
while ((item = pqueue_pop(d->unprocessed_rcds.q)) != NULL) {
|
|
|
|
rdata = (DTLS1_RECORD_DATA *)item->data;
|
2015-05-01 14:02:07 +00:00
|
|
|
OPENSSL_free(rdata->rbuf.buf);
|
2015-02-03 16:05:28 +00:00
|
|
|
OPENSSL_free(item->data);
|
|
|
|
pitem_free(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((item = pqueue_pop(d->processed_rcds.q)) != NULL) {
|
|
|
|
rdata = (DTLS1_RECORD_DATA *)item->data;
|
2015-05-01 14:02:07 +00:00
|
|
|
OPENSSL_free(rdata->rbuf.buf);
|
2015-02-03 16:05:28 +00:00
|
|
|
OPENSSL_free(item->data);
|
|
|
|
pitem_free(item);
|
|
|
|
}
|
|
|
|
|
2015-02-04 10:27:43 +00:00
|
|
|
while ((item = pqueue_pop(d->buffered_app_data.q)) != NULL) {
|
|
|
|
rdata = (DTLS1_RECORD_DATA *)item->data;
|
2015-05-01 14:02:07 +00:00
|
|
|
OPENSSL_free(rdata->rbuf.buf);
|
2015-02-04 10:27:43 +00:00
|
|
|
OPENSSL_free(item->data);
|
|
|
|
pitem_free(item);
|
|
|
|
}
|
|
|
|
|
2015-02-03 16:05:28 +00:00
|
|
|
unprocessed_rcds = d->unprocessed_rcds.q;
|
|
|
|
processed_rcds = d->processed_rcds.q;
|
2015-02-04 10:27:43 +00:00
|
|
|
buffered_app_data = d->buffered_app_data.q;
|
2015-05-02 03:10:31 +00:00
|
|
|
memset(d, 0, sizeof(*d));
|
2015-02-03 16:05:28 +00:00
|
|
|
d->unprocessed_rcds.q = unprocessed_rcds;
|
|
|
|
d->processed_rcds.q = processed_rcds;
|
2015-02-04 10:27:43 +00:00
|
|
|
d->buffered_app_data.q = buffered_app_data;
|
2015-02-03 14:54:13 +00:00
|
|
|
}
|
|
|
|
|
2015-02-04 11:57:34 +00:00
|
|
|
void DTLS_RECORD_LAYER_set_saved_w_epoch(RECORD_LAYER *rl, unsigned short e)
|
|
|
|
{
|
|
|
|
if (e == rl->d->w_epoch - 1) {
|
|
|
|
memcpy(rl->d->curr_write_sequence,
|
2016-08-05 17:03:17 +00:00
|
|
|
rl->write_sequence, sizeof(rl->write_sequence));
|
2015-02-04 11:57:34 +00:00
|
|
|
memcpy(rl->write_sequence,
|
2016-08-05 17:03:17 +00:00
|
|
|
rl->d->last_write_sequence, sizeof(rl->write_sequence));
|
2015-02-04 11:57:34 +00:00
|
|
|
} else if (e == rl->d->w_epoch + 1) {
|
|
|
|
memcpy(rl->d->last_write_sequence,
|
2016-08-05 17:03:17 +00:00
|
|
|
rl->write_sequence, sizeof(unsigned char[8]));
|
2015-02-04 11:57:34 +00:00
|
|
|
memcpy(rl->write_sequence,
|
2016-08-05 17:03:17 +00:00
|
|
|
rl->d->curr_write_sequence, sizeof(rl->write_sequence));
|
2015-02-04 11:57:34 +00:00
|
|
|
}
|
|
|
|
rl->d->w_epoch = e;
|
|
|
|
}
|
|
|
|
|
2015-09-14 21:49:35 +00:00
|
|
|
void DTLS_RECORD_LAYER_set_write_sequence(RECORD_LAYER *rl, unsigned char *seq)
|
|
|
|
{
|
|
|
|
memcpy(rl->write_sequence, seq, SEQ_NUM_SIZE);
|
|
|
|
}
|
|
|
|
|
2005-04-26 16:02:40 +00:00
|
|
|
/* copy buffered record into SSL structure */
|
2015-01-22 03:40:55 +00:00
|
|
|
static int dtls1_copy_record(SSL *s, pitem *item)
|
|
|
|
{
|
2005-04-26 16:02:40 +00:00
|
|
|
DTLS1_RECORD_DATA *rdata;
|
|
|
|
|
|
|
|
rdata = (DTLS1_RECORD_DATA *)item->data;
|
2015-01-22 03:40:55 +00:00
|
|
|
|
2015-02-02 16:02:55 +00:00
|
|
|
SSL3_BUFFER_release(&s->rlayer.rbuf);
|
2015-01-22 03:40:55 +00:00
|
|
|
|
2015-02-02 20:55:15 +00:00
|
|
|
s->rlayer.packet = rdata->packet;
|
|
|
|
s->rlayer.packet_length = rdata->packet_length;
|
2015-02-02 16:02:55 +00:00
|
|
|
memcpy(&s->rlayer.rbuf, &(rdata->rbuf), sizeof(SSL3_BUFFER));
|
|
|
|
memcpy(&s->rlayer.rrec, &(rdata->rrec), sizeof(SSL3_RECORD));
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/* Set proper sequence number for mac calculation */
|
2015-02-03 14:26:50 +00:00
|
|
|
memcpy(&(s->rlayer.read_sequence[2]), &(rdata->packet[5]), 6);
|
2015-01-22 03:40:55 +00:00
|
|
|
|
2017-10-09 11:05:58 +00:00
|
|
|
return 1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-03-26 15:14:42 +00:00
|
|
|
int dtls1_buffer_record(SSL *s, record_pqueue *queue, unsigned char *priority)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
DTLS1_RECORD_DATA *rdata;
|
|
|
|
pitem *item;
|
|
|
|
|
|
|
|
/* Limit the size of the queue to prevent DOS attacks */
|
|
|
|
if (pqueue_size(queue->q) >= 100)
|
|
|
|
return 0;
|
|
|
|
|
2015-05-02 03:10:31 +00:00
|
|
|
rdata = OPENSSL_malloc(sizeof(*rdata));
|
2015-01-22 03:40:55 +00:00
|
|
|
item = pitem_new(priority, rdata);
|
|
|
|
if (rdata == NULL || item == NULL) {
|
2015-05-01 14:02:07 +00:00
|
|
|
OPENSSL_free(rdata);
|
2015-05-01 18:37:16 +00:00
|
|
|
pitem_free(item);
|
2017-12-04 16:16:37 +00:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_DTLS1_BUFFER_RECORD,
|
|
|
|
ERR_R_INTERNAL_ERROR);
|
2015-03-04 21:05:53 +00:00
|
|
|
return -1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
2015-02-02 20:55:15 +00:00
|
|
|
rdata->packet = s->rlayer.packet;
|
|
|
|
rdata->packet_length = s->rlayer.packet_length;
|
2015-02-02 16:02:55 +00:00
|
|
|
memcpy(&(rdata->rbuf), &s->rlayer.rbuf, sizeof(SSL3_BUFFER));
|
|
|
|
memcpy(&(rdata->rrec), &s->rlayer.rrec, sizeof(SSL3_RECORD));
|
2015-01-22 03:40:55 +00:00
|
|
|
|
|
|
|
item->data = rdata;
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2011-12-25 14:45:15 +00:00
|
|
|
#ifndef OPENSSL_NO_SCTP
|
2015-01-22 03:40:55 +00:00
|
|
|
/* Store bio_dgram_sctp_rcvinfo struct */
|
|
|
|
if (BIO_dgram_is_sctp(SSL_get_rbio(s)) &&
|
2015-10-05 09:49:15 +00:00
|
|
|
(SSL_get_state(s) == TLS_ST_SR_FINISHED
|
|
|
|
|| SSL_get_state(s) == TLS_ST_CR_FINISHED)) {
|
2015-01-22 03:40:55 +00:00
|
|
|
BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SCTP_GET_RCVINFO,
|
|
|
|
sizeof(rdata->recordinfo), &rdata->recordinfo);
|
|
|
|
}
|
2011-12-25 14:45:15 +00:00
|
|
|
#endif
|
|
|
|
|
2015-02-02 20:55:15 +00:00
|
|
|
s->rlayer.packet = NULL;
|
|
|
|
s->rlayer.packet_length = 0;
|
2015-05-04 22:00:15 +00:00
|
|
|
memset(&s->rlayer.rbuf, 0, sizeof(s->rlayer.rbuf));
|
|
|
|
memset(&s->rlayer.rrec, 0, sizeof(s->rlayer.rrec));
|
2015-01-22 03:40:55 +00:00
|
|
|
|
|
|
|
if (!ssl3_setup_buffers(s)) {
|
2017-12-04 16:16:37 +00:00
|
|
|
/* SSLfatal() already called */
|
2015-05-01 14:02:07 +00:00
|
|
|
OPENSSL_free(rdata->rbuf.buf);
|
2015-01-22 03:40:55 +00:00
|
|
|
OPENSSL_free(rdata);
|
|
|
|
pitem_free(item);
|
2017-10-17 14:04:09 +00:00
|
|
|
return -1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/* insert should not fail, since duplicates are dropped */
|
|
|
|
if (pqueue_insert(queue->q, item) == NULL) {
|
2017-12-04 16:16:37 +00:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_DTLS1_BUFFER_RECORD,
|
|
|
|
ERR_R_INTERNAL_ERROR);
|
2015-05-01 14:02:07 +00:00
|
|
|
OPENSSL_free(rdata->rbuf.buf);
|
2015-01-22 03:40:55 +00:00
|
|
|
OPENSSL_free(rdata);
|
|
|
|
pitem_free(item);
|
2017-10-17 14:04:09 +00:00
|
|
|
return -1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2017-10-09 11:05:58 +00:00
|
|
|
return 1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
2015-02-01 16:47:15 +00:00
|
|
|
int dtls1_retrieve_buffered_record(SSL *s, record_pqueue *queue)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2005-04-26 16:02:40 +00:00
|
|
|
pitem *item;
|
|
|
|
|
|
|
|
item = pqueue_pop(queue->q);
|
2015-01-22 03:40:55 +00:00
|
|
|
if (item) {
|
2005-04-26 16:02:40 +00:00
|
|
|
dtls1_copy_record(s, item);
|
|
|
|
|
|
|
|
OPENSSL_free(item->data);
|
2015-01-22 03:40:55 +00:00
|
|
|
pitem_free(item);
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2017-10-09 11:05:58 +00:00
|
|
|
return 1;
|
2005-04-26 16:02:40 +00:00
|
|
|
}
|
|
|
|
|
2017-10-17 14:04:09 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* retrieve a buffered record that belongs to the new epoch, i.e., not
|
|
|
|
* processed yet
|
|
|
|
*/
|
2005-04-26 16:02:40 +00:00
|
|
|
#define dtls1_get_unprocessed_record(s) \
|
|
|
|
dtls1_retrieve_buffered_record((s), \
|
2015-02-03 16:05:28 +00:00
|
|
|
&((s)->rlayer.d->unprocessed_rcds))
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-02-01 16:47:15 +00:00
|
|
|
int dtls1_process_buffered_records(SSL *s)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2005-04-26 16:02:40 +00:00
|
|
|
pitem *item;
|
2016-07-05 08:51:08 +00:00
|
|
|
SSL3_BUFFER *rb;
|
2016-07-01 14:20:33 +00:00
|
|
|
SSL3_RECORD *rr;
|
|
|
|
DTLS1_BITMAP *bitmap;
|
|
|
|
unsigned int is_next_epoch;
|
|
|
|
int replayok = 1;
|
2015-01-22 03:40:55 +00:00
|
|
|
|
2015-02-03 16:05:28 +00:00
|
|
|
item = pqueue_peek(s->rlayer.d->unprocessed_rcds.q);
|
2015-01-22 03:40:55 +00:00
|
|
|
if (item) {
|
2005-04-26 16:02:40 +00:00
|
|
|
/* Check if epoch is current. */
|
2015-02-03 16:05:28 +00:00
|
|
|
if (s->rlayer.d->unprocessed_rcds.epoch != s->rlayer.d->r_epoch)
|
2016-07-01 14:20:33 +00:00
|
|
|
return 1; /* Nothing to do. */
|
|
|
|
|
|
|
|
rr = RECORD_LAYER_get_rrec(&s->rlayer);
|
2015-01-22 03:40:55 +00:00
|
|
|
|
2016-07-05 08:51:08 +00:00
|
|
|
rb = RECORD_LAYER_get_rbuf(&s->rlayer);
|
|
|
|
|
|
|
|
if (SSL3_BUFFER_get_left(rb) > 0) {
|
|
|
|
/*
|
|
|
|
* We've still got data from the current packet to read. There could
|
|
|
|
* be a record from the new epoch in it - so don't overwrite it
|
|
|
|
* with the unprocessed records yet (we'll do it when we've
|
|
|
|
* finished reading the current packet).
|
|
|
|
*/
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-04-26 16:02:40 +00:00
|
|
|
/* Process all the records. */
|
2015-02-03 16:05:28 +00:00
|
|
|
while (pqueue_peek(s->rlayer.d->unprocessed_rcds.q)) {
|
2005-04-26 16:02:40 +00:00
|
|
|
dtls1_get_unprocessed_record(s);
|
2016-07-01 14:20:33 +00:00
|
|
|
bitmap = dtls1_get_bitmap(s, rr, &is_next_epoch);
|
|
|
|
if (bitmap == NULL) {
|
|
|
|
/*
|
|
|
|
* Should not happen. This will only ever be NULL when the
|
|
|
|
* current record is from a different epoch. But that cannot
|
|
|
|
* be the case because we already checked the epoch above
|
|
|
|
*/
|
2017-12-04 16:16:37 +00:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR,
|
|
|
|
SSL_F_DTLS1_PROCESS_BUFFERED_RECORDS,
|
|
|
|
ERR_R_INTERNAL_ERROR);
|
2016-07-01 14:20:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#ifndef OPENSSL_NO_SCTP
|
|
|
|
/* Only do replay check if no SCTP bio */
|
|
|
|
if (!BIO_dgram_is_sctp(SSL_get_rbio(s)))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Check whether this is a repeat, or aged record. We did this
|
|
|
|
* check once already when we first received the record - but
|
|
|
|
* we might have updated the window since then due to
|
|
|
|
* records we subsequently processed.
|
|
|
|
*/
|
|
|
|
replayok = dtls1_record_replay_check(s, bitmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!replayok || !dtls1_process_record(s, bitmap)) {
|
2017-12-04 16:16:37 +00:00
|
|
|
if (ossl_statem_in_error(s)) {
|
|
|
|
/* dtls1_process_record called SSLfatal() */
|
|
|
|
return -1;
|
|
|
|
}
|
2016-07-01 14:20:33 +00:00
|
|
|
/* dump this record */
|
|
|
|
rr->length = 0;
|
|
|
|
RECORD_LAYER_reset_packet_length(&s->rlayer);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-02-03 16:05:28 +00:00
|
|
|
if (dtls1_buffer_record(s, &(s->rlayer.d->processed_rcds),
|
2017-12-04 16:16:37 +00:00
|
|
|
SSL3_RECORD_get_seq_num(s->rlayer.rrec)) < 0) {
|
|
|
|
/* SSLfatal() already called */
|
2016-07-01 14:20:33 +00:00
|
|
|
return 0;
|
2017-12-04 16:16:37 +00:00
|
|
|
}
|
2005-04-26 16:02:40 +00:00
|
|
|
}
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* sync epoch numbers once all the unprocessed records have been
|
|
|
|
* processed
|
|
|
|
*/
|
2015-02-03 16:05:28 +00:00
|
|
|
s->rlayer.d->processed_rcds.epoch = s->rlayer.d->r_epoch;
|
|
|
|
s->rlayer.d->unprocessed_rcds.epoch = s->rlayer.d->r_epoch + 1;
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2016-07-01 14:20:33 +00:00
|
|
|
return 1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2014-12-28 02:48:40 +00:00
|
|
|
/*-
|
|
|
|
* Return up to 'len' payload bytes received in 'type' records.
|
2005-04-26 16:02:40 +00:00
|
|
|
* 'type' is one of the following:
|
|
|
|
*
|
|
|
|
* - SSL3_RT_HANDSHAKE (when ssl3_get_message calls us)
|
|
|
|
* - SSL3_RT_APPLICATION_DATA (when ssl3_read calls us)
|
|
|
|
* - 0 (during a shutdown, no data has to be returned)
|
|
|
|
*
|
|
|
|
* If we don't have stored data to work from, read a SSL/TLS record first
|
|
|
|
* (possibly multiple records if we still don't have anything to return).
|
|
|
|
*
|
|
|
|
* This function must handle any surprises the peer may have for us, such as
|
2015-06-02 10:33:07 +00:00
|
|
|
* Alert records (e.g. close_notify) or renegotiation requests. ChangeCipherSpec
|
|
|
|
* messages are treated as if they were handshake messages *if* the |recd_type|
|
|
|
|
* argument is non NULL.
|
2005-04-26 16:02:40 +00:00
|
|
|
* Also if record payloads contain fragments too small to process, we store
|
|
|
|
* them until there is enough for the respective protocol (the record protocol
|
|
|
|
* may use arbitrary fragmentation and even interleaving):
|
|
|
|
* Change cipher spec protocol
|
|
|
|
* just 1 byte needed, no need for keeping anything stored
|
|
|
|
* Alert protocol
|
|
|
|
* 2 bytes needed (AlertLevel, AlertDescription)
|
|
|
|
* Handshake protocol
|
|
|
|
* 4 bytes needed (HandshakeType, uint24 length) -- we just have
|
|
|
|
* to detect unexpected Client Hello and Hello Request messages
|
|
|
|
* here, anything else is handled by higher layers
|
|
|
|
* Application data protocol
|
|
|
|
* none of our business
|
|
|
|
*/
|
2015-05-11 08:35:41 +00:00
|
|
|
int dtls1_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,
|
2016-10-25 22:27:16 +00:00
|
|
|
size_t len, int peek, size_t *readbytes)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-12-04 16:16:37 +00:00
|
|
|
int i, j, iret;
|
2017-05-15 10:24:24 +00:00
|
|
|
size_t n;
|
2015-01-22 03:40:55 +00:00
|
|
|
SSL3_RECORD *rr;
|
|
|
|
void (*cb) (const SSL *ssl, int type2, int val) = NULL;
|
|
|
|
|
2015-02-02 16:02:55 +00:00
|
|
|
if (!SSL3_BUFFER_is_initialised(&s->rlayer.rbuf)) {
|
2015-01-30 14:57:54 +00:00
|
|
|
/* Not initialized yet */
|
2017-12-04 16:16:37 +00:00
|
|
|
if (!ssl3_setup_buffers(s)) {
|
|
|
|
/* SSLfatal() already called */
|
2017-10-17 14:04:09 +00:00
|
|
|
return -1;
|
2017-12-04 16:16:37 +00:00
|
|
|
}
|
2015-01-30 14:57:54 +00:00
|
|
|
}
|
2015-01-22 03:40:55 +00:00
|
|
|
|
|
|
|
if ((type && (type != SSL3_RT_APPLICATION_DATA) &&
|
|
|
|
(type != SSL3_RT_HANDSHAKE)) ||
|
|
|
|
(peek && (type != SSL3_RT_APPLICATION_DATA))) {
|
2017-12-04 16:54:59 +00:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_DTLS1_READ_BYTES,
|
|
|
|
ERR_R_INTERNAL_ERROR);
|
2015-01-22 03:40:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-10-22 12:57:18 +00:00
|
|
|
if (!ossl_statem_get_in_handshake(s) && SSL_in_init(s))
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
/* type == SSL3_RT_APPLICATION_DATA */
|
|
|
|
i = s->handshake_func(s);
|
2017-12-04 16:16:37 +00:00
|
|
|
/* SSLfatal() already called if appropriate */
|
2015-01-22 03:40:55 +00:00
|
|
|
if (i < 0)
|
2016-09-06 11:05:25 +00:00
|
|
|
return i;
|
2017-12-04 16:16:37 +00:00
|
|
|
if (i == 0)
|
2016-09-06 11:05:25 +00:00
|
|
|
return -1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start:
|
|
|
|
s->rwstate = SSL_NOTHING;
|
|
|
|
|
2015-01-05 11:30:03 +00:00
|
|
|
/*-
|
|
|
|
* s->s3->rrec.type - is the type of record
|
|
|
|
* s->s3->rrec.data, - data
|
|
|
|
* s->s3->rrec.off, - offset into 'data' for next read
|
|
|
|
* s->s3->rrec.length, - number of bytes.
|
|
|
|
*/
|
2016-01-12 14:52:35 +00:00
|
|
|
rr = s->rlayer.rrec;
|
2015-01-22 03:40:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We are not handshaking and have no data yet, so process data buffered
|
|
|
|
* during the last handshake in advance, if any.
|
|
|
|
*/
|
2015-09-08 08:13:50 +00:00
|
|
|
if (SSL_is_init_finished(s) && SSL3_RECORD_get_length(rr) == 0) {
|
2015-01-22 03:40:55 +00:00
|
|
|
pitem *item;
|
2015-02-04 10:27:43 +00:00
|
|
|
item = pqueue_pop(s->rlayer.d->buffered_app_data.q);
|
2015-01-22 03:40:55 +00:00
|
|
|
if (item) {
|
2011-12-25 14:45:15 +00:00
|
|
|
#ifndef OPENSSL_NO_SCTP
|
2015-01-22 03:40:55 +00:00
|
|
|
/* Restore bio_dgram_sctp_rcvinfo struct */
|
|
|
|
if (BIO_dgram_is_sctp(SSL_get_rbio(s))) {
|
|
|
|
DTLS1_RECORD_DATA *rdata = (DTLS1_RECORD_DATA *)item->data;
|
|
|
|
BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SCTP_SET_RCVINFO,
|
|
|
|
sizeof(rdata->recordinfo), &rdata->recordinfo);
|
|
|
|
}
|
2011-12-25 14:45:15 +00:00
|
|
|
#endif
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
dtls1_copy_record(s, item);
|
|
|
|
|
|
|
|
OPENSSL_free(item->data);
|
|
|
|
pitem_free(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for timeout */
|
2017-11-23 11:19:34 +00:00
|
|
|
if (dtls1_handle_timeout(s) > 0) {
|
2015-01-22 03:40:55 +00:00
|
|
|
goto start;
|
2017-11-23 11:19:34 +00:00
|
|
|
} else if (ossl_statem_in_error(s)) {
|
|
|
|
/* dtls1_handle_timeout() has failed with a fatal error */
|
|
|
|
return -1;
|
|
|
|
}
|
2015-01-22 03:40:55 +00:00
|
|
|
|
|
|
|
/* get new packet if necessary */
|
2015-03-28 00:33:05 +00:00
|
|
|
if ((SSL3_RECORD_get_length(rr) == 0)
|
2016-08-05 17:03:17 +00:00
|
|
|
|| (s->rlayer.rstate == SSL_ST_READ_BODY)) {
|
2016-09-06 11:05:25 +00:00
|
|
|
iret = dtls1_get_record(s);
|
|
|
|
if (iret <= 0) {
|
|
|
|
iret = dtls1_read_failed(s, iret);
|
2017-12-04 16:16:37 +00:00
|
|
|
/*
|
|
|
|
* Anything other than a timeout is an error. SSLfatal() already
|
|
|
|
* called if appropriate.
|
|
|
|
*/
|
2016-09-06 11:05:25 +00:00
|
|
|
if (iret <= 0)
|
|
|
|
return iret;
|
2015-01-22 03:40:55 +00:00
|
|
|
else
|
|
|
|
goto start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-21 13:07:31 +00:00
|
|
|
/*
|
|
|
|
* Reset the count of consecutive warning alerts if we've got a non-empty
|
|
|
|
* record that isn't an alert.
|
|
|
|
*/
|
|
|
|
if (SSL3_RECORD_get_type(rr) != SSL3_RT_ALERT
|
|
|
|
&& SSL3_RECORD_get_length(rr) != 0)
|
|
|
|
s->rlayer.alert_count = 0;
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/* we now have a packet which can be read and processed */
|
|
|
|
|
|
|
|
if (s->s3->change_cipher_spec /* set when we receive ChangeCipherSpec,
|
|
|
|
* reset by ssl3_get_finished */
|
2015-03-28 00:33:05 +00:00
|
|
|
&& (SSL3_RECORD_get_type(rr) != SSL3_RT_HANDSHAKE)) {
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* We now have application data between CCS and Finished. Most likely
|
|
|
|
* the packets were reordered on their way, so buffer the application
|
|
|
|
* data for later processing rather than dropping the connection.
|
|
|
|
*/
|
2015-02-04 10:27:43 +00:00
|
|
|
if (dtls1_buffer_record(s, &(s->rlayer.d->buffered_app_data),
|
2016-08-05 17:03:17 +00:00
|
|
|
SSL3_RECORD_get_seq_num(rr)) < 0) {
|
2017-12-04 16:16:37 +00:00
|
|
|
/* SSLfatal() already called */
|
2015-01-22 03:40:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2015-03-28 00:33:05 +00:00
|
|
|
SSL3_RECORD_set_length(rr, 0);
|
2015-01-22 03:40:55 +00:00
|
|
|
goto start;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the other end has shut down, throw anything we read away (even in
|
|
|
|
* 'peek' mode)
|
|
|
|
*/
|
|
|
|
if (s->shutdown & SSL_RECEIVED_SHUTDOWN) {
|
2015-03-28 00:33:05 +00:00
|
|
|
SSL3_RECORD_set_length(rr, 0);
|
2015-01-22 03:40:55 +00:00
|
|
|
s->rwstate = SSL_NOTHING;
|
2016-09-06 11:05:25 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 10:33:07 +00:00
|
|
|
if (type == SSL3_RECORD_get_type(rr)
|
2016-08-05 17:03:17 +00:00
|
|
|
|| (SSL3_RECORD_get_type(rr) == SSL3_RT_CHANGE_CIPHER_SPEC
|
|
|
|
&& type == SSL3_RT_HANDSHAKE && recvd_type != NULL)) {
|
2015-06-02 10:33:07 +00:00
|
|
|
/*
|
|
|
|
* SSL3_RT_APPLICATION_DATA or
|
|
|
|
* SSL3_RT_HANDSHAKE or
|
|
|
|
* SSL3_RT_CHANGE_CIPHER_SPEC
|
|
|
|
*/
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* make sure that we are not getting application data when we are
|
|
|
|
* doing a handshake for the first time
|
|
|
|
*/
|
|
|
|
if (SSL_in_init(s) && (type == SSL3_RT_APPLICATION_DATA) &&
|
|
|
|
(s->enc_read_ctx == NULL)) {
|
2017-12-04 16:16:37 +00:00
|
|
|
SSLfatal(s, SSL_AD_UNEXPECTED_MESSAGE, SSL_F_DTLS1_READ_BYTES,
|
|
|
|
SSL_R_APP_DATA_IN_HANDSHAKE);
|
|
|
|
return -1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2011-12-25 14:45:15 +00:00
|
|
|
|
2015-06-02 10:33:07 +00:00
|
|
|
if (recvd_type != NULL)
|
|
|
|
*recvd_type = SSL3_RECORD_get_type(rr);
|
|
|
|
|
2016-09-06 11:05:25 +00:00
|
|
|
if (len == 0)
|
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
|
2016-09-06 11:05:25 +00:00
|
|
|
if (len > SSL3_RECORD_get_length(rr))
|
2015-03-28 00:33:05 +00:00
|
|
|
n = SSL3_RECORD_get_length(rr);
|
2015-01-22 03:40:55 +00:00
|
|
|
else
|
2016-09-06 11:05:25 +00:00
|
|
|
n = len;
|
2015-01-22 03:40:55 +00:00
|
|
|
|
2015-03-28 00:33:05 +00:00
|
|
|
memcpy(buf, &(SSL3_RECORD_get_data(rr)[SSL3_RECORD_get_off(rr)]), n);
|
2015-01-22 03:40:55 +00:00
|
|
|
if (!peek) {
|
2016-05-26 13:47:17 +00:00
|
|
|
SSL3_RECORD_sub_length(rr, n);
|
2015-03-28 00:33:05 +00:00
|
|
|
SSL3_RECORD_add_off(rr, n);
|
|
|
|
if (SSL3_RECORD_get_length(rr) == 0) {
|
2015-02-03 10:48:28 +00:00
|
|
|
s->rlayer.rstate = SSL_ST_READ_HEADER;
|
2015-03-28 00:33:05 +00:00
|
|
|
SSL3_RECORD_set_off(rr, 0);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-25 14:45:15 +00:00
|
|
|
#ifndef OPENSSL_NO_SCTP
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* We might had to delay a close_notify alert because of reordered
|
|
|
|
* app data. If there was an alert and there is no message to read
|
|
|
|
* anymore, finally set shutdown.
|
|
|
|
*/
|
|
|
|
if (BIO_dgram_is_sctp(SSL_get_rbio(s)) &&
|
|
|
|
s->d1->shutdown_received
|
|
|
|
&& !BIO_dgram_sctp_msg_waiting(SSL_get_rbio(s))) {
|
|
|
|
s->shutdown |= SSL_RECEIVED_SHUTDOWN;
|
2016-09-06 11:05:25 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
#endif
|
2016-10-25 22:27:16 +00:00
|
|
|
*readbytes = n;
|
2016-09-06 11:05:25 +00:00
|
|
|
return 1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we get here, then type != rr->type; if we have a handshake message,
|
|
|
|
* then it was unexpected (Hello Request or Client Hello).
|
|
|
|
*/
|
|
|
|
|
2017-05-15 10:24:24 +00:00
|
|
|
if (SSL3_RECORD_get_type(rr) == SSL3_RT_ALERT) {
|
|
|
|
unsigned int alert_level, alert_descr;
|
|
|
|
unsigned char *alert_bytes = SSL3_RECORD_get_data(rr)
|
|
|
|
+ SSL3_RECORD_get_off(rr);
|
|
|
|
PACKET alert;
|
2015-01-22 03:40:55 +00:00
|
|
|
|
2017-05-15 10:24:24 +00:00
|
|
|
if (!PACKET_buf_init(&alert, alert_bytes, SSL3_RECORD_get_length(rr))
|
|
|
|
|| !PACKET_get_1(&alert, &alert_level)
|
|
|
|
|| !PACKET_get_1(&alert, &alert_descr)
|
|
|
|
|| PACKET_remaining(&alert) != 0) {
|
2017-12-04 16:16:37 +00:00
|
|
|
SSLfatal(s, SSL_AD_UNEXPECTED_MESSAGE, SSL_F_DTLS1_READ_BYTES,
|
|
|
|
SSL_R_INVALID_ALERT);
|
|
|
|
return -1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (s->msg_callback)
|
2017-05-15 10:24:24 +00:00
|
|
|
s->msg_callback(0, s->version, SSL3_RT_ALERT, alert_bytes, 2, s,
|
2015-02-04 10:14:36 +00:00
|
|
|
s->msg_callback_arg);
|
2015-01-22 03:40:55 +00:00
|
|
|
|
|
|
|
if (s->info_callback != NULL)
|
|
|
|
cb = s->info_callback;
|
|
|
|
else if (s->ctx->info_callback != NULL)
|
|
|
|
cb = s->ctx->info_callback;
|
|
|
|
|
|
|
|
if (cb != NULL) {
|
|
|
|
j = (alert_level << 8) | alert_descr;
|
|
|
|
cb(s, SSL_CB_READ_ALERT, j);
|
|
|
|
}
|
|
|
|
|
2015-03-04 10:57:45 +00:00
|
|
|
if (alert_level == SSL3_AL_WARNING) {
|
2015-01-22 03:40:55 +00:00
|
|
|
s->s3->warn_alert = alert_descr;
|
2016-09-21 13:07:31 +00:00
|
|
|
|
|
|
|
s->rlayer.alert_count++;
|
|
|
|
if (s->rlayer.alert_count == MAX_WARN_ALERT_COUNT) {
|
2017-12-04 16:16:37 +00:00
|
|
|
SSLfatal(s, SSL_AD_UNEXPECTED_MESSAGE, SSL_F_DTLS1_READ_BYTES,
|
|
|
|
SSL_R_TOO_MANY_WARN_ALERTS);
|
|
|
|
return -1;
|
2016-09-21 13:07:31 +00:00
|
|
|
}
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (alert_descr == SSL_AD_CLOSE_NOTIFY) {
|
2011-12-25 14:45:15 +00:00
|
|
|
#ifndef OPENSSL_NO_SCTP
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* With SCTP and streams the socket may deliver app data
|
|
|
|
* after a close_notify alert. We have to check this first so
|
|
|
|
* that nothing gets discarded.
|
|
|
|
*/
|
|
|
|
if (BIO_dgram_is_sctp(SSL_get_rbio(s)) &&
|
|
|
|
BIO_dgram_sctp_msg_waiting(SSL_get_rbio(s))) {
|
|
|
|
s->d1->shutdown_received = 1;
|
|
|
|
s->rwstate = SSL_READING;
|
|
|
|
BIO_clear_retry_flags(SSL_get_rbio(s));
|
|
|
|
BIO_set_retry_read(SSL_get_rbio(s));
|
|
|
|
return -1;
|
|
|
|
}
|
2011-12-25 14:45:15 +00:00
|
|
|
#endif
|
2015-01-22 03:40:55 +00:00
|
|
|
s->shutdown |= SSL_RECEIVED_SHUTDOWN;
|
2016-09-06 11:05:25 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2015-03-04 10:57:45 +00:00
|
|
|
} else if (alert_level == SSL3_AL_FATAL) {
|
2015-01-22 03:40:55 +00:00
|
|
|
char tmp[16];
|
|
|
|
|
|
|
|
s->rwstate = SSL_NOTHING;
|
|
|
|
s->s3->fatal_alert = alert_descr;
|
2017-12-04 16:16:37 +00:00
|
|
|
SSLfatal(s, SSL_AD_NO_ALERT, SSL_F_DTLS1_READ_BYTES,
|
|
|
|
SSL_AD_REASON_OFFSET + alert_descr);
|
|
|
|
BIO_snprintf(tmp, sizeof tmp, "%d", alert_descr);
|
2015-01-22 03:40:55 +00:00
|
|
|
ERR_add_error_data(2, "SSL alert number ", tmp);
|
|
|
|
s->shutdown |= SSL_RECEIVED_SHUTDOWN;
|
2016-05-26 17:49:36 +00:00
|
|
|
SSL_CTX_remove_session(s->session_ctx, s->session);
|
2016-09-06 11:05:25 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
} else {
|
2017-12-04 16:16:37 +00:00
|
|
|
SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_F_DTLS1_READ_BYTES,
|
|
|
|
SSL_R_UNKNOWN_ALERT_TYPE);
|
|
|
|
return -1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
goto start;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->shutdown & SSL_SENT_SHUTDOWN) { /* but we have not received a
|
|
|
|
* shutdown */
|
|
|
|
s->rwstate = SSL_NOTHING;
|
2015-03-28 00:33:05 +00:00
|
|
|
SSL3_RECORD_set_length(rr, 0);
|
2016-09-06 11:05:25 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
2015-03-28 00:33:05 +00:00
|
|
|
if (SSL3_RECORD_get_type(rr) == SSL3_RT_CHANGE_CIPHER_SPEC) {
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* We can't process a CCS now, because previous handshake messages
|
|
|
|
* are still missing, so just drop it.
|
|
|
|
*/
|
2015-06-02 10:33:07 +00:00
|
|
|
SSL3_RECORD_set_length(rr, 0);
|
2015-01-22 03:40:55 +00:00
|
|
|
goto start;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unexpected handshake message (Client Hello, or protocol violation)
|
|
|
|
*/
|
2017-05-15 10:24:24 +00:00
|
|
|
if ((SSL3_RECORD_get_type(rr) == SSL3_RT_HANDSHAKE) &&
|
|
|
|
!ossl_statem_get_in_handshake(s)) {
|
2015-01-22 03:40:55 +00:00
|
|
|
struct hm_header_st msg_hdr;
|
|
|
|
|
2017-05-15 10:24:24 +00:00
|
|
|
/*
|
|
|
|
* This may just be a stale retransmit. Also sanity check that we have
|
|
|
|
* at least enough record bytes for a message header
|
|
|
|
*/
|
|
|
|
if (SSL3_RECORD_get_epoch(rr) != s->rlayer.d->r_epoch
|
|
|
|
|| SSL3_RECORD_get_length(rr) < DTLS1_HM_HEADER_LENGTH) {
|
2015-03-28 00:33:05 +00:00
|
|
|
SSL3_RECORD_set_length(rr, 0);
|
2015-01-22 03:40:55 +00:00
|
|
|
goto start;
|
|
|
|
}
|
|
|
|
|
2017-05-15 10:24:24 +00:00
|
|
|
dtls1_get_message_header(rr->data, &msg_hdr);
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* If we are server, we may have a repeated FINISHED of the client
|
|
|
|
* here, then retransmit our CCS and FINISHED.
|
|
|
|
*/
|
|
|
|
if (msg_hdr.type == SSL3_MT_FINISHED) {
|
2017-12-04 16:16:37 +00:00
|
|
|
if (dtls1_check_timeout_num(s) < 0) {
|
|
|
|
/* SSLfatal) already called */
|
2015-01-22 03:40:55 +00:00
|
|
|
return -1;
|
2017-12-04 16:16:37 +00:00
|
|
|
}
|
2015-01-22 03:40:55 +00:00
|
|
|
|
2017-11-23 11:19:34 +00:00
|
|
|
if (dtls1_retransmit_buffered_messages(s) <= 0) {
|
|
|
|
/* Fail if we encountered a fatal error */
|
|
|
|
if (ossl_statem_in_error(s))
|
|
|
|
return -1;
|
|
|
|
}
|
2015-03-28 00:33:05 +00:00
|
|
|
SSL3_RECORD_set_length(rr, 0);
|
2015-01-22 03:40:55 +00:00
|
|
|
goto start;
|
|
|
|
}
|
|
|
|
|
2017-01-10 23:02:28 +00:00
|
|
|
/*
|
|
|
|
* To get here we must be trying to read app data but found handshake
|
|
|
|
* data. But if we're trying to read app data, and we're not in init
|
|
|
|
* (which is tested for at the top of this function) then init must be
|
|
|
|
* finished
|
|
|
|
*/
|
2017-05-22 11:33:42 +00:00
|
|
|
if (!ossl_assert(SSL_is_init_finished(s))) {
|
2017-12-04 16:16:37 +00:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_DTLS1_READ_BYTES,
|
|
|
|
ERR_R_INTERNAL_ERROR);
|
|
|
|
return -1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2017-01-10 23:02:28 +00:00
|
|
|
|
|
|
|
/* We found handshake data, so we're going back into init */
|
|
|
|
ossl_statem_set_in_init(s, 1);
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
i = s->handshake_func(s);
|
2017-12-04 16:16:37 +00:00
|
|
|
/* SSLfatal() called if appropriate */
|
2015-01-22 03:40:55 +00:00
|
|
|
if (i < 0)
|
2016-09-06 11:05:25 +00:00
|
|
|
return i;
|
2017-12-04 16:16:37 +00:00
|
|
|
if (i == 0)
|
2016-09-06 11:05:25 +00:00
|
|
|
return -1;
|
2015-01-22 03:40:55 +00:00
|
|
|
|
|
|
|
if (!(s->mode & SSL_MODE_AUTO_RETRY)) {
|
2015-02-02 16:02:55 +00:00
|
|
|
if (SSL3_BUFFER_get_left(&s->rlayer.rbuf) == 0) {
|
2015-01-30 14:57:54 +00:00
|
|
|
/* no read-ahead left? */
|
2015-01-22 03:40:55 +00:00
|
|
|
BIO *bio;
|
|
|
|
/*
|
|
|
|
* In the case where we try to read application data, but we
|
|
|
|
* trigger an SSL handshake, we return -1 with the retry
|
|
|
|
* option set. Otherwise renegotiation may cause nasty
|
|
|
|
* problems in the blocking world
|
|
|
|
*/
|
|
|
|
s->rwstate = SSL_READING;
|
|
|
|
bio = SSL_get_rbio(s);
|
|
|
|
BIO_clear_retry_flags(bio);
|
|
|
|
BIO_set_retry_read(bio);
|
2016-09-06 11:05:25 +00:00
|
|
|
return -1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
goto start;
|
|
|
|
}
|
|
|
|
|
2015-03-28 00:33:05 +00:00
|
|
|
switch (SSL3_RECORD_get_type(rr)) {
|
2015-01-22 03:40:55 +00:00
|
|
|
default:
|
2017-12-04 16:16:37 +00:00
|
|
|
SSLfatal(s, SSL_AD_UNEXPECTED_MESSAGE, SSL_F_DTLS1_READ_BYTES,
|
|
|
|
SSL_R_UNEXPECTED_RECORD);
|
|
|
|
return -1;
|
2015-01-22 03:40:55 +00:00
|
|
|
case SSL3_RT_CHANGE_CIPHER_SPEC:
|
|
|
|
case SSL3_RT_ALERT:
|
|
|
|
case SSL3_RT_HANDSHAKE:
|
|
|
|
/*
|
|
|
|
* we already handled all of these, with the possible exception of
|
2015-10-22 12:57:18 +00:00
|
|
|
* SSL3_RT_HANDSHAKE when ossl_statem_get_in_handshake(s) is true, but
|
|
|
|
* that should not happen when type != rr->type
|
2015-01-22 03:40:55 +00:00
|
|
|
*/
|
2017-12-04 16:16:37 +00:00
|
|
|
SSLfatal(s, SSL_AD_UNEXPECTED_MESSAGE, SSL_F_DTLS1_READ_BYTES,
|
|
|
|
ERR_R_INTERNAL_ERROR);
|
|
|
|
return -1;
|
2015-01-22 03:40:55 +00:00
|
|
|
case SSL3_RT_APPLICATION_DATA:
|
|
|
|
/*
|
|
|
|
* At this point, we were expecting handshake data, but have
|
|
|
|
* application data. If the library was running inside ssl3_read()
|
|
|
|
* (i.e. in_read_app_data is set) and it makes sense to read
|
|
|
|
* application data at this point (session renegotiation not yet
|
|
|
|
* started), we will indulge it.
|
|
|
|
*/
|
|
|
|
if (s->s3->in_read_app_data &&
|
|
|
|
(s->s3->total_renegotiations != 0) &&
|
2015-10-05 09:39:54 +00:00
|
|
|
ossl_statem_app_data_allowed(s)) {
|
2015-01-22 03:40:55 +00:00
|
|
|
s->s3->in_read_app_data = 2;
|
2016-09-06 11:05:25 +00:00
|
|
|
return -1;
|
2015-01-22 03:40:55 +00:00
|
|
|
} else {
|
2017-12-04 16:16:37 +00:00
|
|
|
SSLfatal(s, SSL_AD_UNEXPECTED_MESSAGE, SSL_F_DTLS1_READ_BYTES,
|
|
|
|
SSL_R_UNEXPECTED_RECORD);
|
|
|
|
return -1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* not reached */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call this to write data in records of type 'type' It will return <= 0 if
|
|
|
|
* not all data has been sent or non-blocking IO.
|
2005-04-26 16:02:40 +00:00
|
|
|
*/
|
2016-09-07 10:34:39 +00:00
|
|
|
int dtls1_write_bytes(SSL *s, int type, const void *buf, size_t len,
|
|
|
|
size_t *written)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2017-05-22 11:36:11 +00:00
|
|
|
if (!ossl_assert(len <= SSL3_RT_MAX_PLAIN_LENGTH)) {
|
2017-12-04 16:21:53 +00:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_DTLS1_WRITE_BYTES,
|
|
|
|
ERR_R_INTERNAL_ERROR);
|
2017-05-19 08:35:19 +00:00
|
|
|
return -1;
|
2017-05-22 11:36:11 +00:00
|
|
|
}
|
2015-01-22 03:40:55 +00:00
|
|
|
s->rwstate = SSL_NOTHING;
|
2016-09-07 10:34:39 +00:00
|
|
|
i = do_dtls1_write(s, type, buf, len, 0, written);
|
2015-01-22 03:40:55 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
int do_dtls1_write(SSL *s, int type, const unsigned char *buf,
|
2016-09-07 10:34:39 +00:00
|
|
|
size_t len, int create_empty_fragment, size_t *written)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
unsigned char *p, *pseq;
|
|
|
|
int i, mac_size, clear = 0;
|
2016-09-07 10:34:39 +00:00
|
|
|
size_t prefix_len = 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
int eivlen;
|
2016-02-16 12:10:53 +00:00
|
|
|
SSL3_RECORD wr;
|
2015-01-22 03:40:55 +00:00
|
|
|
SSL3_BUFFER *wb;
|
|
|
|
SSL_SESSION *sess;
|
|
|
|
|
2015-09-22 10:12:50 +00:00
|
|
|
wb = &s->rlayer.wbuf[0];
|
2015-01-30 16:05:47 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* first check if there is a SSL3_BUFFER still being written out. This
|
|
|
|
* will happen with non blocking IO
|
|
|
|
*/
|
2017-05-19 08:35:19 +00:00
|
|
|
if (!ossl_assert(SSL3_BUFFER_get_left(wb) == 0)) {
|
2017-12-04 16:21:53 +00:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_DO_DTLS1_WRITE,
|
|
|
|
ERR_R_INTERNAL_ERROR);
|
2017-05-19 08:35:19 +00:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we have an alert to send, lets send it */
|
|
|
|
if (s->s3->alert_dispatch) {
|
|
|
|
i = s->method->ssl_dispatch_alert(s);
|
|
|
|
if (i <= 0)
|
2016-09-07 10:34:39 +00:00
|
|
|
return i;
|
2015-01-22 03:40:55 +00:00
|
|
|
/* if it went, fall through and send more stuff */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len == 0 && !create_empty_fragment)
|
|
|
|
return 0;
|
|
|
|
|
2017-11-05 16:46:48 +00:00
|
|
|
if (len > ssl_get_max_send_fragment(s)) {
|
2017-12-04 16:21:53 +00:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_DO_DTLS1_WRITE,
|
|
|
|
SSL_R_EXCEEDS_MAX_FRAGMENT_SIZE);
|
2017-04-21 13:00:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
sess = s->session;
|
|
|
|
|
|
|
|
if ((sess == NULL) ||
|
|
|
|
(s->enc_write_ctx == NULL) || (EVP_MD_CTX_md(s->write_hash) == NULL))
|
|
|
|
clear = 1;
|
|
|
|
|
|
|
|
if (clear)
|
|
|
|
mac_size = 0;
|
|
|
|
else {
|
|
|
|
mac_size = EVP_MD_CTX_size(s->write_hash);
|
2017-12-04 16:21:53 +00:00
|
|
|
if (mac_size < 0) {
|
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_DO_DTLS1_WRITE,
|
|
|
|
SSL_R_EXCEEDS_MAX_FRAGMENT_SIZE);
|
|
|
|
return -1;
|
|
|
|
}
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
2015-03-28 00:33:05 +00:00
|
|
|
p = SSL3_BUFFER_get_buf(wb) + prefix_len;
|
2015-01-22 03:40:55 +00:00
|
|
|
|
|
|
|
/* write the header */
|
|
|
|
|
|
|
|
*(p++) = type & 0xff;
|
2016-02-16 12:10:53 +00:00
|
|
|
SSL3_RECORD_set_type(&wr, type);
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* Special case: for hello verify request, client version 1.0 and we
|
|
|
|
* haven't decided which version to use yet send back using version 1.0
|
|
|
|
* header: otherwise some clients will ignore it.
|
|
|
|
*/
|
2016-07-25 17:03:27 +00:00
|
|
|
if (s->method->version == DTLS_ANY_VERSION &&
|
2016-08-05 17:03:17 +00:00
|
|
|
s->max_proto_version != DTLS1_BAD_VER) {
|
2015-01-22 03:40:55 +00:00
|
|
|
*(p++) = DTLS1_VERSION >> 8;
|
|
|
|
*(p++) = DTLS1_VERSION & 0xff;
|
|
|
|
} else {
|
|
|
|
*(p++) = s->version >> 8;
|
|
|
|
*(p++) = s->version & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* field where we are to write out packet epoch, seq num and len */
|
|
|
|
pseq = p;
|
|
|
|
p += 10;
|
|
|
|
|
|
|
|
/* Explicit IV length, block ciphers appropriate version flag */
|
|
|
|
if (s->enc_write_ctx) {
|
|
|
|
int mode = EVP_CIPHER_CTX_mode(s->enc_write_ctx);
|
|
|
|
if (mode == EVP_CIPH_CBC_MODE) {
|
|
|
|
eivlen = EVP_CIPHER_CTX_iv_length(s->enc_write_ctx);
|
|
|
|
if (eivlen <= 1)
|
|
|
|
eivlen = 0;
|
|
|
|
}
|
|
|
|
/* Need explicit part of IV for GCM mode */
|
|
|
|
else if (mode == EVP_CIPH_GCM_MODE)
|
|
|
|
eivlen = EVP_GCM_TLS_EXPLICIT_IV_LEN;
|
2015-07-31 15:54:35 +00:00
|
|
|
else if (mode == EVP_CIPH_CCM_MODE)
|
|
|
|
eivlen = EVP_CCM_TLS_EXPLICIT_IV_LEN;
|
2015-01-22 03:40:55 +00:00
|
|
|
else
|
|
|
|
eivlen = 0;
|
|
|
|
} else
|
|
|
|
eivlen = 0;
|
|
|
|
|
|
|
|
/* lets setup the record stuff. */
|
2016-02-16 12:10:53 +00:00
|
|
|
SSL3_RECORD_set_data(&wr, p + eivlen); /* make room for IV in case of CBC */
|
2016-09-07 10:34:39 +00:00
|
|
|
SSL3_RECORD_set_length(&wr, len);
|
2016-02-16 12:10:53 +00:00
|
|
|
SSL3_RECORD_set_input(&wr, (unsigned char *)buf);
|
2015-01-22 03:40:55 +00:00
|
|
|
|
|
|
|
/*
|
2016-02-16 12:10:53 +00:00
|
|
|
* we now 'read' from wr.input, wr.length bytes into wr.data
|
2015-01-22 03:40:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* first we compress */
|
|
|
|
if (s->compress != NULL) {
|
2016-02-16 12:10:53 +00:00
|
|
|
if (!ssl3_do_compress(s, &wr)) {
|
2017-12-04 16:21:53 +00:00
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_DO_DTLS1_WRITE,
|
|
|
|
SSL_R_COMPRESSION_FAILURE);
|
|
|
|
return -1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-02-16 12:10:53 +00:00
|
|
|
memcpy(SSL3_RECORD_get_data(&wr), SSL3_RECORD_get_input(&wr),
|
|
|
|
SSL3_RECORD_get_length(&wr));
|
|
|
|
SSL3_RECORD_reset_input(&wr);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
2016-02-16 12:10:53 +00:00
|
|
|
* we should still have the output to wr.data and the input from
|
|
|
|
* wr.input. Length should be wr.length. wr.data still points in the
|
2015-01-22 03:40:55 +00:00
|
|
|
* wb->buf
|
|
|
|
*/
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2017-02-03 14:06:20 +00:00
|
|
|
if (!SSL_WRITE_ETM(s) && mac_size != 0) {
|
2016-10-19 13:44:28 +00:00
|
|
|
if (!s->method->ssl3_enc->mac(s, &wr,
|
|
|
|
&(p[SSL3_RECORD_get_length(&wr) + eivlen]),
|
2017-12-04 16:21:53 +00:00
|
|
|
1)) {
|
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_DO_DTLS1_WRITE,
|
|
|
|
ERR_R_INTERNAL_ERROR);
|
|
|
|
return -1;
|
|
|
|
}
|
2016-02-16 12:10:53 +00:00
|
|
|
SSL3_RECORD_add_length(&wr, mac_size);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/* this is true regardless of mac size */
|
2016-02-16 12:10:53 +00:00
|
|
|
SSL3_RECORD_set_data(&wr, p);
|
|
|
|
SSL3_RECORD_reset_input(&wr);
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (eivlen)
|
2016-02-16 12:10:53 +00:00
|
|
|
SSL3_RECORD_add_length(&wr, eivlen);
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2017-12-04 16:21:53 +00:00
|
|
|
if (s->method->ssl3_enc->enc(s, &wr, 1, 1) < 1) {
|
2017-12-04 16:54:59 +00:00
|
|
|
if (!ossl_statem_in_error(s)) {
|
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_DO_DTLS1_WRITE,
|
|
|
|
ERR_R_INTERNAL_ERROR);
|
|
|
|
}
|
2017-12-04 16:21:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2017-02-03 14:06:20 +00:00
|
|
|
if (SSL_WRITE_ETM(s) && mac_size != 0) {
|
2016-10-19 13:44:28 +00:00
|
|
|
if (!s->method->ssl3_enc->mac(s, &wr,
|
2017-12-04 16:21:53 +00:00
|
|
|
&(p[SSL3_RECORD_get_length(&wr)]), 1)) {
|
|
|
|
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_DO_DTLS1_WRITE,
|
|
|
|
ERR_R_INTERNAL_ERROR);
|
|
|
|
return -1;
|
|
|
|
}
|
2016-10-12 22:12:04 +00:00
|
|
|
SSL3_RECORD_add_length(&wr, mac_size);
|
|
|
|
}
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/* record length after mac and block padding */
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/* there's only one epoch between handshake and app data */
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-02-03 15:14:24 +00:00
|
|
|
s2n(s->rlayer.d->w_epoch, pseq);
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-02-03 14:26:50 +00:00
|
|
|
memcpy(pseq, &(s->rlayer.write_sequence[2]), 6);
|
2015-01-22 03:40:55 +00:00
|
|
|
pseq += 6;
|
2016-02-16 12:10:53 +00:00
|
|
|
s2n(SSL3_RECORD_get_length(&wr), pseq);
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (s->msg_callback)
|
|
|
|
s->msg_callback(1, 0, SSL3_RT_HEADER, pseq - DTLS1_RT_HEADER_LENGTH,
|
|
|
|
DTLS1_RT_HEADER_LENGTH, s, s->msg_callback_arg);
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
2016-02-16 12:10:53 +00:00
|
|
|
* we should now have wr.data pointing to the encrypted data, which is
|
2015-01-22 03:40:55 +00:00
|
|
|
* wr->length long
|
|
|
|
*/
|
2016-02-16 12:10:53 +00:00
|
|
|
SSL3_RECORD_set_type(&wr, type); /* not needed but helps for debugging */
|
|
|
|
SSL3_RECORD_add_length(&wr, DTLS1_RT_HEADER_LENGTH);
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-02-03 14:26:50 +00:00
|
|
|
ssl3_record_sequence_update(&(s->rlayer.write_sequence[0]));
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (create_empty_fragment) {
|
|
|
|
/*
|
|
|
|
* we are in a recursive call; just return the length, don't write
|
|
|
|
* out anything here
|
|
|
|
*/
|
2016-09-07 10:34:39 +00:00
|
|
|
*written = wr.length;
|
|
|
|
return 1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/* now let's set up wb */
|
2016-02-16 12:10:53 +00:00
|
|
|
SSL3_BUFFER_set_left(wb, prefix_len + SSL3_RECORD_get_length(&wr));
|
2015-03-28 00:33:05 +00:00
|
|
|
SSL3_BUFFER_set_offset(wb, 0);
|
2015-01-22 03:40:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* memorize arguments so that ssl3_write_pending can detect bad write
|
|
|
|
* retries later
|
|
|
|
*/
|
2015-02-03 13:22:12 +00:00
|
|
|
s->rlayer.wpend_tot = len;
|
|
|
|
s->rlayer.wpend_buf = buf;
|
|
|
|
s->rlayer.wpend_type = type;
|
|
|
|
s->rlayer.wpend_ret = len;
|
2015-01-22 03:40:55 +00:00
|
|
|
|
2017-12-04 16:16:37 +00:00
|
|
|
/* we now just need to write the buffer. Calls SSLfatal() as required. */
|
2016-09-07 10:34:39 +00:00
|
|
|
return ssl3_write_pending(s, type, buf, len, written);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-02-01 16:47:15 +00:00
|
|
|
DTLS1_BITMAP *dtls1_get_bitmap(SSL *s, SSL3_RECORD *rr,
|
2016-08-05 17:03:17 +00:00
|
|
|
unsigned int *is_next_epoch)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
|
|
|
|
2005-04-26 16:02:40 +00:00
|
|
|
*is_next_epoch = 0;
|
|
|
|
|
|
|
|
/* In current epoch, accept HM, CCS, DATA, & ALERT */
|
2015-02-03 15:14:24 +00:00
|
|
|
if (rr->epoch == s->rlayer.d->r_epoch)
|
2015-02-03 15:39:06 +00:00
|
|
|
return &s->rlayer.d->bitmap;
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2016-07-05 08:51:08 +00:00
|
|
|
/*
|
|
|
|
* Only HM and ALERT messages can be from the next epoch and only if we
|
|
|
|
* have already processed all of the unprocessed records from the last
|
|
|
|
* epoch
|
|
|
|
*/
|
2015-02-03 15:14:24 +00:00
|
|
|
else if (rr->epoch == (unsigned long)(s->rlayer.d->r_epoch + 1) &&
|
2016-07-05 08:51:08 +00:00
|
|
|
s->rlayer.d->unprocessed_rcds.epoch != s->rlayer.d->r_epoch &&
|
2016-08-05 17:03:17 +00:00
|
|
|
(rr->type == SSL3_RT_HANDSHAKE || rr->type == SSL3_RT_ALERT)) {
|
2005-04-26 16:02:40 +00:00
|
|
|
*is_next_epoch = 1;
|
2015-02-03 15:39:06 +00:00
|
|
|
return &s->rlayer.d->next_bitmap;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2005-04-26 16:02:40 +00:00
|
|
|
|
|
|
|
return NULL;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2005-04-26 16:02:40 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
void dtls1_reset_seq_numbers(SSL *s, int rw)
|
|
|
|
{
|
|
|
|
unsigned char *seq;
|
2015-02-03 14:26:50 +00:00
|
|
|
unsigned int seq_bytes = sizeof(s->rlayer.read_sequence);
|
2015-01-22 03:40:55 +00:00
|
|
|
|
|
|
|
if (rw & SSL3_CC_READ) {
|
2015-02-03 14:26:50 +00:00
|
|
|
seq = s->rlayer.read_sequence;
|
2015-02-03 15:14:24 +00:00
|
|
|
s->rlayer.d->r_epoch++;
|
2015-05-04 22:00:15 +00:00
|
|
|
memcpy(&s->rlayer.d->bitmap, &s->rlayer.d->next_bitmap,
|
|
|
|
sizeof(s->rlayer.d->bitmap));
|
2016-08-05 17:03:17 +00:00
|
|
|
memset(&s->rlayer.d->next_bitmap, 0, sizeof(s->rlayer.d->next_bitmap));
|
2016-06-30 14:06:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We must not use any buffered messages received from the previous
|
|
|
|
* epoch
|
|
|
|
*/
|
|
|
|
dtls1_clear_received_buffer(s);
|
2015-01-22 03:40:55 +00:00
|
|
|
} else {
|
2015-02-03 14:26:50 +00:00
|
|
|
seq = s->rlayer.write_sequence;
|
2015-02-04 11:57:34 +00:00
|
|
|
memcpy(s->rlayer.d->last_write_sequence, seq,
|
2015-02-03 14:26:50 +00:00
|
|
|
sizeof(s->rlayer.write_sequence));
|
2015-02-03 15:14:24 +00:00
|
|
|
s->rlayer.d->w_epoch++;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
2015-05-04 22:00:15 +00:00
|
|
|
memset(seq, 0, seq_bytes);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|