mesalink.c 19 KB

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