blob: 79f762b9c5db3ad0b64706548fe8e8c3d20ab95a [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-2007 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 */
58/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
59 * All rights reserved.
60 *
61 * This package is an SSL implementation written
62 * by Eric Young (eay@cryptsoft.com).
63 * The implementation was written so as to conform with Netscapes SSL.
64 *
65 * This library is free for commercial and non-commercial use as long as
66 * the following conditions are aheared to. The following conditions
67 * apply to all code found in this distribution, be it the RC4, RSA,
68 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
69 * included with this distribution is covered by the same copyright terms
70 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
71 *
72 * Copyright remains Eric Young's, and as such any Copyright notices in
73 * the code are not to be removed.
74 * If this package is used in a product, Eric Young should be given attribution
75 * as the author of the parts of the library used.
76 * This can be in the form of a textual message at program startup or
77 * in documentation (online or textual) provided with the package.
78 *
79 * Redistribution and use in source and binary forms, with or without
80 * modification, are permitted provided that the following conditions
81 * are met:
82 * 1. Redistributions of source code must retain the copyright
83 * notice, this list of conditions and the following disclaimer.
84 * 2. Redistributions in binary form must reproduce the above copyright
85 * notice, this list of conditions and the following disclaimer in the
86 * documentation and/or other materials provided with the distribution.
87 * 3. All advertising materials mentioning features or use of this software
88 * must display the following acknowledgement:
89 * "This product includes cryptographic software written by
90 * Eric Young (eay@cryptsoft.com)"
91 * The word 'cryptographic' can be left out if the rouines from the library
92 * being used are not cryptographic related :-).
93 * 4. If you include any Windows specific code (or a derivative thereof) from
94 * the apps directory (application code) you must include an acknowledgement:
95 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
96 *
97 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
98 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
99 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
100 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
101 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
102 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
103 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
104 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
105 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
106 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
107 * SUCH DAMAGE.
108 *
109 * The licence and distribution terms for any publically available version or
110 * derivative of this code cannot be changed. i.e. this code cannot simply be
111 * copied and put under another distribution licence
112 * [including the GNU Public Licence.]
113 */
114
David Benjamin9e4e01e2015-09-15 01:48:04 -0400115#include <openssl/ssl.h>
116
David Benjamin0b145c22014-11-26 20:10:09 -0500117#include <assert.h>
Adam Langley95c29f32014-06-20 12:00:00 -0700118#include <stdio.h>
119
120#include <openssl/bn.h>
121#include <openssl/buf.h>
122#include <openssl/dh.h>
David Benjaminf0ae1702015-04-07 23:05:04 -0400123#include <openssl/err.h>
Adam Langley95c29f32014-06-20 12:00:00 -0700124#include <openssl/evp.h>
125#include <openssl/md5.h>
126#include <openssl/obj.h>
127#include <openssl/rand.h>
128#include <openssl/x509.h>
129
David Benjamin2ee94aa2015-04-07 22:38:30 -0400130#include "internal.h"
Adam Langley95c29f32014-06-20 12:00:00 -0700131
Adam Langley24819752014-12-15 18:42:07 -0800132
Adam Langley24819752014-12-15 18:42:07 -0800133int dtls1_accept(SSL *s) {
134 BUF_MEM *buf = NULL;
David Benjamin82170242015-10-17 22:51:17 -0400135 void (*cb)(const SSL *ssl, int type, int value) = NULL;
David Benjamin107db582015-04-08 00:41:59 -0400136 uint32_t alg_a;
Adam Langley24819752014-12-15 18:42:07 -0800137 int ret = -1;
138 int new_state, state, skip = 0;
Adam Langley95c29f32014-06-20 12:00:00 -0700139
Adam Langley24819752014-12-15 18:42:07 -0800140 assert(s->handshake_func == dtls1_accept);
141 assert(s->server);
142 assert(SSL_IS_DTLS(s));
David Benjaminbeb47022014-11-30 02:58:52 -0500143
Adam Langley24819752014-12-15 18:42:07 -0800144 ERR_clear_error();
145 ERR_clear_system_error();
Adam Langley95c29f32014-06-20 12:00:00 -0700146
Adam Langley24819752014-12-15 18:42:07 -0800147 if (s->info_callback != NULL) {
148 cb = s->info_callback;
149 } else if (s->ctx->info_callback != NULL) {
150 cb = s->ctx->info_callback;
151 }
Adam Langley95c29f32014-06-20 12:00:00 -0700152
Adam Langley24819752014-12-15 18:42:07 -0800153 s->in_handshake++;
Adam Langley95c29f32014-06-20 12:00:00 -0700154
Adam Langley24819752014-12-15 18:42:07 -0800155 for (;;) {
156 state = s->state;
Adam Langley95c29f32014-06-20 12:00:00 -0700157
Adam Langley24819752014-12-15 18:42:07 -0800158 switch (s->state) {
Adam Langley24819752014-12-15 18:42:07 -0800159 case SSL_ST_ACCEPT:
Adam Langley24819752014-12-15 18:42:07 -0800160 if (cb != NULL) {
161 cb(s, SSL_CB_HANDSHAKE_START, 1);
162 }
Adam Langley95c29f32014-06-20 12:00:00 -0700163
Adam Langley24819752014-12-15 18:42:07 -0800164 if (s->init_buf == NULL) {
165 buf = BUF_MEM_new();
166 if (buf == NULL || !BUF_MEM_grow(buf, SSL3_RT_MAX_PLAIN_LENGTH)) {
167 ret = -1;
168 goto end;
169 }
170 s->init_buf = buf;
171 buf = NULL;
172 }
Adam Langley95c29f32014-06-20 12:00:00 -0700173
Adam Langley24819752014-12-15 18:42:07 -0800174 s->init_num = 0;
Adam Langley95c29f32014-06-20 12:00:00 -0700175
David Benjamind23d5a52015-05-15 21:48:48 -0400176 if (!ssl_init_wbio_buffer(s, 1)) {
177 ret = -1;
Adam Langley24819752014-12-15 18:42:07 -0800178 goto end;
179 }
Adam Langley95c29f32014-06-20 12:00:00 -0700180
David Benjamin9550c3a2015-08-05 08:50:34 -0400181 if (!ssl3_init_handshake_buffer(s)) {
David Benjamin3570d732015-06-29 00:28:17 -0400182 OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
Adam Langley24819752014-12-15 18:42:07 -0800183 ret = -1;
184 goto end;
185 }
Adam Langley95c29f32014-06-20 12:00:00 -0700186
David Benjamind23d5a52015-05-15 21:48:48 -0400187 s->state = SSL3_ST_SR_CLNT_HELLO_A;
Adam Langley24819752014-12-15 18:42:07 -0800188 break;
Adam Langley95c29f32014-06-20 12:00:00 -0700189
Adam Langley24819752014-12-15 18:42:07 -0800190 case SSL3_ST_SR_CLNT_HELLO_A:
191 case SSL3_ST_SR_CLNT_HELLO_B:
192 case SSL3_ST_SR_CLNT_HELLO_C:
193 case SSL3_ST_SR_CLNT_HELLO_D:
194 s->shutdown = 0;
195 ret = ssl3_get_client_hello(s);
196 if (ret <= 0) {
197 goto end;
198 }
199 dtls1_stop_timer(s);
David Benjamina54e2e82015-02-16 16:31:43 -0500200 s->state = SSL3_ST_SW_SRVR_HELLO_A;
Adam Langley24819752014-12-15 18:42:07 -0800201 s->init_num = 0;
202 break;
Adam Langley95c29f32014-06-20 12:00:00 -0700203
Adam Langley24819752014-12-15 18:42:07 -0800204 case SSL3_ST_SW_SRVR_HELLO_A:
205 case SSL3_ST_SW_SRVR_HELLO_B:
Adam Langley24819752014-12-15 18:42:07 -0800206 dtls1_start_timer(s);
207 ret = ssl3_send_server_hello(s);
208 if (ret <= 0) {
209 goto end;
210 }
Adam Langley95c29f32014-06-20 12:00:00 -0700211
Adam Langley24819752014-12-15 18:42:07 -0800212 if (s->hit) {
213 if (s->tlsext_ticket_expected) {
214 s->state = SSL3_ST_SW_SESSION_TICKET_A;
215 } else {
216 s->state = SSL3_ST_SW_CHANGE_A;
217 }
218 } else {
219 s->state = SSL3_ST_SW_CERT_A;
220 }
221 s->init_num = 0;
222 break;
Adam Langley95c29f32014-06-20 12:00:00 -0700223
Adam Langley24819752014-12-15 18:42:07 -0800224 case SSL3_ST_SW_CERT_A:
225 case SSL3_ST_SW_CERT_B:
David Benjamine95d20d2014-12-23 11:16:01 -0500226 if (ssl_cipher_has_server_public_key(s->s3->tmp.new_cipher)) {
Adam Langley24819752014-12-15 18:42:07 -0800227 dtls1_start_timer(s);
228 ret = ssl3_send_server_certificate(s);
229 if (ret <= 0) {
230 goto end;
231 }
232 if (s->s3->tmp.certificate_status_expected) {
233 s->state = SSL3_ST_SW_CERT_STATUS_A;
234 } else {
235 s->state = SSL3_ST_SW_KEY_EXCH_A;
236 }
237 } else {
238 skip = 1;
239 s->state = SSL3_ST_SW_KEY_EXCH_A;
240 }
241 s->init_num = 0;
242 break;
Adam Langley95c29f32014-06-20 12:00:00 -0700243
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100244 case SSL3_ST_SW_CERT_STATUS_A:
245 case SSL3_ST_SW_CERT_STATUS_B:
246 ret = ssl3_send_certificate_status(s);
247 if (ret <= 0) {
248 goto end;
249 }
250 s->state = SSL3_ST_SW_KEY_EXCH_A;
251 s->init_num = 0;
252 break;
253
Adam Langley24819752014-12-15 18:42:07 -0800254 case SSL3_ST_SW_KEY_EXCH_A:
255 case SSL3_ST_SW_KEY_EXCH_B:
nagendra modadugu601448a2015-07-24 09:31:31 -0700256 case SSL3_ST_SW_KEY_EXCH_C:
Adam Langley24819752014-12-15 18:42:07 -0800257 alg_a = s->s3->tmp.new_cipher->algorithm_auth;
Adam Langley95c29f32014-06-20 12:00:00 -0700258
Adam Langley24819752014-12-15 18:42:07 -0800259 /* Send a ServerKeyExchange message if:
260 * - The key exchange is ephemeral or anonymous
261 * Diffie-Hellman.
262 * - There is a PSK identity hint.
263 *
264 * TODO(davidben): This logic is currently duplicated
265 * in s3_srvr.c. Fix this. In the meantime, keep them
266 * in sync. */
267 if (ssl_cipher_requires_server_key_exchange(s->s3->tmp.new_cipher) ||
268 ((alg_a & SSL_aPSK) && s->psk_identity_hint)) {
269 dtls1_start_timer(s);
270 ret = ssl3_send_server_key_exchange(s);
271 if (ret <= 0) {
272 goto end;
273 }
274 } else {
275 skip = 1;
276 }
Adam Langley95c29f32014-06-20 12:00:00 -0700277
Adam Langley24819752014-12-15 18:42:07 -0800278 s->state = SSL3_ST_SW_CERT_REQ_A;
279 s->init_num = 0;
280 break;
Adam Langley95c29f32014-06-20 12:00:00 -0700281
Adam Langley24819752014-12-15 18:42:07 -0800282 case SSL3_ST_SW_CERT_REQ_A:
283 case SSL3_ST_SW_CERT_REQ_B:
David Benjamin5c1ce292015-05-26 16:59:43 -0400284 if (s->s3->tmp.cert_request) {
Adam Langley24819752014-12-15 18:42:07 -0800285 dtls1_start_timer(s);
286 ret = ssl3_send_certificate_request(s);
287 if (ret <= 0) {
288 goto end;
289 }
David Benjamin5c1ce292015-05-26 16:59:43 -0400290 } else {
291 skip = 1;
Adam Langley24819752014-12-15 18:42:07 -0800292 }
David Benjamin5c1ce292015-05-26 16:59:43 -0400293 s->state = SSL3_ST_SW_SRVR_DONE_A;
294 s->init_num = 0;
Adam Langley24819752014-12-15 18:42:07 -0800295 break;
Adam Langley95c29f32014-06-20 12:00:00 -0700296
Adam Langley24819752014-12-15 18:42:07 -0800297 case SSL3_ST_SW_SRVR_DONE_A:
298 case SSL3_ST_SW_SRVR_DONE_B:
299 dtls1_start_timer(s);
300 ret = ssl3_send_server_done(s);
301 if (ret <= 0) {
302 goto end;
303 }
304 s->s3->tmp.next_state = SSL3_ST_SR_CERT_A;
305 s->state = SSL3_ST_SW_FLUSH;
306 s->init_num = 0;
307 break;
Adam Langley95c29f32014-06-20 12:00:00 -0700308
Adam Langley24819752014-12-15 18:42:07 -0800309 case SSL3_ST_SW_FLUSH:
310 s->rwstate = SSL_WRITING;
311 if (BIO_flush(s->wbio) <= 0) {
Adam Langley24819752014-12-15 18:42:07 -0800312 ret = -1;
313 goto end;
314 }
315 s->rwstate = SSL_NOTHING;
316 s->state = s->s3->tmp.next_state;
317 break;
Adam Langley95c29f32014-06-20 12:00:00 -0700318
Adam Langley24819752014-12-15 18:42:07 -0800319 case SSL3_ST_SR_CERT_A:
320 case SSL3_ST_SR_CERT_B:
321 if (s->s3->tmp.cert_request) {
322 ret = ssl3_get_client_certificate(s);
323 if (ret <= 0) {
324 goto end;
325 }
326 }
327 s->init_num = 0;
328 s->state = SSL3_ST_SR_KEY_EXCH_A;
329 break;
Adam Langley95c29f32014-06-20 12:00:00 -0700330
Adam Langley24819752014-12-15 18:42:07 -0800331 case SSL3_ST_SR_KEY_EXCH_A:
332 case SSL3_ST_SR_KEY_EXCH_B:
nagendra modadugu3398dbf2015-08-07 14:07:52 -0700333 case SSL3_ST_SR_KEY_EXCH_C:
Adam Langley24819752014-12-15 18:42:07 -0800334 ret = ssl3_get_client_key_exchange(s);
335 if (ret <= 0) {
336 goto end;
337 }
338 s->state = SSL3_ST_SR_CERT_VRFY_A;
339 s->init_num = 0;
340 break;
Adam Langley95c29f32014-06-20 12:00:00 -0700341
Adam Langley24819752014-12-15 18:42:07 -0800342 case SSL3_ST_SR_CERT_VRFY_A:
343 case SSL3_ST_SR_CERT_VRFY_B:
Adam Langley24819752014-12-15 18:42:07 -0800344 ret = ssl3_get_cert_verify(s);
345 if (ret <= 0) {
346 goto end;
347 }
348 s->state = SSL3_ST_SR_FINISHED_A;
349 s->init_num = 0;
350 break;
Adam Langley95c29f32014-06-20 12:00:00 -0700351
Adam Langley24819752014-12-15 18:42:07 -0800352 case SSL3_ST_SR_FINISHED_A:
353 case SSL3_ST_SR_FINISHED_B:
354 s->d1->change_cipher_spec_ok = 1;
355 ret =
356 ssl3_get_finished(s, SSL3_ST_SR_FINISHED_A, SSL3_ST_SR_FINISHED_B);
357 if (ret <= 0) {
358 goto end;
359 }
360 dtls1_stop_timer(s);
361 if (s->hit) {
362 s->state = SSL_ST_OK;
363 } else if (s->tlsext_ticket_expected) {
364 s->state = SSL3_ST_SW_SESSION_TICKET_A;
365 } else {
366 s->state = SSL3_ST_SW_CHANGE_A;
367 }
368 s->init_num = 0;
369 break;
Adam Langley95c29f32014-06-20 12:00:00 -0700370
Adam Langley24819752014-12-15 18:42:07 -0800371 case SSL3_ST_SW_SESSION_TICKET_A:
372 case SSL3_ST_SW_SESSION_TICKET_B:
373 ret = ssl3_send_new_session_ticket(s);
374 if (ret <= 0) {
375 goto end;
376 }
377 s->state = SSL3_ST_SW_CHANGE_A;
378 s->init_num = 0;
379 break;
Adam Langley95c29f32014-06-20 12:00:00 -0700380
Adam Langley24819752014-12-15 18:42:07 -0800381 case SSL3_ST_SW_CHANGE_A:
382 case SSL3_ST_SW_CHANGE_B:
383 s->session->cipher = s->s3->tmp.new_cipher;
384 if (!s->enc_method->setup_key_block(s)) {
385 ret = -1;
386 goto end;
387 }
Adam Langley95c29f32014-06-20 12:00:00 -0700388
Adam Langley24819752014-12-15 18:42:07 -0800389 ret = dtls1_send_change_cipher_spec(s, SSL3_ST_SW_CHANGE_A,
390 SSL3_ST_SW_CHANGE_B);
Adam Langley95c29f32014-06-20 12:00:00 -0700391
Adam Langley24819752014-12-15 18:42:07 -0800392 if (ret <= 0) {
393 goto end;
394 }
Adam Langley95c29f32014-06-20 12:00:00 -0700395
Adam Langley24819752014-12-15 18:42:07 -0800396 s->state = SSL3_ST_SW_FINISHED_A;
397 s->init_num = 0;
Adam Langley95c29f32014-06-20 12:00:00 -0700398
Adam Langley24819752014-12-15 18:42:07 -0800399 if (!s->enc_method->change_cipher_state(
400 s, SSL3_CHANGE_CIPHER_SERVER_WRITE)) {
401 ret = -1;
402 goto end;
403 }
Adam Langley24819752014-12-15 18:42:07 -0800404 break;
Adam Langley95c29f32014-06-20 12:00:00 -0700405
Adam Langley24819752014-12-15 18:42:07 -0800406 case SSL3_ST_SW_FINISHED_A:
407 case SSL3_ST_SW_FINISHED_B:
408 ret =
409 ssl3_send_finished(s, SSL3_ST_SW_FINISHED_A, SSL3_ST_SW_FINISHED_B,
410 s->enc_method->server_finished_label,
411 s->enc_method->server_finished_label_len);
412 if (ret <= 0) {
413 goto end;
414 }
415 s->state = SSL3_ST_SW_FLUSH;
416 if (s->hit) {
417 s->s3->tmp.next_state = SSL3_ST_SR_FINISHED_A;
418 } else {
419 s->s3->tmp.next_state = SSL_ST_OK;
420 }
421 s->init_num = 0;
422 break;
Adam Langley95c29f32014-06-20 12:00:00 -0700423
Adam Langley24819752014-12-15 18:42:07 -0800424 case SSL_ST_OK:
425 ssl3_cleanup_key_block(s);
Adam Langley95c29f32014-06-20 12:00:00 -0700426
Adam Langley24819752014-12-15 18:42:07 -0800427 /* remove buffering on output */
428 ssl_free_wbio_buffer(s);
Adam Langley95c29f32014-06-20 12:00:00 -0700429
Adam Langley24819752014-12-15 18:42:07 -0800430 s->init_num = 0;
David Benjamind23d5a52015-05-15 21:48:48 -0400431 s->s3->initial_handshake_complete = 1;
Adam Langley95c29f32014-06-20 12:00:00 -0700432
David Benjamind23d5a52015-05-15 21:48:48 -0400433 ssl_update_cache(s, SSL_SESS_CACHE_SERVER);
Adam Langley95c29f32014-06-20 12:00:00 -0700434
David Benjamind23d5a52015-05-15 21:48:48 -0400435 if (cb != NULL) {
436 cb(s, SSL_CB_HANDSHAKE_DONE, 1);
Adam Langley24819752014-12-15 18:42:07 -0800437 }
Adam Langley95c29f32014-06-20 12:00:00 -0700438
Adam Langley24819752014-12-15 18:42:07 -0800439 ret = 1;
Adam Langley95c29f32014-06-20 12:00:00 -0700440
Adam Langley24819752014-12-15 18:42:07 -0800441 /* done handshaking, next message is client hello */
442 s->d1->handshake_read_seq = 0;
443 /* next message is server hello */
444 s->d1->handshake_write_seq = 0;
445 s->d1->next_handshake_write_seq = 0;
446 goto end;
447
448 default:
David Benjamin3570d732015-06-29 00:28:17 -0400449 OPENSSL_PUT_ERROR(SSL, SSL_R_UNKNOWN_STATE);
Adam Langley24819752014-12-15 18:42:07 -0800450 ret = -1;
451 goto end;
452 }
453
454 if (!s->s3->tmp.reuse_message && !skip) {
455 if (cb != NULL && s->state != state) {
456 new_state = s->state;
457 s->state = state;
458 cb(s, SSL_CB_ACCEPT_LOOP, 1);
459 s->state = new_state;
460 }
461 }
462 skip = 0;
463 }
464
Adam Langley95c29f32014-06-20 12:00:00 -0700465end:
Adam Langley24819752014-12-15 18:42:07 -0800466 s->in_handshake--;
David Benjamin2755a3e2015-04-22 16:17:58 -0400467 BUF_MEM_free(buf);
Adam Langley24819752014-12-15 18:42:07 -0800468 if (cb != NULL) {
469 cb(s, SSL_CB_ACCEPT_EXIT, ret);
470 }
471 return ret;
472}