reqwest icon indicating copy to clipboard operation
reqwest copied to clipboard

Use `rustls` default provider unless specified

Open GreenYun opened this issue 1 year ago • 2 comments

Starting from rustls 0.23, the backend provider is aws-lc-rs. However, request hard coded many rings, especially the default rustls-tls feature. Will this change in the future to use the default setup from rustls unless some more other features specified?

GreenYun avatar Sep 14 '24 17:09 GreenYun

I hope that ring would still remain an option even if aws-lc-rs becomes available as a feature. For those without compliance need, ring is much more lightweight.

Congyuwang avatar Oct 12 '24 03:10 Congyuwang

I hope that ring would still remain an option even if aws-lc-rs. For those without compliance need, ring is much more lightweight.

I think the library should not eliminate the potential to have another choice. ring may be lightweight but was-lc could have other benefits.

My current implementation is to build the requester myself:

use std::sync::OnceLock;

use reqwest::Client;
use rustls::{ClientConfig, RootCertStore};
use webpki_roots::TLS_SERVER_ROOTS;

static HTTP_CLIENT: OnceLock<Client> = OnceLock::new();

pub fn client() -> Client {
	HTTP_CLIENT.get_or_init(init_client).clone()
}

fn init_client() -> Client {
	static USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);

	let cert_store: RootCertStore = TLS_SERVER_ROOTS.iter().cloned().collect();
	let mut tls = ClientConfig::builder().with_root_certificates(cert_store).with_no_client_auth();
	tls.enable_early_data = true;
	tls.alpn_protocols = vec!["h2".into(), "http/1.1".into()];

	let client = Client::builder().use_preconfigured_tls(tls).user_agent(USER_AGENT).build();
	match client {
		Ok(client) => client,
		Err(e) => {
			log::error!("{e}");
			panic!("{e}");
		}
	}
}

Most of the code to build the Client is copied from reqwest, and no hard coding ring or was_lc_rs. However, install_default() should be called before the client initialized.

GreenYun avatar Oct 12 '24 03:10 GreenYun

ring may be lightweight but aws-lc could have other benefits.

Seems to be covered well here: https://www.reddit.com/r/rust/comments/1de13y6/ring_vs_awslcrs/

polarathene avatar Nov 16 '24 01:11 polarathene