Skip to content

Commit 4d7db75

Browse files
author
Danielle Thomas
authored
Merge pull request #169 from ngrok/danielle/remove-hyper-proxy
2 parents 70fca68 + 3da68ec commit 4d7db75

File tree

6 files changed

+96
-72
lines changed

6 files changed

+96
-72
lines changed

cargo-doc-ngrok/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ http = "1.0.0"
1717
hyper = { version = "1.1.0", features = ["server"] }
1818
hyper-staticfile = "0.10.0"
1919
hyper-util = { version = "0.1.3", features = ["server", "tokio", "server-auto", "http1"] }
20-
ngrok = { path = "../ngrok", version = "0.14.0", features = ["hyper", "axum"] }
20+
ngrok = { path = "../ngrok", version = "0.15.0", features = ["hyper", "axum"] }
2121
tokio = { version = "1.23.0", features = ["full"] }
2222
watchexec = "2.3.0"
2323
# watchexec-signals 1.0.1 causes a compilation error.

ngrok/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.15.0
2+
- - Removes `hyper-proxy` and `ring` dependencies
3+
14
## 0.14.0
25
- - Adds `pooling_enabled` option, allowing the endpoint to pool with other endpoints with the same host/port/binding
36

ngrok/Cargo.toml

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,80 @@
11
[package]
22
name = "ngrok"
3-
version = "0.14.0"
3+
version = "0.15.0"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
66
description = "The ngrok agent SDK"
77
repository = "https://github.com/ngrok/ngrok-rust"
88

99
[dependencies]
10+
arc-swap = "1.5.1"
11+
async-trait = "0.1.59"
12+
awaitdrop = "0.1.1"
13+
axum = { version = "0.7.4", features = ["tokio"], optional = true }
14+
axum-core = "0.4.3"
15+
16+
base64 = "0.21.7"
17+
bitflags = "2.4.2"
18+
bytes = "1.3.0"
19+
20+
futures = "0.3.25"
21+
futures-rustls = { version = "0.26.0" }
22+
futures-util = "0.3.30"
23+
hostname = "0.3.1"
24+
hyper = { version = "^1.1.0", optional = true }
25+
hyper-http-proxy = "1.1.0"
26+
hyper-util = { version = "0.1.3", features = ["tokio"] }
27+
once_cell = "1.17.1"
1028
muxado = { path = "../muxado", version = "0.5" }
29+
pin-project = "1.1.3"
30+
parking_lot = "0.12.1"
31+
proxy-protocol = "0.5.0"
32+
regex = "1.7.3"
33+
rustls-native-certs = "0.7.0"
34+
rustls-pemfile = "2.0.0"
1135
serde = { version = "1.0.149", features = ["derive"] }
1236
serde_json = "1.0.89"
1337
thiserror = "1.0.37"
14-
base64 = "0.21.7"
1538
tokio = { version = "1.23.0", features = [
1639
"io-util",
1740
"net",
1841
"sync",
1942
"time",
2043
"rt",
2144
] }
22-
tracing = "0.1.37"
23-
futures-rustls = { version = "0.25.1" }
24-
tokio-util = { version = "0.7.4", features = ["compat"] }
25-
futures = "0.3.25"
26-
hyper-0-14 = { package = "hyper", version = "0.14" }
27-
hyper = { version = "1.1.0", optional = true }
28-
axum = { version = "0.7.4", features = ["tokio"], optional = true }
29-
rustls-pemfile = "2.0.0"
30-
async-trait = "0.1.59"
31-
bytes = "1.3.0"
32-
arc-swap = "1.5.1"
3345
tokio-retry = "0.3.0"
34-
awaitdrop = "0.1.1"
35-
parking_lot = "0.12.1"
36-
once_cell = "1.17.1"
37-
hostname = "0.3.1"
38-
regex = "1.7.3"
3946
tokio-socks = "0.5.1"
40-
hyper-proxy = { version = "0.9.1", default-features = false, features = [
41-
"rustls",
42-
] }
47+
tokio-util = { version = "0.7.4", features = ["compat"] }
48+
tower-service = { version = "0.3.3"}
49+
tracing = "0.1.37"
4350
url = "2.4.0"
44-
rustls-native-certs = "0.7.0"
45-
proxy-protocol = "0.5.0"
46-
pin-project = "1.1.3"
47-
bitflags = "2.4.2"
48-
axum-core = "0.4.3"
49-
futures-util = "0.3.30"
5051

5152
[target.'cfg(windows)'.dependencies]
5253
windows-sys = { version = "0.45.0", features = ["Win32_Foundation"] }
5354

5455
[dev-dependencies]
55-
hyper = "1.1.0"
56+
anyhow = "1.0.66"
57+
axum = { version = "0.7.4", features = ["tokio"] }
58+
flate2 = "1.0.25"
59+
hyper = { version = "1.1.0" }
5660
hyper-util = { version = "0.1.3", features = [
5761
"tokio",
5862
"server",
5963
"http1",
6064
"http2",
61-
] }
62-
tokio = { version = "1.23.0", features = ["full"] }
63-
anyhow = "1.0.66"
64-
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
65-
reqwest = "0.11.13"
66-
flate2 = "1.0.25"
67-
tracing-test = "0.2.3"
68-
rand = "0.8.5"
65+
]}
6966
paste = "1.0.11"
70-
tokio-tungstenite = { version = "0.21.0", features = [
67+
rand = "0.8.5"
68+
reqwest = "0.12"
69+
tokio = { version = "1.23.0", features = ["full"] }
70+
tokio-tungstenite = { version = "0.26.2", features = [
7171
"rustls",
7272
"rustls-tls-webpki-roots",
7373
] }
7474
tower = { version = "0.5", features = ["util"] }
75-
axum = { version = "0.7.4", features = ["tokio"] }
75+
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
76+
tracing-test = "0.2.3"
77+
7678

7779
[[example]]
7880
name = "tls"
@@ -91,8 +93,7 @@ name = "mingrok"
9193
required-features = ["hyper"]
9294

9395
[features]
94-
default = []
95-
hyper = ["hyper/server", "hyper/http1"]
96+
hyper = ["hyper/server", "hyper/http1", "dep:hyper"]
9697
axum = ["dep:axum", "hyper"]
9798
online-tests = ["axum", "hyper"]
9899
long-tests = ["online-tests"]

ngrok/src/online_tests.rs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{
22
convert::Infallible,
3+
error::Error,
34
io,
45
io::prelude::*,
56
net::SocketAddr,
@@ -40,10 +41,6 @@ use hyper::{
4041
Request,
4142
Uri,
4243
};
43-
use hyper_0_14::{
44-
header,
45-
StatusCode,
46-
};
4744
use hyper_util::{
4845
rt::TokioExecutor,
4946
server,
@@ -56,6 +53,10 @@ use rand::{
5653
thread_rng,
5754
Rng,
5855
};
56+
use reqwest::{
57+
header,
58+
StatusCode,
59+
};
5960
use tokio::{
6061
io::{
6162
AsyncReadExt,
@@ -565,7 +566,7 @@ macro_rules! proxy_proto_test {
565566
}
566567

567568
proxy_proto_test!(
568-
[(V1, &b"PROXY TCP4"[..]), (V2, &b"\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A"[..])]
569+
[(V1, &b"PROXY TCP"[..]), (V2, &b"\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A"[..])]
569570
[
570571
(http, |tun| {
571572
reqwest::get(tun.url().to_string())
@@ -704,16 +705,37 @@ async fn tls() -> Result<(), BoxError> {
704705
.await?;
705706

706707
let tun = start_http_server(tun, hello_router());
707-
708708
let url = tun.url.replacen("tls", "http", 1);
709709

710+
// Create a client with verbose logging and longer timeout
710711
let client = reqwest::Client::new();
712+
711713
let resp = client.get(url.clone()).send().await;
712714

713715
assert!(resp.is_err());
714-
let err_str = resp.err().unwrap().to_string();
715-
tracing::debug!(?err_str);
716-
assert!(err_str.contains("certificate"));
716+
717+
let err = resp.err().unwrap();
718+
719+
// Check if the error is a certificate error
720+
let is_certificate_error = if let Some(source) = err.source() {
721+
// Try to downcast to hyper_util::client::legacy::Error
722+
if let Some(hyper_error) = source.downcast_ref::<hyper_util::client::legacy::Error>() {
723+
// Convert the entire error to a string to extract the message
724+
let error_str = hyper_error.source().unwrap().to_string();
725+
726+
error_str.contains("certificate")
727+
} else {
728+
// If we can't downcast to the specific error type, fall back to string matching
729+
let source_str = format!("{:?}", source);
730+
assert!(source_str.contains("certificate"));
731+
return Ok(());
732+
}
733+
} else {
734+
// If there's no source, return an error
735+
return Err("No error source found".into());
736+
};
737+
738+
assert!(is_certificate_error);
717739

718740
Ok(())
719741
}

ngrok/src/session.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,12 @@ use futures_rustls::rustls::{
2727
pki_types,
2828
RootCertStore,
2929
};
30-
use hyper_0_14::{
31-
client::HttpConnector,
32-
service::Service,
33-
};
34-
use hyper_proxy::{
30+
use hyper_http_proxy::{
3531
Intercept,
3632
Proxy,
3733
ProxyConnector,
3834
};
35+
use hyper_util::client::legacy::connect::HttpConnector;
3936
use muxado::heartbeat::HeartbeatConfig;
4037
pub use muxado::heartbeat::HeartbeatHandler;
4138
use once_cell::sync::{
@@ -68,6 +65,7 @@ use tokio_util::compat::{
6865
FuturesAsyncReadCompatExt,
6966
TokioAsyncReadCompatExt,
7067
};
68+
use tower_service::Service;
7169
use tracing::{
7270
debug,
7371
warn,
@@ -262,7 +260,8 @@ fn connect_http_proxy(url: Url) -> impl Connector {
262260
url.as_str().try_into().expect("urls should be valid uris"),
263261
);
264262
proxy.force_connect();
265-
let connector = HttpConnector::new();
263+
let mut connector = HttpConnector::new();
264+
connector.enforce_http(false);
266265
async move {
267266
let mut connector = ProxyConnector::from_proxy(connector, proxy)
268267
.map_err(|e| ConnectError::ProxyConnect(Box::new(e)))?;
@@ -274,14 +273,13 @@ fn connect_http_proxy(url: Url) -> impl Connector {
274273
let conn = connector
275274
.call(server_uri)
276275
.await
277-
.map_err(|e| ConnectError::ProxyConnect(Box::new(e)))?
278-
.compat();
276+
.map_err(|e| ConnectError::ProxyConnect(Box::new(e)))?;
279277

280278
let tls_conn = futures_rustls::TlsConnector::from(tls_config)
281279
.connect(
282280
pki_types::ServerName::try_from(host)
283281
.expect("host should have been validated by SessionBuilder::server_addr"),
284-
conn,
282+
hyper_util::rt::TokioIo::new(conn).compat(),
285283
)
286284
.await
287285
.map_err(ConnectError::Tls)?;

ngrok/src/tunnel_ext.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ use std::{
1414
};
1515

1616
use async_trait::async_trait;
17-
#[cfg(feature = "axum")]
18-
use axum_core::response::Response;
1917
use bitflags::bitflags;
2018
use futures::stream::TryStreamExt;
2119
use futures_rustls::rustls::{
@@ -27,11 +25,11 @@ use futures_rustls::rustls::{
2725
use hyper::{
2826
server::conn::http1,
2927
service::service_fn,
28+
Response,
3029
StatusCode,
3130
};
3231
use once_cell::sync::Lazy;
3332
use proxy_protocol::ProxyHeader;
34-
use rustls::crypto::ring as provider;
3533
#[cfg(feature = "hyper")]
3634
#[cfg(target_os = "windows")]
3735
use tokio::net::windows::named_pipe::ClientOptions;
@@ -212,6 +210,15 @@ impl ConnExt for EndpointConn {
212210
}
213211
}
214212

213+
bitflags! {
214+
struct TlsFlags: u8 {
215+
const FLAG_HTTP2 = 0b01;
216+
const FLAG_verify_upstream_tls = 0b10;
217+
const FLAG_MAX = Self::FLAG_HTTP2.bits()
218+
| Self::FLAG_verify_upstream_tls.bits();
219+
}
220+
}
221+
215222
fn tls_config(
216223
app_protocol: Option<String>,
217224
verify_upstream_tls: bool,
@@ -235,7 +242,9 @@ fn tls_config(
235242
let mut config = crate::session::host_certs_tls_config()?;
236243
if !verify_upstream_tls {
237244
config.dangerous().set_certificate_verifier(Arc::new(
238-
danger::NoCertificateVerification::new(provider::default_provider()),
245+
danger::NoCertificateVerification::new(
246+
rustls::crypto::aws_lc_rs::default_provider(),
247+
),
239248
));
240249
}
241250

@@ -265,15 +274,6 @@ fn tls_config(
265274
.clone())
266275
}
267276

268-
bitflags! {
269-
struct TlsFlags: u8 {
270-
const FLAG_HTTP2 = 0b01;
271-
const FLAG_verify_upstream_tls = 0b10;
272-
const FLAG_MAX = Self::FLAG_HTTP2.bits()
273-
| Self::FLAG_verify_upstream_tls.bits();
274-
}
275-
}
276-
277277
// Establish the connection to forward the tunnel stream to.
278278
// Takes the tunnel and connection to make additional decisions on how to wrap
279279
// the forwarded connection, i.e. reordering tls termination and proxyproto.

0 commit comments

Comments
 (0)