You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

638 line
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 || ver == DTLS1_BAD_VER)
  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. (s->version & 0xff00 ) != (DTLS1_BAD_VER & 0xff00))
  185. {
  186. OPENSSL_PUT_ERROR(SSL, dtls1_connect, ERR_R_INTERNAL_ERROR);
  187. ret = -1;
  188. goto end;
  189. }
  190. /* s->version=SSL3_VERSION; */
  191. s->type=SSL_ST_CONNECT;
  192. if (s->init_buf == NULL)
  193. {
  194. if ((buf=BUF_MEM_new()) == NULL)
  195. {
  196. ret= -1;
  197. goto end;
  198. }
  199. if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
  200. {
  201. ret= -1;
  202. goto end;
  203. }
  204. s->init_buf=buf;
  205. buf=NULL;
  206. }
  207. if (!ssl3_setup_buffers(s)) { ret= -1; goto end; }
  208. /* setup buffing BIO */
  209. if (!ssl_init_wbio_buffer(s,0)) { ret= -1; goto end; }
  210. /* don't push the buffering BIO quite yet */
  211. s->state=SSL3_ST_CW_CLNT_HELLO_A;
  212. s->ctx->stats.sess_connect++;
  213. s->init_num=0;
  214. /* mark client_random uninitialized */
  215. memset(s->s3->client_random,0,sizeof(s->s3->client_random));
  216. s->d1->send_cookie = 0;
  217. s->hit = 0;
  218. break;
  219. case SSL3_ST_CW_CLNT_HELLO_A:
  220. case SSL3_ST_CW_CLNT_HELLO_B:
  221. s->shutdown=0;
  222. /* every DTLS ClientHello resets Finished MAC */
  223. ssl3_init_finished_mac(s);
  224. dtls1_start_timer(s);
  225. ret=ssl3_client_hello(s);
  226. if (ret <= 0) goto end;
  227. if ( s->d1->send_cookie)
  228. {
  229. s->state=SSL3_ST_CW_FLUSH;
  230. s->s3->tmp.next_state=SSL3_ST_CR_SRVR_HELLO_A;
  231. }
  232. else
  233. s->state=SSL3_ST_CR_SRVR_HELLO_A;
  234. s->init_num=0;
  235. /* turn on buffering for the next lot of output */
  236. if (s->bbio != s->wbio)
  237. s->wbio=BIO_push(s->bbio,s->wbio);
  238. break;
  239. case SSL3_ST_CR_SRVR_HELLO_A:
  240. case SSL3_ST_CR_SRVR_HELLO_B:
  241. ret=ssl3_get_server_hello(s);
  242. if (ret <= 0) goto end;
  243. else
  244. {
  245. if (s->hit)
  246. {
  247. s->state=SSL3_ST_CR_FINISHED_A;
  248. }
  249. else
  250. s->state=DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A;
  251. }
  252. s->init_num=0;
  253. break;
  254. case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
  255. case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
  256. ret = dtls1_get_hello_verify(s);
  257. if ( ret <= 0)
  258. goto end;
  259. dtls1_stop_timer(s);
  260. if ( s->d1->send_cookie) /* start again, with a cookie */
  261. s->state=SSL3_ST_CW_CLNT_HELLO_A;
  262. else
  263. s->state = SSL3_ST_CR_CERT_A;
  264. s->init_num = 0;
  265. break;
  266. case SSL3_ST_CR_CERT_A:
  267. case SSL3_ST_CR_CERT_B:
  268. /* Check if it is anon DH or PSK */
  269. if (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL) &&
  270. !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK))
  271. {
  272. ret=ssl3_get_server_certificate(s);
  273. if (ret <= 0) goto end;
  274. if (s->tlsext_status_expected)
  275. s->state=SSL3_ST_CR_CERT_STATUS_A;
  276. else
  277. s->state=SSL3_ST_CR_KEY_EXCH_A;
  278. }
  279. else
  280. {
  281. skip = 1;
  282. s->state=SSL3_ST_CR_KEY_EXCH_A;
  283. }
  284. s->init_num=0;
  285. break;
  286. case SSL3_ST_CR_KEY_EXCH_A:
  287. case SSL3_ST_CR_KEY_EXCH_B:
  288. ret=ssl3_get_server_key_exchange(s);
  289. if (ret <= 0) goto end;
  290. s->state=SSL3_ST_CR_CERT_REQ_A;
  291. s->init_num=0;
  292. /* at this point we check that we have the
  293. * required stuff from the server */
  294. if (!ssl3_check_cert_and_algorithm(s))
  295. {
  296. ret= -1;
  297. goto end;
  298. }
  299. break;
  300. case SSL3_ST_CR_CERT_REQ_A:
  301. case SSL3_ST_CR_CERT_REQ_B:
  302. ret=ssl3_get_certificate_request(s);
  303. if (ret <= 0) goto end;
  304. s->state=SSL3_ST_CR_SRVR_DONE_A;
  305. s->init_num=0;
  306. break;
  307. case SSL3_ST_CR_SRVR_DONE_A:
  308. case SSL3_ST_CR_SRVR_DONE_B:
  309. ret=ssl3_get_server_done(s);
  310. if (ret <= 0) goto end;
  311. dtls1_stop_timer(s);
  312. if (s->s3->tmp.cert_req)
  313. s->s3->tmp.next_state=SSL3_ST_CW_CERT_A;
  314. else
  315. s->s3->tmp.next_state=SSL3_ST_CW_KEY_EXCH_A;
  316. s->init_num=0;
  317. s->state=s->s3->tmp.next_state;
  318. break;
  319. case SSL3_ST_CW_CERT_A:
  320. case SSL3_ST_CW_CERT_B:
  321. case SSL3_ST_CW_CERT_C:
  322. case SSL3_ST_CW_CERT_D:
  323. dtls1_start_timer(s);
  324. ret=ssl3_send_client_certificate(s);
  325. if (ret <= 0) goto end;
  326. s->state=SSL3_ST_CW_KEY_EXCH_A;
  327. s->init_num=0;
  328. break;
  329. case SSL3_ST_CW_KEY_EXCH_A:
  330. case SSL3_ST_CW_KEY_EXCH_B:
  331. dtls1_start_timer(s);
  332. ret=ssl3_send_client_key_exchange(s);
  333. if (ret <= 0) goto end;
  334. /* EAY EAY EAY need to check for DH fix cert
  335. * sent back */
  336. /* For TLS, cert_req is set to 2, so a cert chain
  337. * of nothing is sent, but no verify packet is sent */
  338. if (s->s3->tmp.cert_req == 1)
  339. {
  340. s->state=SSL3_ST_CW_CERT_VRFY_A;
  341. }
  342. else
  343. {
  344. s->state=SSL3_ST_CW_CHANGE_A;
  345. s->s3->change_cipher_spec=0;
  346. }
  347. s->init_num=0;
  348. break;
  349. case SSL3_ST_CW_CERT_VRFY_A:
  350. case SSL3_ST_CW_CERT_VRFY_B:
  351. dtls1_start_timer(s);
  352. ret=ssl3_send_client_verify(s);
  353. if (ret <= 0) goto end;
  354. s->state=SSL3_ST_CW_CHANGE_A;
  355. s->init_num=0;
  356. s->s3->change_cipher_spec=0;
  357. break;
  358. case SSL3_ST_CW_CHANGE_A:
  359. case SSL3_ST_CW_CHANGE_B:
  360. if (!s->hit)
  361. dtls1_start_timer(s);
  362. ret=dtls1_send_change_cipher_spec(s,
  363. SSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B);
  364. if (ret <= 0) goto end;
  365. s->state=SSL3_ST_CW_FINISHED_A;
  366. s->init_num=0;
  367. s->session->cipher=s->s3->tmp.new_cipher;
  368. if (!s->method->ssl3_enc->setup_key_block(s))
  369. {
  370. ret= -1;
  371. goto end;
  372. }
  373. if (!s->method->ssl3_enc->change_cipher_state(s,
  374. SSL3_CHANGE_CIPHER_CLIENT_WRITE))
  375. {
  376. ret= -1;
  377. goto end;
  378. }
  379. dtls1_reset_seq_numbers(s, SSL3_CC_WRITE);
  380. break;
  381. case SSL3_ST_CW_FINISHED_A:
  382. case SSL3_ST_CW_FINISHED_B:
  383. if (!s->hit)
  384. dtls1_start_timer(s);
  385. ret=ssl3_send_finished(s,
  386. SSL3_ST_CW_FINISHED_A,SSL3_ST_CW_FINISHED_B,
  387. s->method->ssl3_enc->client_finished_label,
  388. s->method->ssl3_enc->client_finished_label_len);
  389. if (ret <= 0) goto end;
  390. s->state=SSL3_ST_CW_FLUSH;
  391. /* clear flags */
  392. s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;
  393. if (s->hit)
  394. {
  395. s->s3->tmp.next_state=SSL_ST_OK;
  396. }
  397. else
  398. {
  399. /* Allow NewSessionTicket if ticket expected */
  400. if (s->tlsext_ticket_expected)
  401. s->s3->tmp.next_state=SSL3_ST_CR_SESSION_TICKET_A;
  402. else
  403. s->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A;
  404. }
  405. s->init_num=0;
  406. break;
  407. case SSL3_ST_CR_SESSION_TICKET_A:
  408. case SSL3_ST_CR_SESSION_TICKET_B:
  409. ret=ssl3_get_new_session_ticket(s);
  410. if (ret <= 0) goto end;
  411. s->state=SSL3_ST_CR_FINISHED_A;
  412. s->init_num=0;
  413. break;
  414. case SSL3_ST_CR_CERT_STATUS_A:
  415. case SSL3_ST_CR_CERT_STATUS_B:
  416. ret=ssl3_get_cert_status(s);
  417. if (ret <= 0) goto end;
  418. s->state=SSL3_ST_CR_KEY_EXCH_A;
  419. s->init_num=0;
  420. break;
  421. case SSL3_ST_CR_FINISHED_A:
  422. case SSL3_ST_CR_FINISHED_B:
  423. s->d1->change_cipher_spec_ok = 1;
  424. ret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A,
  425. SSL3_ST_CR_FINISHED_B);
  426. if (ret <= 0) goto end;
  427. dtls1_stop_timer(s);
  428. if (s->hit)
  429. s->state=SSL3_ST_CW_CHANGE_A;
  430. else
  431. s->state=SSL_ST_OK;
  432. s->init_num=0;
  433. break;
  434. case SSL3_ST_CW_FLUSH:
  435. s->rwstate=SSL_WRITING;
  436. if (BIO_flush(s->wbio) <= 0)
  437. {
  438. /* If the write error was fatal, stop trying */
  439. if (!BIO_should_retry(s->wbio))
  440. {
  441. s->rwstate=SSL_NOTHING;
  442. s->state=s->s3->tmp.next_state;
  443. }
  444. ret= -1;
  445. goto end;
  446. }
  447. s->rwstate=SSL_NOTHING;
  448. s->state=s->s3->tmp.next_state;
  449. break;
  450. case SSL_ST_OK:
  451. /* clean a few things up */
  452. ssl3_cleanup_key_block(s);
  453. #if 0
  454. if (s->init_buf != NULL)
  455. {
  456. BUF_MEM_free(s->init_buf);
  457. s->init_buf=NULL;
  458. }
  459. #endif
  460. /* If we are not 'joining' the last two packets,
  461. * remove the buffering now */
  462. if (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER))
  463. ssl_free_wbio_buffer(s);
  464. /* else do it later in ssl3_write */
  465. s->init_num=0;
  466. s->renegotiate=0;
  467. s->new_session=0;
  468. ssl_update_cache(s,SSL_SESS_CACHE_CLIENT);
  469. if (s->hit) s->ctx->stats.sess_hit++;
  470. ret=1;
  471. /* s->server=0; */
  472. s->handshake_func=dtls1_connect;
  473. s->ctx->stats.sess_connect_good++;
  474. if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);
  475. /* done with handshaking */
  476. s->d1->handshake_read_seq = 0;
  477. s->d1->next_handshake_write_seq = 0;
  478. goto end;
  479. /* break; */
  480. default:
  481. OPENSSL_PUT_ERROR(SSL, dtls1_connect, SSL_R_UNKNOWN_STATE);
  482. ret= -1;
  483. goto end;
  484. /* break; */
  485. }
  486. /* did we do anything */
  487. if (!s->s3->tmp.reuse_message && !skip)
  488. {
  489. if (s->debug)
  490. {
  491. if ((ret=BIO_flush(s->wbio)) <= 0)
  492. goto end;
  493. }
  494. if ((cb != NULL) && (s->state != state))
  495. {
  496. new_state=s->state;
  497. s->state=state;
  498. cb(s,SSL_CB_CONNECT_LOOP,1);
  499. s->state=new_state;
  500. }
  501. }
  502. skip=0;
  503. }
  504. end:
  505. s->in_handshake--;
  506. if (buf != NULL)
  507. BUF_MEM_free(buf);
  508. if (cb != NULL)
  509. cb(s,SSL_CB_CONNECT_EXIT,ret);
  510. return(ret);
  511. }
  512. static int dtls1_get_hello_verify(SSL *s)
  513. {
  514. int n, al, ok = 0;
  515. unsigned char *data;
  516. unsigned int cookie_len;
  517. s->first_packet = 1;
  518. n=s->method->ssl_get_message(s,
  519. DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A,
  520. DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B,
  521. -1,
  522. s->max_cert_list,
  523. &ok);
  524. s->first_packet = 0;
  525. if (!ok) return((int)n);
  526. if (s->s3->tmp.message_type != DTLS1_MT_HELLO_VERIFY_REQUEST)
  527. {
  528. s->d1->send_cookie = 0;
  529. s->s3->tmp.reuse_message=1;
  530. return(1);
  531. }
  532. data = s->init_msg;
  533. #if 0
  534. if (s->method->version != DTLS_ANY_VERSION &&
  535. ((data[0] != (s->version>>8)) || (data[1] != (s->version&0xff))))
  536. {
  537. OPENSSL_PUT_ERROR(SSL, dtls1_get_hello_verify, SSL_R_WRONG_SSL_VERSION);
  538. s->version=(s->version&0xff00)|data[1];
  539. al = SSL_AD_PROTOCOL_VERSION;
  540. goto f_err;
  541. }
  542. #endif
  543. data+=2;
  544. cookie_len = *(data++);
  545. if ( cookie_len > sizeof(s->d1->cookie))
  546. {
  547. al=SSL_AD_ILLEGAL_PARAMETER;
  548. goto f_err;
  549. }
  550. memcpy(s->d1->cookie, data, cookie_len);
  551. s->d1->cookie_len = cookie_len;
  552. s->d1->send_cookie = 1;
  553. return 1;
  554. f_err:
  555. ssl3_send_alert(s, SSL3_AL_FATAL, al);
  556. return -1;
  557. }