Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

640 рядки
17 KiB

  1. /*
  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. #include <stdio.h>
  115. #include <openssl/bn.h>
  116. #include <openssl/buf.h>
  117. #include <openssl/dh.h>
  118. #include <openssl/evp.h>
  119. #include <openssl/md5.h>
  120. #include <openssl/mem.h>
  121. #include <openssl/obj.h>
  122. #include <openssl/rand.h>
  123. #include "ssl_locl.h"
  124. static const SSL_METHOD *dtls1_get_client_method(int ver);
  125. static int dtls1_get_hello_verify(SSL *s);
  126. static const SSL_METHOD *dtls1_get_client_method(int ver)
  127. {
  128. if (ver == DTLS1_VERSION)
  129. return(DTLSv1_client_method());
  130. else if (ver == DTLS1_2_VERSION)
  131. return(DTLSv1_2_client_method());
  132. else
  133. return(NULL);
  134. }
  135. IMPLEMENT_dtls1_meth_func(DTLS1_VERSION,
  136. DTLSv1_client_method,
  137. ssl_undefined_function,
  138. dtls1_connect,
  139. dtls1_get_client_method,
  140. DTLSv1_enc_data)
  141. IMPLEMENT_dtls1_meth_func(DTLS1_2_VERSION,
  142. DTLSv1_2_client_method,
  143. ssl_undefined_function,
  144. dtls1_connect,
  145. dtls1_get_client_method,
  146. DTLSv1_2_enc_data)
  147. IMPLEMENT_dtls1_meth_func(DTLS_ANY_VERSION,
  148. DTLS_client_method,
  149. ssl_undefined_function,
  150. dtls1_connect,
  151. dtls1_get_client_method,
  152. DTLSv1_2_enc_data)
  153. int dtls1_connect(SSL *s)
  154. {
  155. BUF_MEM *buf=NULL;
  156. void (*cb)(const SSL *ssl,int type,int val)=NULL;
  157. int ret= -1;
  158. int new_state,state,skip=0;
  159. ERR_clear_error();
  160. ERR_clear_system_error();
  161. if (s->info_callback != NULL)
  162. cb=s->info_callback;
  163. else if (s->ctx->info_callback != NULL)
  164. cb=s->ctx->info_callback;
  165. s->in_handshake++;
  166. if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
  167. for (;;)
  168. {
  169. state=s->state;
  170. switch(s->state)
  171. {
  172. case SSL_ST_RENEGOTIATE:
  173. s->renegotiate=1;
  174. s->state=SSL_ST_CONNECT;
  175. s->ctx->stats.sess_connect_renegotiate++;
  176. /* break */
  177. case SSL_ST_BEFORE:
  178. case SSL_ST_CONNECT:
  179. case SSL_ST_BEFORE|SSL_ST_CONNECT:
  180. case SSL_ST_OK|SSL_ST_CONNECT:
  181. s->server=0;
  182. if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
  183. if ((s->version & 0xff00 ) != (DTLS1_VERSION & 0xff00))
  184. {
  185. OPENSSL_PUT_ERROR(SSL, dtls1_connect, ERR_R_INTERNAL_ERROR);
  186. ret = -1;
  187. goto end;
  188. }
  189. /* s->version=SSL3_VERSION; */
  190. s->type=SSL_ST_CONNECT;
  191. if (s->init_buf == NULL)
  192. {
  193. if ((buf=BUF_MEM_new()) == NULL)
  194. {
  195. ret= -1;
  196. goto end;
  197. }
  198. if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
  199. {
  200. ret= -1;
  201. goto end;
  202. }
  203. s->init_buf=buf;
  204. buf=NULL;
  205. }
  206. if (!ssl3_setup_buffers(s)) { ret= -1; goto end; }
  207. /* setup buffing BIO */
  208. if (!ssl_init_wbio_buffer(s,0)) { ret= -1; goto end; }
  209. /* don't push the buffering BIO quite yet */
  210. s->state=SSL3_ST_CW_CLNT_HELLO_A;
  211. s->ctx->stats.sess_connect++;
  212. s->init_num=0;
  213. s->d1->send_cookie = 0;
  214. s->hit = 0;
  215. break;
  216. case SSL3_ST_CW_CLNT_HELLO_A:
  217. case SSL3_ST_CW_CLNT_HELLO_B:
  218. s->shutdown=0;
  219. /* every DTLS ClientHello resets Finished MAC */
  220. ssl3_init_finished_mac(s);
  221. dtls1_start_timer(s);
  222. ret=ssl3_send_client_hello(s);
  223. if (ret <= 0) goto end;
  224. if ( s->d1->send_cookie)
  225. {
  226. s->state=SSL3_ST_CW_FLUSH;
  227. s->s3->tmp.next_state=SSL3_ST_CR_SRVR_HELLO_A;
  228. }
  229. else
  230. s->state=DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A;
  231. s->init_num=0;
  232. /* turn on buffering for the next lot of output */
  233. if (s->bbio != s->wbio)
  234. s->wbio=BIO_push(s->bbio,s->wbio);
  235. break;
  236. case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
  237. case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
  238. ret = dtls1_get_hello_verify(s);
  239. if ( ret <= 0)
  240. goto end;
  241. if ( s->d1->send_cookie)
  242. {
  243. /* start again, with a cookie */
  244. dtls1_stop_timer(s);
  245. s->state = SSL3_ST_CW_CLNT_HELLO_A;
  246. }
  247. else
  248. {
  249. s->state = SSL3_ST_CR_SRVR_HELLO_A;
  250. }
  251. s->init_num = 0;
  252. break;
  253. case SSL3_ST_CR_SRVR_HELLO_A:
  254. case SSL3_ST_CR_SRVR_HELLO_B:
  255. ret=ssl3_get_server_hello(s);
  256. if (ret <= 0) goto end;
  257. if (s->hit)
  258. {
  259. s->state=SSL3_ST_CR_FINISHED_A;
  260. if (s->tlsext_ticket_expected)
  261. {
  262. /* receive renewed session ticket */
  263. s->state=SSL3_ST_CR_SESSION_TICKET_A;
  264. }
  265. }
  266. else
  267. {
  268. s->state=SSL3_ST_CR_CERT_A;
  269. }
  270. s->init_num=0;
  271. break;
  272. case SSL3_ST_CR_CERT_A:
  273. case SSL3_ST_CR_CERT_B:
  274. if (ssl_cipher_has_server_public_key(s->s3->tmp.new_cipher))
  275. {
  276. ret=ssl3_get_server_certificate(s);
  277. if (ret <= 0) goto end;
  278. if (s->s3->tmp.certificate_status_expected)
  279. s->state=SSL3_ST_CR_CERT_STATUS_A;
  280. else
  281. s->state=SSL3_ST_CR_KEY_EXCH_A;
  282. }
  283. else
  284. {
  285. skip = 1;
  286. s->state=SSL3_ST_CR_KEY_EXCH_A;
  287. }
  288. s->init_num=0;
  289. break;
  290. case SSL3_ST_CR_KEY_EXCH_A:
  291. case SSL3_ST_CR_KEY_EXCH_B:
  292. ret=ssl3_get_server_key_exchange(s);
  293. if (ret <= 0) goto end;
  294. s->state=SSL3_ST_CR_CERT_REQ_A;
  295. s->init_num=0;
  296. /* at this point we check that we have the
  297. * required stuff from the server */
  298. if (!ssl3_check_cert_and_algorithm(s))
  299. {
  300. ret= -1;
  301. goto end;
  302. }
  303. break;
  304. case SSL3_ST_CR_CERT_REQ_A:
  305. case SSL3_ST_CR_CERT_REQ_B:
  306. ret=ssl3_get_certificate_request(s);
  307. if (ret <= 0) goto end;
  308. s->state=SSL3_ST_CR_SRVR_DONE_A;
  309. s->init_num=0;
  310. break;
  311. case SSL3_ST_CR_SRVR_DONE_A:
  312. case SSL3_ST_CR_SRVR_DONE_B:
  313. ret=ssl3_get_server_done(s);
  314. if (ret <= 0) goto end;
  315. dtls1_stop_timer(s);
  316. if (s->s3->tmp.cert_req)
  317. s->s3->tmp.next_state=SSL3_ST_CW_CERT_A;
  318. else
  319. s->s3->tmp.next_state=SSL3_ST_CW_KEY_EXCH_A;
  320. s->init_num=0;
  321. s->state=s->s3->tmp.next_state;
  322. break;
  323. case SSL3_ST_CW_CERT_A:
  324. case SSL3_ST_CW_CERT_B:
  325. case SSL3_ST_CW_CERT_C:
  326. case SSL3_ST_CW_CERT_D:
  327. dtls1_start_timer(s);
  328. ret=ssl3_send_client_certificate(s);
  329. if (ret <= 0) goto end;
  330. s->state=SSL3_ST_CW_KEY_EXCH_A;
  331. s->init_num=0;
  332. break;
  333. case SSL3_ST_CW_KEY_EXCH_A:
  334. case SSL3_ST_CW_KEY_EXCH_B:
  335. dtls1_start_timer(s);
  336. ret=ssl3_send_client_key_exchange(s);
  337. if (ret <= 0) goto end;
  338. /* For TLS, cert_req is set to 2, so a cert chain
  339. * of nothing is sent, but no verify packet is sent */
  340. if (s->s3->tmp.cert_req == 1)
  341. {
  342. s->state=SSL3_ST_CW_CERT_VRFY_A;
  343. }
  344. else
  345. {
  346. s->state=SSL3_ST_CW_CHANGE_A;
  347. s->s3->change_cipher_spec=0;
  348. }
  349. s->init_num=0;
  350. break;
  351. case SSL3_ST_CW_CERT_VRFY_A:
  352. case SSL3_ST_CW_CERT_VRFY_B:
  353. dtls1_start_timer(s);
  354. ret=ssl3_send_cert_verify(s);
  355. if (ret <= 0) goto end;
  356. s->state=SSL3_ST_CW_CHANGE_A;
  357. s->init_num=0;
  358. s->s3->change_cipher_spec=0;
  359. break;
  360. case SSL3_ST_CW_CHANGE_A:
  361. case SSL3_ST_CW_CHANGE_B:
  362. if (!s->hit)
  363. dtls1_start_timer(s);
  364. ret=dtls1_send_change_cipher_spec(s,
  365. SSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B);
  366. if (ret <= 0) goto end;
  367. s->state=SSL3_ST_CW_FINISHED_A;
  368. s->init_num=0;
  369. s->session->cipher=s->s3->tmp.new_cipher;
  370. if (!s->method->ssl3_enc->setup_key_block(s))
  371. {
  372. ret= -1;
  373. goto end;
  374. }
  375. if (!s->method->ssl3_enc->change_cipher_state(s,
  376. SSL3_CHANGE_CIPHER_CLIENT_WRITE))
  377. {
  378. ret= -1;
  379. goto end;
  380. }
  381. dtls1_reset_seq_numbers(s, SSL3_CC_WRITE);
  382. break;
  383. case SSL3_ST_CW_FINISHED_A:
  384. case SSL3_ST_CW_FINISHED_B:
  385. if (!s->hit)
  386. dtls1_start_timer(s);
  387. ret=ssl3_send_finished(s,
  388. SSL3_ST_CW_FINISHED_A,SSL3_ST_CW_FINISHED_B,
  389. s->method->ssl3_enc->client_finished_label,
  390. s->method->ssl3_enc->client_finished_label_len);
  391. if (ret <= 0) goto end;
  392. s->state=SSL3_ST_CW_FLUSH;
  393. /* clear flags */
  394. s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;
  395. if (s->hit)
  396. {
  397. s->s3->tmp.next_state=SSL_ST_OK;
  398. }
  399. else
  400. {
  401. /* Allow NewSessionTicket if ticket expected */
  402. if (s->tlsext_ticket_expected)
  403. s->s3->tmp.next_state=SSL3_ST_CR_SESSION_TICKET_A;
  404. else
  405. s->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A;
  406. }
  407. s->init_num=0;
  408. break;
  409. case SSL3_ST_CR_SESSION_TICKET_A:
  410. case SSL3_ST_CR_SESSION_TICKET_B:
  411. ret=ssl3_get_new_session_ticket(s);
  412. if (ret <= 0) goto end;
  413. s->state=SSL3_ST_CR_FINISHED_A;
  414. s->init_num=0;
  415. break;
  416. case SSL3_ST_CR_CERT_STATUS_A:
  417. case SSL3_ST_CR_CERT_STATUS_B:
  418. ret=ssl3_get_cert_status(s);
  419. if (ret <= 0) goto end;
  420. s->state=SSL3_ST_CR_KEY_EXCH_A;
  421. s->init_num=0;
  422. break;
  423. case SSL3_ST_CR_FINISHED_A:
  424. case SSL3_ST_CR_FINISHED_B:
  425. s->d1->change_cipher_spec_ok = 1;
  426. ret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A,
  427. SSL3_ST_CR_FINISHED_B);
  428. if (ret <= 0) goto end;
  429. dtls1_stop_timer(s);
  430. if (s->hit)
  431. s->state=SSL3_ST_CW_CHANGE_A;
  432. else
  433. s->state=SSL_ST_OK;
  434. s->init_num=0;
  435. break;
  436. case SSL3_ST_CW_FLUSH:
  437. s->rwstate=SSL_WRITING;
  438. if (BIO_flush(s->wbio) <= 0)
  439. {
  440. /* If the write error was fatal, stop trying */
  441. if (!BIO_should_retry(s->wbio))
  442. {
  443. s->rwstate=SSL_NOTHING;
  444. s->state=s->s3->tmp.next_state;
  445. }
  446. ret= -1;
  447. goto end;
  448. }
  449. s->rwstate=SSL_NOTHING;
  450. s->state=s->s3->tmp.next_state;
  451. break;
  452. case SSL_ST_OK:
  453. /* clean a few things up */
  454. ssl3_cleanup_key_block(s);
  455. #if 0
  456. if (s->init_buf != NULL)
  457. {
  458. BUF_MEM_free(s->init_buf);
  459. s->init_buf=NULL;
  460. }
  461. #endif
  462. /* If we are not 'joining' the last two packets,
  463. * remove the buffering now */
  464. if (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER))
  465. ssl_free_wbio_buffer(s);
  466. /* else do it later in ssl3_write */
  467. s->init_num=0;
  468. s->renegotiate=0;
  469. s->new_session=0;
  470. ssl_update_cache(s,SSL_SESS_CACHE_CLIENT);
  471. if (s->hit) s->ctx->stats.sess_hit++;
  472. ret=1;
  473. /* s->server=0; */
  474. s->handshake_func=dtls1_connect;
  475. s->ctx->stats.sess_connect_good++;
  476. if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);
  477. /* done with handshaking */
  478. s->d1->handshake_read_seq = 0;
  479. s->d1->next_handshake_write_seq = 0;
  480. goto end;
  481. /* break; */
  482. default:
  483. OPENSSL_PUT_ERROR(SSL, dtls1_connect, SSL_R_UNKNOWN_STATE);
  484. ret= -1;
  485. goto end;
  486. /* break; */
  487. }
  488. /* did we do anything */
  489. if (!s->s3->tmp.reuse_message && !skip)
  490. {
  491. if (s->debug)
  492. {
  493. if ((ret=BIO_flush(s->wbio)) <= 0)
  494. goto end;
  495. }
  496. if ((cb != NULL) && (s->state != state))
  497. {
  498. new_state=s->state;
  499. s->state=state;
  500. cb(s,SSL_CB_CONNECT_LOOP,1);
  501. s->state=new_state;
  502. }
  503. }
  504. skip=0;
  505. }
  506. end:
  507. s->in_handshake--;
  508. if (buf != NULL)
  509. BUF_MEM_free(buf);
  510. if (cb != NULL)
  511. cb(s,SSL_CB_CONNECT_EXIT,ret);
  512. return(ret);
  513. }
  514. static int dtls1_get_hello_verify(SSL *s)
  515. {
  516. long n;
  517. int al, ok = 0;
  518. CBS hello_verify_request, cookie;
  519. uint16_t server_version;
  520. s->first_packet = 1;
  521. n=s->method->ssl_get_message(s,
  522. DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A,
  523. DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B,
  524. -1,
  525. /* Use the same maximum size as ssl3_get_server_hello. */
  526. 20000,
  527. SSL_GET_MESSAGE_HASH_MESSAGE,
  528. &ok);
  529. s->first_packet = 0;
  530. if (!ok) return((int)n);
  531. if (s->s3->tmp.message_type != DTLS1_MT_HELLO_VERIFY_REQUEST)
  532. {
  533. s->d1->send_cookie = 0;
  534. s->s3->tmp.reuse_message = 1;
  535. return(1);
  536. }
  537. CBS_init(&hello_verify_request, s->init_msg, n);
  538. if (!CBS_get_u16(&hello_verify_request, &server_version) ||
  539. !CBS_get_u8_length_prefixed(&hello_verify_request, &cookie) ||
  540. CBS_len(&hello_verify_request) != 0)
  541. {
  542. al = SSL_AD_DECODE_ERROR;
  543. OPENSSL_PUT_ERROR(SSL, ssl3_get_cert_status, SSL_R_DECODE_ERROR);
  544. goto f_err;
  545. }
  546. if (CBS_len(&cookie) > sizeof(s->d1->cookie))
  547. {
  548. al=SSL_AD_ILLEGAL_PARAMETER;
  549. goto f_err;
  550. }
  551. memcpy(s->d1->cookie, CBS_data(&cookie), CBS_len(&cookie));
  552. s->d1->cookie_len = CBS_len(&cookie);
  553. s->d1->send_cookie = 1;
  554. return 1;
  555. f_err:
  556. ssl3_send_alert(s, SSL3_AL_FATAL, al);
  557. return -1;
  558. }