From 27887c2e82f3236c99129a33197a6384ffb95204 Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Sun, 17 Jul 2022 16:00:20 -0400 Subject: [PATCH] Remove un-needed tokio-tungstenite features, prepare for fixing reqwest to use our root certs --- Cargo.lock | 6 ------ Cargo.toml | 4 +--- src/srv.rs | 16 +++++++++++----- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 25a69be..e340a51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1194,12 +1194,8 @@ checksum = "06cda1232a49558c46f8a504d5b93101d42c0bf7f911f12a105ba48168f821ae" dependencies = [ "futures-util", "log", - "rustls", - "rustls-native-certs", "tokio", - "tokio-rustls", "tungstenite", - "webpki", ] [[package]] @@ -1327,12 +1323,10 @@ dependencies = [ "httparse", "log", "rand", - "rustls", "sha-1", "thiserror", "url", "utf-8", - "webpki", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index c11e6e0..33b4be2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,9 +57,7 @@ rustls = { version = "0.20.2", optional = true } rustls-pemfile = { version = "1.0.0", optional = true } # websocket deps -# todo: fix up the situation with these roots -#tokio-tungstenite = { version = "0.17", optional = true, features = ["rustls-tls-webpki-roots"] } -tokio-tungstenite = { version = "0.17", optional = true, features = ["rustls-tls-native-roots"] } +tokio-tungstenite = { version = "0.17", optional = true, default-features = false } futures-util = { version = "0.3", default-features = false, features = ["async-await", "sink", "std"], optional = true } [features] diff --git a/src/srv.rs b/src/srv.rs index d19a5b2..0ac80b8 100644 --- a/src/srv.rs +++ b/src/srv.rs @@ -13,6 +13,7 @@ use crate::{ use anyhow::{bail, Result}; use data_encoding::BASE64; use log::{debug, error, trace}; +use reqwest::Client; use ring::digest::{Algorithm, Context as DigestContext, SHA256, SHA512}; use serde::Deserialize; use std::{ @@ -31,6 +32,7 @@ use trust_dns_resolver::{ lazy_static::lazy_static! { static ref RESOLVER: TokioAsyncResolver = make_resolver(); + static ref HTTPS_CLIENT: Client = make_https_client(); } fn make_resolver() -> TokioAsyncResolver { @@ -39,6 +41,15 @@ fn make_resolver() -> TokioAsyncResolver { TokioAsyncResolver::tokio(config, options).unwrap() } +fn make_https_client() -> Client { + // todo: configure our root certs here + Client::builder().https_only(true).build().expect("failed to make https client?") +} + +async fn https_get(url: T) -> reqwest::Result { + HTTPS_CLIENT.get(url).send().await +} + #[derive(Clone, Debug, PartialEq, Eq)] enum XmppConnectionType { #[cfg(feature = "tls")] @@ -706,11 +717,6 @@ async fn collect_host_meta_xml(ret: &mut Vec, domain: &str, is_c } } -async fn https_get(url: T) -> reqwest::Result { - // todo: resolve URL with our resolver - reqwest::Client::builder().https_only(true).build()?.get(url).send().await -} - // https://datatracker.ietf.org/doc/html/rfc7711 // https://www.iana.org/assignments/posh-service-names/posh-service-names.xhtml async fn collect_posh(domain: &str) -> Result {