mesalink.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 2017 - 2018, Yiming Jing, <[email protected]>
  9. * Copyright (C) 1998 - 2021, Daniel Stenberg, <[email protected]>, et al.
  10. *
  11. * This software is licensed as described in the file COPYING, which
  12. * you should have received as part of this distribution. The terms
  13. * are also available at https://curl.se/docs/copyright.html.
  14. *
  15. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. * copies of the Software, and permit persons to whom the Software is
  17. * furnished to do so, under the terms of the COPYING file.
  18. *
  19. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. * KIND, either express or implied.
  21. *
  22. ***************************************************************************/
  23. /*
  24. * Source file for all MesaLink-specific code for the TLS/SSL layer. No code
  25. * but vtls.c should ever call or use these functions.
  26. *
  27. */
  28. /*
  29. * Based upon the CyaSSL implementation in cyassl.c and cyassl.h:
  30. * Copyright (C) 1998 - 2017, Daniel Stenberg, <[email protected]>, et al.
  31. *
  32. * Thanks for code and inspiration!
  33. */
  34. #include "curl_setup.h"
  35. #ifdef USE_MESALINK
  36. #include <mesalink/options.h>
  37. #include <mesalink/version.h>
  38. #include "urldata.h"
  39. #include "sendf.h"
  40. #include "inet_pton.h"
  41. #include "vtls.h"
  42. #include "parsedate.h"
  43. #include "connect.h" /* for the connect timeout */
  44. #include "select.h"
  45. #include "strcase.h"
  46. #include "x509asn1.h"
  47. #include "curl_printf.h"
  48. #include "mesalink.h"
  49. #include <mesalink/openssl/ssl.h>
  50. #include <mesalink/openssl/err.h>
  51. /* The last #include files should be: */
  52. #include "curl_memory.h"
  53. #include "memdebug.h"
  54. #define MESALINK_MAX_ERROR_SZ 80
  55. struct ssl_backend_data
  56. {
  57. SSL_CTX *ctx;
  58. SSL *handle;
  59. };
  60. #define BACKEND connssl->backend
  61. static Curl_recv mesalink_recv;
  62. static Curl_send mesalink_send;
  63. static int do_file_type(const char *type)
  64. {
  65. if(!type || !type[0])
  66. return SSL_FILETYPE_PEM;
  67. if(strcasecompare(type, "PEM"))
  68. return SSL_FILETYPE_PEM;
  69. if(strcasecompare(type, "DER"))
  70. return SSL_FILETYPE_ASN1;
  71. return -1;
  72. }
  73. /*
  74. * This function loads all the client/CA certificates and CRLs. Setup the TLS
  75. * layer and do all necessary magic.
  76. */
  77. static CURLcode
  78. mesalink_connect_step1(struct Curl_easy *data,
  79. struct connectdata *conn, int sockindex)
  80. {
  81. char *ciphers;
  82. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  83. struct in_addr addr4;
  84. #ifdef ENABLE_IPV6
  85. struct in6_addr addr6;
  86. #endif
  87. const char * const hostname = SSL_HOST_NAME();
  88. size_t hostname_len = strlen(hostname);
  89. SSL_METHOD *req_method = NULL;
  90. curl_socket_t sockfd = conn->sock[sockindex];
  91. if(connssl->state == ssl_connection_complete)
  92. return CURLE_OK;
  93. if(SSL_CONN_CONFIG(version_max) != CURL_SSLVERSION_MAX_NONE) {
  94. failf(data, "MesaLink does not support to set maximum SSL/TLS version");
  95. return CURLE_SSL_CONNECT_ERROR;
  96. }
  97. switch(SSL_CONN_CONFIG(version)) {
  98. case CURL_SSLVERSION_SSLv3:
  99. case CURL_SSLVERSION_TLSv1:
  100. case CURL_SSLVERSION_TLSv1_0:
  101. case CURL_SSLVERSION_TLSv1_1:
  102. failf(data, "MesaLink does not support SSL 3.0, TLS 1.0, or TLS 1.1");
  103. return CURLE_NOT_BUILT_IN;
  104. case CURL_SSLVERSION_DEFAULT:
  105. case CURL_SSLVERSION_TLSv1_2:
  106. req_method = TLSv1_2_client_method();
  107. break;
  108. case CURL_SSLVERSION_TLSv1_3:
  109. req_method = TLSv1_3_client_method();
  110. break;
  111. case CURL_SSLVERSION_SSLv2:
  112. failf(data, "MesaLink does not support SSLv2");
  113. return CURLE_SSL_CONNECT_ERROR;
  114. default:
  115. failf(data, "Unrecognized parameter passed via CURLOPT_SSLVERSION");
  116. return CURLE_SSL_CONNECT_ERROR;
  117. }
  118. if(!req_method) {
  119. failf(data, "SSL: couldn't create a method!");
  120. return CURLE_OUT_OF_MEMORY;
  121. }
  122. if(BACKEND->ctx)
  123. SSL_CTX_free(BACKEND->ctx);
  124. BACKEND->ctx = SSL_CTX_new(req_method);
  125. if(!BACKEND->ctx) {
  126. failf(data, "SSL: couldn't create a context!");
  127. return CURLE_OUT_OF_MEMORY;
  128. }
  129. SSL_CTX_set_verify(
  130. BACKEND->ctx, SSL_CONN_CONFIG(verifypeer) ?
  131. SSL_VERIFY_PEER : SSL_VERIFY_NONE, NULL);
  132. if(SSL_CONN_CONFIG(CAfile) || SSL_CONN_CONFIG(CApath)) {
  133. if(!SSL_CTX_load_verify_locations(BACKEND->ctx, SSL_CONN_CONFIG(CAfile),
  134. SSL_CONN_CONFIG(CApath))) {
  135. if(SSL_CONN_CONFIG(verifypeer)) {
  136. failf(data,
  137. "error setting certificate verify locations: "
  138. " CAfile: %s CApath: %s",
  139. SSL_CONN_CONFIG(CAfile) ?
  140. SSL_CONN_CONFIG(CAfile) : "none",
  141. SSL_CONN_CONFIG(CApath) ?
  142. SSL_CONN_CONFIG(CApath) : "none");
  143. return CURLE_SSL_CACERT_BADFILE;
  144. }
  145. infof(data,
  146. "error setting certificate verify locations,"
  147. " continuing anyway:");
  148. }
  149. else {
  150. infof(data, "successfully set certificate verify locations:");
  151. }
  152. infof(data, " CAfile: %s",
  153. SSL_CONN_CONFIG(CAfile) ? SSL_CONN_CONFIG(CAfile): "none");
  154. infof(data, " CApath: %s",
  155. SSL_CONN_CONFIG(CApath) ? SSL_CONN_CONFIG(CApath): "none");
  156. }
  157. if(SSL_SET_OPTION(primary.clientcert) && SSL_SET_OPTION(key)) {
  158. int file_type = do_file_type(SSL_SET_OPTION(cert_type));
  159. if(SSL_CTX_use_certificate_chain_file(BACKEND->ctx,
  160. SSL_SET_OPTION(primary.clientcert),
  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(SSL_SET_OPTION(key_type));
  167. if(SSL_CTX_use_PrivateKey_file(BACKEND->ctx, SSL_SET_OPTION(key),
  168. file_type) != 1) {
  169. failf(data, "unable to set private key");
  170. return CURLE_SSL_CONNECT_ERROR;
  171. }
  172. infof(data,
  173. "client cert: %s",
  174. SSL_CONN_CONFIG(clientcert)?
  175. SSL_CONN_CONFIG(clientcert): "none");
  176. }
  177. ciphers = SSL_CONN_CONFIG(cipher_list);
  178. if(ciphers) {
  179. #ifdef MESALINK_HAVE_CIPHER
  180. if(!SSL_CTX_set_cipher_list(BACKEND->ctx, ciphers)) {
  181. failf(data, "failed setting cipher list: %s", ciphers);
  182. return CURLE_SSL_CIPHER;
  183. }
  184. #endif
  185. infof(data, "Cipher selection: %s", ciphers);
  186. }
  187. if(BACKEND->handle)
  188. SSL_free(BACKEND->handle);
  189. BACKEND->handle = SSL_new(BACKEND->ctx);
  190. if(!BACKEND->handle) {
  191. failf(data, "SSL: couldn't create a context (handle)!");
  192. return CURLE_OUT_OF_MEMORY;
  193. }
  194. if((hostname_len < USHRT_MAX) &&
  195. (0 == Curl_inet_pton(AF_INET, hostname, &addr4))
  196. #ifdef ENABLE_IPV6
  197. && (0 == Curl_inet_pton(AF_INET6, hostname, &addr6))
  198. #endif
  199. ) {
  200. /* hostname is not a valid IP address */
  201. if(SSL_set_tlsext_host_name(BACKEND->handle, hostname) != SSL_SUCCESS) {
  202. failf(data,
  203. "WARNING: failed to configure server name indication (SNI) "
  204. "TLS extension\n");
  205. return CURLE_SSL_CONNECT_ERROR;
  206. }
  207. }
  208. else {
  209. #ifdef CURLDEBUG
  210. /* Check if the hostname is 127.0.0.1 or [::1];
  211. * otherwise reject because MesaLink always wants a valid DNS Name
  212. * specified in RFC 5280 Section 7.2 */
  213. if(strncmp(hostname, "127.0.0.1", 9) == 0
  214. #ifdef ENABLE_IPV6
  215. || strncmp(hostname, "[::1]", 5) == 0
  216. #endif
  217. ) {
  218. SSL_set_tlsext_host_name(BACKEND->handle, "localhost");
  219. }
  220. else
  221. #endif
  222. {
  223. failf(data,
  224. "ERROR: MesaLink does not accept an IP address as a hostname\n");
  225. return CURLE_SSL_CONNECT_ERROR;
  226. }
  227. }
  228. #ifdef MESALINK_HAVE_SESSION
  229. if(SSL_SET_OPTION(primary.sessionid)) {
  230. void *ssl_sessionid = NULL;
  231. Curl_ssl_sessionid_lock(data);
  232. if(!Curl_ssl_getsessionid(data, conn,
  233. SSL_IS_PROXY() ? TRUE : FALSE,
  234. &ssl_sessionid, NULL, sockindex)) {
  235. /* we got a session id, use it! */
  236. if(!SSL_set_session(BACKEND->handle, ssl_sessionid)) {
  237. Curl_ssl_sessionid_unlock(data);
  238. failf(
  239. data,
  240. "SSL: SSL_set_session failed: %s",
  241. ERR_error_string(SSL_get_error(BACKEND->handle, 0), error_buffer));
  242. return CURLE_SSL_CONNECT_ERROR;
  243. }
  244. /* Informational message */
  245. infof(data, "SSL re-using session ID");
  246. }
  247. Curl_ssl_sessionid_unlock(data);
  248. }
  249. #endif /* MESALINK_HAVE_SESSION */
  250. if(SSL_set_fd(BACKEND->handle, (int)sockfd) != SSL_SUCCESS) {
  251. failf(data, "SSL: SSL_set_fd failed");
  252. return CURLE_SSL_CONNECT_ERROR;
  253. }
  254. connssl->connecting_state = ssl_connect_2;
  255. return CURLE_OK;
  256. }
  257. static CURLcode
  258. mesalink_connect_step2(struct Curl_easy *data,
  259. struct connectdata *conn, int sockindex)
  260. {
  261. int ret = -1;
  262. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  263. conn->recv[sockindex] = mesalink_recv;
  264. conn->send[sockindex] = mesalink_send;
  265. ret = SSL_connect(BACKEND->handle);
  266. if(ret != SSL_SUCCESS) {
  267. int detail = SSL_get_error(BACKEND->handle, ret);
  268. if(SSL_ERROR_WANT_CONNECT == detail || SSL_ERROR_WANT_READ == detail) {
  269. connssl->connecting_state = ssl_connect_2_reading;
  270. return CURLE_OK;
  271. }
  272. else {
  273. char error_buffer[MESALINK_MAX_ERROR_SZ];
  274. failf(data,
  275. "SSL_connect failed with error %d: %s",
  276. detail,
  277. ERR_error_string_n(detail, error_buffer, sizeof(error_buffer)));
  278. ERR_print_errors_fp(stderr);
  279. if(detail && SSL_CONN_CONFIG(verifypeer)) {
  280. detail &= ~0xFF;
  281. if(detail == TLS_ERROR_WEBPKI_ERRORS) {
  282. failf(data, "Cert verify failed");
  283. return CURLE_PEER_FAILED_VERIFICATION;
  284. }
  285. }
  286. return CURLE_SSL_CONNECT_ERROR;
  287. }
  288. }
  289. connssl->connecting_state = ssl_connect_3;
  290. infof(data,
  291. "SSL connection using %s / %s",
  292. SSL_get_version(BACKEND->handle),
  293. SSL_get_cipher_name(BACKEND->handle));
  294. return CURLE_OK;
  295. }
  296. static CURLcode
  297. mesalink_connect_step3(struct connectdata *conn, int sockindex)
  298. {
  299. CURLcode result = CURLE_OK;
  300. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  301. DEBUGASSERT(ssl_connect_3 == connssl->connecting_state);
  302. #ifdef MESALINK_HAVE_SESSION
  303. if(SSL_SET_OPTION(primary.sessionid)) {
  304. bool incache;
  305. SSL_SESSION *our_ssl_sessionid;
  306. void *old_ssl_sessionid = NULL;
  307. bool isproxy = SSL_IS_PROXY() ? TRUE : FALSE;
  308. our_ssl_sessionid = SSL_get_session(BACKEND->handle);
  309. Curl_ssl_sessionid_lock(data);
  310. incache =
  311. !(Curl_ssl_getsessionid(data, conn, isproxy, &old_ssl_sessionid, NULL,
  312. sockindex));
  313. if(incache) {
  314. if(old_ssl_sessionid != our_ssl_sessionid) {
  315. infof(data, "old SSL session ID is stale, removing");
  316. Curl_ssl_delsessionid(data, old_ssl_sessionid);
  317. incache = FALSE;
  318. }
  319. }
  320. if(!incache) {
  321. result =
  322. Curl_ssl_addsessionid(data, conn, isproxy, our_ssl_sessionid, 0,
  323. sockindex, NULL);
  324. if(result) {
  325. Curl_ssl_sessionid_unlock(data);
  326. failf(data, "failed to store ssl session");
  327. return result;
  328. }
  329. }
  330. Curl_ssl_sessionid_unlock(data);
  331. }
  332. #endif /* MESALINK_HAVE_SESSION */
  333. connssl->connecting_state = ssl_connect_done;
  334. return result;
  335. }
  336. static ssize_t
  337. mesalink_send(struct Curl_easy *data, int sockindex, const void *mem,
  338. size_t len, CURLcode *curlcode)
  339. {
  340. struct connectdata *conn = data->conn;
  341. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  342. char error_buffer[MESALINK_MAX_ERROR_SZ];
  343. int memlen = (len > (size_t)INT_MAX) ? INT_MAX : (int)len;
  344. int rc = SSL_write(BACKEND->handle, mem, memlen);
  345. if(rc < 0) {
  346. int err = SSL_get_error(BACKEND->handle, rc);
  347. switch(err) {
  348. case SSL_ERROR_WANT_READ:
  349. case SSL_ERROR_WANT_WRITE:
  350. /* there's data pending, re-invoke SSL_write() */
  351. *curlcode = CURLE_AGAIN;
  352. return -1;
  353. default:
  354. failf(data,
  355. "SSL write: %s, errno %d",
  356. ERR_error_string_n(err, error_buffer, sizeof(error_buffer)),
  357. SOCKERRNO);
  358. *curlcode = CURLE_SEND_ERROR;
  359. return -1;
  360. }
  361. }
  362. return rc;
  363. }
  364. static void
  365. mesalink_close(struct Curl_easy *data, struct connectdata *conn, int sockindex)
  366. {
  367. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  368. (void) data;
  369. if(BACKEND->handle) {
  370. (void)SSL_shutdown(BACKEND->handle);
  371. SSL_free(BACKEND->handle);
  372. BACKEND->handle = NULL;
  373. }
  374. if(BACKEND->ctx) {
  375. SSL_CTX_free(BACKEND->ctx);
  376. BACKEND->ctx = NULL;
  377. }
  378. }
  379. static ssize_t
  380. mesalink_recv(struct Curl_easy *data, int num, char *buf, size_t buffersize,
  381. CURLcode *curlcode)
  382. {
  383. struct connectdata *conn = data->conn;
  384. struct ssl_connect_data *connssl = &conn->ssl[num];
  385. char error_buffer[MESALINK_MAX_ERROR_SZ];
  386. int buffsize = (buffersize > (size_t)INT_MAX) ? INT_MAX : (int)buffersize;
  387. int nread = SSL_read(BACKEND->handle, buf, buffsize);
  388. if(nread <= 0) {
  389. int err = SSL_get_error(BACKEND->handle, nread);
  390. switch(err) {
  391. case SSL_ERROR_ZERO_RETURN: /* no more data */
  392. case IO_ERROR_CONNECTION_ABORTED:
  393. break;
  394. case SSL_ERROR_WANT_READ:
  395. case SSL_ERROR_WANT_WRITE:
  396. /* there's data pending, re-invoke SSL_read() */
  397. *curlcode = CURLE_AGAIN;
  398. return -1;
  399. default:
  400. failf(data,
  401. "SSL read: %s, errno %d",
  402. ERR_error_string_n(err, error_buffer, sizeof(error_buffer)),
  403. SOCKERRNO);
  404. *curlcode = CURLE_RECV_ERROR;
  405. return -1;
  406. }
  407. }
  408. return nread;
  409. }
  410. static size_t
  411. mesalink_version(char *buffer, size_t size)
  412. {
  413. return msnprintf(buffer, size, "MesaLink/%s", MESALINK_VERSION_STRING);
  414. }
  415. static int
  416. mesalink_init(void)
  417. {
  418. return (SSL_library_init() == SSL_SUCCESS);
  419. }
  420. /*
  421. * This function is called to shut down the SSL layer but keep the
  422. * socket open (CCC - Clear Command Channel)
  423. */
  424. static int
  425. mesalink_shutdown(struct Curl_easy *data,
  426. struct connectdata *conn, int sockindex)
  427. {
  428. int retval = 0;
  429. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  430. (void) data;
  431. if(BACKEND->handle) {
  432. SSL_free(BACKEND->handle);
  433. BACKEND->handle = NULL;
  434. }
  435. return retval;
  436. }
  437. static CURLcode
  438. mesalink_connect_common(struct Curl_easy *data, struct connectdata *conn,
  439. int sockindex, bool nonblocking, bool *done)
  440. {
  441. CURLcode result;
  442. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  443. curl_socket_t sockfd = conn->sock[sockindex];
  444. timediff_t timeout_ms;
  445. int what;
  446. /* check if the connection has already been established */
  447. if(ssl_connection_complete == connssl->state) {
  448. *done = TRUE;
  449. return CURLE_OK;
  450. }
  451. if(ssl_connect_1 == connssl->connecting_state) {
  452. /* Find out how much more time we're allowed */
  453. timeout_ms = Curl_timeleft(data, NULL, TRUE);
  454. if(timeout_ms < 0) {
  455. /* no need to continue if time already is up */
  456. failf(data, "SSL connection timeout");
  457. return CURLE_OPERATION_TIMEDOUT;
  458. }
  459. result = mesalink_connect_step1(data, conn, sockindex);
  460. if(result)
  461. return result;
  462. }
  463. while(ssl_connect_2 == connssl->connecting_state ||
  464. ssl_connect_2_reading == connssl->connecting_state ||
  465. ssl_connect_2_writing == connssl->connecting_state) {
  466. /* check allowed time left */
  467. timeout_ms = Curl_timeleft(data, NULL, TRUE);
  468. if(timeout_ms < 0) {
  469. /* no need to continue if time already is up */
  470. failf(data, "SSL connection timeout");
  471. return CURLE_OPERATION_TIMEDOUT;
  472. }
  473. /* if ssl is expecting something, check if it's available. */
  474. if(connssl->connecting_state == ssl_connect_2_reading ||
  475. connssl->connecting_state == ssl_connect_2_writing) {
  476. curl_socket_t writefd =
  477. ssl_connect_2_writing == connssl->connecting_state ? sockfd
  478. : CURL_SOCKET_BAD;
  479. curl_socket_t readfd = ssl_connect_2_reading == connssl->connecting_state
  480. ? sockfd
  481. : CURL_SOCKET_BAD;
  482. what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
  483. 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. result = mesalink_connect_step2(data, conn, sockindex);
  510. if(result ||
  511. (nonblocking && (ssl_connect_2 == connssl->connecting_state ||
  512. ssl_connect_2_reading == connssl->connecting_state ||
  513. ssl_connect_2_writing == connssl->connecting_state))) {
  514. return result;
  515. }
  516. } /* repeat step2 until all transactions are done. */
  517. if(ssl_connect_3 == connssl->connecting_state) {
  518. result = mesalink_connect_step3(conn, sockindex);
  519. if(result)
  520. return result;
  521. }
  522. if(ssl_connect_done == connssl->connecting_state) {
  523. connssl->state = ssl_connection_complete;
  524. conn->recv[sockindex] = mesalink_recv;
  525. conn->send[sockindex] = mesalink_send;
  526. *done = TRUE;
  527. }
  528. else
  529. *done = FALSE;
  530. /* Reset our connect state machine */
  531. connssl->connecting_state = ssl_connect_1;
  532. return CURLE_OK;
  533. }
  534. static CURLcode
  535. mesalink_connect_nonblocking(struct Curl_easy *data, struct connectdata *conn,
  536. int sockindex, bool *done)
  537. {
  538. return mesalink_connect_common(data, conn, sockindex, TRUE, done);
  539. }
  540. static CURLcode
  541. mesalink_connect(struct Curl_easy *data, struct connectdata *conn,
  542. int sockindex)
  543. {
  544. CURLcode result;
  545. bool done = FALSE;
  546. result = mesalink_connect_common(data, conn, sockindex, FALSE, &done);
  547. if(result)
  548. return result;
  549. DEBUGASSERT(done);
  550. return CURLE_OK;
  551. }
  552. static void *
  553. mesalink_get_internals(struct ssl_connect_data *connssl,
  554. CURLINFO info UNUSED_PARAM)
  555. {
  556. (void)info;
  557. return BACKEND->handle;
  558. }
  559. const struct Curl_ssl Curl_ssl_mesalink = {
  560. { CURLSSLBACKEND_MESALINK, "MesaLink" }, /* info */
  561. SSLSUPP_SSL_CTX,
  562. sizeof(struct ssl_backend_data),
  563. mesalink_init, /* init */
  564. Curl_none_cleanup, /* cleanup */
  565. mesalink_version, /* version */
  566. Curl_none_check_cxn, /* check_cxn */
  567. mesalink_shutdown, /* shutdown */
  568. Curl_none_data_pending, /* data_pending */
  569. Curl_none_random, /* random */
  570. Curl_none_cert_status_request, /* cert_status_request */
  571. mesalink_connect, /* connect */
  572. mesalink_connect_nonblocking, /* connect_nonblocking */
  573. Curl_ssl_getsock, /* getsock */
  574. mesalink_get_internals, /* get_internals */
  575. mesalink_close, /* close_one */
  576. Curl_none_close_all, /* close_all */
  577. Curl_none_session_free, /* session_free */
  578. Curl_none_set_engine, /* set_engine */
  579. Curl_none_set_engine_default, /* set_engine_default */
  580. Curl_none_engines_list, /* engines_list */
  581. Curl_none_false_start, /* false_start */
  582. NULL, /* sha256sum */
  583. NULL, /* associate_connection */
  584. NULL /* disassociate_connection */
  585. };
  586. #endif