blob: 9fcc05013620312f429b254f631918860943b572 [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
57#include <openssl/base.h>
58
59#include <stdio.h>
60
61#if defined(OPENSSL_WINDOWS)
62#include <sys/timeb.h>
63#else
64#include <sys/socket.h>
Adam Langleyded93582014-07-31 15:23:51 -070065#include <sys/time.h>
Adam Langley95c29f32014-06-20 12:00:00 -070066#endif
67
68#include <openssl/err.h>
69#include <openssl/mem.h>
70#include <openssl/obj.h>
71
72#include "ssl_locl.h"
73
Adam Langleyded93582014-07-31 15:23:51 -070074static void get_current_time(OPENSSL_timeval *t);
Adam Langley71d8a082014-12-13 16:28:18 -080075static OPENSSL_timeval *dtls1_get_timeout(SSL *s, OPENSSL_timeval *timeleft);
Adam Langley95c29f32014-06-20 12:00:00 -070076static void dtls1_set_handshake_header(SSL *s, int type, unsigned long len);
David Benjamine4824e82014-12-14 19:44:34 -050077static int dtls1_handshake_write(SSL *s);
Adam Langley95c29f32014-06-20 12:00:00 -070078
David Benjamin338fcaf2014-12-11 01:20:52 -050079const SSL3_ENC_METHOD DTLSv1_enc_data = {
Adam Langley71d8a082014-12-13 16:28:18 -080080 tls1_enc,
David Benjamin41ac9792014-12-23 10:41:06 -050081 tls1_prf,
Adam Langley71d8a082014-12-13 16:28:18 -080082 tls1_setup_key_block,
83 tls1_generate_master_secret,
84 tls1_change_cipher_state,
85 tls1_final_finish_mac,
86 TLS1_FINISH_MAC_LENGTH,
87 tls1_cert_verify_mac,
88 TLS_MD_CLIENT_FINISH_CONST,TLS_MD_CLIENT_FINISH_CONST_SIZE,
89 TLS_MD_SERVER_FINISH_CONST,TLS_MD_SERVER_FINISH_CONST_SIZE,
90 tls1_alert_code,
91 tls1_export_keying_material,
92 SSL_ENC_FLAG_DTLS|SSL_ENC_FLAG_EXPLICIT_IV,
93 DTLS1_HM_HEADER_LENGTH,
94 dtls1_set_handshake_header,
95 dtls1_handshake_write,
Adam Langley71d8a082014-12-13 16:28:18 -080096};
Adam Langley95c29f32014-06-20 12:00:00 -070097
David Benjamin338fcaf2014-12-11 01:20:52 -050098const SSL3_ENC_METHOD DTLSv1_2_enc_data = {
Adam Langley71d8a082014-12-13 16:28:18 -080099 tls1_enc,
David Benjamin41ac9792014-12-23 10:41:06 -0500100 tls1_prf,
Adam Langley71d8a082014-12-13 16:28:18 -0800101 tls1_setup_key_block,
102 tls1_generate_master_secret,
103 tls1_change_cipher_state,
104 tls1_final_finish_mac,
105 TLS1_FINISH_MAC_LENGTH,
106 tls1_cert_verify_mac,
107 TLS_MD_CLIENT_FINISH_CONST,TLS_MD_CLIENT_FINISH_CONST_SIZE,
108 TLS_MD_SERVER_FINISH_CONST,TLS_MD_SERVER_FINISH_CONST_SIZE,
109 tls1_alert_code,
110 tls1_export_keying_material,
111 SSL_ENC_FLAG_DTLS | SSL_ENC_FLAG_EXPLICIT_IV | SSL_ENC_FLAG_SIGALGS |
112 SSL_ENC_FLAG_SHA256_PRF | SSL_ENC_FLAG_TLS1_2_CIPHERS,
113 DTLS1_HM_HEADER_LENGTH,
114 dtls1_set_handshake_header,
115 dtls1_handshake_write,
Adam Langley71d8a082014-12-13 16:28:18 -0800116};
Adam Langley95c29f32014-06-20 12:00:00 -0700117
Adam Langley71d8a082014-12-13 16:28:18 -0800118int dtls1_new(SSL *s) {
119 DTLS1_STATE *d1;
Adam Langley95c29f32014-06-20 12:00:00 -0700120
Adam Langley71d8a082014-12-13 16:28:18 -0800121 if (!ssl3_new(s)) {
122 return 0;
123 }
124 d1 = OPENSSL_malloc(sizeof *d1);
125 if (d1 == NULL) {
126 ssl3_free(s);
127 return 0;
128 }
129 memset(d1, 0, sizeof *d1);
Adam Langley95c29f32014-06-20 12:00:00 -0700130
Adam Langley71d8a082014-12-13 16:28:18 -0800131 d1->unprocessed_rcds.q = pqueue_new();
132 d1->processed_rcds.q = pqueue_new();
133 d1->buffered_messages = pqueue_new();
134 d1->sent_messages = pqueue_new();
135 d1->buffered_app_data.q = pqueue_new();
Adam Langley95c29f32014-06-20 12:00:00 -0700136
Adam Langley71d8a082014-12-13 16:28:18 -0800137 if (!d1->unprocessed_rcds.q || !d1->processed_rcds.q ||
138 !d1->buffered_messages || !d1->sent_messages ||
139 !d1->buffered_app_data.q) {
140 if (d1->unprocessed_rcds.q) {
141 pqueue_free(d1->unprocessed_rcds.q);
142 }
143 if (d1->processed_rcds.q) {
144 pqueue_free(d1->processed_rcds.q);
145 }
146 if (d1->buffered_messages) {
147 pqueue_free(d1->buffered_messages);
148 }
149 if (d1->sent_messages) {
150 pqueue_free(d1->sent_messages);
151 }
152 if (d1->buffered_app_data.q) {
153 pqueue_free(d1->buffered_app_data.q);
154 }
155 OPENSSL_free(d1);
156 ssl3_free(s);
157 return 0;
158 }
Adam Langley95c29f32014-06-20 12:00:00 -0700159
Adam Langley71d8a082014-12-13 16:28:18 -0800160 s->d1 = d1;
David Benjamin62fd1622015-01-11 13:30:01 -0500161
162 /* Set the version to the highest version for DTLS. This controls the initial
163 * state of |s->enc_method| and what the API reports as the version prior to
164 * negotiation.
165 *
166 * TODO(davidben): This is fragile and confusing. */
167 s->version = DTLS1_2_VERSION;
Adam Langley71d8a082014-12-13 16:28:18 -0800168 return 1;
169}
Adam Langley95c29f32014-06-20 12:00:00 -0700170
Adam Langley71d8a082014-12-13 16:28:18 -0800171static void dtls1_clear_queues(SSL *s) {
172 pitem *item = NULL;
173 hm_fragment *frag = NULL;
174 DTLS1_RECORD_DATA *rdata;
Adam Langley95c29f32014-06-20 12:00:00 -0700175
Adam Langley71d8a082014-12-13 16:28:18 -0800176 while ((item = pqueue_pop(s->d1->unprocessed_rcds.q)) != NULL) {
177 rdata = (DTLS1_RECORD_DATA *)item->data;
178 if (rdata->rbuf.buf) {
179 OPENSSL_free(rdata->rbuf.buf);
180 }
181 OPENSSL_free(item->data);
182 pitem_free(item);
183 }
Adam Langley95c29f32014-06-20 12:00:00 -0700184
Adam Langley71d8a082014-12-13 16:28:18 -0800185 while ((item = pqueue_pop(s->d1->processed_rcds.q)) != NULL) {
186 rdata = (DTLS1_RECORD_DATA *)item->data;
187 if (rdata->rbuf.buf) {
188 OPENSSL_free(rdata->rbuf.buf);
189 }
190 OPENSSL_free(item->data);
191 pitem_free(item);
192 }
Adam Langley95c29f32014-06-20 12:00:00 -0700193
Adam Langley71d8a082014-12-13 16:28:18 -0800194 while ((item = pqueue_pop(s->d1->buffered_messages)) != NULL) {
195 frag = (hm_fragment *)item->data;
196 dtls1_hm_fragment_free(frag);
197 pitem_free(item);
198 }
Adam Langley95c29f32014-06-20 12:00:00 -0700199
Adam Langley71d8a082014-12-13 16:28:18 -0800200 while ((item = pqueue_pop(s->d1->sent_messages)) != NULL) {
201 frag = (hm_fragment *)item->data;
202 dtls1_hm_fragment_free(frag);
203 pitem_free(item);
204 }
Adam Langley95c29f32014-06-20 12:00:00 -0700205
Adam Langley71d8a082014-12-13 16:28:18 -0800206 while ((item = pqueue_pop(s->d1->buffered_app_data.q)) != NULL) {
207 rdata = (DTLS1_RECORD_DATA *)item->data;
208 if (rdata->rbuf.buf) {
209 OPENSSL_free(rdata->rbuf.buf);
210 }
211 OPENSSL_free(item->data);
212 pitem_free(item);
213 }
214}
Adam Langley95c29f32014-06-20 12:00:00 -0700215
Adam Langley71d8a082014-12-13 16:28:18 -0800216void dtls1_free(SSL *s) {
217 ssl3_free(s);
Adam Langley95c29f32014-06-20 12:00:00 -0700218
David Benjamin62fd1622015-01-11 13:30:01 -0500219 if (s == NULL || s->d1 == NULL) {
220 return;
221 }
222
Adam Langley71d8a082014-12-13 16:28:18 -0800223 dtls1_clear_queues(s);
Adam Langley95c29f32014-06-20 12:00:00 -0700224
Adam Langley71d8a082014-12-13 16:28:18 -0800225 pqueue_free(s->d1->unprocessed_rcds.q);
226 pqueue_free(s->d1->processed_rcds.q);
227 pqueue_free(s->d1->buffered_messages);
228 pqueue_free(s->d1->sent_messages);
229 pqueue_free(s->d1->buffered_app_data.q);
Adam Langley95c29f32014-06-20 12:00:00 -0700230
Adam Langley71d8a082014-12-13 16:28:18 -0800231 OPENSSL_free(s->d1);
232 s->d1 = NULL;
233}
Adam Langley95c29f32014-06-20 12:00:00 -0700234
Adam Langley71d8a082014-12-13 16:28:18 -0800235long dtls1_ctrl(SSL *s, int cmd, long larg, void *parg) {
236 int ret = 0;
Adam Langley95c29f32014-06-20 12:00:00 -0700237
Adam Langley71d8a082014-12-13 16:28:18 -0800238 switch (cmd) {
239 case DTLS_CTRL_GET_TIMEOUT:
240 if (dtls1_get_timeout(s, (OPENSSL_timeval *)parg) != NULL) {
241 ret = 1;
242 }
243 break;
Adam Langley95c29f32014-06-20 12:00:00 -0700244
Adam Langley71d8a082014-12-13 16:28:18 -0800245 case DTLS_CTRL_HANDLE_TIMEOUT:
246 ret = dtls1_handle_timeout(s);
247 break;
Adam Langley95c29f32014-06-20 12:00:00 -0700248
Adam Langley71d8a082014-12-13 16:28:18 -0800249 default:
250 ret = ssl3_ctrl(s, cmd, larg, parg);
251 break;
252 }
Adam Langley95c29f32014-06-20 12:00:00 -0700253
Adam Langley71d8a082014-12-13 16:28:18 -0800254 return ret;
255}
256
Adam Langley71d8a082014-12-13 16:28:18 -0800257const SSL_CIPHER *dtls1_get_cipher(unsigned int u) {
258 const SSL_CIPHER *ciph = ssl3_get_cipher(u);
David Benjamine95d20d2014-12-23 11:16:01 -0500259 /* DTLS does not support stream ciphers. */
260 if (ciph == NULL || ciph->algorithm_enc == SSL_RC4) {
261 return NULL;
Adam Langley71d8a082014-12-13 16:28:18 -0800262 }
Adam Langley95c29f32014-06-20 12:00:00 -0700263
Adam Langley71d8a082014-12-13 16:28:18 -0800264 return ciph;
265}
Adam Langley95c29f32014-06-20 12:00:00 -0700266
Adam Langley71d8a082014-12-13 16:28:18 -0800267void dtls1_start_timer(SSL *s) {
268 /* If timer is not set, initialize duration with 1 second */
269 if (s->d1->next_timeout.tv_sec == 0 && s->d1->next_timeout.tv_usec == 0) {
270 s->d1->timeout_duration = 1;
271 }
Adam Langley95c29f32014-06-20 12:00:00 -0700272
Adam Langley71d8a082014-12-13 16:28:18 -0800273 /* Set timeout to current time */
274 get_current_time(&s->d1->next_timeout);
Adam Langley95c29f32014-06-20 12:00:00 -0700275
Adam Langley71d8a082014-12-13 16:28:18 -0800276 /* Add duration to current time */
277 s->d1->next_timeout.tv_sec += s->d1->timeout_duration;
278 BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0,
279 &s->d1->next_timeout);
280}
Adam Langley95c29f32014-06-20 12:00:00 -0700281
Adam Langley71d8a082014-12-13 16:28:18 -0800282static OPENSSL_timeval *dtls1_get_timeout(SSL *s, OPENSSL_timeval *timeleft) {
283 OPENSSL_timeval timenow;
Adam Langley95c29f32014-06-20 12:00:00 -0700284
Adam Langley71d8a082014-12-13 16:28:18 -0800285 /* If no timeout is set, just return NULL */
286 if (s->d1->next_timeout.tv_sec == 0 && s->d1->next_timeout.tv_usec == 0) {
287 return NULL;
288 }
Adam Langley95c29f32014-06-20 12:00:00 -0700289
Adam Langley71d8a082014-12-13 16:28:18 -0800290 /* Get current time */
291 get_current_time(&timenow);
Adam Langley95c29f32014-06-20 12:00:00 -0700292
Adam Langley71d8a082014-12-13 16:28:18 -0800293 /* If timer already expired, set remaining time to 0 */
294 if (s->d1->next_timeout.tv_sec < timenow.tv_sec ||
295 (s->d1->next_timeout.tv_sec == timenow.tv_sec &&
296 s->d1->next_timeout.tv_usec <= timenow.tv_usec)) {
297 memset(timeleft, 0, sizeof(OPENSSL_timeval));
298 return timeleft;
299 }
Adam Langley95c29f32014-06-20 12:00:00 -0700300
Adam Langley71d8a082014-12-13 16:28:18 -0800301 /* Calculate time left until timer expires */
302 memcpy(timeleft, &s->d1->next_timeout, sizeof(OPENSSL_timeval));
303 timeleft->tv_sec -= timenow.tv_sec;
304 timeleft->tv_usec -= timenow.tv_usec;
305 if (timeleft->tv_usec < 0) {
306 timeleft->tv_sec--;
307 timeleft->tv_usec += 1000000;
308 }
Adam Langley95c29f32014-06-20 12:00:00 -0700309
Adam Langley71d8a082014-12-13 16:28:18 -0800310 /* If remaining time is less than 15 ms, set it to 0 to prevent issues
311 * because of small devergences with socket timeouts. */
312 if (timeleft->tv_sec == 0 && timeleft->tv_usec < 15000) {
313 memset(timeleft, 0, sizeof(OPENSSL_timeval));
314 }
Adam Langley95c29f32014-06-20 12:00:00 -0700315
Adam Langley71d8a082014-12-13 16:28:18 -0800316 return timeleft;
317}
Adam Langley95c29f32014-06-20 12:00:00 -0700318
Adam Langley71d8a082014-12-13 16:28:18 -0800319int dtls1_is_timer_expired(SSL *s) {
320 OPENSSL_timeval timeleft;
Adam Langley95c29f32014-06-20 12:00:00 -0700321
Adam Langley71d8a082014-12-13 16:28:18 -0800322 /* Get time left until timeout, return false if no timer running */
323 if (dtls1_get_timeout(s, &timeleft) == NULL) {
324 return 0;
325 }
Adam Langley95c29f32014-06-20 12:00:00 -0700326
Adam Langley71d8a082014-12-13 16:28:18 -0800327 /* Return false if timer is not expired yet */
328 if (timeleft.tv_sec > 0 || timeleft.tv_usec > 0) {
329 return 0;
330 }
Adam Langley95c29f32014-06-20 12:00:00 -0700331
Adam Langley71d8a082014-12-13 16:28:18 -0800332 /* Timer expired, so return true */
333 return 1;
334}
Adam Langley95c29f32014-06-20 12:00:00 -0700335
Adam Langley71d8a082014-12-13 16:28:18 -0800336void dtls1_double_timeout(SSL *s) {
337 s->d1->timeout_duration *= 2;
338 if (s->d1->timeout_duration > 60) {
339 s->d1->timeout_duration = 60;
340 }
341 dtls1_start_timer(s);
342}
Adam Langley95c29f32014-06-20 12:00:00 -0700343
Adam Langley71d8a082014-12-13 16:28:18 -0800344void dtls1_stop_timer(SSL *s) {
345 /* Reset everything */
346 memset(&(s->d1->timeout), 0, sizeof(struct dtls1_timeout_st));
347 memset(&s->d1->next_timeout, 0, sizeof(OPENSSL_timeval));
348 s->d1->timeout_duration = 1;
349 BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0,
350 &s->d1->next_timeout);
351 /* Clear retransmission buffer */
352 dtls1_clear_record_buffer(s);
353}
Adam Langley95c29f32014-06-20 12:00:00 -0700354
Adam Langley71d8a082014-12-13 16:28:18 -0800355int dtls1_check_timeout_num(SSL *s) {
356 s->d1->timeout.num_alerts++;
Adam Langley95c29f32014-06-20 12:00:00 -0700357
Adam Langley71d8a082014-12-13 16:28:18 -0800358 /* Reduce MTU after 2 unsuccessful retransmissions */
359 if (s->d1->timeout.num_alerts > 2) {
360 s->d1->mtu =
361 BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_GET_FALLBACK_MTU, 0, NULL);
362 }
Adam Langley95c29f32014-06-20 12:00:00 -0700363
Adam Langley71d8a082014-12-13 16:28:18 -0800364 if (s->d1->timeout.num_alerts > DTLS1_TMO_ALERT_COUNT) {
365 /* fail the connection, enough alerts have been sent */
366 OPENSSL_PUT_ERROR(SSL, dtls1_check_timeout_num, SSL_R_READ_TIMEOUT_EXPIRED);
367 return -1;
368 }
Adam Langley95c29f32014-06-20 12:00:00 -0700369
Adam Langley71d8a082014-12-13 16:28:18 -0800370 return 0;
371}
Adam Langley95c29f32014-06-20 12:00:00 -0700372
Adam Langley71d8a082014-12-13 16:28:18 -0800373int dtls1_handle_timeout(SSL *s) {
374 /* if no timer is expired, don't do anything */
375 if (!dtls1_is_timer_expired(s)) {
376 return 0;
377 }
Adam Langley95c29f32014-06-20 12:00:00 -0700378
Adam Langley71d8a082014-12-13 16:28:18 -0800379 dtls1_double_timeout(s);
Adam Langley95c29f32014-06-20 12:00:00 -0700380
Adam Langley71d8a082014-12-13 16:28:18 -0800381 if (dtls1_check_timeout_num(s) < 0) {
382 return -1;
383 }
Adam Langley95c29f32014-06-20 12:00:00 -0700384
Adam Langley71d8a082014-12-13 16:28:18 -0800385 s->d1->timeout.read_timeouts++;
386 if (s->d1->timeout.read_timeouts > DTLS1_TMO_READ_COUNT) {
387 s->d1->timeout.read_timeouts = 1;
388 }
Adam Langley95c29f32014-06-20 12:00:00 -0700389
Adam Langley71d8a082014-12-13 16:28:18 -0800390 dtls1_start_timer(s);
391 return dtls1_retransmit_buffered_messages(s);
392}
393
394static void get_current_time(OPENSSL_timeval *t) {
Adam Langleyded93582014-07-31 15:23:51 -0700395#if defined(OPENSSL_WINDOWS)
Adam Langley71d8a082014-12-13 16:28:18 -0800396 struct _timeb time;
397 _ftime(&time);
398 t->tv_sec = time.time;
399 t->tv_usec = time.millitm * 1000;
Adam Langley95c29f32014-06-20 12:00:00 -0700400#else
Adam Langley71d8a082014-12-13 16:28:18 -0800401 gettimeofday(t, NULL);
Adam Langley95c29f32014-06-20 12:00:00 -0700402#endif
403}
404
Adam Langley71d8a082014-12-13 16:28:18 -0800405static void dtls1_set_handshake_header(SSL *s, int htype, unsigned long len) {
David Benjamine4824e82014-12-14 19:44:34 -0500406 uint8_t *message = (uint8_t *)s->init_buf->data;
407 const struct hm_header_st *msg_hdr = &s->d1->w_msg_hdr;
408 uint8_t serialised_header[DTLS1_HM_HEADER_LENGTH];
409 uint8_t *p = serialised_header;
410
David Benjamin16d031a2014-12-14 18:52:44 -0500411 s->d1->handshake_write_seq = s->d1->next_handshake_write_seq;
412 s->d1->next_handshake_write_seq++;
413
414 dtls1_set_message_header(s, htype, len, s->d1->handshake_write_seq, 0, len);
Adam Langley71d8a082014-12-13 16:28:18 -0800415 s->init_num = (int)len + DTLS1_HM_HEADER_LENGTH;
416 s->init_off = 0;
David Benjamin16d031a2014-12-14 18:52:44 -0500417
Adam Langley71d8a082014-12-13 16:28:18 -0800418 /* Buffer the message to handle re-xmits */
419 dtls1_buffer_message(s, 0);
Adam Langley95c29f32014-06-20 12:00:00 -0700420
David Benjamine4824e82014-12-14 19:44:34 -0500421 /* Add the new message to the handshake hash. Serialize the message
422 * header as if it were a single fragment. */
Adam Langley71d8a082014-12-13 16:28:18 -0800423 *p++ = msg_hdr->type;
424 l2n3(msg_hdr->msg_len, p);
425 s2n(msg_hdr->seq, p);
426 l2n3(0, p);
427 l2n3(msg_hdr->msg_len, p);
428 ssl3_finish_mac(s, serialised_header, sizeof(serialised_header));
David Benjamine4824e82014-12-14 19:44:34 -0500429 ssl3_finish_mac(s, message + DTLS1_HM_HEADER_LENGTH, len);
430}
431
432static int dtls1_handshake_write(SSL *s) {
433 return dtls1_do_write(s, SSL3_RT_HANDSHAKE);
Adam Langley71d8a082014-12-13 16:28:18 -0800434}