import libssl (LibreSSL 2.5.4)
[unleashed.git] / lib / libssl / d1_clnt.c
blob8e4c2586a305f8ce5d172d8000c82274a3ada6bc
1 /* $OpenBSD: d1_clnt.c,v 1.74 2017/02/07 02:08:38 beck Exp $ */
2 /*
3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
5 */
6 /* ====================================================================
7 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * openssl-core@OpenSSL.org.
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
59 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
60 * All rights reserved.
62 * This package is an SSL implementation written
63 * by Eric Young (eay@cryptsoft.com).
64 * The implementation was written so as to conform with Netscapes SSL.
66 * This library is free for commercial and non-commercial use as long as
67 * the following conditions are aheared to. The following conditions
68 * apply to all code found in this distribution, be it the RC4, RSA,
69 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
70 * included with this distribution is covered by the same copyright terms
71 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
73 * Copyright remains Eric Young's, and as such any Copyright notices in
74 * the code are not to be removed.
75 * If this package is used in a product, Eric Young should be given attribution
76 * as the author of the parts of the library used.
77 * This can be in the form of a textual message at program startup or
78 * in documentation (online or textual) provided with the package.
80 * Redistribution and use in source and binary forms, with or without
81 * modification, are permitted provided that the following conditions
82 * are met:
83 * 1. Redistributions of source code must retain the copyright
84 * notice, this list of conditions and the following disclaimer.
85 * 2. Redistributions in binary form must reproduce the above copyright
86 * notice, this list of conditions and the following disclaimer in the
87 * documentation and/or other materials provided with the distribution.
88 * 3. All advertising materials mentioning features or use of this software
89 * must display the following acknowledgement:
90 * "This product includes cryptographic software written by
91 * Eric Young (eay@cryptsoft.com)"
92 * The word 'cryptographic' can be left out if the rouines from the library
93 * being used are not cryptographic related :-).
94 * 4. If you include any Windows specific code (or a derivative thereof) from
95 * the apps directory (application code) you must include an acknowledgement:
96 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
98 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
99 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
100 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
101 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
102 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
103 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
104 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
105 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
106 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
107 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
108 * SUCH DAMAGE.
110 * The licence and distribution terms for any publically available version or
111 * derivative of this code cannot be changed. i.e. this code cannot simply be
112 * copied and put under another distribution licence
113 * [including the GNU Public Licence.]
116 #include <limits.h>
117 #include <stdio.h>
119 #include "ssl_locl.h"
121 #include <openssl/bn.h>
122 #include <openssl/buffer.h>
123 #include <openssl/dh.h>
124 #include <openssl/evp.h>
125 #include <openssl/md5.h>
126 #include <openssl/objects.h>
128 #include "bytestring.h"
130 static int dtls1_get_hello_verify(SSL *s);
132 static const SSL_METHOD_INTERNAL DTLSv1_client_method_internal_data = {
133 .version = DTLS1_VERSION,
134 .min_version = DTLS1_VERSION,
135 .max_version = DTLS1_VERSION,
136 .ssl_new = dtls1_new,
137 .ssl_clear = dtls1_clear,
138 .ssl_free = dtls1_free,
139 .ssl_accept = ssl_undefined_function,
140 .ssl_connect = dtls1_connect,
141 .ssl_read = ssl3_read,
142 .ssl_peek = ssl3_peek,
143 .ssl_write = ssl3_write,
144 .ssl_shutdown = dtls1_shutdown,
145 .ssl_pending = ssl3_pending,
146 .get_ssl_method = dtls1_get_client_method,
147 .get_timeout = dtls1_default_timeout,
148 .ssl_version = ssl_undefined_void_function,
149 .ssl_renegotiate = ssl3_renegotiate,
150 .ssl_renegotiate_check = ssl3_renegotiate_check,
151 .ssl_get_message = dtls1_get_message,
152 .ssl_read_bytes = dtls1_read_bytes,
153 .ssl_write_bytes = dtls1_write_app_data_bytes,
154 .ssl3_enc = &DTLSv1_enc_data,
157 static const SSL_METHOD DTLSv1_client_method_data = {
158 .ssl_dispatch_alert = dtls1_dispatch_alert,
159 .num_ciphers = ssl3_num_ciphers,
160 .get_cipher = dtls1_get_cipher,
161 .get_cipher_by_char = ssl3_get_cipher_by_char,
162 .put_cipher_by_char = ssl3_put_cipher_by_char,
163 .internal = &DTLSv1_client_method_internal_data,
166 const SSL_METHOD *
167 DTLSv1_client_method(void)
169 return &DTLSv1_client_method_data;
172 const SSL_METHOD *
173 dtls1_get_client_method(int ver)
175 if (ver == DTLS1_VERSION)
176 return (DTLSv1_client_method());
177 return (NULL);
181 dtls1_connect(SSL *s)
183 void (*cb)(const SSL *ssl, int type, int val) = NULL;
184 int ret = -1;
185 int new_state, state, skip = 0;
187 ERR_clear_error();
188 errno = 0;
190 if (s->internal->info_callback != NULL)
191 cb = s->internal->info_callback;
192 else if (s->ctx->internal->info_callback != NULL)
193 cb = s->ctx->internal->info_callback;
195 s->internal->in_handshake++;
196 if (!SSL_in_init(s) || SSL_in_before(s))
197 SSL_clear(s);
200 for (;;) {
201 state = s->internal->state;
203 switch (s->internal->state) {
204 case SSL_ST_RENEGOTIATE:
205 s->internal->renegotiate = 1;
206 s->internal->state = SSL_ST_CONNECT;
207 s->ctx->internal->stats.sess_connect_renegotiate++;
208 /* break */
209 case SSL_ST_BEFORE:
210 case SSL_ST_CONNECT:
211 case SSL_ST_BEFORE|SSL_ST_CONNECT:
212 case SSL_ST_OK|SSL_ST_CONNECT:
214 s->server = 0;
215 if (cb != NULL)
216 cb(s, SSL_CB_HANDSHAKE_START, 1);
218 if ((s->version & 0xff00 ) != (DTLS1_VERSION & 0xff00)) {
219 SSLerror(s, ERR_R_INTERNAL_ERROR);
220 ret = -1;
221 goto end;
224 /* s->version=SSL3_VERSION; */
225 s->internal->type = SSL_ST_CONNECT;
227 if (!ssl3_setup_init_buffer(s)) {
228 ret = -1;
229 goto end;
231 if (!ssl3_setup_buffers(s)) {
232 ret = -1;
233 goto end;
235 if (!ssl_init_wbio_buffer(s, 0)) {
236 ret = -1;
237 goto end;
240 /* don't push the buffering BIO quite yet */
242 s->internal->state = SSL3_ST_CW_CLNT_HELLO_A;
243 s->ctx->internal->stats.sess_connect++;
244 s->internal->init_num = 0;
245 /* mark client_random uninitialized */
246 memset(s->s3->client_random, 0,
247 sizeof(s->s3->client_random));
248 D1I(s)->send_cookie = 0;
249 s->internal->hit = 0;
250 break;
253 case SSL3_ST_CW_CLNT_HELLO_A:
254 case SSL3_ST_CW_CLNT_HELLO_B:
256 s->internal->shutdown = 0;
258 /* every DTLS ClientHello resets Finished MAC */
259 if (!tls1_init_finished_mac(s)) {
260 ret = -1;
261 goto end;
264 dtls1_start_timer(s);
265 ret = ssl3_client_hello(s);
266 if (ret <= 0)
267 goto end;
269 if (D1I(s)->send_cookie) {
270 s->internal->state = SSL3_ST_CW_FLUSH;
271 S3I(s)->tmp.next_state = SSL3_ST_CR_SRVR_HELLO_A;
272 } else
273 s->internal->state = SSL3_ST_CR_SRVR_HELLO_A;
275 s->internal->init_num = 0;
277 /* turn on buffering for the next lot of output */
278 if (s->bbio != s->wbio)
279 s->wbio = BIO_push(s->bbio, s->wbio);
281 break;
283 case SSL3_ST_CR_SRVR_HELLO_A:
284 case SSL3_ST_CR_SRVR_HELLO_B:
285 ret = ssl3_get_server_hello(s);
286 if (ret <= 0)
287 goto end;
288 else {
289 if (s->internal->hit) {
291 s->internal->state = SSL3_ST_CR_FINISHED_A;
292 } else
293 s->internal->state = DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A;
295 s->internal->init_num = 0;
296 break;
298 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
299 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
301 ret = dtls1_get_hello_verify(s);
302 if (ret <= 0)
303 goto end;
304 dtls1_stop_timer(s);
305 if ( D1I(s)->send_cookie) /* start again, with a cookie */
306 s->internal->state = SSL3_ST_CW_CLNT_HELLO_A;
307 else
308 s->internal->state = SSL3_ST_CR_CERT_A;
309 s->internal->init_num = 0;
310 break;
312 case SSL3_ST_CR_CERT_A:
313 case SSL3_ST_CR_CERT_B:
314 ret = ssl3_check_finished(s);
315 if (ret <= 0)
316 goto end;
317 if (ret == 2) {
318 s->internal->hit = 1;
319 if (s->internal->tlsext_ticket_expected)
320 s->internal->state = SSL3_ST_CR_SESSION_TICKET_A;
321 else
322 s->internal->state = SSL3_ST_CR_FINISHED_A;
323 s->internal->init_num = 0;
324 break;
326 /* Check if it is anon DH. */
327 if (!(S3I(s)->tmp.new_cipher->algorithm_auth &
328 SSL_aNULL)) {
329 ret = ssl3_get_server_certificate(s);
330 if (ret <= 0)
331 goto end;
332 if (s->internal->tlsext_status_expected)
333 s->internal->state = SSL3_ST_CR_CERT_STATUS_A;
334 else
335 s->internal->state = SSL3_ST_CR_KEY_EXCH_A;
336 } else {
337 skip = 1;
338 s->internal->state = SSL3_ST_CR_KEY_EXCH_A;
340 s->internal->init_num = 0;
341 break;
343 case SSL3_ST_CR_KEY_EXCH_A:
344 case SSL3_ST_CR_KEY_EXCH_B:
345 ret = ssl3_get_server_key_exchange(s);
346 if (ret <= 0)
347 goto end;
348 s->internal->state = SSL3_ST_CR_CERT_REQ_A;
349 s->internal->init_num = 0;
351 /* at this point we check that we have the
352 * required stuff from the server */
353 if (!ssl3_check_cert_and_algorithm(s)) {
354 ret = -1;
355 goto end;
357 break;
359 case SSL3_ST_CR_CERT_REQ_A:
360 case SSL3_ST_CR_CERT_REQ_B:
361 ret = ssl3_get_certificate_request(s);
362 if (ret <= 0)
363 goto end;
364 s->internal->state = SSL3_ST_CR_SRVR_DONE_A;
365 s->internal->init_num = 0;
366 break;
368 case SSL3_ST_CR_SRVR_DONE_A:
369 case SSL3_ST_CR_SRVR_DONE_B:
370 ret = ssl3_get_server_done(s);
371 if (ret <= 0)
372 goto end;
373 dtls1_stop_timer(s);
374 if (S3I(s)->tmp.cert_req)
375 S3I(s)->tmp.next_state = SSL3_ST_CW_CERT_A;
376 else
377 S3I(s)->tmp.next_state = SSL3_ST_CW_KEY_EXCH_A;
378 s->internal->init_num = 0;
379 s->internal->state = S3I(s)->tmp.next_state;
380 break;
382 case SSL3_ST_CW_CERT_A:
383 case SSL3_ST_CW_CERT_B:
384 case SSL3_ST_CW_CERT_C:
385 case SSL3_ST_CW_CERT_D:
386 dtls1_start_timer(s);
387 ret = ssl3_send_client_certificate(s);
388 if (ret <= 0)
389 goto end;
390 s->internal->state = SSL3_ST_CW_KEY_EXCH_A;
391 s->internal->init_num = 0;
392 break;
394 case SSL3_ST_CW_KEY_EXCH_A:
395 case SSL3_ST_CW_KEY_EXCH_B:
396 dtls1_start_timer(s);
397 ret = ssl3_send_client_key_exchange(s);
398 if (ret <= 0)
399 goto end;
401 /* EAY EAY EAY need to check for DH fix cert
402 * sent back */
403 /* For TLS, cert_req is set to 2, so a cert chain
404 * of nothing is sent, but no verify packet is sent */
405 if (S3I(s)->tmp.cert_req == 1) {
406 s->internal->state = SSL3_ST_CW_CERT_VRFY_A;
407 } else {
408 s->internal->state = SSL3_ST_CW_CHANGE_A;
409 S3I(s)->change_cipher_spec = 0;
412 s->internal->init_num = 0;
413 break;
415 case SSL3_ST_CW_CERT_VRFY_A:
416 case SSL3_ST_CW_CERT_VRFY_B:
417 dtls1_start_timer(s);
418 ret = ssl3_send_client_verify(s);
419 if (ret <= 0)
420 goto end;
421 s->internal->state = SSL3_ST_CW_CHANGE_A;
422 s->internal->init_num = 0;
423 S3I(s)->change_cipher_spec = 0;
424 break;
426 case SSL3_ST_CW_CHANGE_A:
427 case SSL3_ST_CW_CHANGE_B:
428 if (!s->internal->hit)
429 dtls1_start_timer(s);
430 ret = dtls1_send_change_cipher_spec(s,
431 SSL3_ST_CW_CHANGE_A, SSL3_ST_CW_CHANGE_B);
432 if (ret <= 0)
433 goto end;
435 s->internal->state = SSL3_ST_CW_FINISHED_A;
436 s->internal->init_num = 0;
438 s->session->cipher = S3I(s)->tmp.new_cipher;
439 if (!tls1_setup_key_block(s)) {
440 ret = -1;
441 goto end;
444 if (!tls1_change_cipher_state(s,
445 SSL3_CHANGE_CIPHER_CLIENT_WRITE)) {
446 ret = -1;
447 goto end;
451 dtls1_reset_seq_numbers(s, SSL3_CC_WRITE);
452 break;
454 case SSL3_ST_CW_FINISHED_A:
455 case SSL3_ST_CW_FINISHED_B:
456 if (!s->internal->hit)
457 dtls1_start_timer(s);
458 ret = ssl3_send_finished(s,
459 SSL3_ST_CW_FINISHED_A, SSL3_ST_CW_FINISHED_B,
460 TLS_MD_CLIENT_FINISH_CONST,
461 TLS_MD_CLIENT_FINISH_CONST_SIZE);
462 if (ret <= 0)
463 goto end;
464 s->internal->state = SSL3_ST_CW_FLUSH;
466 /* clear flags */
467 s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;
468 if (s->internal->hit) {
469 S3I(s)->tmp.next_state = SSL_ST_OK;
470 if (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED) {
471 s->internal->state = SSL_ST_OK;
472 s->s3->flags |= SSL3_FLAGS_POP_BUFFER;
473 S3I(s)->delay_buf_pop_ret = 0;
475 } else {
477 /* Allow NewSessionTicket if ticket expected */
478 if (s->internal->tlsext_ticket_expected)
479 S3I(s)->tmp.next_state =
480 SSL3_ST_CR_SESSION_TICKET_A;
481 else
482 S3I(s)->tmp.next_state =
483 SSL3_ST_CR_FINISHED_A;
485 s->internal->init_num = 0;
486 break;
488 case SSL3_ST_CR_SESSION_TICKET_A:
489 case SSL3_ST_CR_SESSION_TICKET_B:
490 ret = ssl3_get_new_session_ticket(s);
491 if (ret <= 0)
492 goto end;
493 s->internal->state = SSL3_ST_CR_FINISHED_A;
494 s->internal->init_num = 0;
495 break;
497 case SSL3_ST_CR_CERT_STATUS_A:
498 case SSL3_ST_CR_CERT_STATUS_B:
499 ret = ssl3_get_cert_status(s);
500 if (ret <= 0)
501 goto end;
502 s->internal->state = SSL3_ST_CR_KEY_EXCH_A;
503 s->internal->init_num = 0;
504 break;
506 case SSL3_ST_CR_FINISHED_A:
507 case SSL3_ST_CR_FINISHED_B:
508 D1I(s)->change_cipher_spec_ok = 1;
509 ret = ssl3_get_finished(s, SSL3_ST_CR_FINISHED_A,
510 SSL3_ST_CR_FINISHED_B);
511 if (ret <= 0)
512 goto end;
513 dtls1_stop_timer(s);
515 if (s->internal->hit)
516 s->internal->state = SSL3_ST_CW_CHANGE_A;
517 else
518 s->internal->state = SSL_ST_OK;
521 s->internal->init_num = 0;
522 break;
524 case SSL3_ST_CW_FLUSH:
525 s->internal->rwstate = SSL_WRITING;
526 if (BIO_flush(s->wbio) <= 0) {
527 /* If the write error was fatal, stop trying */
528 if (!BIO_should_retry(s->wbio)) {
529 s->internal->rwstate = SSL_NOTHING;
530 s->internal->state = S3I(s)->tmp.next_state;
533 ret = -1;
534 goto end;
536 s->internal->rwstate = SSL_NOTHING;
537 s->internal->state = S3I(s)->tmp.next_state;
538 break;
540 case SSL_ST_OK:
541 /* clean a few things up */
542 tls1_cleanup_key_block(s);
544 /* If we are not 'joining' the last two packets,
545 * remove the buffering now */
546 if (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER))
547 ssl_free_wbio_buffer(s);
548 /* else do it later in ssl3_write */
550 s->internal->init_num = 0;
551 s->internal->renegotiate = 0;
552 s->internal->new_session = 0;
554 ssl_update_cache(s, SSL_SESS_CACHE_CLIENT);
555 if (s->internal->hit)
556 s->ctx->internal->stats.sess_hit++;
558 ret = 1;
559 /* s->server=0; */
560 s->internal->handshake_func = dtls1_connect;
561 s->ctx->internal->stats.sess_connect_good++;
563 if (cb != NULL)
564 cb(s, SSL_CB_HANDSHAKE_DONE, 1);
566 /* done with handshaking */
567 D1I(s)->handshake_read_seq = 0;
568 D1I(s)->next_handshake_write_seq = 0;
569 goto end;
570 /* break; */
572 default:
573 SSLerror(s, SSL_R_UNKNOWN_STATE);
574 ret = -1;
575 goto end;
576 /* break; */
579 /* did we do anything */
580 if (!S3I(s)->tmp.reuse_message && !skip) {
581 if (s->internal->debug) {
582 if ((ret = BIO_flush(s->wbio)) <= 0)
583 goto end;
586 if ((cb != NULL) && (s->internal->state != state)) {
587 new_state = s->internal->state;
588 s->internal->state = state;
589 cb(s, SSL_CB_CONNECT_LOOP, 1);
590 s->internal->state = new_state;
593 skip = 0;
596 end:
597 s->internal->in_handshake--;
598 if (cb != NULL)
599 cb(s, SSL_CB_CONNECT_EXIT, ret);
601 return (ret);
604 static int
605 dtls1_get_hello_verify(SSL *s)
607 long n;
608 int al, ok = 0;
609 size_t cookie_len;
610 uint16_t ssl_version;
611 CBS hello_verify_request, cookie;
613 n = s->method->internal->ssl_get_message(s, DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A,
614 DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B, -1, s->internal->max_cert_list, &ok);
616 if (!ok)
617 return ((int)n);
619 if (S3I(s)->tmp.message_type != DTLS1_MT_HELLO_VERIFY_REQUEST) {
620 D1I(s)->send_cookie = 0;
621 S3I(s)->tmp.reuse_message = 1;
622 return (1);
625 if (n < 0)
626 goto truncated;
628 CBS_init(&hello_verify_request, s->internal->init_msg, n);
630 if (!CBS_get_u16(&hello_verify_request, &ssl_version))
631 goto truncated;
633 if (ssl_version != s->version) {
634 SSLerror(s, SSL_R_WRONG_SSL_VERSION);
635 s->version = (s->version & 0xff00) | (ssl_version & 0xff);
636 al = SSL_AD_PROTOCOL_VERSION;
637 goto f_err;
640 if (!CBS_get_u8_length_prefixed(&hello_verify_request, &cookie))
641 goto truncated;
643 if (!CBS_write_bytes(&cookie, D1I(s)->cookie,
644 sizeof(D1I(s)->cookie), &cookie_len)) {
645 D1I(s)->cookie_len = 0;
646 al = SSL_AD_ILLEGAL_PARAMETER;
647 goto f_err;
649 D1I(s)->cookie_len = cookie_len;
650 D1I(s)->send_cookie = 1;
652 return 1;
654 truncated:
655 al = SSL_AD_DECODE_ERROR;
656 f_err:
657 ssl3_send_alert(s, SSL3_AL_FATAL, al);
658 return -1;