rustls.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 2020 - 2022, Jacob Hoffman-Andrews,
  9. * <github@hoffman-andrews.com>
  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. * SPDX-License-Identifier: curl
  23. *
  24. ***************************************************************************/
  25. #include "curl_setup.h"
  26. #ifdef USE_RUSTLS
  27. #include "curl_printf.h"
  28. #include <errno.h>
  29. #include <rustls.h>
  30. #include "inet_pton.h"
  31. #include "urldata.h"
  32. #include "sendf.h"
  33. #include "vtls.h"
  34. #include "select.h"
  35. #include "strerror.h"
  36. #include "multiif.h"
  37. struct ssl_backend_data
  38. {
  39. const struct rustls_client_config *config;
  40. struct rustls_connection *conn;
  41. bool data_pending;
  42. };
  43. /* For a given rustls_result error code, return the best-matching CURLcode. */
  44. static CURLcode map_error(rustls_result r)
  45. {
  46. if(rustls_result_is_cert_error(r)) {
  47. return CURLE_PEER_FAILED_VERIFICATION;
  48. }
  49. switch(r) {
  50. case RUSTLS_RESULT_OK:
  51. return CURLE_OK;
  52. case RUSTLS_RESULT_NULL_PARAMETER:
  53. return CURLE_BAD_FUNCTION_ARGUMENT;
  54. default:
  55. return CURLE_READ_ERROR;
  56. }
  57. }
  58. static bool
  59. cr_data_pending(const struct connectdata *conn, int sockindex)
  60. {
  61. const struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  62. struct ssl_backend_data *backend = connssl->backend;
  63. DEBUGASSERT(backend);
  64. return backend->data_pending;
  65. }
  66. static CURLcode
  67. cr_connect(struct Curl_easy *data UNUSED_PARAM,
  68. struct connectdata *conn UNUSED_PARAM,
  69. int sockindex UNUSED_PARAM)
  70. {
  71. infof(data, "rustls_connect: unimplemented");
  72. return CURLE_SSL_CONNECT_ERROR;
  73. }
  74. static int
  75. read_cb(void *userdata, uint8_t *buf, uintptr_t len, uintptr_t *out_n)
  76. {
  77. ssize_t n = sread(*(int *)userdata, buf, len);
  78. if(n < 0) {
  79. return SOCKERRNO;
  80. }
  81. *out_n = n;
  82. return 0;
  83. }
  84. static int
  85. write_cb(void *userdata, const uint8_t *buf, uintptr_t len, uintptr_t *out_n)
  86. {
  87. ssize_t n = swrite(*(int *)userdata, buf, len);
  88. if(n < 0) {
  89. return SOCKERRNO;
  90. }
  91. *out_n = n;
  92. return 0;
  93. }
  94. /*
  95. * On each run:
  96. * - Read a chunk of bytes from the socket into rustls' TLS input buffer.
  97. * - Tell rustls to process any new packets.
  98. * - Read out as many plaintext bytes from rustls as possible, until hitting
  99. * error, EOF, or EAGAIN/EWOULDBLOCK, or plainbuf/plainlen is filled up.
  100. *
  101. * It's okay to call this function with plainbuf == NULL and plainlen == 0.
  102. * In that case, it will copy bytes from the socket into rustls' TLS input
  103. * buffer, and process packets, but won't consume bytes from rustls' plaintext
  104. * output buffer.
  105. */
  106. static ssize_t
  107. cr_recv(struct Curl_easy *data, int sockindex,
  108. char *plainbuf, size_t plainlen, CURLcode *err)
  109. {
  110. struct connectdata *conn = data->conn;
  111. struct ssl_connect_data *const connssl = &conn->ssl[sockindex];
  112. struct ssl_backend_data *const backend = connssl->backend;
  113. struct rustls_connection *rconn = NULL;
  114. size_t n = 0;
  115. size_t tls_bytes_read = 0;
  116. size_t plain_bytes_copied = 0;
  117. rustls_result rresult = 0;
  118. char errorbuf[255];
  119. rustls_io_result io_error;
  120. DEBUGASSERT(backend);
  121. rconn = backend->conn;
  122. io_error = rustls_connection_read_tls(rconn, read_cb,
  123. &conn->sock[sockindex], &tls_bytes_read);
  124. if(io_error == EAGAIN || io_error == EWOULDBLOCK) {
  125. infof(data, "sread: EAGAIN or EWOULDBLOCK");
  126. }
  127. else if(io_error) {
  128. char buffer[STRERROR_LEN];
  129. failf(data, "reading from socket: %s",
  130. Curl_strerror(io_error, buffer, sizeof(buffer)));
  131. *err = CURLE_READ_ERROR;
  132. return -1;
  133. }
  134. infof(data, "cr_recv read %ld bytes from the network", tls_bytes_read);
  135. rresult = rustls_connection_process_new_packets(rconn);
  136. if(rresult != RUSTLS_RESULT_OK) {
  137. rustls_error(rresult, errorbuf, sizeof(errorbuf), &n);
  138. failf(data, "%.*s", n, errorbuf);
  139. *err = map_error(rresult);
  140. return -1;
  141. }
  142. backend->data_pending = TRUE;
  143. while(plain_bytes_copied < plainlen) {
  144. rresult = rustls_connection_read(rconn,
  145. (uint8_t *)plainbuf + plain_bytes_copied,
  146. plainlen - plain_bytes_copied,
  147. &n);
  148. if(rresult == RUSTLS_RESULT_PLAINTEXT_EMPTY) {
  149. infof(data, "cr_recv got PLAINTEXT_EMPTY. will try again later.");
  150. backend->data_pending = FALSE;
  151. break;
  152. }
  153. else if(rresult != RUSTLS_RESULT_OK) {
  154. /* n always equals 0 in this case, don't need to check it */
  155. failf(data, "error in rustls_connection_read: %d", rresult);
  156. *err = CURLE_READ_ERROR;
  157. return -1;
  158. }
  159. else if(n == 0) {
  160. /* n == 0 indicates clean EOF, but we may have read some other
  161. plaintext bytes before we reached this. Break out of the loop
  162. so we can figure out whether to return success or EOF. */
  163. break;
  164. }
  165. else {
  166. infof(data, "cr_recv copied out %ld bytes of plaintext", n);
  167. plain_bytes_copied += n;
  168. }
  169. }
  170. if(plain_bytes_copied) {
  171. *err = CURLE_OK;
  172. return plain_bytes_copied;
  173. }
  174. /* If we wrote out 0 plaintext bytes, that means either we hit a clean EOF,
  175. OR we got a RUSTLS_RESULT_PLAINTEXT_EMPTY.
  176. If the latter, return CURLE_AGAIN so curl doesn't treat this as EOF. */
  177. if(!backend->data_pending) {
  178. *err = CURLE_AGAIN;
  179. return -1;
  180. }
  181. /* Zero bytes read, and no RUSTLS_RESULT_PLAINTEXT_EMPTY, means the TCP
  182. connection was cleanly closed (with a close_notify alert). */
  183. *err = CURLE_OK;
  184. return 0;
  185. }
  186. /*
  187. * On each call:
  188. * - Copy `plainlen` bytes into rustls' plaintext input buffer (if > 0).
  189. * - Fully drain rustls' plaintext output buffer into the socket until
  190. * we get either an error or EAGAIN/EWOULDBLOCK.
  191. *
  192. * It's okay to call this function with plainbuf == NULL and plainlen == 0.
  193. * In that case, it won't read anything into rustls' plaintext input buffer.
  194. * It will only drain rustls' plaintext output buffer into the socket.
  195. */
  196. static ssize_t
  197. cr_send(struct Curl_easy *data, int sockindex,
  198. const void *plainbuf, size_t plainlen, CURLcode *err)
  199. {
  200. struct connectdata *conn = data->conn;
  201. struct ssl_connect_data *const connssl = &conn->ssl[sockindex];
  202. struct ssl_backend_data *const backend = connssl->backend;
  203. struct rustls_connection *rconn = NULL;
  204. size_t plainwritten = 0;
  205. size_t tlswritten = 0;
  206. size_t tlswritten_total = 0;
  207. rustls_result rresult;
  208. rustls_io_result io_error;
  209. DEBUGASSERT(backend);
  210. rconn = backend->conn;
  211. infof(data, "cr_send %ld bytes of plaintext", plainlen);
  212. if(plainlen > 0) {
  213. rresult = rustls_connection_write(rconn, plainbuf, plainlen,
  214. &plainwritten);
  215. if(rresult != RUSTLS_RESULT_OK) {
  216. failf(data, "error in rustls_connection_write");
  217. *err = CURLE_WRITE_ERROR;
  218. return -1;
  219. }
  220. else if(plainwritten == 0) {
  221. failf(data, "EOF in rustls_connection_write");
  222. *err = CURLE_WRITE_ERROR;
  223. return -1;
  224. }
  225. }
  226. while(rustls_connection_wants_write(rconn)) {
  227. io_error = rustls_connection_write_tls(rconn, write_cb,
  228. &conn->sock[sockindex], &tlswritten);
  229. if(io_error == EAGAIN || io_error == EWOULDBLOCK) {
  230. infof(data, "swrite: EAGAIN after %ld bytes", tlswritten_total);
  231. *err = CURLE_AGAIN;
  232. return -1;
  233. }
  234. else if(io_error) {
  235. char buffer[STRERROR_LEN];
  236. failf(data, "writing to socket: %s",
  237. Curl_strerror(io_error, buffer, sizeof(buffer)));
  238. *err = CURLE_WRITE_ERROR;
  239. return -1;
  240. }
  241. if(tlswritten == 0) {
  242. failf(data, "EOF in swrite");
  243. *err = CURLE_WRITE_ERROR;
  244. return -1;
  245. }
  246. infof(data, "cr_send wrote %ld bytes to network", tlswritten);
  247. tlswritten_total += tlswritten;
  248. }
  249. return plainwritten;
  250. }
  251. /* A server certificate verify callback for rustls that always returns
  252. RUSTLS_RESULT_OK, or in other words disable certificate verification. */
  253. static enum rustls_result
  254. cr_verify_none(void *userdata UNUSED_PARAM,
  255. const rustls_verify_server_cert_params *params UNUSED_PARAM)
  256. {
  257. return RUSTLS_RESULT_OK;
  258. }
  259. static bool
  260. cr_hostname_is_ip(const char *hostname)
  261. {
  262. struct in_addr in;
  263. #ifdef ENABLE_IPV6
  264. struct in6_addr in6;
  265. if(Curl_inet_pton(AF_INET6, hostname, &in6) > 0) {
  266. return true;
  267. }
  268. #endif /* ENABLE_IPV6 */
  269. if(Curl_inet_pton(AF_INET, hostname, &in) > 0) {
  270. return true;
  271. }
  272. return false;
  273. }
  274. static CURLcode
  275. cr_init_backend(struct Curl_easy *data, struct connectdata *conn,
  276. struct ssl_backend_data *const backend)
  277. {
  278. struct rustls_connection *rconn = NULL;
  279. struct rustls_client_config_builder *config_builder = NULL;
  280. struct rustls_root_cert_store *roots = NULL;
  281. const struct curl_blob *ca_info_blob = SSL_CONN_CONFIG(ca_info_blob);
  282. const char * const ssl_cafile =
  283. /* CURLOPT_CAINFO_BLOB overrides CURLOPT_CAINFO */
  284. (ca_info_blob ? NULL : SSL_CONN_CONFIG(CAfile));
  285. const bool verifypeer = SSL_CONN_CONFIG(verifypeer);
  286. const char *hostname = conn->host.name;
  287. char errorbuf[256];
  288. size_t errorlen;
  289. int result;
  290. rustls_slice_bytes alpn[2] = {
  291. { (const uint8_t *)ALPN_HTTP_1_1, ALPN_HTTP_1_1_LENGTH },
  292. { (const uint8_t *)ALPN_H2, ALPN_H2_LENGTH },
  293. };
  294. DEBUGASSERT(backend);
  295. rconn = backend->conn;
  296. config_builder = rustls_client_config_builder_new();
  297. #ifdef USE_HTTP2
  298. infof(data, VTLS_INFOF_ALPN_OFFER_1STR, ALPN_H2);
  299. rustls_client_config_builder_set_alpn_protocols(config_builder, alpn, 2);
  300. #else
  301. rustls_client_config_builder_set_alpn_protocols(config_builder, alpn, 1);
  302. #endif
  303. infof(data, VTLS_INFOF_ALPN_OFFER_1STR, ALPN_HTTP_1_1);
  304. if(!verifypeer) {
  305. rustls_client_config_builder_dangerous_set_certificate_verifier(
  306. config_builder, cr_verify_none);
  307. /* rustls doesn't support IP addresses (as of 0.19.0), and will reject
  308. * connections created with an IP address, even when certificate
  309. * verification is turned off. Set a placeholder hostname and disable
  310. * SNI. */
  311. if(cr_hostname_is_ip(hostname)) {
  312. rustls_client_config_builder_set_enable_sni(config_builder, false);
  313. hostname = "example.invalid";
  314. }
  315. }
  316. else if(ca_info_blob) {
  317. roots = rustls_root_cert_store_new();
  318. /* Enable strict parsing only if verification isn't disabled. */
  319. result = rustls_root_cert_store_add_pem(roots, ca_info_blob->data,
  320. ca_info_blob->len, verifypeer);
  321. if(result != RUSTLS_RESULT_OK) {
  322. failf(data, "failed to parse trusted certificates from blob");
  323. rustls_root_cert_store_free(roots);
  324. rustls_client_config_free(
  325. rustls_client_config_builder_build(config_builder));
  326. return CURLE_SSL_CACERT_BADFILE;
  327. }
  328. result = rustls_client_config_builder_use_roots(config_builder, roots);
  329. rustls_root_cert_store_free(roots);
  330. if(result != RUSTLS_RESULT_OK) {
  331. failf(data, "failed to load trusted certificates");
  332. rustls_client_config_free(
  333. rustls_client_config_builder_build(config_builder));
  334. return CURLE_SSL_CACERT_BADFILE;
  335. }
  336. }
  337. else if(ssl_cafile) {
  338. result = rustls_client_config_builder_load_roots_from_file(
  339. config_builder, ssl_cafile);
  340. if(result != RUSTLS_RESULT_OK) {
  341. failf(data, "failed to load trusted certificates");
  342. rustls_client_config_free(
  343. rustls_client_config_builder_build(config_builder));
  344. return CURLE_SSL_CACERT_BADFILE;
  345. }
  346. }
  347. backend->config = rustls_client_config_builder_build(config_builder);
  348. DEBUGASSERT(rconn == NULL);
  349. {
  350. char *snihost = Curl_ssl_snihost(data, hostname, NULL);
  351. if(!snihost) {
  352. failf(data, "Failed to set SNI");
  353. return CURLE_SSL_CONNECT_ERROR;
  354. }
  355. result = rustls_client_connection_new(backend->config, snihost, &rconn);
  356. }
  357. if(result != RUSTLS_RESULT_OK) {
  358. rustls_error(result, errorbuf, sizeof(errorbuf), &errorlen);
  359. failf(data, "rustls_client_connection_new: %.*s", errorlen, errorbuf);
  360. return CURLE_COULDNT_CONNECT;
  361. }
  362. rustls_connection_set_userdata(rconn, backend);
  363. backend->conn = rconn;
  364. return CURLE_OK;
  365. }
  366. static void
  367. cr_set_negotiated_alpn(struct Curl_easy *data, struct connectdata *conn,
  368. const struct rustls_connection *rconn)
  369. {
  370. const uint8_t *protocol = NULL;
  371. size_t len = 0;
  372. rustls_connection_get_alpn_protocol(rconn, &protocol, &len);
  373. if(!protocol) {
  374. infof(data, VTLS_INFOF_NO_ALPN);
  375. return;
  376. }
  377. #ifdef USE_HTTP2
  378. if(len == ALPN_H2_LENGTH && 0 == memcmp(ALPN_H2, protocol, len)) {
  379. infof(data, VTLS_INFOF_ALPN_ACCEPTED_1STR, ALPN_H2);
  380. conn->alpn = CURL_HTTP_VERSION_2;
  381. }
  382. else
  383. #endif
  384. if(len == ALPN_HTTP_1_1_LENGTH &&
  385. 0 == memcmp(ALPN_HTTP_1_1, protocol, len)) {
  386. infof(data, VTLS_INFOF_ALPN_ACCEPTED_1STR, ALPN_HTTP_1_1);
  387. conn->alpn = CURL_HTTP_VERSION_1_1;
  388. }
  389. else {
  390. infof(data, "ALPN, negotiated an unrecognized protocol");
  391. }
  392. Curl_multiuse_state(data, conn->alpn == CURL_HTTP_VERSION_2 ?
  393. BUNDLE_MULTIPLEX : BUNDLE_NO_MULTIUSE);
  394. }
  395. static CURLcode
  396. cr_connect_nonblocking(struct Curl_easy *data, struct connectdata *conn,
  397. int sockindex, bool *done)
  398. {
  399. struct ssl_connect_data *const connssl = &conn->ssl[sockindex];
  400. curl_socket_t sockfd = conn->sock[sockindex];
  401. struct ssl_backend_data *const backend = connssl->backend;
  402. struct rustls_connection *rconn = NULL;
  403. CURLcode tmperr = CURLE_OK;
  404. int result;
  405. int what;
  406. bool wants_read;
  407. bool wants_write;
  408. curl_socket_t writefd;
  409. curl_socket_t readfd;
  410. DEBUGASSERT(backend);
  411. if(ssl_connection_none == connssl->state) {
  412. result = cr_init_backend(data, conn, connssl->backend);
  413. if(result != CURLE_OK) {
  414. return result;
  415. }
  416. connssl->state = ssl_connection_negotiating;
  417. }
  418. rconn = backend->conn;
  419. /* Read/write data until the handshake is done or the socket would block. */
  420. for(;;) {
  421. /*
  422. * Connection has been established according to rustls. Set send/recv
  423. * handlers, and update the state machine.
  424. */
  425. if(!rustls_connection_is_handshaking(rconn)) {
  426. infof(data, "Done handshaking");
  427. /* Done with the handshake. Set up callbacks to send/receive data. */
  428. connssl->state = ssl_connection_complete;
  429. cr_set_negotiated_alpn(data, conn, rconn);
  430. conn->recv[sockindex] = cr_recv;
  431. conn->send[sockindex] = cr_send;
  432. *done = TRUE;
  433. return CURLE_OK;
  434. }
  435. wants_read = rustls_connection_wants_read(rconn);
  436. wants_write = rustls_connection_wants_write(rconn);
  437. DEBUGASSERT(wants_read || wants_write);
  438. writefd = wants_write?sockfd:CURL_SOCKET_BAD;
  439. readfd = wants_read?sockfd:CURL_SOCKET_BAD;
  440. what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd, 0);
  441. if(what < 0) {
  442. /* fatal error */
  443. failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
  444. return CURLE_SSL_CONNECT_ERROR;
  445. }
  446. if(0 == what) {
  447. infof(data, "Curl_socket_check: %s would block",
  448. wants_read&&wants_write ? "writing and reading" :
  449. wants_write ? "writing" : "reading");
  450. *done = FALSE;
  451. return CURLE_OK;
  452. }
  453. /* socket is readable or writable */
  454. if(wants_write) {
  455. infof(data, "rustls_connection wants us to write_tls.");
  456. cr_send(data, sockindex, NULL, 0, &tmperr);
  457. if(tmperr == CURLE_AGAIN) {
  458. infof(data, "writing would block");
  459. /* fall through */
  460. }
  461. else if(tmperr != CURLE_OK) {
  462. return tmperr;
  463. }
  464. }
  465. if(wants_read) {
  466. infof(data, "rustls_connection wants us to read_tls.");
  467. cr_recv(data, sockindex, NULL, 0, &tmperr);
  468. if(tmperr == CURLE_AGAIN) {
  469. infof(data, "reading would block");
  470. /* fall through */
  471. }
  472. else if(tmperr != CURLE_OK) {
  473. if(tmperr == CURLE_READ_ERROR) {
  474. return CURLE_SSL_CONNECT_ERROR;
  475. }
  476. else {
  477. return tmperr;
  478. }
  479. }
  480. }
  481. }
  482. /* We should never fall through the loop. We should return either because
  483. the handshake is done or because we can't read/write without blocking. */
  484. DEBUGASSERT(false);
  485. }
  486. /* returns a bitmap of flags for this connection's first socket indicating
  487. whether we want to read or write */
  488. static int
  489. cr_getsock(struct connectdata *conn, curl_socket_t *socks)
  490. {
  491. struct ssl_connect_data *const connssl = &conn->ssl[FIRSTSOCKET];
  492. curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
  493. struct ssl_backend_data *const backend = connssl->backend;
  494. struct rustls_connection *rconn = NULL;
  495. DEBUGASSERT(backend);
  496. rconn = backend->conn;
  497. if(rustls_connection_wants_write(rconn)) {
  498. socks[0] = sockfd;
  499. return GETSOCK_WRITESOCK(0);
  500. }
  501. if(rustls_connection_wants_read(rconn)) {
  502. socks[0] = sockfd;
  503. return GETSOCK_READSOCK(0);
  504. }
  505. return GETSOCK_BLANK;
  506. }
  507. static void *
  508. cr_get_internals(struct ssl_connect_data *connssl,
  509. CURLINFO info UNUSED_PARAM)
  510. {
  511. struct ssl_backend_data *backend = connssl->backend;
  512. DEBUGASSERT(backend);
  513. return &backend->conn;
  514. }
  515. static void
  516. cr_close(struct Curl_easy *data, struct connectdata *conn,
  517. int sockindex)
  518. {
  519. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  520. struct ssl_backend_data *backend = connssl->backend;
  521. CURLcode tmperr = CURLE_OK;
  522. ssize_t n = 0;
  523. DEBUGASSERT(backend);
  524. if(backend->conn) {
  525. rustls_connection_send_close_notify(backend->conn);
  526. n = cr_send(data, sockindex, NULL, 0, &tmperr);
  527. if(n < 0) {
  528. failf(data, "error sending close notify: %d", tmperr);
  529. }
  530. rustls_connection_free(backend->conn);
  531. backend->conn = NULL;
  532. }
  533. if(backend->config) {
  534. rustls_client_config_free(backend->config);
  535. backend->config = NULL;
  536. }
  537. }
  538. static size_t cr_version(char *buffer, size_t size)
  539. {
  540. struct rustls_str ver = rustls_version();
  541. return msnprintf(buffer, size, "%.*s", (int)ver.len, ver.data);
  542. }
  543. const struct Curl_ssl Curl_ssl_rustls = {
  544. { CURLSSLBACKEND_RUSTLS, "rustls" },
  545. SSLSUPP_CAINFO_BLOB | /* supports */
  546. SSLSUPP_TLS13_CIPHERSUITES,
  547. sizeof(struct ssl_backend_data),
  548. Curl_none_init, /* init */
  549. Curl_none_cleanup, /* cleanup */
  550. cr_version, /* version */
  551. Curl_none_check_cxn, /* check_cxn */
  552. Curl_none_shutdown, /* shutdown */
  553. cr_data_pending, /* data_pending */
  554. Curl_none_random, /* random */
  555. Curl_none_cert_status_request, /* cert_status_request */
  556. cr_connect, /* connect */
  557. cr_connect_nonblocking, /* connect_nonblocking */
  558. cr_getsock, /* cr_getsock */
  559. cr_get_internals, /* get_internals */
  560. cr_close, /* close_one */
  561. Curl_none_close_all, /* close_all */
  562. Curl_none_session_free, /* session_free */
  563. Curl_none_set_engine, /* set_engine */
  564. Curl_none_set_engine_default, /* set_engine_default */
  565. Curl_none_engines_list, /* engines_list */
  566. Curl_none_false_start, /* false_start */
  567. NULL, /* sha256sum */
  568. NULL, /* associate_connection */
  569. NULL /* disassociate_connection */
  570. };
  571. #endif /* USE_RUSTLS */