diff --git a/Cargo.lock b/Cargo.lock index 6546972..16e52d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -103,18 +103,19 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "axum" -version = "0.6.20" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" +checksum = "1236b4b292f6c4d6dc34604bb5120d85c3fe1d1aa596bd5cc52ca054d13e7b9e" dependencies = [ "async-trait", "axum-core", - "bitflags 1.3.2", "bytes", "futures-util", - "http 0.2.12", - "http-body 0.4.6", - "hyper 0.14.28", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", "itoa", "matchit", "memchr", @@ -131,23 +132,28 @@ dependencies = [ "tower", "tower-layer", "tower-service", + "tracing", ] [[package]] name = "axum-core" -version = "0.3.4" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" dependencies = [ "async-trait", "bytes", "futures-util", - "http 0.2.12", - "http-body 0.4.6", + "http", + "http-body", + "http-body-util", "mime", + "pin-project-lite", "rustversion", + "sync_wrapper", "tower-layer", "tower-service", + "tracing", ] [[package]] @@ -212,8 +218,10 @@ dependencies = [ "clap", "hex", "hmac", - "hyper 0.14.28", + "http-body-util", + "hyper", "hyper-rustls", + "hyper-util", "reqwest", "sha-1", "thiserror", @@ -524,25 +532,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "h2" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fbd2820c5e49886948654ab546d0688ff24530286bdcf8fca3cefb16d4618eb" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http 0.2.12", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - [[package]] name = "h2" version = "0.4.3" @@ -554,7 +543,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http 1.1.0", + "http", "indexmap", "slab", "tokio", @@ -595,17 +584,6 @@ dependencies = [ "digest", ] -[[package]] -name = "http" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" -dependencies = [ - "bytes", - "fnv", - "itoa", -] - [[package]] name = "http" version = "1.1.0" @@ -617,17 +595,6 @@ dependencies = [ "itoa", ] -[[package]] -name = "http-body" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" -dependencies = [ - "bytes", - "http 0.2.12", - "pin-project-lite", -] - [[package]] name = "http-body" version = "1.0.0" @@ -635,7 +602,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" dependencies = [ "bytes", - "http 1.1.0", + "http", ] [[package]] @@ -646,8 +613,8 @@ checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" dependencies = [ "bytes", "futures-core", - "http 1.1.0", - "http-body 1.0.0", + "http", + "http-body", "pin-project-lite", ] @@ -663,30 +630,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" -[[package]] -name = "hyper" -version = "0.14.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2 0.3.25", - "http 0.2.12", - "http-body 0.4.6", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - [[package]] name = "hyper" version = "1.2.0" @@ -696,9 +639,9 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "h2 0.4.3", - "http 1.1.0", - "http-body 1.0.0", + "h2", + "http", + "http-body", "httparse", "httpdate", "itoa", @@ -710,18 +653,21 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.24.2" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" +checksum = "a0bea761b46ae2b24eb4aef630d8d1c398157b6fc29e6350ecf090a0b70c952c" dependencies = [ "futures-util", - "http 0.2.12", - "hyper 0.14.28", + "http", + "hyper", + "hyper-util", "log", "rustls", "rustls-native-certs", + "rustls-pki-types", "tokio", "tokio-rustls", + "tower-service", ] [[package]] @@ -732,7 +678,7 @@ checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" dependencies = [ "bytes", "http-body-util", - "hyper 1.2.0", + "hyper", "hyper-util", "native-tls", "tokio", @@ -749,9 +695,9 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "http 1.1.0", - "http-body 1.0.0", - "hyper 1.2.0", + "http", + "http-body", + "hyper", "pin-project-lite", "socket2", "tokio", @@ -1110,11 +1056,11 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2 0.4.3", - "http 1.1.0", - "http-body 1.0.0", + "h2", + "http", + "http-body", "http-body-util", - "hyper 1.2.0", + "hyper", "hyper-tls", "hyper-util", "ipnet", @@ -1125,7 +1071,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls-pemfile", + "rustls-pemfile 1.0.4", "serde", "serde_json", "serde_urlencoded", @@ -1177,24 +1123,27 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.10" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" +checksum = "e87c9956bd9807afa1f77e0f7594af32566e830e088a5576d27c5b6f30f49d41" dependencies = [ "log", "ring", + "rustls-pki-types", "rustls-webpki", - "sct", + "subtle", + "zeroize", ] [[package]] name = "rustls-native-certs" -version = "0.6.3" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" +checksum = "8f1fb85efa936c42c6d5fc28d2629bb51e4b2f4b8a5211e297d599cc5a093792" dependencies = [ "openssl-probe", - "rustls-pemfile", + "rustls-pemfile 2.1.1", + "rustls-pki-types", "schannel", "security-framework", ] @@ -1208,13 +1157,30 @@ dependencies = [ "base64", ] +[[package]] +name = "rustls-pemfile" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f48172685e6ff52a556baa527774f61fcaa884f59daf3375c62a3f1cd2549dab" +dependencies = [ + "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "868e20fada228fefaf6b652e00cc73623d54f8171e7352c18bb281571f2d92da" + [[package]] name = "rustls-webpki" -version = "0.101.7" +version = "0.102.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +checksum = "faaa0a62740bedb9b2ef5afa303da42764c012f743917351dc9a237ea1663610" dependencies = [ "ring", + "rustls-pki-types", "untrusted", ] @@ -1245,16 +1211,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "sct" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" -dependencies = [ - "ring", - "untrusted", -] - [[package]] name = "security-framework" version = "2.9.2" @@ -1550,11 +1506,12 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.24.1" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" +checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" dependencies = [ "rustls", + "rustls-pki-types", "tokio", ] @@ -2011,9 +1968,9 @@ dependencies = [ "base64", "deadpool", "futures", - "http 1.1.0", + "http", "http-body-util", - "hyper 1.2.0", + "hyper", "hyper-util", "log", "once_cell", @@ -2023,3 +1980,9 @@ dependencies = [ "tokio", "url", ] + +[[package]] +name = "zeroize" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/Cargo.toml b/Cargo.toml index 35bd7f6..6c1e5a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,12 +9,14 @@ edition = "2021" default-run = "camo" [dependencies] -axum = "0.6" +axum = "0.7" clap = { version = "4", features = ["cargo", "derive", "env", "wrap_help"] } hex = "0.4" hmac = "0.12" -hyper = { version = "0.14", features = ["full"] } -hyper-rustls = { version = "0.24", features = ["http2"] } +http-body-util = "0.1" +hyper = { version = "1", features = ["full"] } +hyper-rustls = { version = "0.26", features = ["http2"] } +hyper-util = "0.1" sha-1 = "0.10" thiserror = "1.0" tokio = { version = "1", features = ["full"] } diff --git a/src/bin/camo.rs b/src/bin/camo.rs index 17634e5..c8ad1d0 100644 --- a/src/bin/camo.rs +++ b/src/bin/camo.rs @@ -1,6 +1,7 @@ use std::{net::SocketAddr, str::FromStr}; use clap::Parser; +use tokio::net::TcpListener; use camo_rs::{server, settings::LogFormat, Settings}; @@ -36,9 +37,10 @@ async fn main() { } let listen_addr = SocketAddr::from_str(&settings.listen).unwrap(); + let listener = TcpListener::bind(&listen_addr).await.unwrap(); + let server = server::build(settings); - axum::Server::bind(&listen_addr) - .serve(server.into_make_service()) + axum::serve(listener, server.into_make_service()) .with_graceful_shutdown(shutdown_signal()) .await .unwrap() diff --git a/src/errors.rs b/src/errors.rs index 03a1d3d..b1a076f 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -2,9 +2,12 @@ use std::string::FromUtf8Error; -use axum::response::{IntoResponse, Response}; +use axum::{ + body::Body, + response::{IntoResponse, Response}, +}; use hex::FromHexError; -use hyper::{header, Body, StatusCode}; +use hyper::{header, StatusCode}; use thiserror::Error; use tracing::{info, warn}; @@ -131,7 +134,7 @@ pub enum ProxyError { /// Returned if the request to the upstream failed. #[error("upstream error: {0}")] - UpstreamError(#[source] hyper::Error), + UpstreamError(#[source] hyper_util::client::legacy::Error), /// Returned if the connection didn't get established until the configurable /// timeout expired. diff --git a/src/proxy.rs b/src/proxy.rs index a26ff05..7577c20 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -2,8 +2,13 @@ use std::time::Duration; -use axum::http::HeaderValue; -use hyper::{header, Body, HeaderMap, Method, Request, Response}; +use axum::{http::HeaderValue, response::IntoResponse}; +use http_body_util::Empty; +use hyper::{body::Bytes, header, HeaderMap, Method, Request, Response}; +use hyper_util::{ + client::legacy::{connect::HttpConnector, Client}, + rt::TokioExecutor, +}; use crate::{errors::ProxyError, header_wrangler}; @@ -12,7 +17,7 @@ use crate::{errors::ProxyError, header_wrangler}; pub struct Proxy { via_header: String, upstream_timeout: usize, - http_client: hyper::Client>, + http_client: Client, Empty>, } impl Proxy { @@ -24,11 +29,12 @@ impl Proxy { pub fn new(via_header: &str, upstream_timeout: usize) -> Self { let https = hyper_rustls::HttpsConnectorBuilder::new() .with_native_roots() + .expect("native roots to be there") .https_or_http() .enable_http1() .enable_http2() .build(); - let http_client = hyper::Client::builder().build::<_, Body>(https); + let http_client = Client::builder(TokioExecutor::new()).build::<_, Empty>(https); Self { via_header: via_header.to_owned(), @@ -47,13 +53,13 @@ impl Proxy { method: &Method, headers: &HeaderMap, target: &str, - ) -> Result, ProxyError> { + ) -> Result, ProxyError> { let mut req = Request::builder() .method(method) .uri(target) .header(header::USER_AGENT, &self.via_header) .header(header::VIA, &self.via_header) - .body(Body::empty()) + .body(Empty::new()) .map_err(ProxyError::RequestBuildingFailed)?; header_wrangler::assign_filtered_request_headers(headers, req.headers_mut()); @@ -73,6 +79,6 @@ impl Proxy { HeaderValue::from_str(target).expect("target is always a valid URL at this point"), ); - Ok(res) + Ok(res.into_response()) } } diff --git a/src/server.rs b/src/server.rs index 55cf6bd..b790ab8 100644 --- a/src/server.rs +++ b/src/server.rs @@ -3,6 +3,7 @@ use std::str::FromStr; use axum::{ + body::Body, extract::{Path, State}, http::HeaderValue, response::{IntoResponse, Response}, @@ -11,7 +12,7 @@ use axum::{ }; use hyper::{ header::{self, HeaderName}, - Body, HeaderMap, Method, + HeaderMap, Method, }; use tracing::{instrument, Span}; diff --git a/tests/proxy.rs b/tests/proxy.rs index 6d74ae3..ceea6f1 100644 --- a/tests/proxy.rs +++ b/tests/proxy.rs @@ -1,3 +1,4 @@ +use axum::body::Body; use hyper::{HeaderMap, Method}; use wiremock::MockServer; @@ -6,9 +7,7 @@ use camo_rs::{errors::ProxyError, proxy::*}; pub mod helpers; use helpers::wiremock::*; -async fn run_proxy_request( - upstream: &MockServer, -) -> Result, ProxyError> { +async fn run_proxy_request(upstream: &MockServer) -> Result, ProxyError> { let proxy = Proxy::new("camo-rs", 10); let headers = HeaderMap::new(); diff --git a/tests/server.rs b/tests/server.rs index cfa6402..f5ea274 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -1,5 +1,6 @@ -use std::net::{SocketAddr, TcpListener}; +use std::net::SocketAddr; +use tokio::net::TcpListener; use wiremock::MockServer; use camo_rs::{server::*, AuthenticatedTarget, Settings}; @@ -8,7 +9,9 @@ pub mod helpers; use helpers::{application::*, wiremock::*}; async fn run_test_server(mut settings: Settings) -> (SocketAddr, reqwest::Client) { - let listener = TcpListener::bind("127.0.0.1:0").expect("could not bind ephemeral socket"); + let listener = TcpListener::bind("127.0.0.1:0") + .await + .expect("could not bind ephemeral socket"); let listen_addr = listener.local_addr().unwrap(); let client = reqwest::Client::builder() .redirect(reqwest::redirect::Policy::none()) @@ -18,9 +21,7 @@ async fn run_test_server(mut settings: Settings) -> (SocketAddr, reqwest::Client settings.root_url = format!("http://{listen_addr}/"); tokio::spawn(async move { - axum::Server::from_tcp(listener) - .unwrap() - .serve(build(settings).into_make_service()) + axum::serve(listener, build(settings).into_make_service()) .await .unwrap() });