mesalink.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  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 =
  88. SSL_IS_PROXY() ? conn->http_proxy.host.name : conn->host.name;
  89. size_t hostname_len = strlen(hostname);
  90. SSL_METHOD *req_method = NULL;
  91. curl_socket_t sockfd = conn->sock[sockindex];
  92. if(connssl->state == ssl_connection_complete)
  93. return CURLE_OK;
  94. if(SSL_CONN_CONFIG(version_max) != CURL_SSLVERSION_MAX_NONE) {
  95. failf(data, "MesaLink does not support to set maximum SSL/TLS version");
  96. return CURLE_SSL_CONNECT_ERROR;
  97. }
  98. switch(SSL_CONN_CONFIG(version)) {
  99. case CURL_SSLVERSION_SSLv3:
  100. case CURL_SSLVERSION_TLSv1:
  101. case CURL_SSLVERSION_TLSv1_0:
  102. case CURL_SSLVERSION_TLSv1_1:
  103. failf(data, "MesaLink does not support SSL 3.0, TLS 1.0, or TLS 1.1");
  104. return CURLE_NOT_BUILT_IN;
  105. case CURL_SSLVERSION_DEFAULT:
  106. case CURL_SSLVERSION_TLSv1_2:
  107. req_method = TLSv1_2_client_method();
  108. break;
  109. case CURL_SSLVERSION_TLSv1_3:
  110. req_method = TLSv1_3_client_method();
  111. break;
  112. case CURL_SSLVERSION_SSLv2:
  113. failf(data, "MesaLink does not support SSLv2");
  114. return CURLE_SSL_CONNECT_ERROR;
  115. default:
  116. failf(data, "Unrecognized parameter passed via CURLOPT_SSLVERSION");
  117. return CURLE_SSL_CONNECT_ERROR;
  118. }
  119. if(!req_method) {
  120. failf(data, "SSL: couldn't create a method!");
  121. return CURLE_OUT_OF_MEMORY;
  122. }
  123. if(BACKEND->ctx)
  124. SSL_CTX_free(BACKEND->ctx);
  125. BACKEND->ctx = SSL_CTX_new(req_method);
  126. if(!BACKEND->ctx) {
  127. failf(data, "SSL: couldn't create a context!");
  128. return CURLE_OUT_OF_MEMORY;
  129. }
  130. SSL_CTX_set_verify(
  131. BACKEND->ctx, SSL_CONN_CONFIG(verifypeer) ?
  132. SSL_VERIFY_PEER : SSL_VERIFY_NONE, NULL);
  133. if(SSL_CONN_CONFIG(CAfile) || SSL_CONN_CONFIG(CApath)) {
  134. if(!SSL_CTX_load_verify_locations(BACKEND->ctx, SSL_CONN_CONFIG(CAfile),
  135. SSL_CONN_CONFIG(CApath))) {
  136. if(SSL_CONN_CONFIG(verifypeer)) {
  137. failf(data,
  138. "error setting certificate verify locations: "
  139. " CAfile: %s CApath: %s",
  140. SSL_CONN_CONFIG(CAfile) ?
  141. SSL_CONN_CONFIG(CAfile) : "none",
  142. SSL_CONN_CONFIG(CApath) ?
  143. SSL_CONN_CONFIG(CApath) : "none");
  144. return CURLE_SSL_CACERT_BADFILE;
  145. }
  146. infof(data,
  147. "error setting certificate verify locations,"
  148. " continuing anyway:\n");
  149. }
  150. else {
  151. infof(data, "successfully set certificate verify locations:\n");
  152. }
  153. infof(data, " CAfile: %s\n",
  154. SSL_CONN_CONFIG(CAfile) ? SSL_CONN_CONFIG(CAfile): "none");
  155. infof(data, " CApath: %s\n",
  156. SSL_CONN_CONFIG(CApath) ? SSL_CONN_CONFIG(CApath): "none");
  157. }
  158. if(SSL_SET_OPTION(primary.clientcert) && SSL_SET_OPTION(key)) {
  159. int file_type = do_file_type(SSL_SET_OPTION(cert_type));
  160. if(SSL_CTX_use_certificate_chain_file(BACKEND->ctx,
  161. SSL_SET_OPTION(primary.clientcert),
  162. file_type) != 1) {
  163. failf(data, "unable to use client certificate (no key or wrong pass"
  164. " phrase?)");
  165. return CURLE_SSL_CONNECT_ERROR;
  166. }
  167. file_type = do_file_type(SSL_SET_OPTION(key_type));
  168. if(SSL_CTX_use_PrivateKey_file(BACKEND->ctx, SSL_SET_OPTION(key),
  169. file_type) != 1) {
  170. failf(data, "unable to set private key");
  171. return CURLE_SSL_CONNECT_ERROR;
  172. }
  173. infof(data,
  174. "client cert: %s\n",
  175. SSL_CONN_CONFIG(clientcert)?
  176. SSL_CONN_CONFIG(clientcert): "none");
  177. }
  178. ciphers = SSL_CONN_CONFIG(cipher_list);
  179. if(ciphers) {
  180. #ifdef MESALINK_HAVE_CIPHER
  181. if(!SSL_CTX_set_cipher_list(BACKEND->ctx, ciphers)) {
  182. failf(data, "failed setting cipher list: %s", ciphers);
  183. return CURLE_SSL_CIPHER;
  184. }
  185. #endif
  186. infof(data, "Cipher selection: %s\n", ciphers);
  187. }
  188. if(BACKEND->handle)
  189. SSL_free(BACKEND->handle);
  190. BACKEND->handle = SSL_new(BACKEND->ctx);
  191. if(!BACKEND->handle) {
  192. failf(data, "SSL: couldn't create a context (handle)!");
  193. return CURLE_OUT_OF_MEMORY;
  194. }
  195. if((hostname_len < USHRT_MAX) &&
  196. (0 == Curl_inet_pton(AF_INET, hostname, &addr4))
  197. #ifdef ENABLE_IPV6
  198. && (0 == Curl_inet_pton(AF_INET6, hostname, &addr6))
  199. #endif
  200. ) {
  201. /* hostname is not a valid IP address */
  202. if(SSL_set_tlsext_host_name(BACKEND->handle, hostname) != SSL_SUCCESS) {
  203. failf(data,
  204. "WARNING: failed to configure server name indication (SNI) "
  205. "TLS extension\n");
  206. return CURLE_SSL_CONNECT_ERROR;
  207. }
  208. }
  209. else {
  210. #ifdef CURLDEBUG
  211. /* Check if the hostname is 127.0.0.1 or [::1];
  212. * otherwise reject because MesaLink always wants a valid DNS Name
  213. * specified in RFC 5280 Section 7.2 */
  214. if(strncmp(hostname, "127.0.0.1", 9) == 0
  215. #ifdef ENABLE_IPV6
  216. || strncmp(hostname, "[::1]", 5) == 0
  217. #endif
  218. ) {
  219. SSL_set_tlsext_host_name(BACKEND->handle, "localhost");
  220. }
  221. else
  222. #endif
  223. {
  224. failf(data,
  225. "ERROR: MesaLink does not accept an IP address as a hostname\n");
  226. return CURLE_SSL_CONNECT_ERROR;
  227. }
  228. }
  229. #ifdef MESALINK_HAVE_SESSION
  230. if(SSL_SET_OPTION(primary.sessionid)) {
  231. void *ssl_sessionid = NULL;
  232. Curl_ssl_sessionid_lock(data);
  233. if(!Curl_ssl_getsessionid(data, conn, &ssl_sessionid, NULL, sockindex)) {
  234. /* we got a session id, use it! */
  235. if(!SSL_set_session(BACKEND->handle, ssl_sessionid)) {
  236. Curl_ssl_sessionid_unlock(data);
  237. failf(
  238. data,
  239. "SSL: SSL_set_session failed: %s",
  240. ERR_error_string(SSL_get_error(BACKEND->handle, 0), error_buffer));
  241. return CURLE_SSL_CONNECT_ERROR;
  242. }
  243. /* Informational message */
  244. infof(data, "SSL re-using session ID\n");
  245. }
  246. Curl_ssl_sessionid_unlock(data);
  247. }
  248. #endif /* MESALINK_HAVE_SESSION */
  249. if(SSL_set_fd(BACKEND->handle, (int)sockfd) != SSL_SUCCESS) {
  250. failf(data, "SSL: SSL_set_fd failed");
  251. return CURLE_SSL_CONNECT_ERROR;
  252. }
  253. connssl->connecting_state = ssl_connect_2;
  254. return CURLE_OK;
  255. }
  256. static CURLcode
  257. mesalink_connect_step2(struct Curl_easy *data,
  258. struct connectdata *conn, int sockindex)
  259. {
  260. int ret = -1;
  261. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  262. conn->recv[sockindex] = mesalink_recv;
  263. conn->send[sockindex] = mesalink_send;
  264. ret = SSL_connect(BACKEND->handle);
  265. if(ret != SSL_SUCCESS) {
  266. int detail = SSL_get_error(BACKEND->handle, ret);
  267. if(SSL_ERROR_WANT_CONNECT == detail || SSL_ERROR_WANT_READ == detail) {
  268. connssl->connecting_state = ssl_connect_2_reading;
  269. return CURLE_OK;
  270. }
  271. else {
  272. char error_buffer[MESALINK_MAX_ERROR_SZ];
  273. failf(data,
  274. "SSL_connect failed with error %d: %s",
  275. detail,
  276. ERR_error_string_n(detail, error_buffer, sizeof(error_buffer)));
  277. ERR_print_errors_fp(stderr);
  278. if(detail && SSL_CONN_CONFIG(verifypeer)) {
  279. detail &= ~0xFF;
  280. if(detail == TLS_ERROR_WEBPKI_ERRORS) {
  281. failf(data, "Cert verify failed");
  282. return CURLE_PEER_FAILED_VERIFICATION;
  283. }
  284. }
  285. return CURLE_SSL_CONNECT_ERROR;
  286. }
  287. }
  288. connssl->connecting_state = ssl_connect_3;
  289. infof(data,
  290. "SSL connection using %s / %s\n",
  291. SSL_get_version(BACKEND->handle),
  292. SSL_get_cipher_name(BACKEND->handle));
  293. return CURLE_OK;
  294. }
  295. static CURLcode
  296. mesalink_connect_step3(struct connectdata *conn, int sockindex)
  297. {
  298. CURLcode result = CURLE_OK;
  299. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  300. DEBUGASSERT(ssl_connect_3 == connssl->connecting_state);
  301. #ifdef MESALINK_HAVE_SESSION
  302. if(SSL_SET_OPTION(primary.sessionid)) {
  303. bool incache;
  304. SSL_SESSION *our_ssl_sessionid;
  305. void *old_ssl_sessionid = NULL;
  306. our_ssl_sessionid = SSL_get_session(BACKEND->handle);
  307. Curl_ssl_sessionid_lock(data);
  308. incache =
  309. !(Curl_ssl_getsessionid(data, conn,
  310. &old_ssl_sessionid, NULL, sockindex));
  311. if(incache) {
  312. if(old_ssl_sessionid != our_ssl_sessionid) {
  313. infof(data, "old SSL session ID is stale, removing\n");
  314. Curl_ssl_delsessionid(data, old_ssl_sessionid);
  315. incache = FALSE;
  316. }
  317. }
  318. if(!incache) {
  319. result = Curl_ssl_addsessionid(
  320. data, conn, our_ssl_sessionid, 0 /* unknown size */, sockindex);
  321. if(result) {
  322. Curl_ssl_sessionid_unlock(data);
  323. failf(data, "failed to store ssl session");
  324. return result;
  325. }
  326. }
  327. Curl_ssl_sessionid_unlock(data);
  328. }
  329. #endif /* MESALINK_HAVE_SESSION */
  330. connssl->connecting_state = ssl_connect_done;
  331. return result;
  332. }
  333. static ssize_t
  334. mesalink_send(struct Curl_easy *data, int sockindex, const void *mem,
  335. size_t len, CURLcode *curlcode)
  336. {
  337. struct connectdata *conn = data->conn;
  338. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  339. char error_buffer[MESALINK_MAX_ERROR_SZ];
  340. int memlen = (len > (size_t)INT_MAX) ? INT_MAX : (int)len;
  341. int rc = SSL_write(BACKEND->handle, mem, memlen);
  342. if(rc < 0) {
  343. int err = SSL_get_error(BACKEND->handle, rc);
  344. switch(err) {
  345. case SSL_ERROR_WANT_READ:
  346. case SSL_ERROR_WANT_WRITE:
  347. /* there's data pending, re-invoke SSL_write() */
  348. *curlcode = CURLE_AGAIN;
  349. return -1;
  350. default:
  351. failf(data,
  352. "SSL write: %s, errno %d",
  353. ERR_error_string_n(err, error_buffer, sizeof(error_buffer)),
  354. SOCKERRNO);
  355. *curlcode = CURLE_SEND_ERROR;
  356. return -1;
  357. }
  358. }
  359. return rc;
  360. }
  361. static void
  362. mesalink_close(struct Curl_easy *data, struct connectdata *conn, int sockindex)
  363. {
  364. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  365. (void) data;
  366. if(BACKEND->handle) {
  367. (void)SSL_shutdown(BACKEND->handle);
  368. SSL_free(BACKEND->handle);
  369. BACKEND->handle = NULL;
  370. }
  371. if(BACKEND->ctx) {
  372. SSL_CTX_free(BACKEND->ctx);
  373. BACKEND->ctx = NULL;
  374. }
  375. }
  376. static ssize_t
  377. mesalink_recv(struct Curl_easy *data, int num, char *buf, size_t buffersize,
  378. CURLcode *curlcode)
  379. {
  380. struct connectdata *conn = data->conn;
  381. struct ssl_connect_data *connssl = &conn->ssl[num];
  382. char error_buffer[MESALINK_MAX_ERROR_SZ];
  383. int buffsize = (buffersize > (size_t)INT_MAX) ? INT_MAX : (int)buffersize;
  384. int nread = SSL_read(BACKEND->handle, buf, buffsize);
  385. if(nread <= 0) {
  386. int err = SSL_get_error(BACKEND->handle, nread);
  387. switch(err) {
  388. case SSL_ERROR_ZERO_RETURN: /* no more data */
  389. case IO_ERROR_CONNECTION_ABORTED:
  390. break;
  391. case SSL_ERROR_WANT_READ:
  392. case SSL_ERROR_WANT_WRITE:
  393. /* there's data pending, re-invoke SSL_read() */
  394. *curlcode = CURLE_AGAIN;
  395. return -1;
  396. default:
  397. failf(data,
  398. "SSL read: %s, errno %d",
  399. ERR_error_string_n(err, error_buffer, sizeof(error_buffer)),
  400. SOCKERRNO);
  401. *curlcode = CURLE_RECV_ERROR;
  402. return -1;
  403. }
  404. }
  405. return nread;
  406. }
  407. static size_t
  408. mesalink_version(char *buffer, size_t size)
  409. {
  410. return msnprintf(buffer, size, "MesaLink/%s", MESALINK_VERSION_STRING);
  411. }
  412. static int
  413. mesalink_init(void)
  414. {
  415. return (SSL_library_init() == SSL_SUCCESS);
  416. }
  417. /*
  418. * This function is called to shut down the SSL layer but keep the
  419. * socket open (CCC - Clear Command Channel)
  420. */
  421. static int
  422. mesalink_shutdown(struct Curl_easy *data,
  423. struct connectdata *conn, int sockindex)
  424. {
  425. int retval = 0;
  426. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  427. (void) data;
  428. if(BACKEND->handle) {
  429. SSL_free(BACKEND->handle);
  430. BACKEND->handle = NULL;
  431. }
  432. return retval;
  433. }
  434. static CURLcode
  435. mesalink_connect_common(struct Curl_easy *data, struct connectdata *conn,
  436. int sockindex, bool nonblocking, bool *done)
  437. {
  438. CURLcode result;
  439. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  440. curl_socket_t sockfd = conn->sock[sockindex];
  441. timediff_t timeout_ms;
  442. int what;
  443. /* check if the connection has already been established */
  444. if(ssl_connection_complete == connssl->state) {
  445. *done = TRUE;
  446. return CURLE_OK;
  447. }
  448. if(ssl_connect_1 == connssl->connecting_state) {
  449. /* Find out how much more time we're allowed */
  450. timeout_ms = Curl_timeleft(data, NULL, TRUE);
  451. if(timeout_ms < 0) {
  452. /* no need to continue if time already is up */
  453. failf(data, "SSL connection timeout");
  454. return CURLE_OPERATION_TIMEDOUT;
  455. }
  456. result = mesalink_connect_step1(data, conn, sockindex);
  457. if(result)
  458. return result;
  459. }
  460. while(ssl_connect_2 == connssl->connecting_state ||
  461. ssl_connect_2_reading == connssl->connecting_state ||
  462. ssl_connect_2_writing == connssl->connecting_state) {
  463. /* check allowed time left */
  464. timeout_ms = Curl_timeleft(data, NULL, TRUE);
  465. if(timeout_ms < 0) {
  466. /* no need to continue if time already is up */
  467. failf(data, "SSL connection timeout");
  468. return CURLE_OPERATION_TIMEDOUT;
  469. }
  470. /* if ssl is expecting something, check if it's available. */
  471. if(connssl->connecting_state == ssl_connect_2_reading ||
  472. connssl->connecting_state == ssl_connect_2_writing) {
  473. curl_socket_t writefd =
  474. ssl_connect_2_writing == connssl->connecting_state ? sockfd
  475. : CURL_SOCKET_BAD;
  476. curl_socket_t readfd = ssl_connect_2_reading == connssl->connecting_state
  477. ? sockfd
  478. : CURL_SOCKET_BAD;
  479. what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
  480. nonblocking ? 0 : timeout_ms);
  481. if(what < 0) {
  482. /* fatal error */
  483. failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
  484. return CURLE_SSL_CONNECT_ERROR;
  485. }
  486. else if(0 == what) {
  487. if(nonblocking) {
  488. *done = FALSE;
  489. return CURLE_OK;
  490. }
  491. else {
  492. /* timeout */
  493. failf(data, "SSL connection timeout");
  494. return CURLE_OPERATION_TIMEDOUT;
  495. }
  496. }
  497. /* socket is readable or writable */
  498. }
  499. /* Run transaction, and return to the caller if it failed or if
  500. * this connection is part of a multi handle and this loop would
  501. * execute again. This permits the owner of a multi handle to
  502. * abort a connection attempt before step2 has completed while
  503. * ensuring that a client using select() or epoll() will always
  504. * have a valid fdset to wait on.
  505. */
  506. result = mesalink_connect_step2(data, conn, sockindex);
  507. if(result ||
  508. (nonblocking && (ssl_connect_2 == connssl->connecting_state ||
  509. ssl_connect_2_reading == connssl->connecting_state ||
  510. ssl_connect_2_writing == connssl->connecting_state))) {
  511. return result;
  512. }
  513. } /* repeat step2 until all transactions are done. */
  514. if(ssl_connect_3 == connssl->connecting_state) {
  515. result = mesalink_connect_step3(conn, sockindex);
  516. if(result)
  517. return result;
  518. }
  519. if(ssl_connect_done == connssl->connecting_state) {
  520. connssl->state = ssl_connection_complete;
  521. conn->recv[sockindex] = mesalink_recv;
  522. conn->send[sockindex] = mesalink_send;
  523. *done = TRUE;
  524. }
  525. else
  526. *done = FALSE;
  527. /* Reset our connect state machine */
  528. connssl->connecting_state = ssl_connect_1;
  529. return CURLE_OK;
  530. }
  531. static CURLcode
  532. mesalink_connect_nonblocking(struct Curl_easy *data, struct connectdata *conn,
  533. int sockindex, bool *done)
  534. {
  535. return mesalink_connect_common(data, conn, sockindex, TRUE, done);
  536. }
  537. static CURLcode
  538. mesalink_connect(struct Curl_easy *data, struct connectdata *conn,
  539. int sockindex)
  540. {
  541. CURLcode result;
  542. bool done = FALSE;
  543. result = mesalink_connect_common(data, conn, sockindex, FALSE, &done);
  544. if(result)
  545. return result;
  546. DEBUGASSERT(done);
  547. return CURLE_OK;
  548. }
  549. static void *
  550. mesalink_get_internals(struct ssl_connect_data *connssl,
  551. CURLINFO info UNUSED_PARAM)
  552. {
  553. (void)info;
  554. return BACKEND->handle;
  555. }
  556. const struct Curl_ssl Curl_ssl_mesalink = {
  557. { CURLSSLBACKEND_MESALINK, "MesaLink" }, /* info */
  558. SSLSUPP_SSL_CTX,
  559. sizeof(struct ssl_backend_data),
  560. mesalink_init, /* init */
  561. Curl_none_cleanup, /* cleanup */
  562. mesalink_version, /* version */
  563. Curl_none_check_cxn, /* check_cxn */
  564. mesalink_shutdown, /* shutdown */
  565. Curl_none_data_pending, /* data_pending */
  566. Curl_none_random, /* random */
  567. Curl_none_cert_status_request, /* cert_status_request */
  568. mesalink_connect, /* connect */
  569. mesalink_connect_nonblocking, /* connect_nonblocking */
  570. mesalink_get_internals, /* get_internals */
  571. mesalink_close, /* close_one */
  572. Curl_none_close_all, /* close_all */
  573. Curl_none_session_free, /* session_free */
  574. Curl_none_set_engine, /* set_engine */
  575. Curl_none_set_engine_default, /* set_engine_default */
  576. Curl_none_engines_list, /* engines_list */
  577. Curl_none_false_start, /* false_start */
  578. NULL /* sha256sum */
  579. };
  580. #endif