Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vtls/rustls: 0.14.0 update and assoc. improvements #14889

Closed
wants to merge 5 commits into from

Conversation

cpu
Copy link
Contributor

@cpu cpu commented Sep 12, 2024

👋 This branch updates the experimental rustls vtls backend for curl to use the just-released rustls-ffi 0.14.0, and the latest release of the main rust crate, rustls 0.23.13.

Along the way I made a handful of other small improvements and so I recommend reviewing commit-by-commit. My goal was to have each commit build independent of the others, and to avoid introducing new functionality at the same time as updating breaking API changes. I've done my best to match local style but I'm still quite green at contributing to curl: feedback very welcome.

In addition to the 0.14.0 update, this branch resolves the "weak RNG" situation described in #14770 and replaces the ciphersuite name string comparison logic from #14840 with a more robust solution based on protocol version constants.

Don't build `config_builder` just to free the resulting config, free the
builder directly.

When `cr_init_backend` encounters an error condition setting up the
Rustls client configuration it must do something with the
`config_builder` that was constructed earlier to avoid a memory leak.

The previous implementation preferred to use a pattern of building the
builder (thus consuming it) and then freeing the built config (to avoid
a memory leak). However, the purpose/intent is clearer when we just free
the builder directly instead of building it and freeing the result.
It's easier to diagnose a problem when there is one place where the
error message can be emitted. For that reason this commit updates two
errors that were shared between other fallible operations to use unique
messages.
* Documentation is updated to describe new required version, and to link
  to the upstream README about cryptography providers.
* GitHub workflow is updated to fetch 0.14.0.
* Breaking changes in`lib/vtls/rustls.c` are addressed:
  * The `rustls_client_config_builder_build()` function now uses an out
    parameter for the built config instead of returning it directly.
    This allows the building process to fail if the default crypto
    provider state isn't appropriate, or another error condition occurs.
  * Default ciphersuites are collected using renamed functions named to
    make it clear the ciphersuites are associated with the default
    crypto provider.
  * Customization of ciphersuites is now done via
    a `rustls_crypto_provider_builder` used to instantiate a
    `rustls_crypto_provider`. The customized provider can then can be
    used with `rustls_client_config_builder_new_custom` in place of
    providing ciphersuites directly.
  * `rustls_connection_get_negotiated_ciphersuite()` now returns the
    ciphersuite ID directly.
@github-actions github-actions bot added the CI Continuous Integration label Sep 12, 2024
@cpu
Copy link
Contributor Author

cpu commented Sep 12, 2024

(cc @ctz in case you were interested in giving this a 🔍)

lib/rand.c Show resolved Hide resolved
lib/vtls/rustls.c Show resolved Hide resolved
Now that the rustls vtls backend is using rustls 0.14 we can take
advantage of `rustls_supported_ciphersuite_protocol_version()` to skip
TLS 1.3 and TLS 1.2 ciphersuites as required without needing to
interrogate the ciphersuite names as `rustls_str`s.
@cpu cpu force-pushed the cpu-rustls-ffi-0.14-tidy/ci branch from 750ce4f to 0d65a9c Compare September 12, 2024 19:13
@cpu cpu force-pushed the cpu-rustls-ffi-0.14-tidy/ci branch 2 times, most recently from f2d8a9d to 2ea09f8 Compare September 12, 2024 19:42
lib/vtls/rustls.c Outdated Show resolved Hide resolved
lib/rand.c Outdated Show resolved Hide resolved
@cpu cpu force-pushed the cpu-rustls-ffi-0.14-tidy/ci branch from 2ea09f8 to 7b5134b Compare September 12, 2024 19:48
Now that the curl rustls vtls backend is using rustls 0.14 we can
address the weak random situation by using
`rustls_default_crypto_provider_random()` to provide a `Curl_ssl`
`random` callback that fills the provided buffer with cryptographically
secure random data.

The mentions in `docs/` about weak RNG when using rustls are removed as
they are no longer applicable.
@cpu cpu force-pushed the cpu-rustls-ffi-0.14-tidy/ci branch from 7b5134b to d3b3480 Compare September 12, 2024 19:51
Copy link
Member

@bagder bagder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@bagder bagder closed this in d38458d Sep 13, 2024
bagder pushed a commit that referenced this pull request Sep 13, 2024
It's easier to diagnose a problem when there is one place where the
error message can be emitted. For that reason this commit updates two
errors that were shared between other fallible operations to use unique
messages.

Closes #14889
bagder pushed a commit that referenced this pull request Sep 13, 2024
* Documentation is updated to describe new required version, and to link
  to the upstream README about cryptography providers.
* GitHub workflow is updated to fetch 0.14.0.
* Breaking changes in`lib/vtls/rustls.c` are addressed:
  * The `rustls_client_config_builder_build()` function now uses an out
    parameter for the built config instead of returning it directly.
    This allows the building process to fail if the default crypto
    provider state isn't appropriate, or another error condition occurs.
  * Default ciphersuites are collected using renamed functions named to
    make it clear the ciphersuites are associated with the default
    crypto provider.
  * Customization of ciphersuites is now done via
    a `rustls_crypto_provider_builder` used to instantiate a
    `rustls_crypto_provider`. The customized provider can then can be
    used with `rustls_client_config_builder_new_custom` in place of
    providing ciphersuites directly.
  * `rustls_connection_get_negotiated_ciphersuite()` now returns the
    ciphersuite ID directly.

Closes #14889
bagder pushed a commit that referenced this pull request Sep 13, 2024
Now that the rustls vtls backend is using rustls 0.14 we can take
advantage of `rustls_supported_ciphersuite_protocol_version()` to skip
TLS 1.3 and TLS 1.2 ciphersuites as required without needing to
interrogate the ciphersuite names as `rustls_str`s.

Closes #14889
bagder pushed a commit that referenced this pull request Sep 13, 2024
Now that the curl rustls vtls backend is using rustls 0.14 we can
address the weak random situation by using
`rustls_default_crypto_provider_random()` to provide a `Curl_ssl`
`random` callback that fills the provided buffer with cryptographically
secure random data.

The mentions in `docs/` about weak RNG when using rustls are removed as
they are no longer applicable.

Closes #14889
@bagder
Copy link
Member

bagder commented Sep 13, 2024

Thanks!

@cpu cpu deleted the cpu-rustls-ffi-0.14-tidy/ci branch September 13, 2024 12:46
@cpu
Copy link
Contributor Author

cpu commented Sep 13, 2024

Thanks for the reviews :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Continuous Integration
Development

Successfully merging this pull request may close these issues.

3 participants