cyassl.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2014, Daniel Stenberg, <[email protected]>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at http://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. /*
  23. * Source file for all CyaSSL-specific code for the TLS/SSL layer. No code
  24. * but vtls.c should ever call or use these functions.
  25. *
  26. */
  27. #include "curl_setup.h"
  28. #ifdef USE_CYASSL
  29. #ifdef HAVE_LIMITS_H
  30. #include <limits.h>
  31. #endif
  32. #include "urldata.h"
  33. #include "sendf.h"
  34. #include "inet_pton.h"
  35. #include "cyassl.h"
  36. #include "vtls.h"
  37. #include "parsedate.h"
  38. #include "connect.h" /* for the connect timeout */
  39. #include "select.h"
  40. #include "rawstr.h"
  41. #define _MPRINTF_REPLACE /* use our functions only */
  42. #include <curl/mprintf.h>
  43. #include "curl_memory.h"
  44. #include <cyassl/ssl.h>
  45. #ifdef HAVE_CYASSL_ERROR_SSL_H
  46. #include <cyassl/error-ssl.h>
  47. #else
  48. #include <cyassl/error.h>
  49. #endif
  50. #include <cyassl/ctaocrypt/random.h>
  51. /* The last #include file should be: */
  52. #include "memdebug.h"
  53. static Curl_recv cyassl_recv;
  54. static Curl_send cyassl_send;
  55. static int do_file_type(const char *type)
  56. {
  57. if(!type || !type[0])
  58. return SSL_FILETYPE_PEM;
  59. if(Curl_raw_equal(type, "PEM"))
  60. return SSL_FILETYPE_PEM;
  61. if(Curl_raw_equal(type, "DER"))
  62. return SSL_FILETYPE_ASN1;
  63. return -1;
  64. }
  65. /*
  66. * This function loads all the client/CA certificates and CRLs. Setup the TLS
  67. * layer and do all necessary magic.
  68. */
  69. static CURLcode
  70. cyassl_connect_step1(struct connectdata *conn,
  71. int sockindex)
  72. {
  73. struct SessionHandle *data = conn->data;
  74. struct ssl_connect_data* conssl = &conn->ssl[sockindex];
  75. SSL_METHOD* req_method = NULL;
  76. void* ssl_sessionid = NULL;
  77. curl_socket_t sockfd = conn->sock[sockindex];
  78. if(conssl->state == ssl_connection_complete)
  79. return CURLE_OK;
  80. /* CyaSSL doesn't support SSLv2 */
  81. if(data->set.ssl.version == CURL_SSLVERSION_SSLv2) {
  82. failf(data, "CyaSSL does not support SSLv2");
  83. return CURLE_SSL_CONNECT_ERROR;
  84. }
  85. /* check to see if we've been told to use an explicit SSL/TLS version */
  86. switch(data->set.ssl.version) {
  87. case CURL_SSLVERSION_DEFAULT:
  88. /* we try to figure out version */
  89. req_method = SSLv23_client_method();
  90. break;
  91. case CURL_SSLVERSION_TLSv1:
  92. infof(data, "CyaSSL cannot be configured to use TLS 1.0-1.2, "
  93. "TLS 1.0 is used exclusively\n");
  94. req_method = TLSv1_client_method();
  95. break;
  96. case CURL_SSLVERSION_TLSv1_0:
  97. req_method = TLSv1_client_method();
  98. break;
  99. case CURL_SSLVERSION_TLSv1_1:
  100. req_method = TLSv1_1_client_method();
  101. break;
  102. case CURL_SSLVERSION_TLSv1_2:
  103. req_method = TLSv1_2_client_method();
  104. break;
  105. case CURL_SSLVERSION_SSLv3:
  106. req_method = SSLv3_client_method();
  107. break;
  108. default:
  109. req_method = TLSv1_client_method();
  110. }
  111. if(!req_method) {
  112. failf(data, "SSL: couldn't create a method!");
  113. return CURLE_OUT_OF_MEMORY;
  114. }
  115. if(conssl->ctx)
  116. SSL_CTX_free(conssl->ctx);
  117. conssl->ctx = SSL_CTX_new(req_method);
  118. if(!conssl->ctx) {
  119. failf(data, "SSL: couldn't create a context!");
  120. return CURLE_OUT_OF_MEMORY;
  121. }
  122. #ifndef NO_FILESYSTEM
  123. /* load trusted cacert */
  124. if(data->set.str[STRING_SSL_CAFILE]) {
  125. if(!SSL_CTX_load_verify_locations(conssl->ctx,
  126. data->set.str[STRING_SSL_CAFILE],
  127. data->set.str[STRING_SSL_CAPATH])) {
  128. if(data->set.ssl.verifypeer) {
  129. /* Fail if we insist on successfully verifying the server. */
  130. failf(data,"error setting certificate verify locations:\n"
  131. " CAfile: %s\n CApath: %s",
  132. data->set.str[STRING_SSL_CAFILE]?
  133. data->set.str[STRING_SSL_CAFILE]: "none",
  134. data->set.str[STRING_SSL_CAPATH]?
  135. data->set.str[STRING_SSL_CAPATH] : "none");
  136. return CURLE_SSL_CACERT_BADFILE;
  137. }
  138. else {
  139. /* Just continue with a warning if no strict certificate
  140. verification is required. */
  141. infof(data, "error setting certificate verify locations,"
  142. " continuing anyway:\n");
  143. }
  144. }
  145. else {
  146. /* Everything is fine. */
  147. infof(data, "successfully set certificate verify locations:\n");
  148. }
  149. infof(data,
  150. " CAfile: %s\n"
  151. " CApath: %s\n",
  152. data->set.str[STRING_SSL_CAFILE] ? data->set.str[STRING_SSL_CAFILE]:
  153. "none",
  154. data->set.str[STRING_SSL_CAPATH] ? data->set.str[STRING_SSL_CAPATH]:
  155. "none");
  156. }
  157. /* Load the client certificate, and private key */
  158. if(data->set.str[STRING_CERT] && data->set.str[STRING_KEY]) {
  159. int file_type = do_file_type(data->set.str[STRING_CERT_TYPE]);
  160. if(SSL_CTX_use_certificate_file(conssl->ctx, data->set.str[STRING_CERT],
  161. file_type) != 1) {
  162. failf(data, "unable to use client certificate (no key or wrong pass"
  163. " phrase?)");
  164. return CURLE_SSL_CONNECT_ERROR;
  165. }
  166. file_type = do_file_type(data->set.str[STRING_KEY_TYPE]);
  167. if(SSL_CTX_use_PrivateKey_file(conssl->ctx, data->set.str[STRING_KEY],
  168. file_type) != 1) {
  169. failf(data, "unable to set private key");
  170. return CURLE_SSL_CONNECT_ERROR;
  171. }
  172. }
  173. #else
  174. if(CyaSSL_no_filesystem_verify(conssl->ctx)!= SSL_SUCCESS) {
  175. return CURLE_SSL_CONNECT_ERROR;
  176. }
  177. #endif /* NO_FILESYSTEM */
  178. /* SSL always tries to verify the peer, this only says whether it should
  179. * fail to connect if the verification fails, or if it should continue
  180. * anyway. In the latter case the result of the verification is checked with
  181. * SSL_get_verify_result() below. */
  182. SSL_CTX_set_verify(conssl->ctx,
  183. data->set.ssl.verifypeer?SSL_VERIFY_PEER:SSL_VERIFY_NONE,
  184. NULL);
  185. /* Let's make an SSL structure */
  186. if(conssl->handle)
  187. SSL_free(conssl->handle);
  188. conssl->handle = SSL_new(conssl->ctx);
  189. if(!conssl->handle) {
  190. failf(data, "SSL: couldn't create a context (handle)!");
  191. return CURLE_OUT_OF_MEMORY;
  192. }
  193. /* Check if there's a cached ID we can/should use here! */
  194. if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL)) {
  195. /* we got a session id, use it! */
  196. if(!SSL_set_session(conssl->handle, ssl_sessionid)) {
  197. failf(data, "SSL: SSL_set_session failed: %s",
  198. ERR_error_string(SSL_get_error(conssl->handle, 0),NULL));
  199. return CURLE_SSL_CONNECT_ERROR;
  200. }
  201. /* Informational message */
  202. infof (data, "SSL re-using session ID\n");
  203. }
  204. /* pass the raw socket into the SSL layer */
  205. if(!SSL_set_fd(conssl->handle, (int)sockfd)) {
  206. failf(data, "SSL: SSL_set_fd failed");
  207. return CURLE_SSL_CONNECT_ERROR;
  208. }
  209. conssl->connecting_state = ssl_connect_2;
  210. return CURLE_OK;
  211. }
  212. static CURLcode
  213. cyassl_connect_step2(struct connectdata *conn,
  214. int sockindex)
  215. {
  216. int ret = -1;
  217. struct SessionHandle *data = conn->data;
  218. struct ssl_connect_data* conssl = &conn->ssl[sockindex];
  219. infof(data, "CyaSSL: Connecting to %s:%d\n",
  220. conn->host.name, conn->remote_port);
  221. conn->recv[sockindex] = cyassl_recv;
  222. conn->send[sockindex] = cyassl_send;
  223. /* Enable RFC2818 checks */
  224. if(data->set.ssl.verifyhost) {
  225. ret = CyaSSL_check_domain_name(conssl->handle, conn->host.name);
  226. if(ret == SSL_FAILURE)
  227. return CURLE_OUT_OF_MEMORY;
  228. }
  229. ret = SSL_connect(conssl->handle);
  230. if(ret != 1) {
  231. char error_buffer[80];
  232. int detail = SSL_get_error(conssl->handle, ret);
  233. if(SSL_ERROR_WANT_READ == detail) {
  234. conssl->connecting_state = ssl_connect_2_reading;
  235. return CURLE_OK;
  236. }
  237. else if(SSL_ERROR_WANT_WRITE == detail) {
  238. conssl->connecting_state = ssl_connect_2_writing;
  239. return CURLE_OK;
  240. }
  241. /* There is no easy way to override only the CN matching.
  242. * This will enable the override of both mismatching SubjectAltNames
  243. * as also mismatching CN fields */
  244. else if(DOMAIN_NAME_MISMATCH == detail) {
  245. #if 1
  246. failf(data, "\tsubject alt name(s) or common name do not match \"%s\"\n",
  247. conn->host.dispname);
  248. return CURLE_PEER_FAILED_VERIFICATION;
  249. #else
  250. /* When the CyaSSL_check_domain_name() is used and you desire to continue
  251. * on a DOMAIN_NAME_MISMATCH, i.e. 'data->set.ssl.verifyhost == 0',
  252. * CyaSSL version 2.4.0 will fail with an INCOMPLETE_DATA error. The only
  253. * way to do this is currently to switch the CyaSSL_check_domain_name()
  254. * in and out based on the 'data->set.ssl.verifyhost' value. */
  255. if(data->set.ssl.verifyhost) {
  256. failf(data,
  257. "\tsubject alt name(s) or common name do not match \"%s\"\n",
  258. conn->host.dispname);
  259. return CURLE_PEER_FAILED_VERIFICATION;
  260. }
  261. else {
  262. infof(data,
  263. "\tsubject alt name(s) and/or common name do not match \"%s\"\n",
  264. conn->host.dispname);
  265. return CURLE_OK;
  266. }
  267. #endif
  268. }
  269. #if LIBCYASSL_VERSION_HEX >= 0x02007000 /* 2.7.0 */
  270. else if(ASN_NO_SIGNER_E == detail) {
  271. if(data->set.ssl.verifypeer) {
  272. failf(data, "\tCA signer not available for verification\n");
  273. return CURLE_SSL_CACERT_BADFILE;
  274. }
  275. else {
  276. /* Just continue with a warning if no strict certificate
  277. verification is required. */
  278. infof(data, "CA signer not available for verification, "
  279. "continuing anyway\n");
  280. }
  281. }
  282. #endif
  283. else {
  284. failf(data, "SSL_connect failed with error %d: %s", detail,
  285. ERR_error_string(detail, error_buffer));
  286. return CURLE_SSL_CONNECT_ERROR;
  287. }
  288. }
  289. conssl->connecting_state = ssl_connect_3;
  290. infof(data, "SSL connected\n");
  291. return CURLE_OK;
  292. }
  293. static CURLcode
  294. cyassl_connect_step3(struct connectdata *conn,
  295. int sockindex)
  296. {
  297. CURLcode retcode = CURLE_OK;
  298. void *old_ssl_sessionid=NULL;
  299. struct SessionHandle *data = conn->data;
  300. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  301. int incache;
  302. SSL_SESSION *our_ssl_sessionid;
  303. DEBUGASSERT(ssl_connect_3 == connssl->connecting_state);
  304. our_ssl_sessionid = SSL_get_session(connssl->handle);
  305. incache = !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL));
  306. if(incache) {
  307. if(old_ssl_sessionid != our_ssl_sessionid) {
  308. infof(data, "old SSL session ID is stale, removing\n");
  309. Curl_ssl_delsessionid(conn, old_ssl_sessionid);
  310. incache = FALSE;
  311. }
  312. }
  313. if(!incache) {
  314. retcode = Curl_ssl_addsessionid(conn, our_ssl_sessionid,
  315. 0 /* unknown size */);
  316. if(retcode) {
  317. failf(data, "failed to store ssl session");
  318. return retcode;
  319. }
  320. }
  321. connssl->connecting_state = ssl_connect_done;
  322. return retcode;
  323. }
  324. static ssize_t cyassl_send(struct connectdata *conn,
  325. int sockindex,
  326. const void *mem,
  327. size_t len,
  328. CURLcode *curlcode)
  329. {
  330. char error_buffer[80];
  331. int memlen = (len > (size_t)INT_MAX) ? INT_MAX : (int)len;
  332. int rc = SSL_write(conn->ssl[sockindex].handle, mem, memlen);
  333. if(rc < 0) {
  334. int err = SSL_get_error(conn->ssl[sockindex].handle, rc);
  335. switch(err) {
  336. case SSL_ERROR_WANT_READ:
  337. case SSL_ERROR_WANT_WRITE:
  338. /* there's data pending, re-invoke SSL_write() */
  339. *curlcode = CURLE_AGAIN;
  340. return -1;
  341. default:
  342. failf(conn->data, "SSL write: %s, errno %d",
  343. ERR_error_string(err, error_buffer),
  344. SOCKERRNO);
  345. *curlcode = CURLE_SEND_ERROR;
  346. return -1;
  347. }
  348. }
  349. return rc;
  350. }
  351. void Curl_cyassl_close_all(struct SessionHandle *data)
  352. {
  353. (void)data;
  354. }
  355. void Curl_cyassl_close(struct connectdata *conn, int sockindex)
  356. {
  357. struct ssl_connect_data *conssl = &conn->ssl[sockindex];
  358. if(conssl->handle) {
  359. (void)SSL_shutdown(conssl->handle);
  360. SSL_free (conssl->handle);
  361. conssl->handle = NULL;
  362. }
  363. if(conssl->ctx) {
  364. SSL_CTX_free (conssl->ctx);
  365. conssl->ctx = NULL;
  366. }
  367. }
  368. static ssize_t cyassl_recv(struct connectdata *conn,
  369. int num,
  370. char *buf,
  371. size_t buffersize,
  372. CURLcode *curlcode)
  373. {
  374. char error_buffer[80];
  375. int buffsize = (buffersize > (size_t)INT_MAX) ? INT_MAX : (int)buffersize;
  376. int nread = SSL_read(conn->ssl[num].handle, buf, buffsize);
  377. if(nread < 0) {
  378. int err = SSL_get_error(conn->ssl[num].handle, nread);
  379. switch(err) {
  380. case SSL_ERROR_ZERO_RETURN: /* no more data */
  381. break;
  382. case SSL_ERROR_WANT_READ:
  383. case SSL_ERROR_WANT_WRITE:
  384. /* there's data pending, re-invoke SSL_read() */
  385. *curlcode = CURLE_AGAIN;
  386. return -1;
  387. default:
  388. failf(conn->data, "SSL read: %s, errno %d",
  389. ERR_error_string(err, error_buffer),
  390. SOCKERRNO);
  391. *curlcode = CURLE_RECV_ERROR;
  392. return -1;
  393. }
  394. }
  395. return nread;
  396. }
  397. void Curl_cyassl_session_free(void *ptr)
  398. {
  399. (void)ptr;
  400. /* CyaSSL reuses sessions on own, no free */
  401. }
  402. size_t Curl_cyassl_version(char *buffer, size_t size)
  403. {
  404. #ifdef CYASSL_VERSION
  405. return snprintf(buffer, size, "CyaSSL/%s", CYASSL_VERSION);
  406. #else
  407. return snprintf(buffer, size, "CyaSSL/%s", "<1.8.8");
  408. #endif
  409. }
  410. int Curl_cyassl_init(void)
  411. {
  412. if(CyaSSL_Init() == 0)
  413. return 1;
  414. return -1;
  415. }
  416. bool Curl_cyassl_data_pending(const struct connectdata* conn, int connindex)
  417. {
  418. if(conn->ssl[connindex].handle) /* SSL is in use */
  419. return (0 != SSL_pending(conn->ssl[connindex].handle)) ? TRUE : FALSE;
  420. else
  421. return FALSE;
  422. }
  423. /*
  424. * This function is called to shut down the SSL layer but keep the
  425. * socket open (CCC - Clear Command Channel)
  426. */
  427. int Curl_cyassl_shutdown(struct connectdata *conn, int sockindex)
  428. {
  429. int retval = 0;
  430. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  431. if(connssl->handle) {
  432. SSL_free (connssl->handle);
  433. connssl->handle = NULL;
  434. }
  435. return retval;
  436. }
  437. static CURLcode
  438. cyassl_connect_common(struct connectdata *conn,
  439. int sockindex,
  440. bool nonblocking,
  441. bool *done)
  442. {
  443. CURLcode retcode;
  444. struct SessionHandle *data = conn->data;
  445. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  446. curl_socket_t sockfd = conn->sock[sockindex];
  447. long timeout_ms;
  448. int what;
  449. /* check if the connection has already been established */
  450. if(ssl_connection_complete == connssl->state) {
  451. *done = TRUE;
  452. return CURLE_OK;
  453. }
  454. if(ssl_connect_1==connssl->connecting_state) {
  455. /* Find out how much more time we're allowed */
  456. timeout_ms = Curl_timeleft(data, NULL, TRUE);
  457. if(timeout_ms < 0) {
  458. /* no need to continue if time already is up */
  459. failf(data, "SSL connection timeout");
  460. return CURLE_OPERATION_TIMEDOUT;
  461. }
  462. retcode = cyassl_connect_step1(conn, sockindex);
  463. if(retcode)
  464. return retcode;
  465. }
  466. while(ssl_connect_2 == connssl->connecting_state ||
  467. ssl_connect_2_reading == connssl->connecting_state ||
  468. ssl_connect_2_writing == connssl->connecting_state) {
  469. /* check allowed time left */
  470. timeout_ms = Curl_timeleft(data, NULL, TRUE);
  471. if(timeout_ms < 0) {
  472. /* no need to continue if time already is up */
  473. failf(data, "SSL connection timeout");
  474. return CURLE_OPERATION_TIMEDOUT;
  475. }
  476. /* if ssl is expecting something, check if it's available. */
  477. if(connssl->connecting_state == ssl_connect_2_reading
  478. || connssl->connecting_state == ssl_connect_2_writing) {
  479. curl_socket_t writefd = ssl_connect_2_writing==
  480. connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
  481. curl_socket_t readfd = ssl_connect_2_reading==
  482. connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
  483. what = Curl_socket_ready(readfd, writefd, nonblocking?0:timeout_ms);
  484. if(what < 0) {
  485. /* fatal error */
  486. failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
  487. return CURLE_SSL_CONNECT_ERROR;
  488. }
  489. else if(0 == what) {
  490. if(nonblocking) {
  491. *done = FALSE;
  492. return CURLE_OK;
  493. }
  494. else {
  495. /* timeout */
  496. failf(data, "SSL connection timeout");
  497. return CURLE_OPERATION_TIMEDOUT;
  498. }
  499. }
  500. /* socket is readable or writable */
  501. }
  502. /* Run transaction, and return to the caller if it failed or if
  503. * this connection is part of a multi handle and this loop would
  504. * execute again. This permits the owner of a multi handle to
  505. * abort a connection attempt before step2 has completed while
  506. * ensuring that a client using select() or epoll() will always
  507. * have a valid fdset to wait on.
  508. */
  509. retcode = cyassl_connect_step2(conn, sockindex);
  510. if(retcode || (nonblocking &&
  511. (ssl_connect_2 == connssl->connecting_state ||
  512. ssl_connect_2_reading == connssl->connecting_state ||
  513. ssl_connect_2_writing == connssl->connecting_state)))
  514. return retcode;
  515. } /* repeat step2 until all transactions are done. */
  516. if(ssl_connect_3==connssl->connecting_state) {
  517. retcode = cyassl_connect_step3(conn, sockindex);
  518. if(retcode)
  519. return retcode;
  520. }
  521. if(ssl_connect_done==connssl->connecting_state) {
  522. connssl->state = ssl_connection_complete;
  523. conn->recv[sockindex] = cyassl_recv;
  524. conn->send[sockindex] = cyassl_send;
  525. *done = TRUE;
  526. }
  527. else
  528. *done = FALSE;
  529. /* Reset our connect state machine */
  530. connssl->connecting_state = ssl_connect_1;
  531. return CURLE_OK;
  532. }
  533. CURLcode
  534. Curl_cyassl_connect_nonblocking(struct connectdata *conn,
  535. int sockindex,
  536. bool *done)
  537. {
  538. return cyassl_connect_common(conn, sockindex, TRUE, done);
  539. }
  540. CURLcode
  541. Curl_cyassl_connect(struct connectdata *conn,
  542. int sockindex)
  543. {
  544. CURLcode retcode;
  545. bool done = FALSE;
  546. retcode = cyassl_connect_common(conn, sockindex, FALSE, &done);
  547. if(retcode)
  548. return retcode;
  549. DEBUGASSERT(done);
  550. return CURLE_OK;
  551. }
  552. int Curl_cyassl_random(struct SessionHandle *data,
  553. unsigned char *entropy,
  554. size_t length)
  555. {
  556. RNG rng;
  557. (void)data;
  558. if(InitRng(&rng))
  559. return 1;
  560. if(RNG_GenerateBlock(&rng, entropy, length))
  561. return 1;
  562. return 0;
  563. }
  564. #endif