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.
 
 
 
 
 
 

610 regels
19 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 <assert.h>
  115. #include <stdio.h>
  116. #include <openssl/bn.h>
  117. #include <openssl/buf.h>
  118. #include <openssl/dh.h>
  119. #include <openssl/evp.h>
  120. #include <openssl/md5.h>
  121. #include <openssl/obj.h>
  122. #include <openssl/rand.h>
  123. #include <openssl/x509.h>
  124. #include "ssl_locl.h"
  125. static int dtls1_send_hello_verify_request(SSL *s);
  126. int dtls1_accept(SSL *s) {
  127. BUF_MEM *buf = NULL;
  128. void (*cb)(const SSL *ssl, int type, int val) = NULL;
  129. unsigned long alg_a;
  130. int ret = -1;
  131. int new_state, state, skip = 0;
  132. assert(s->handshake_func == dtls1_accept);
  133. assert(s->server);
  134. assert(SSL_IS_DTLS(s));
  135. ERR_clear_error();
  136. ERR_clear_system_error();
  137. if (s->info_callback != NULL) {
  138. cb = s->info_callback;
  139. } else if (s->ctx->info_callback != NULL) {
  140. cb = s->ctx->info_callback;
  141. }
  142. s->in_handshake++;
  143. if (s->cert == NULL) {
  144. OPENSSL_PUT_ERROR(SSL, dtls1_accept, SSL_R_NO_CERTIFICATE_SET);
  145. return -1;
  146. }
  147. for (;;) {
  148. state = s->state;
  149. switch (s->state) {
  150. case SSL_ST_RENEGOTIATE:
  151. s->renegotiate = 1;
  152. /* s->state=SSL_ST_ACCEPT; */
  153. case SSL_ST_ACCEPT:
  154. case SSL_ST_BEFORE | SSL_ST_ACCEPT:
  155. if (cb != NULL) {
  156. cb(s, SSL_CB_HANDSHAKE_START, 1);
  157. }
  158. if (s->init_buf == NULL) {
  159. buf = BUF_MEM_new();
  160. if (buf == NULL || !BUF_MEM_grow(buf, SSL3_RT_MAX_PLAIN_LENGTH)) {
  161. ret = -1;
  162. goto end;
  163. }
  164. s->init_buf = buf;
  165. buf = NULL;
  166. }
  167. if (!ssl3_setup_buffers(s)) {
  168. ret = -1;
  169. goto end;
  170. }
  171. s->init_num = 0;
  172. if (s->state != SSL_ST_RENEGOTIATE) {
  173. if (!ssl_init_wbio_buffer(s, 1)) {
  174. ret = -1;
  175. goto end;
  176. }
  177. if (!ssl3_init_finished_mac(s)) {
  178. OPENSSL_PUT_ERROR(SSL, dtls1_accept, ERR_R_INTERNAL_ERROR);
  179. ret = -1;
  180. goto end;
  181. }
  182. s->state = SSL3_ST_SR_CLNT_HELLO_A;
  183. s->ctx->stats.sess_accept++;
  184. } else {
  185. /* s->state == SSL_ST_RENEGOTIATE, * we will just send a
  186. * HelloRequest */
  187. s->ctx->stats.sess_accept_renegotiate++;
  188. s->state = SSL3_ST_SW_HELLO_REQ_A;
  189. }
  190. break;
  191. case SSL3_ST_SW_HELLO_REQ_A:
  192. case SSL3_ST_SW_HELLO_REQ_B:
  193. s->shutdown = 0;
  194. dtls1_clear_record_buffer(s);
  195. dtls1_start_timer(s);
  196. ret = ssl3_send_hello_request(s);
  197. if (ret <= 0) {
  198. goto end;
  199. }
  200. s->s3->tmp.next_state = SSL3_ST_SR_CLNT_HELLO_A;
  201. s->state = SSL3_ST_SW_FLUSH;
  202. s->init_num = 0;
  203. if (!ssl3_init_finished_mac(s)) {
  204. OPENSSL_PUT_ERROR(SSL, dtls1_accept, ERR_R_INTERNAL_ERROR);
  205. ret = -1;
  206. goto end;
  207. }
  208. break;
  209. case SSL3_ST_SW_HELLO_REQ_C:
  210. s->state = SSL_ST_OK;
  211. break;
  212. case SSL3_ST_SR_CLNT_HELLO_A:
  213. case SSL3_ST_SR_CLNT_HELLO_B:
  214. case SSL3_ST_SR_CLNT_HELLO_C:
  215. case SSL3_ST_SR_CLNT_HELLO_D:
  216. s->shutdown = 0;
  217. ret = ssl3_get_client_hello(s);
  218. if (ret <= 0) {
  219. goto end;
  220. }
  221. dtls1_stop_timer(s);
  222. if (ret == 1 && (SSL_get_options(s) & SSL_OP_COOKIE_EXCHANGE)) {
  223. s->state = DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A;
  224. } else {
  225. s->state = SSL3_ST_SW_SRVR_HELLO_A;
  226. }
  227. s->init_num = 0;
  228. break;
  229. case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:
  230. case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:
  231. ret = dtls1_send_hello_verify_request(s);
  232. if (ret <= 0) {
  233. goto end;
  234. }
  235. s->state = SSL3_ST_SW_FLUSH;
  236. s->s3->tmp.next_state = SSL3_ST_SR_CLNT_HELLO_A;
  237. /* HelloVerifyRequest resets Finished MAC */
  238. if (!ssl3_init_finished_mac(s)) {
  239. OPENSSL_PUT_ERROR(SSL, dtls1_accept, ERR_R_INTERNAL_ERROR);
  240. ret = -1;
  241. goto end;
  242. }
  243. break;
  244. case SSL3_ST_SW_SRVR_HELLO_A:
  245. case SSL3_ST_SW_SRVR_HELLO_B:
  246. s->renegotiate = 2;
  247. dtls1_start_timer(s);
  248. ret = ssl3_send_server_hello(s);
  249. if (ret <= 0) {
  250. goto end;
  251. }
  252. if (s->hit) {
  253. if (s->tlsext_ticket_expected) {
  254. s->state = SSL3_ST_SW_SESSION_TICKET_A;
  255. } else {
  256. s->state = SSL3_ST_SW_CHANGE_A;
  257. }
  258. } else {
  259. s->state = SSL3_ST_SW_CERT_A;
  260. }
  261. s->init_num = 0;
  262. break;
  263. case SSL3_ST_SW_CERT_A:
  264. case SSL3_ST_SW_CERT_B:
  265. /* Check if it is anon DH or normal PSK */
  266. if (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL) &&
  267. !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK)) {
  268. dtls1_start_timer(s);
  269. ret = ssl3_send_server_certificate(s);
  270. if (ret <= 0) {
  271. goto end;
  272. }
  273. if (s->s3->tmp.certificate_status_expected) {
  274. s->state = SSL3_ST_SW_CERT_STATUS_A;
  275. } else {
  276. s->state = SSL3_ST_SW_KEY_EXCH_A;
  277. }
  278. } else {
  279. skip = 1;
  280. s->state = SSL3_ST_SW_KEY_EXCH_A;
  281. }
  282. s->init_num = 0;
  283. break;
  284. case SSL3_ST_SW_KEY_EXCH_A:
  285. case SSL3_ST_SW_KEY_EXCH_B:
  286. alg_a = s->s3->tmp.new_cipher->algorithm_auth;
  287. /* Send a ServerKeyExchange message if:
  288. * - The key exchange is ephemeral or anonymous
  289. * Diffie-Hellman.
  290. * - There is a PSK identity hint.
  291. *
  292. * TODO(davidben): This logic is currently duplicated
  293. * in s3_srvr.c. Fix this. In the meantime, keep them
  294. * in sync. */
  295. if (ssl_cipher_requires_server_key_exchange(s->s3->tmp.new_cipher) ||
  296. ((alg_a & SSL_aPSK) && s->psk_identity_hint)) {
  297. dtls1_start_timer(s);
  298. ret = ssl3_send_server_key_exchange(s);
  299. if (ret <= 0) {
  300. goto end;
  301. }
  302. } else {
  303. skip = 1;
  304. }
  305. s->state = SSL3_ST_SW_CERT_REQ_A;
  306. s->init_num = 0;
  307. break;
  308. case SSL3_ST_SW_CERT_REQ_A:
  309. case SSL3_ST_SW_CERT_REQ_B:
  310. if (/* don't request cert unless asked for it: */
  311. !(s->verify_mode & SSL_VERIFY_PEER) ||
  312. /* if SSL_VERIFY_CLIENT_ONCE is set,
  313. * don't request cert during re-negotiation: */
  314. ((s->session->peer != NULL) &&
  315. (s->verify_mode & SSL_VERIFY_CLIENT_ONCE)) ||
  316. /* never request cert in anonymous ciphersuites
  317. * (see section "Certificate request" in SSL 3 drafts
  318. * and in RFC 2246): */
  319. ((s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL) &&
  320. /* ... except when the application insists on verification
  321. * (against the specs, but s3_clnt.c accepts this for SSL 3) */
  322. !(s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) ||
  323. /* With normal PSK Certificates and
  324. * Certificate Requests are omitted */
  325. (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK)) {
  326. /* no cert request */
  327. skip = 1;
  328. s->s3->tmp.cert_request = 0;
  329. s->state = SSL3_ST_SW_SRVR_DONE_A;
  330. } else {
  331. s->s3->tmp.cert_request = 1;
  332. dtls1_start_timer(s);
  333. ret = ssl3_send_certificate_request(s);
  334. if (ret <= 0) {
  335. goto end;
  336. }
  337. #ifndef NETSCAPE_HANG_BUG
  338. s->state = SSL3_ST_SW_SRVR_DONE_A;
  339. #else
  340. s->state = SSL3_ST_SW_FLUSH;
  341. s->s3->tmp.next_state = SSL3_ST_SR_CERT_A;
  342. #endif
  343. s->init_num = 0;
  344. }
  345. break;
  346. case SSL3_ST_SW_SRVR_DONE_A:
  347. case SSL3_ST_SW_SRVR_DONE_B:
  348. dtls1_start_timer(s);
  349. ret = ssl3_send_server_done(s);
  350. if (ret <= 0) {
  351. goto end;
  352. }
  353. s->s3->tmp.next_state = SSL3_ST_SR_CERT_A;
  354. s->state = SSL3_ST_SW_FLUSH;
  355. s->init_num = 0;
  356. break;
  357. case SSL3_ST_SW_FLUSH:
  358. s->rwstate = SSL_WRITING;
  359. if (BIO_flush(s->wbio) <= 0) {
  360. /* If the write error was fatal, stop trying */
  361. if (!BIO_should_retry(s->wbio)) {
  362. s->rwstate = SSL_NOTHING;
  363. s->state = s->s3->tmp.next_state;
  364. }
  365. ret = -1;
  366. goto end;
  367. }
  368. s->rwstate = SSL_NOTHING;
  369. s->state = s->s3->tmp.next_state;
  370. break;
  371. case SSL3_ST_SR_CERT_A:
  372. case SSL3_ST_SR_CERT_B:
  373. if (s->s3->tmp.cert_request) {
  374. ret = ssl3_get_client_certificate(s);
  375. if (ret <= 0) {
  376. goto end;
  377. }
  378. }
  379. s->init_num = 0;
  380. s->state = SSL3_ST_SR_KEY_EXCH_A;
  381. break;
  382. case SSL3_ST_SR_KEY_EXCH_A:
  383. case SSL3_ST_SR_KEY_EXCH_B:
  384. ret = ssl3_get_client_key_exchange(s);
  385. if (ret <= 0) {
  386. goto end;
  387. }
  388. s->state = SSL3_ST_SR_CERT_VRFY_A;
  389. s->init_num = 0;
  390. break;
  391. case SSL3_ST_SR_CERT_VRFY_A:
  392. case SSL3_ST_SR_CERT_VRFY_B:
  393. s->d1->change_cipher_spec_ok = 1;
  394. /* we should decide if we expected this one */
  395. ret = ssl3_get_cert_verify(s);
  396. if (ret <= 0) {
  397. goto end;
  398. }
  399. s->state = SSL3_ST_SR_FINISHED_A;
  400. s->init_num = 0;
  401. break;
  402. case SSL3_ST_SR_FINISHED_A:
  403. case SSL3_ST_SR_FINISHED_B:
  404. s->d1->change_cipher_spec_ok = 1;
  405. ret =
  406. ssl3_get_finished(s, SSL3_ST_SR_FINISHED_A, SSL3_ST_SR_FINISHED_B);
  407. if (ret <= 0) {
  408. goto end;
  409. }
  410. dtls1_stop_timer(s);
  411. if (s->hit) {
  412. s->state = SSL_ST_OK;
  413. } else if (s->tlsext_ticket_expected) {
  414. s->state = SSL3_ST_SW_SESSION_TICKET_A;
  415. } else {
  416. s->state = SSL3_ST_SW_CHANGE_A;
  417. }
  418. s->init_num = 0;
  419. break;
  420. case SSL3_ST_SW_SESSION_TICKET_A:
  421. case SSL3_ST_SW_SESSION_TICKET_B:
  422. ret = ssl3_send_new_session_ticket(s);
  423. if (ret <= 0) {
  424. goto end;
  425. }
  426. s->state = SSL3_ST_SW_CHANGE_A;
  427. s->init_num = 0;
  428. break;
  429. case SSL3_ST_SW_CHANGE_A:
  430. case SSL3_ST_SW_CHANGE_B:
  431. s->session->cipher = s->s3->tmp.new_cipher;
  432. if (!s->enc_method->setup_key_block(s)) {
  433. ret = -1;
  434. goto end;
  435. }
  436. ret = dtls1_send_change_cipher_spec(s, SSL3_ST_SW_CHANGE_A,
  437. SSL3_ST_SW_CHANGE_B);
  438. if (ret <= 0) {
  439. goto end;
  440. }
  441. s->state = SSL3_ST_SW_FINISHED_A;
  442. s->init_num = 0;
  443. if (!s->enc_method->change_cipher_state(
  444. s, SSL3_CHANGE_CIPHER_SERVER_WRITE)) {
  445. ret = -1;
  446. goto end;
  447. }
  448. dtls1_reset_seq_numbers(s, SSL3_CC_WRITE);
  449. break;
  450. case SSL3_ST_SW_FINISHED_A:
  451. case SSL3_ST_SW_FINISHED_B:
  452. ret =
  453. ssl3_send_finished(s, SSL3_ST_SW_FINISHED_A, SSL3_ST_SW_FINISHED_B,
  454. s->enc_method->server_finished_label,
  455. s->enc_method->server_finished_label_len);
  456. if (ret <= 0) {
  457. goto end;
  458. }
  459. s->state = SSL3_ST_SW_FLUSH;
  460. if (s->hit) {
  461. s->s3->tmp.next_state = SSL3_ST_SR_FINISHED_A;
  462. } else {
  463. s->s3->tmp.next_state = SSL_ST_OK;
  464. }
  465. s->init_num = 0;
  466. break;
  467. case SSL_ST_OK:
  468. ssl3_cleanup_key_block(s);
  469. /* remove buffering on output */
  470. ssl_free_wbio_buffer(s);
  471. s->init_num = 0;
  472. if (s->renegotiate == 2) {
  473. /* skipped if we just sent a HelloRequest */
  474. s->renegotiate = 0;
  475. s->new_session = 0;
  476. ssl_update_cache(s, SSL_SESS_CACHE_SERVER);
  477. s->ctx->stats.sess_accept_good++;
  478. if (cb != NULL) {
  479. cb(s, SSL_CB_HANDSHAKE_DONE, 1);
  480. }
  481. }
  482. ret = 1;
  483. /* done handshaking, next message is client hello */
  484. s->d1->handshake_read_seq = 0;
  485. /* next message is server hello */
  486. s->d1->handshake_write_seq = 0;
  487. s->d1->next_handshake_write_seq = 0;
  488. goto end;
  489. default:
  490. OPENSSL_PUT_ERROR(SSL, dtls1_accept, SSL_R_UNKNOWN_STATE);
  491. ret = -1;
  492. goto end;
  493. }
  494. if (!s->s3->tmp.reuse_message && !skip) {
  495. if (cb != NULL && s->state != state) {
  496. new_state = s->state;
  497. s->state = state;
  498. cb(s, SSL_CB_ACCEPT_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. }
  509. if (cb != NULL) {
  510. cb(s, SSL_CB_ACCEPT_EXIT, ret);
  511. }
  512. return ret;
  513. }
  514. int dtls1_send_hello_verify_request(SSL *s) {
  515. uint8_t *msg, *p;
  516. if (s->state == DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A) {
  517. msg = p = ssl_handshake_start(s);
  518. /* Always use DTLS 1.0 version: see RFC 6347 */
  519. *(p++) = DTLS1_VERSION >> 8;
  520. *(p++) = DTLS1_VERSION & 0xFF;
  521. /* Inform the callback how much space is in the
  522. * cookie's buffer. */
  523. s->d1->cookie_len = sizeof(s->d1->cookie);
  524. if (s->ctx->app_gen_cookie_cb == NULL ||
  525. s->ctx->app_gen_cookie_cb(s, s->d1->cookie, &(s->d1->cookie_len)) ==
  526. 0) {
  527. OPENSSL_PUT_ERROR(SSL, dtls1_send_hello_verify_request,
  528. ERR_R_INTERNAL_ERROR);
  529. return 0;
  530. }
  531. *(p++) = (uint8_t)s->d1->cookie_len;
  532. memcpy(p, s->d1->cookie, s->d1->cookie_len);
  533. p += s->d1->cookie_len;
  534. ssl_set_handshake_header(s, DTLS1_MT_HELLO_VERIFY_REQUEST, p - msg);
  535. s->state = DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B;
  536. }
  537. /* s->state = DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B */
  538. return ssl_do_write(s);
  539. }