vtls/rustls: adapt to the updated rustls_version proto

Closes #7956
This commit is contained in:
Daniel Stenberg 2021-11-04 10:37:32 +01:00
parent 1fef5922da
commit 76d9e07c6b
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
3 changed files with 21 additions and 14 deletions

View File

@ -3,7 +3,7 @@
[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
@ -12,7 +12,7 @@ First, [install Rust](https://rustup.rs/).
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

View File

@ -161,21 +161,21 @@ cr_recv(struct Curl_easy *data, int sockindex,
(uint8_t *)plainbuf + plain_bytes_copied,
plainlen - plain_bytes_copied,
&n);
if(n == 0) {
*err = CURLE_OK;
return 0;
}
else if(rresult != RUSTLS_RESULT_OK &&
rresult != RUSTLS_RESULT_PLAINTEXT_EMPTY) {
failf(data, "error in rustls_connection_read");
*err = CURLE_READ_ERROR;
return -1;
}
else if(rresult == RUSTLS_RESULT_PLAINTEXT_EMPTY) {
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) {
/* 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(n == 0) {
*err = CURLE_OK;
return 0;
}
else {
infof(data, "cr_recv copied out %ld bytes of plaintext", n);
plain_bytes_copied += n;
@ -540,6 +540,12 @@ cr_close(struct Curl_easy *data, struct connectdata *conn,
}
}
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 */
@ -547,7 +553,7 @@ const struct Curl_ssl Curl_ssl_rustls = {
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 */

View File

@ -131,6 +131,7 @@
- libzstd-dev
curl_env:
T: debug-rustls
# Keep this in sync with the version in docs/RUSTLS.md
RUSTLS_VERSION: v0.8.0
LIBS: -lm
C: >-