From d25e3d86a25b69972d20fb4bd5731d49f3f1fc32 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Wed, 15 Nov 2023 17:18:24 -0500 Subject: [PATCH] Make TLS an optional feature of simple-request Removes 14 crates from the tree when compiling the message-queue client. Also performs a non-intrusive cargo update. --- Cargo.lock | 77 ++++++++++++++++++++------------------- coins/bitcoin/Cargo.toml | 2 +- coins/monero/Cargo.toml | 2 +- common/request/Cargo.toml | 5 ++- common/request/src/lib.rs | 47 +++++++++++++----------- 5 files changed, 72 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a0b3f02ce..9d8a4d5f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1236,9 +1236,9 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "crypto-bigint" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "740fe28e594155f10cfc383984cbefd529d7396050557148f79cb0f621204124" +checksum = "28f85c3514d2a6e64160359b45a3918c3b4178bcbf4ae5d03ab2d02e521c479a" dependencies = [ "generic-array 0.14.7", "rand_core", @@ -1785,9 +1785,9 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "elliptic-curve" -version = "0.13.6" +version = "0.13.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d97ca172ae9dc9f9b779a6e3a65d308f2af74e5b8c921299075bdb4a0370e914" +checksum = "e9775b22bc152ad86a0cf23f0f348b884b26add12bf741e7ffc4d4ab2ab4d205" dependencies = [ "base16ct", "crypto-bigint", @@ -1881,9 +1881,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c18ee0ed65a5f1f81cac6b1d213b69c35fa47d4252ad41f1486dbd8226fe36e" +checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8" dependencies = [ "libc", "windows-sys", @@ -2176,9 +2176,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f69037fe1b785e84986b4f2cbcf647381876a00671d25ceef715d7812dd7e1dd" +checksum = "53a56f0780318174bad1c127063fd0c5fdfb35398e3cd79ffaab931a6c79df80" [[package]] name = "file-per-thread-logger" @@ -2482,9 +2482,12 @@ dependencies = [ [[package]] name = "fs-err" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0845fa252299212f0389d64ba26f34fa32cfe41588355f21ed507c59a0f64541" +checksum = "fb5fd9bcbe8b1087cbd395b51498c01bc997cef73e778a80b77a811af5e2d29f" +dependencies = [ + "autocfg", +] [[package]] name = "fs2" @@ -2787,9 +2790,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.21" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" +checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178" dependencies = [ "bytes", "fnv", @@ -2797,7 +2800,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap 1.9.3", + "indexmap 2.1.0", "slab", "tokio", "tokio-util", @@ -2938,9 +2941,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f95b9abcae896730d42b78e09c155ed4ddf82c07b4de772c64aee5b2d8b7c150" +checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" dependencies = [ "bytes", "fnv", @@ -3270,7 +3273,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi", - "rustix 0.38.21", + "rustix 0.38.24", "windows-sys", ] @@ -3714,19 +3717,19 @@ dependencies = [ [[package]] name = "libp2p-identity" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdd6317441f361babc74c2989c6484eb0726045399b6648de039e1805ea96972" +checksum = "999ec70441b2fb35355076726a6bc466c932e9bdc66f6a11c6c0aa17c7ab9be0" dependencies = [ "bs58", "ed25519-dalek", "hkdf", - "log", "multihash 0.19.1", "quick-protobuf", "rand", "sha2", "thiserror", + "tracing", "zeroize", ] @@ -4276,7 +4279,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" dependencies = [ - "rustix 0.38.21", + "rustix 0.38.24", ] [[package]] @@ -6182,9 +6185,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.21" +version = "0.38.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" +checksum = "9ad981d6c340a49cdc40a1028d9c6084ec7e9fa33fcb839cab656a267071e234" dependencies = [ "bitflags 2.4.1", "errno", @@ -6655,7 +6658,7 @@ dependencies = [ "cfg-if", "libc", "log", - "rustix 0.38.21", + "rustix 0.38.24", "sc-allocator", "sc-executor-common", "sp-runtime-interface", @@ -9254,7 +9257,7 @@ dependencies = [ "cfg-if", "fastrand 2.0.1", "redox_syscall 0.4.1", - "rustix 0.38.21", + "rustix 0.38.24", "windows-sys", ] @@ -9273,9 +9276,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" +checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449" dependencies = [ "winapi-util", ] @@ -10169,7 +10172,7 @@ dependencies = [ "directories-next", "file-per-thread-logger", "log", - "rustix 0.38.21", + "rustix 0.38.24", "serde", "sha2", "toml 0.5.11", @@ -10251,7 +10254,7 @@ dependencies = [ "log", "object 0.31.1", "rustc-demangle", - "rustix 0.38.21", + "rustix 0.38.24", "serde", "target-lexicon", "wasmtime-environ", @@ -10269,7 +10272,7 @@ checksum = "aef27ea6c34ef888030d15560037fe7ef27a5609fbbba8e1e3e41dc4245f5bb2" dependencies = [ "object 0.31.1", "once_cell", - "rustix 0.38.21", + "rustix 0.38.24", "wasmtime-versioned-export-macros", ] @@ -10301,7 +10304,7 @@ dependencies = [ "memoffset", "paste", "rand", - "rustix 0.38.21", + "rustix 0.38.24", "sptr", "wasm-encoder", "wasmtime-asm-macros", @@ -10359,7 +10362,7 @@ dependencies = [ "either", "home", "once_cell", - "rustix 0.38.21", + "rustix 0.38.24", ] [[package]] @@ -10633,18 +10636,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.25" +version = "0.7.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd369a67c0edfef15010f980c3cbe45d7f651deac2cd67ce097cd801de16557" +checksum = "e97e415490559a91254a2979b4829267a57d2fcd741a98eee8b722fb57289aa0" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.25" +version = "0.7.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2f140bda219a26ccc0cdb03dba58af72590c53b22642577d88a927bc5c87d6b" +checksum = "dd7e48ccf166952882ca8bd778a43502c64f33bf94c12ebe2a7f08e5a0f6689f" dependencies = [ "proc-macro2", "quote", @@ -10653,9 +10656,9 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" +checksum = "12a3946ecfc929b583800f4629b6c25b88ac6e92a40ea5670f77112a85d40a8b" dependencies = [ "zeroize_derive", ] diff --git a/coins/bitcoin/Cargo.toml b/coins/bitcoin/Cargo.toml index 1f54c9e61..816d91874 100644 --- a/coins/bitcoin/Cargo.toml +++ b/coins/bitcoin/Cargo.toml @@ -25,7 +25,7 @@ frost = { package = "modular-frost", path = "../../crypto/frost", version = "0.8 hex = { version = "0.4", default-features = false, optional = true } serde = { version = "1", default-features = false, features = ["derive"], optional = true } serde_json = { version = "1", default-features = false, optional = true } -simple-request = { path = "../../common/request", version = "0.1", default-features = false, features = ["basic-auth"], optional = true } +simple-request = { path = "../../common/request", version = "0.1", default-features = false, features = ["tls", "basic-auth"], optional = true } [dev-dependencies] secp256k1 = { version = "0.28", default-features = false, features = ["std"] } diff --git a/coins/monero/Cargo.toml b/coins/monero/Cargo.toml index 2960fb46e..8d5ed1d4b 100644 --- a/coins/monero/Cargo.toml +++ b/coins/monero/Cargo.toml @@ -55,7 +55,7 @@ base58-monero = { version = "2", default-features = false, features = ["check"] # Used for the provided HTTP RPC digest_auth = { version = "0.3", default-features = false, optional = true } -simple-request = { path = "../../common/request", version = "0.1", default-features = false, optional = true } +simple-request = { path = "../../common/request", version = "0.1", default-features = false, features = ["tls"], optional = true } tokio = { version = "1", default-features = false, optional = true } [build-dependencies] diff --git a/common/request/Cargo.toml b/common/request/Cargo.toml index 0ae3789e4..3f56a82ca 100644 --- a/common/request/Cargo.toml +++ b/common/request/Cargo.toml @@ -15,11 +15,14 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] # Deprecated here means to enable deprecated warnings, not to restore deprecated APIs hyper = { version = "0.14", default-features = false, features = ["http1", "tcp", "client", "backports", "deprecated"] } -hyper-rustls = { version = "0.24", default-features = false, features = ["http1", "native-tokio"] } tokio = { version = "1", default-features = false } +hyper-rustls = { version = "0.24", default-features = false, features = ["http1", "native-tokio"], optional = true } + zeroize = { version = "1", optional = true } base64ct = { version = "1", features = ["alloc"], optional = true } [features] +tls = ["hyper-rustls"] basic-auth = ["zeroize", "base64ct"] +default = ["tls"] diff --git a/common/request/src/lib.rs b/common/request/src/lib.rs index 8dbab9c0a..1764ece27 100644 --- a/common/request/src/lib.rs +++ b/common/request/src/lib.rs @@ -5,6 +5,7 @@ use std::sync::Arc; use tokio::sync::Mutex; +#[cfg(feature = "tls")] use hyper_rustls::{HttpsConnectorBuilder, HttpsConnector}; use hyper::{ Uri, @@ -26,18 +27,19 @@ pub enum Error { InvalidUri, MissingHost, InconsistentHost, - SslError(Box), + ConnectionError(Box), Hyper(hyper::Error), } +#[cfg(not(feature = "tls"))] +type Connector = HttpConnector; +#[cfg(feature = "tls")] +type Connector = HttpsConnector; + #[derive(Clone, Debug)] enum Connection { - ConnectionPool(hyper::Client>), - Connection { - https_builder: HttpsConnector, - host: Uri, - connection: Arc>>>, - }, + ConnectionPool(hyper::Client), + Connection { connector: Connector, host: Uri, connection: Arc>>> }, } #[derive(Clone, Debug)] @@ -46,24 +48,25 @@ pub struct Client { } impl Client { - fn https_builder() -> HttpsConnector { - HttpsConnectorBuilder::new().with_native_roots().https_or_http().enable_http1().build() + fn connector() -> Connector { + #[cfg(feature = "tls")] + let res = + HttpsConnectorBuilder::new().with_native_roots().https_or_http().enable_http1().build(); + #[cfg(not(feature = "tls"))] + let res = HttpConnector::new(); + res } pub fn with_connection_pool() -> Client { Client { - connection: Connection::ConnectionPool(hyper::Client::builder().build(Self::https_builder())), + connection: Connection::ConnectionPool(hyper::Client::builder().build(Self::connector())), } } pub fn without_connection_pool(host: String) -> Result { Ok(Client { connection: Connection::Connection { - https_builder: HttpsConnectorBuilder::new() - .with_native_roots() - .https_or_http() - .enable_http1() - .build(), + connector: Self::connector(), host: { let uri: Uri = host.parse().map_err(|_| Error::InvalidUri)?; if uri.host().is_none() { @@ -110,16 +113,18 @@ impl Client { Ok(Response(match &self.connection { Connection::ConnectionPool(client) => client.request(request).await.map_err(Error::Hyper)?, - Connection::Connection { https_builder, host, connection } => { + Connection::Connection { connector, host, connection } => { let mut connection_lock = connection.lock().await; // If there's not a connection... if connection_lock.is_none() { - let (requester, connection) = hyper::client::conn::http1::handshake( - https_builder.clone().call(host.clone()).await.map_err(Error::SslError)?, - ) - .await - .map_err(Error::Hyper)?; + let call_res = connector.clone().call(host.clone()).await; + #[cfg(not(feature = "tls"))] + let call_res = call_res.map_err(|e| Error::ConnectionError(format!("{e:?}").into())); + #[cfg(feature = "tls")] + let call_res = call_res.map_err(Error::ConnectionError); + let (requester, connection) = + hyper::client::conn::http1::handshake(call_res?).await.map_err(Error::Hyper)?; // This will die when we drop the requester, so we don't need to track an AbortHandle for // it tokio::spawn(connection);