mesalink.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 2017 - 2018, Yiming Jing, <jingyiming@baidu.com>
  9. * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, 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, <daniel@haxx.se>, 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 connectdata *conn, int sockindex)
  79. {
  80. char *ciphers;
  81. struct Curl_easy *data = conn->data;
  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(conn);
  233. if(!Curl_ssl_getsessionid(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(conn);
  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(conn);
  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 connectdata *conn, int sockindex)
  258. {
  259. int ret = -1;
  260. struct Curl_easy *data = conn->data;
  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(conn);
  308. incache =
  309. !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL, sockindex));
  310. if(incache) {
  311. if(old_ssl_sessionid != our_ssl_sessionid) {
  312. infof(data, "old SSL session ID is stale, removing\n");
  313. Curl_ssl_delsessionid(conn, old_ssl_sessionid);
  314. incache = FALSE;
  315. }
  316. }
  317. if(!incache) {
  318. result = Curl_ssl_addsessionid(
  319. conn, our_ssl_sessionid, 0 /* unknown size */, sockindex);
  320. if(result) {
  321. Curl_ssl_sessionid_unlock(conn);
  322. failf(data, "failed to store ssl session");
  323. return result;
  324. }
  325. }
  326. Curl_ssl_sessionid_unlock(conn);
  327. }
  328. #endif /* MESALINK_HAVE_SESSION */
  329. connssl->connecting_state = ssl_connect_done;
  330. return result;
  331. }
  332. static ssize_t
  333. mesalink_send(struct connectdata *conn, int sockindex, const void *mem,
  334. size_t len, CURLcode *curlcode)
  335. {
  336. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  337. char error_buffer[MESALINK_MAX_ERROR_SZ];
  338. int memlen = (len > (size_t)INT_MAX) ? INT_MAX : (int)len;
  339. int rc = SSL_write(BACKEND->handle, mem, memlen);
  340. if(rc < 0) {
  341. int err = SSL_get_error(BACKEND->handle, rc);
  342. switch(err) {
  343. case SSL_ERROR_WANT_READ:
  344. case SSL_ERROR_WANT_WRITE:
  345. /* there's data pending, re-invoke SSL_write() */
  346. *curlcode = CURLE_AGAIN;
  347. return -1;
  348. default:
  349. failf(conn->data,
  350. "SSL write: %s, errno %d",
  351. ERR_error_string_n(err, error_buffer, sizeof(error_buffer)),
  352. SOCKERRNO);
  353. *curlcode = CURLE_SEND_ERROR;
  354. return -1;
  355. }
  356. }
  357. return rc;
  358. }
  359. static void
  360. Curl_mesalink_close(struct connectdata *conn, int sockindex)
  361. {
  362. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  363. if(BACKEND->handle) {
  364. (void)SSL_shutdown(BACKEND->handle);
  365. SSL_free(BACKEND->handle);
  366. BACKEND->handle = NULL;
  367. }
  368. if(BACKEND->ctx) {
  369. SSL_CTX_free(BACKEND->ctx);
  370. BACKEND->ctx = NULL;
  371. }
  372. }
  373. static ssize_t
  374. mesalink_recv(struct connectdata *conn, int num, char *buf, size_t buffersize,
  375. CURLcode *curlcode)
  376. {
  377. struct ssl_connect_data *connssl = &conn->ssl[num];
  378. char error_buffer[MESALINK_MAX_ERROR_SZ];
  379. int buffsize = (buffersize > (size_t)INT_MAX) ? INT_MAX : (int)buffersize;
  380. int nread = SSL_read(BACKEND->handle, buf, buffsize);
  381. if(nread <= 0) {
  382. int err = SSL_get_error(BACKEND->handle, nread);
  383. switch(err) {
  384. case SSL_ERROR_ZERO_RETURN: /* no more data */
  385. case IO_ERROR_CONNECTION_ABORTED:
  386. break;
  387. case SSL_ERROR_WANT_READ:
  388. case SSL_ERROR_WANT_WRITE:
  389. /* there's data pending, re-invoke SSL_read() */
  390. *curlcode = CURLE_AGAIN;
  391. return -1;
  392. default:
  393. failf(conn->data,
  394. "SSL read: %s, errno %d",
  395. ERR_error_string_n(err, error_buffer, sizeof(error_buffer)),
  396. SOCKERRNO);
  397. *curlcode = CURLE_RECV_ERROR;
  398. return -1;
  399. }
  400. }
  401. return nread;
  402. }
  403. static size_t
  404. Curl_mesalink_version(char *buffer, size_t size)
  405. {
  406. return msnprintf(buffer, size, "MesaLink/%s", MESALINK_VERSION_STRING);
  407. }
  408. static int
  409. Curl_mesalink_init(void)
  410. {
  411. return (SSL_library_init() == SSL_SUCCESS);
  412. }
  413. /*
  414. * This function is called to shut down the SSL layer but keep the
  415. * socket open (CCC - Clear Command Channel)
  416. */
  417. static int
  418. Curl_mesalink_shutdown(struct connectdata *conn, int sockindex)
  419. {
  420. int retval = 0;
  421. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  422. if(BACKEND->handle) {
  423. SSL_free(BACKEND->handle);
  424. BACKEND->handle = NULL;
  425. }
  426. return retval;
  427. }
  428. static CURLcode
  429. mesalink_connect_common(struct connectdata *conn, int sockindex,
  430. bool nonblocking, bool *done)
  431. {
  432. CURLcode result;
  433. struct Curl_easy *data = conn->data;
  434. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  435. curl_socket_t sockfd = conn->sock[sockindex];
  436. timediff_t timeout_ms;
  437. int what;
  438. /* check if the connection has already been established */
  439. if(ssl_connection_complete == connssl->state) {
  440. *done = TRUE;
  441. return CURLE_OK;
  442. }
  443. if(ssl_connect_1 == connssl->connecting_state) {
  444. /* Find out how much more time we're allowed */
  445. timeout_ms = Curl_timeleft(data, NULL, TRUE);
  446. if(timeout_ms < 0) {
  447. /* no need to continue if time already is up */
  448. failf(data, "SSL connection timeout");
  449. return CURLE_OPERATION_TIMEDOUT;
  450. }
  451. result = mesalink_connect_step1(conn, sockindex);
  452. if(result)
  453. return result;
  454. }
  455. while(ssl_connect_2 == connssl->connecting_state ||
  456. ssl_connect_2_reading == connssl->connecting_state ||
  457. ssl_connect_2_writing == connssl->connecting_state) {
  458. /* check allowed time left */
  459. timeout_ms = Curl_timeleft(data, NULL, TRUE);
  460. if(timeout_ms < 0) {
  461. /* no need to continue if time already is up */
  462. failf(data, "SSL connection timeout");
  463. return CURLE_OPERATION_TIMEDOUT;
  464. }
  465. /* if ssl is expecting something, check if it's available. */
  466. if(connssl->connecting_state == ssl_connect_2_reading ||
  467. connssl->connecting_state == ssl_connect_2_writing) {
  468. curl_socket_t writefd =
  469. ssl_connect_2_writing == connssl->connecting_state ? sockfd
  470. : CURL_SOCKET_BAD;
  471. curl_socket_t readfd = ssl_connect_2_reading == connssl->connecting_state
  472. ? sockfd
  473. : CURL_SOCKET_BAD;
  474. what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
  475. nonblocking ? 0 : timeout_ms);
  476. if(what < 0) {
  477. /* fatal error */
  478. failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
  479. return CURLE_SSL_CONNECT_ERROR;
  480. }
  481. else if(0 == what) {
  482. if(nonblocking) {
  483. *done = FALSE;
  484. return CURLE_OK;
  485. }
  486. else {
  487. /* timeout */
  488. failf(data, "SSL connection timeout");
  489. return CURLE_OPERATION_TIMEDOUT;
  490. }
  491. }
  492. /* socket is readable or writable */
  493. }
  494. /* Run transaction, and return to the caller if it failed or if
  495. * this connection is part of a multi handle and this loop would
  496. * execute again. This permits the owner of a multi handle to
  497. * abort a connection attempt before step2 has completed while
  498. * ensuring that a client using select() or epoll() will always
  499. * have a valid fdset to wait on.
  500. */
  501. result = mesalink_connect_step2(conn, sockindex);
  502. if(result ||
  503. (nonblocking && (ssl_connect_2 == connssl->connecting_state ||
  504. ssl_connect_2_reading == connssl->connecting_state ||
  505. ssl_connect_2_writing == connssl->connecting_state))) {
  506. return result;
  507. }
  508. } /* repeat step2 until all transactions are done. */
  509. if(ssl_connect_3 == connssl->connecting_state) {
  510. result = mesalink_connect_step3(conn, sockindex);
  511. if(result)
  512. return result;
  513. }
  514. if(ssl_connect_done == connssl->connecting_state) {
  515. connssl->state = ssl_connection_complete;
  516. conn->recv[sockindex] = mesalink_recv;
  517. conn->send[sockindex] = mesalink_send;
  518. *done = TRUE;
  519. }
  520. else
  521. *done = FALSE;
  522. /* Reset our connect state machine */
  523. connssl->connecting_state = ssl_connect_1;
  524. return CURLE_OK;
  525. }
  526. static CURLcode
  527. Curl_mesalink_connect_nonblocking(struct connectdata *conn, int sockindex,
  528. bool *done)
  529. {
  530. return mesalink_connect_common(conn, sockindex, TRUE, done);
  531. }
  532. static CURLcode
  533. Curl_mesalink_connect(struct connectdata *conn, int sockindex)
  534. {
  535. CURLcode result;
  536. bool done = FALSE;
  537. result = mesalink_connect_common(conn, sockindex, FALSE, &done);
  538. if(result)
  539. return result;
  540. DEBUGASSERT(done);
  541. return CURLE_OK;
  542. }
  543. static void *
  544. Curl_mesalink_get_internals(struct ssl_connect_data *connssl,
  545. CURLINFO info UNUSED_PARAM)
  546. {
  547. (void)info;
  548. return BACKEND->handle;
  549. }
  550. const struct Curl_ssl Curl_ssl_mesalink = {
  551. { CURLSSLBACKEND_MESALINK, "MesaLink" }, /* info */
  552. SSLSUPP_SSL_CTX,
  553. sizeof(struct ssl_backend_data),
  554. Curl_mesalink_init, /* init */
  555. Curl_none_cleanup, /* cleanup */
  556. Curl_mesalink_version, /* version */
  557. Curl_none_check_cxn, /* check_cxn */
  558. Curl_mesalink_shutdown, /* shutdown */
  559. Curl_none_data_pending, /* data_pending */
  560. Curl_none_random, /* random */
  561. Curl_none_cert_status_request, /* cert_status_request */
  562. Curl_mesalink_connect, /* connect */
  563. Curl_mesalink_connect_nonblocking, /* connect_nonblocking */
  564. Curl_mesalink_get_internals, /* get_internals */
  565. Curl_mesalink_close, /* close_one */
  566. Curl_none_close_all, /* close_all */
  567. Curl_none_session_free, /* session_free */
  568. Curl_none_set_engine, /* set_engine */
  569. Curl_none_set_engine_default, /* set_engine_default */
  570. Curl_none_engines_list, /* engines_list */
  571. Curl_none_false_start, /* false_start */
  572. Curl_none_md5sum, /* md5sum */
  573. NULL /* sha256sum */
  574. };
  575. #endif