blob: 73ae4cfd0b9af01985836adc1c81ee8487ea887a [file] [log] [blame]
Adam Langley95c29f32014-06-20 12:00:00 -07001/*
2 * DTLS implementation written by Nagendra Modadugu
3 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com). */
56
David Benjamin9e4e01e2015-09-15 01:48:04 -040057#include <openssl/ssl.h>
Adam Langley95c29f32014-06-20 12:00:00 -070058
David Benjamin80cee912015-01-11 19:36:58 -050059#include <limits.h>
David Benjaminf0ae1702015-04-07 23:05:04 -040060#include <string.h>
Adam Langley95c29f32014-06-20 12:00:00 -070061
David Benjamin9e4e01e2015-09-15 01:48:04 -040062#include <openssl/err.h>
63#include <openssl/mem.h>
David Benjamin98193672016-03-25 18:07:11 -040064#include <openssl/nid.h>
David Benjamin9e4e01e2015-09-15 01:48:04 -040065
66#include "internal.h"
67
Adam Langley95c29f32014-06-20 12:00:00 -070068#if defined(OPENSSL_WINDOWS)
69#include <sys/timeb.h>
70#else
71#include <sys/socket.h>
Adam Langleyded93582014-07-31 15:23:51 -070072#include <sys/time.h>
Adam Langley95c29f32014-06-20 12:00:00 -070073#endif
74
Adam Langley95c29f32014-06-20 12:00:00 -070075
David Benjamine33b9b02015-01-26 01:27:22 -050076/* DTLS1_MTU_TIMEOUTS is the maximum number of timeouts to expire
77 * before starting to decrease the MTU. */
78#define DTLS1_MTU_TIMEOUTS 2
79
80/* DTLS1_MAX_TIMEOUTS is the maximum number of timeouts to expire
81 * before failing the DTLS handshake. */
82#define DTLS1_MAX_TIMEOUTS 12
83
David Benjamin4d2e7ce2015-05-08 13:29:45 -040084static void get_current_time(const SSL *ssl, struct timeval *out_clock);
Adam Langley95c29f32014-06-20 12:00:00 -070085
David Benjamin0d56f882015-12-19 17:05:56 -050086int dtls1_new(SSL *ssl) {
Adam Langley71d8a082014-12-13 16:28:18 -080087 DTLS1_STATE *d1;
Adam Langley95c29f32014-06-20 12:00:00 -070088
David Benjamin0d56f882015-12-19 17:05:56 -050089 if (!ssl3_new(ssl)) {
Adam Langley71d8a082014-12-13 16:28:18 -080090 return 0;
91 }
92 d1 = OPENSSL_malloc(sizeof *d1);
93 if (d1 == NULL) {
David Benjamin0d56f882015-12-19 17:05:56 -050094 ssl3_free(ssl);
Adam Langley71d8a082014-12-13 16:28:18 -080095 return 0;
96 }
97 memset(d1, 0, sizeof *d1);
Adam Langley95c29f32014-06-20 12:00:00 -070098
Adam Langley71d8a082014-12-13 16:28:18 -080099 d1->buffered_messages = pqueue_new();
100 d1->sent_messages = pqueue_new();
Adam Langley95c29f32014-06-20 12:00:00 -0700101
David Benjamin4417d052015-04-05 04:17:25 -0400102 if (!d1->buffered_messages || !d1->sent_messages) {
David Benjamin2755a3e2015-04-22 16:17:58 -0400103 pqueue_free(d1->buffered_messages);
104 pqueue_free(d1->sent_messages);
Adam Langley71d8a082014-12-13 16:28:18 -0800105 OPENSSL_free(d1);
David Benjamin0d56f882015-12-19 17:05:56 -0500106 ssl3_free(ssl);
Adam Langley71d8a082014-12-13 16:28:18 -0800107 return 0;
108 }
Adam Langley95c29f32014-06-20 12:00:00 -0700109
David Benjamin0d56f882015-12-19 17:05:56 -0500110 ssl->d1 = d1;
David Benjamin62fd1622015-01-11 13:30:01 -0500111
David Benjaminb83003e2015-12-30 17:39:26 -0500112 /* Set the version to the highest supported version.
David Benjamin62fd1622015-01-11 13:30:01 -0500113 *
David Benjaminb83003e2015-12-30 17:39:26 -0500114 * TODO(davidben): Move this field into |s3|, have it store the normalized
115 * protocol version, and implement this pre-negotiation quirk in |SSL_version|
116 * at the API boundary rather than in internal state. */
David Benjamin0d56f882015-12-19 17:05:56 -0500117 ssl->version = DTLS1_2_VERSION;
Adam Langley71d8a082014-12-13 16:28:18 -0800118 return 1;
119}
Adam Langley95c29f32014-06-20 12:00:00 -0700120
David Benjamin0d56f882015-12-19 17:05:56 -0500121static void dtls1_clear_queues(SSL *ssl) {
Adam Langley71d8a082014-12-13 16:28:18 -0800122 pitem *item = NULL;
123 hm_fragment *frag = NULL;
Adam Langley95c29f32014-06-20 12:00:00 -0700124
David Benjamin0d56f882015-12-19 17:05:56 -0500125 while ((item = pqueue_pop(ssl->d1->buffered_messages)) != NULL) {
Adam Langley71d8a082014-12-13 16:28:18 -0800126 frag = (hm_fragment *)item->data;
127 dtls1_hm_fragment_free(frag);
128 pitem_free(item);
129 }
Adam Langley95c29f32014-06-20 12:00:00 -0700130
David Benjamin0d56f882015-12-19 17:05:56 -0500131 while ((item = pqueue_pop(ssl->d1->sent_messages)) != NULL) {
Adam Langley71d8a082014-12-13 16:28:18 -0800132 frag = (hm_fragment *)item->data;
133 dtls1_hm_fragment_free(frag);
134 pitem_free(item);
135 }
Adam Langley71d8a082014-12-13 16:28:18 -0800136}
Adam Langley95c29f32014-06-20 12:00:00 -0700137
David Benjamin0d56f882015-12-19 17:05:56 -0500138void dtls1_free(SSL *ssl) {
139 ssl3_free(ssl);
Adam Langley95c29f32014-06-20 12:00:00 -0700140
David Benjamin0d56f882015-12-19 17:05:56 -0500141 if (ssl == NULL || ssl->d1 == NULL) {
David Benjamin62fd1622015-01-11 13:30:01 -0500142 return;
143 }
144
David Benjamin0d56f882015-12-19 17:05:56 -0500145 dtls1_clear_queues(ssl);
Adam Langley95c29f32014-06-20 12:00:00 -0700146
David Benjamin0d56f882015-12-19 17:05:56 -0500147 pqueue_free(ssl->d1->buffered_messages);
148 pqueue_free(ssl->d1->sent_messages);
Adam Langley95c29f32014-06-20 12:00:00 -0700149
David Benjamin0d56f882015-12-19 17:05:56 -0500150 OPENSSL_free(ssl->d1);
151 ssl->d1 = NULL;
Adam Langley71d8a082014-12-13 16:28:18 -0800152}
Adam Langley95c29f32014-06-20 12:00:00 -0700153
David Benjamina1c90a52015-05-30 17:03:14 -0400154int dtls1_supports_cipher(const SSL_CIPHER *cipher) {
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700155 /* DTLS does not support stream ciphers. The NULL cipher is rejected because
156 * it's not needed. */
157 return cipher->algorithm_enc != SSL_RC4 && cipher->algorithm_enc != SSL_eNULL;
Adam Langley71d8a082014-12-13 16:28:18 -0800158}
Adam Langley95c29f32014-06-20 12:00:00 -0700159
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -0700160void DTLSv1_set_initial_timeout_duration(SSL *ssl, unsigned int duration_ms) {
161 ssl->initial_timeout_duration_ms = duration_ms;
162}
163
David Benjamin0d56f882015-12-19 17:05:56 -0500164void dtls1_start_timer(SSL *ssl) {
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -0700165 /* If timer is not set, initialize duration (by default, 1 second) */
David Benjamin0d56f882015-12-19 17:05:56 -0500166 if (ssl->d1->next_timeout.tv_sec == 0 && ssl->d1->next_timeout.tv_usec == 0) {
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -0700167 ssl->d1->timeout_duration_ms = ssl->initial_timeout_duration_ms;
Adam Langley71d8a082014-12-13 16:28:18 -0800168 }
Adam Langley95c29f32014-06-20 12:00:00 -0700169
Adam Langley71d8a082014-12-13 16:28:18 -0800170 /* Set timeout to current time */
David Benjamin0d56f882015-12-19 17:05:56 -0500171 get_current_time(ssl, &ssl->d1->next_timeout);
Adam Langley95c29f32014-06-20 12:00:00 -0700172
Adam Langley71d8a082014-12-13 16:28:18 -0800173 /* Add duration to current time */
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -0700174 ssl->d1->next_timeout.tv_sec += ssl->d1->timeout_duration_ms / 1000;
175 ssl->d1->next_timeout.tv_usec += (ssl->d1->timeout_duration_ms % 1000) * 1000;
176 if (ssl->d1->next_timeout.tv_usec >= 1000000) {
177 ssl->d1->next_timeout.tv_sec++;
178 ssl->d1->next_timeout.tv_usec -= 1000000;
179 }
David Benjamin2f871122016-05-20 14:27:17 -0400180 BIO_ctrl(ssl->rbio, BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0,
David Benjamin0d56f882015-12-19 17:05:56 -0500181 &ssl->d1->next_timeout);
Adam Langley71d8a082014-12-13 16:28:18 -0800182}
Adam Langley95c29f32014-06-20 12:00:00 -0700183
David Benjamin4d2e7ce2015-05-08 13:29:45 -0400184int DTLSv1_get_timeout(const SSL *ssl, struct timeval *out) {
David Benjamin8c249802015-05-05 09:44:18 -0400185 if (!SSL_IS_DTLS(ssl)) {
186 return 0;
187 }
Adam Langley95c29f32014-06-20 12:00:00 -0700188
Adam Langley71d8a082014-12-13 16:28:18 -0800189 /* If no timeout is set, just return NULL */
David Benjamin8c249802015-05-05 09:44:18 -0400190 if (ssl->d1->next_timeout.tv_sec == 0 && ssl->d1->next_timeout.tv_usec == 0) {
191 return 0;
Adam Langley71d8a082014-12-13 16:28:18 -0800192 }
Adam Langley95c29f32014-06-20 12:00:00 -0700193
Adam Langley71d8a082014-12-13 16:28:18 -0800194 /* Get current time */
David Benjamin4d2e7ce2015-05-08 13:29:45 -0400195 struct timeval timenow;
David Benjamin8c249802015-05-05 09:44:18 -0400196 get_current_time(ssl, &timenow);
Adam Langley95c29f32014-06-20 12:00:00 -0700197
Adam Langley71d8a082014-12-13 16:28:18 -0800198 /* If timer already expired, set remaining time to 0 */
David Benjamin8c249802015-05-05 09:44:18 -0400199 if (ssl->d1->next_timeout.tv_sec < timenow.tv_sec ||
200 (ssl->d1->next_timeout.tv_sec == timenow.tv_sec &&
201 ssl->d1->next_timeout.tv_usec <= timenow.tv_usec)) {
David Benjamin4d2e7ce2015-05-08 13:29:45 -0400202 memset(out, 0, sizeof(struct timeval));
David Benjamin8c249802015-05-05 09:44:18 -0400203 return 1;
Adam Langley71d8a082014-12-13 16:28:18 -0800204 }
Adam Langley95c29f32014-06-20 12:00:00 -0700205
Adam Langley71d8a082014-12-13 16:28:18 -0800206 /* Calculate time left until timer expires */
David Benjamin4d2e7ce2015-05-08 13:29:45 -0400207 memcpy(out, &ssl->d1->next_timeout, sizeof(struct timeval));
David Benjamin8c249802015-05-05 09:44:18 -0400208 out->tv_sec -= timenow.tv_sec;
209 out->tv_usec -= timenow.tv_usec;
210 if (out->tv_usec < 0) {
211 out->tv_sec--;
212 out->tv_usec += 1000000;
Adam Langley71d8a082014-12-13 16:28:18 -0800213 }
Adam Langley95c29f32014-06-20 12:00:00 -0700214
Adam Langley71d8a082014-12-13 16:28:18 -0800215 /* If remaining time is less than 15 ms, set it to 0 to prevent issues
216 * because of small devergences with socket timeouts. */
David Benjamin8c249802015-05-05 09:44:18 -0400217 if (out->tv_sec == 0 && out->tv_usec < 15000) {
David Benjamin4d2e7ce2015-05-08 13:29:45 -0400218 memset(out, 0, sizeof(struct timeval));
Adam Langley71d8a082014-12-13 16:28:18 -0800219 }
Adam Langley95c29f32014-06-20 12:00:00 -0700220
David Benjamin8c249802015-05-05 09:44:18 -0400221 return 1;
Adam Langley71d8a082014-12-13 16:28:18 -0800222}
Adam Langley95c29f32014-06-20 12:00:00 -0700223
David Benjamin0d56f882015-12-19 17:05:56 -0500224int dtls1_is_timer_expired(SSL *ssl) {
David Benjamin4d2e7ce2015-05-08 13:29:45 -0400225 struct timeval timeleft;
Adam Langley95c29f32014-06-20 12:00:00 -0700226
Adam Langley71d8a082014-12-13 16:28:18 -0800227 /* Get time left until timeout, return false if no timer running */
David Benjamin0d56f882015-12-19 17:05:56 -0500228 if (!DTLSv1_get_timeout(ssl, &timeleft)) {
Adam Langley71d8a082014-12-13 16:28:18 -0800229 return 0;
230 }
Adam Langley95c29f32014-06-20 12:00:00 -0700231
Adam Langley71d8a082014-12-13 16:28:18 -0800232 /* Return false if timer is not expired yet */
233 if (timeleft.tv_sec > 0 || timeleft.tv_usec > 0) {
234 return 0;
235 }
Adam Langley95c29f32014-06-20 12:00:00 -0700236
Adam Langley71d8a082014-12-13 16:28:18 -0800237 /* Timer expired, so return true */
238 return 1;
239}
Adam Langley95c29f32014-06-20 12:00:00 -0700240
David Benjamin0d56f882015-12-19 17:05:56 -0500241void dtls1_double_timeout(SSL *ssl) {
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -0700242 ssl->d1->timeout_duration_ms *= 2;
243 if (ssl->d1->timeout_duration_ms > 60000) {
244 ssl->d1->timeout_duration_ms = 60000;
Adam Langley71d8a082014-12-13 16:28:18 -0800245 }
David Benjamin0d56f882015-12-19 17:05:56 -0500246 dtls1_start_timer(ssl);
Adam Langley71d8a082014-12-13 16:28:18 -0800247}
Adam Langley95c29f32014-06-20 12:00:00 -0700248
David Benjamin0d56f882015-12-19 17:05:56 -0500249void dtls1_stop_timer(SSL *ssl) {
Adam Langley71d8a082014-12-13 16:28:18 -0800250 /* Reset everything */
David Benjamin0d56f882015-12-19 17:05:56 -0500251 ssl->d1->num_timeouts = 0;
252 memset(&ssl->d1->next_timeout, 0, sizeof(struct timeval));
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -0700253 ssl->d1->timeout_duration_ms = ssl->initial_timeout_duration_ms;
David Benjamin2f871122016-05-20 14:27:17 -0400254 BIO_ctrl(ssl->rbio, BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0,
David Benjamin0d56f882015-12-19 17:05:56 -0500255 &ssl->d1->next_timeout);
Adam Langley71d8a082014-12-13 16:28:18 -0800256 /* Clear retransmission buffer */
David Benjamin0d56f882015-12-19 17:05:56 -0500257 dtls1_clear_record_buffer(ssl);
Adam Langley71d8a082014-12-13 16:28:18 -0800258}
Adam Langley95c29f32014-06-20 12:00:00 -0700259
David Benjamin0d56f882015-12-19 17:05:56 -0500260int dtls1_check_timeout_num(SSL *ssl) {
261 ssl->d1->num_timeouts++;
Adam Langley95c29f32014-06-20 12:00:00 -0700262
Adam Langley71d8a082014-12-13 16:28:18 -0800263 /* Reduce MTU after 2 unsuccessful retransmissions */
David Benjamin0d56f882015-12-19 17:05:56 -0500264 if (ssl->d1->num_timeouts > DTLS1_MTU_TIMEOUTS &&
265 !(SSL_get_options(ssl) & SSL_OP_NO_QUERY_MTU)) {
David Benjamin2f871122016-05-20 14:27:17 -0400266 long mtu = BIO_ctrl(ssl->wbio, BIO_CTRL_DGRAM_GET_FALLBACK_MTU, 0, NULL);
David Benjamin80cee912015-01-11 19:36:58 -0500267 if (mtu >= 0 && mtu <= (1 << 30) && (unsigned)mtu >= dtls1_min_mtu()) {
David Benjamin0d56f882015-12-19 17:05:56 -0500268 ssl->d1->mtu = (unsigned)mtu;
David Benjamin80cee912015-01-11 19:36:58 -0500269 }
Adam Langley71d8a082014-12-13 16:28:18 -0800270 }
Adam Langley95c29f32014-06-20 12:00:00 -0700271
David Benjamin0d56f882015-12-19 17:05:56 -0500272 if (ssl->d1->num_timeouts > DTLS1_MAX_TIMEOUTS) {
Adam Langley71d8a082014-12-13 16:28:18 -0800273 /* fail the connection, enough alerts have been sent */
David Benjamin3570d732015-06-29 00:28:17 -0400274 OPENSSL_PUT_ERROR(SSL, SSL_R_READ_TIMEOUT_EXPIRED);
Adam Langley71d8a082014-12-13 16:28:18 -0800275 return -1;
276 }
Adam Langley95c29f32014-06-20 12:00:00 -0700277
Adam Langley71d8a082014-12-13 16:28:18 -0800278 return 0;
279}
Adam Langley95c29f32014-06-20 12:00:00 -0700280
David Benjamin8c249802015-05-05 09:44:18 -0400281int DTLSv1_handle_timeout(SSL *ssl) {
David Benjamin4c5ddb82016-03-11 22:56:19 -0500282 ssl->rwstate = SSL_NOTHING;
David Benjamin15c14882016-03-14 14:25:46 -0400283 /* Functions which use SSL_get_error must clear the error queue on entry. */
284 ERR_clear_error();
285
David Benjamin8c249802015-05-05 09:44:18 -0400286 if (!SSL_IS_DTLS(ssl)) {
Adam Langley71d8a082014-12-13 16:28:18 -0800287 return -1;
288 }
Adam Langley95c29f32014-06-20 12:00:00 -0700289
David Benjamin8c249802015-05-05 09:44:18 -0400290 /* if no timer is expired, don't do anything */
291 if (!dtls1_is_timer_expired(ssl)) {
292 return 0;
293 }
294
295 dtls1_double_timeout(ssl);
296
297 if (dtls1_check_timeout_num(ssl) < 0) {
298 return -1;
299 }
300
301 dtls1_start_timer(ssl);
302 return dtls1_retransmit_buffered_messages(ssl);
Adam Langley71d8a082014-12-13 16:28:18 -0800303}
304
David Benjamin4d2e7ce2015-05-08 13:29:45 -0400305static void get_current_time(const SSL *ssl, struct timeval *out_clock) {
David Benjamin377fc312015-01-26 00:22:12 -0500306 if (ssl->ctx->current_time_cb != NULL) {
307 ssl->ctx->current_time_cb(ssl, out_clock);
308 return;
309 }
310
Adam Langleyded93582014-07-31 15:23:51 -0700311#if defined(OPENSSL_WINDOWS)
Adam Langley71d8a082014-12-13 16:28:18 -0800312 struct _timeb time;
313 _ftime(&time);
David Benjamin377fc312015-01-26 00:22:12 -0500314 out_clock->tv_sec = time.time;
315 out_clock->tv_usec = time.millitm * 1000;
Adam Langley95c29f32014-06-20 12:00:00 -0700316#else
David Benjamin377fc312015-01-26 00:22:12 -0500317 gettimeofday(out_clock, NULL);
Adam Langley95c29f32014-06-20 12:00:00 -0700318#endif
319}
320
David Benjamin0d56f882015-12-19 17:05:56 -0500321int dtls1_set_handshake_header(SSL *ssl, int htype, unsigned long len) {
322 uint8_t *message = (uint8_t *)ssl->init_buf->data;
323 const struct hm_header_st *msg_hdr = &ssl->d1->w_msg_hdr;
David Benjamine4824e82014-12-14 19:44:34 -0500324 uint8_t serialised_header[DTLS1_HM_HEADER_LENGTH];
325 uint8_t *p = serialised_header;
326
David Benjamin0d56f882015-12-19 17:05:56 -0500327 ssl->d1->handshake_write_seq = ssl->d1->next_handshake_write_seq;
328 ssl->d1->next_handshake_write_seq++;
David Benjamin16d031a2014-12-14 18:52:44 -0500329
David Benjamin0d56f882015-12-19 17:05:56 -0500330 dtls1_set_message_header(ssl, htype, len, ssl->d1->handshake_write_seq, 0,
331 len);
332 ssl->init_num = (int)len + DTLS1_HM_HEADER_LENGTH;
333 ssl->init_off = 0;
David Benjamin16d031a2014-12-14 18:52:44 -0500334
Adam Langley71d8a082014-12-13 16:28:18 -0800335 /* Buffer the message to handle re-xmits */
David Benjamin0d56f882015-12-19 17:05:56 -0500336 dtls1_buffer_message(ssl);
Adam Langley95c29f32014-06-20 12:00:00 -0700337
David Benjamine4824e82014-12-14 19:44:34 -0500338 /* Add the new message to the handshake hash. Serialize the message
339 * header as if it were a single fragment. */
Adam Langley71d8a082014-12-13 16:28:18 -0800340 *p++ = msg_hdr->type;
341 l2n3(msg_hdr->msg_len, p);
342 s2n(msg_hdr->seq, p);
343 l2n3(0, p);
344 l2n3(msg_hdr->msg_len, p);
David Benjamin0d56f882015-12-19 17:05:56 -0500345 return ssl3_update_handshake_hash(ssl, serialised_header,
David Benjamin9550c3a2015-08-05 08:50:34 -0400346 sizeof(serialised_header)) &&
David Benjamin0d56f882015-12-19 17:05:56 -0500347 ssl3_update_handshake_hash(ssl, message + DTLS1_HM_HEADER_LENGTH, len);
David Benjamine4824e82014-12-14 19:44:34 -0500348}
349
David Benjamin0d56f882015-12-19 17:05:56 -0500350int dtls1_handshake_write(SSL *ssl) {
351 return dtls1_do_handshake_write(ssl, dtls1_use_current_epoch);
Adam Langley71d8a082014-12-13 16:28:18 -0800352}
David Benjaminaa7734b2016-06-07 16:40:46 -0400353
354void dtls1_expect_flight(SSL *ssl) {
355 dtls1_start_timer(ssl);
356}
357
358void dtls1_received_flight(SSL *ssl) {
359 dtls1_stop_timer(ssl);
360}