Avoid enabling multiple rustls backends by accident

For this, we had to:

- Make the choice(s) of backend explicit in tokio-xmpp features
- Avoid picking a backend through transitive dependencies in xmpp
  (reqwest->hyper->rustls).

In addition, we choose the default rustls backend by default and adapt
the examples so that they can cope with either situation.
This commit is contained in:
Jonas Schäfer 2025-05-10 09:54:01 +02:00
commit 4e9e18444c
11 changed files with 134 additions and 15 deletions

View file

@ -33,7 +33,9 @@ required-features = ["avatars"]
[features]
default = ["avatars", "starttls-rust"]
starttls-native = ["tokio-xmpp/starttls", "tokio-xmpp/tls-native", "reqwest/native-tls"]
starttls-rust = ["tokio-xmpp/starttls", "tokio-xmpp/tls-rust", "reqwest/rustls-tls"]
starttls-rust = ["tokio-xmpp/starttls", "tokio-xmpp/tls-rust", "reqwest/rustls-tls-no-provider", "tokio-xmpp/tls-rust-webpki-roots"]
starttls-rust-aws_lc_rs = ["tokio-xmpp/tls-rust-aws_lc_rs", "starttls-rust"]
starttls-rust-ring = ["tokio-xmpp/tls-rust-ring", "starttls-rust"]
avatars = []
escape-hatch = []
syntax-highlighting = [ "tokio-xmpp/syntax-highlighting" ]

View file

@ -15,6 +15,13 @@ XXXX-YY-ZZ [ RELEASER <admin@localhost> ]
- Agent::send_room_private_message now takes RoomPrivateMessageSettings (!487)
- Event now exposes Option<MessageId> for incoming messages, and MessageId
for incoming message corrections; type alias Id has been removed (!504)
- The `starttls-rust` feature flag does not automatically enable a
`rustls` crypto provider anymore. This is to avoid conflict between
two crypto providers and to avoid linking unnecessary code. The
`aws_lc_rs` crypto provider is still built by default, however,
applications which use `xmpp` without default features will have to
adapt their feature flags to explicitly enable the
`starttls-rust-aws_lc_rs` or `starttls-rust-ring` features. (!581)
* Added:
- Agent::send_room_message takes RoomMessageSettings argument (!483)
- Agent::send_raw_message takes RawMessageSettings for any message type (!487)

View file

@ -4,6 +4,11 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#[cfg(all(
feature = "starttls-rust",
any(feature = "starttls-rust-aws_lc_rs", feature = "starttls-rust-ring")
))]
use xmpp::tokio_xmpp::rustls;
use xmpp::{
jid::BareJid,
muc::room::{JoinRoomSettings, RoomMessageSettings},
@ -19,6 +24,20 @@ use std::str::FromStr;
async fn main() -> Result<(), Option<()>> {
env_logger::init();
#[cfg(all(feature = "starttls-rust", feature = "starttls-rust-aws_lc_rs"))]
rustls::crypto::aws_lc_rs::default_provider()
.install_default()
.expect("failed to install rustls crypto provider");
#[cfg(all(
feature = "starttls-rust",
feature = "starttls-rust-ring",
not(feature = "starttls-rust-aws_lc_rs")
))]
rustls::crypto::ring::default_provider()
.install_default()
.expect("failed to install rustls crypto provider");
let args: Vec<String> = args().collect();
if args.len() < 3 {
println!("Usage: {} <jid> <password> [ROOM...]", args[0]);