[Rustls is a TLS backend written in Rust.](https://docs.rs/rustls/). Curl can
be built to use it as an alternative to OpenSSL or other TLS backends. We use
the [rustls-ffi C bindings](https://github.com/rustls/rustls-ffi/). This
-version of curl depends on version v0.7.0 of rustls-ffi.
+version of curl depends on version v0.8.0 of rustls-ffi.
# Building with rustls
Next, check out, build, and install the appropriate version of rustls-ffi:
% cargo install cbindgen
- % git clone https://github.com/rustls/rustls-ffi -b v0.7.0
+ % git clone https://github.com/rustls/rustls-ffi -b v0.8.0
% cd rustls-ffi
% make
% make DESTDIR=${HOME}/rustls-ffi-built/ install
(uint8_t *)plainbuf + plain_bytes_copied,
plainlen - plain_bytes_copied,
&n);
- if(n == 0) {
- *err = CURLE_OK;
- return 0;
+ if(rresult == RUSTLS_RESULT_PLAINTEXT_EMPTY) {
+ infof(data, "cr_recv got 0 bytes of plaintext");
+ backend->data_pending = FALSE;
+ break;
}
- else if(rresult != RUSTLS_RESULT_OK &&
- rresult != RUSTLS_RESULT_PLAINTEXT_EMPTY) {
- failf(data, "error in rustls_connection_read");
+ else if(rresult != RUSTLS_RESULT_OK) {
+ /* n always equals 0 in this case, don't need to check it */
+ failf(data, "error in rustls_connection_read: %d", rresult);
*err = CURLE_READ_ERROR;
return -1;
}
- else if(rresult == RUSTLS_RESULT_PLAINTEXT_EMPTY) {
- infof(data, "cr_recv got 0 bytes of plaintext");
- backend->data_pending = FALSE;
- break;
+ else if(n == 0) {
+ *err = CURLE_OK;
+ return 0;
}
else {
infof(data, "cr_recv copied out %ld bytes of plaintext", n);
}
}
+static size_t cr_version(char *buffer, size_t size)
+{
+ struct rustls_str ver = rustls_version();
+ return msnprintf(buffer, size, "%.*s", (int)ver.len, ver.data);
+}
+
const struct Curl_ssl Curl_ssl_rustls = {
{ CURLSSLBACKEND_RUSTLS, "rustls" },
SSLSUPP_TLS13_CIPHERSUITES, /* supports */
Curl_none_init, /* init */
Curl_none_cleanup, /* cleanup */
- rustls_version, /* version */
+ cr_version, /* version */
Curl_none_check_cxn, /* check_cxn */
Curl_none_shutdown, /* shutdown */
cr_data_pending, /* data_pending */