Skip to content

Commit a691efc

Browse files
committed
add verify_upstream_tls support
1 parent 2b2c0bf commit a691efc

File tree

9 files changed

+67
-4
lines changed

9 files changed

+67
-4
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ jobs:
280280
run: ls -R .
281281
shell: bash
282282
- name: Test bindings
283+
run: docker run -e NGROK_AUTHTOKEN=${{ secrets.NGROK_AUTHTOKEN }} --mount type=bind,src=/etc/ssl,dst=/etc/ssl --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn test -m smoke
284+
- name: Full Test Suite
285+
if: matrix.node == '18'
283286
# run full suite of online tests
284287
run: docker run -e NGROK_AUTHTOKEN=${{ secrets.NGROK_AUTHTOKEN }} --mount type=bind,src=/etc/ssl,dst=/etc/ssl --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn test
285288
test-linux-x64-musl-binding:

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ version = "1.1.1"
77
crate-type = ["cdylib"]
88

99
[dependencies]
10-
async-rustls = { version = "0.3.0" }
1110
async-trait = "0.1.59"
1211
bytes = "1.3.0"
1312
futures = "0.3.26"
@@ -18,10 +17,11 @@ mio = { version = "=0.8.6" }
1817
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
1918
napi = { version = "2.12.1", default-features = false, features = ["napi4", "tokio_rt"] }
2019
napi-derive = "2.12.1"
21-
ngrok = { version = "0.14.0-pre.11" }
20+
ngrok = { version = "0.14.0-pre.12" }
2221
parking_lot = "0.12.1"
2322
regex = "1.9.5"
24-
rustls-pemfile = "1.0.1"
23+
rustls = "0.22.2"
24+
rustls-pemfile = "2.0.0"
2525
tokio = { version = "1.23.0", features = ["sync"] }
2626
tracing = "0.1.37"
2727
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }

__test__/connect.spec.mjs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,27 @@ test("forward http2", async (t) => {
9999
t.assert(res.data.includes(expected));
100100
});
101101

102+
test("forward http2 no cert validation", async (t) => {
103+
const httpServer = await makeHttp({useHttp2: true});
104+
const listener = await ngrok.forward({
105+
// numeric port
106+
addr: parseInt(httpServer.listenTo.split(":")[1], 10),
107+
// authtoken from env
108+
authtoken: process.env["NGROK_AUTHTOKEN"],
109+
// The L7 app_protocol
110+
app_protocol: "http2",
111+
// No upstream cert validation
112+
verify_upstream_tls: false,
113+
});
114+
115+
const url = listener.url();
116+
t.truthy(url.startsWith("https://"), url);
117+
const res = await validateShutdown(t, httpServer, url);
118+
119+
t.assert(res.status === 200);
120+
t.assert(res.data.includes(expected));
121+
});
122+
102123
test("connect number", async (t) => {
103124
const httpServer = await makeHttp();
104125
ngrok.authtoken(process.env["NGROK_AUTHTOKEN"]);

__test__/online.spec.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,22 @@ test("tls backend", async (t) => {
141141
await listener.close();
142142
});
143143

144+
test("unverified tls backend", async (t) => {
145+
const session = await makeSession();
146+
const listener = await session.httpEndpoint().verifyUpstreamTls(false)
147+
.listenAndForward("https://dashboard.ngrok.com");
148+
149+
const error = await t.throwsAsync(
150+
async () => {
151+
await axios.get(listener.url());
152+
},
153+
{ instanceOf: AxiosError }
154+
);
155+
t.is(421, error.response.status);
156+
t.truthy(error.response.headers["ngrok-trace-id"]);
157+
await listener.close();
158+
});
159+
144160
test("http headers", async (t) => {
145161
const httpServer = http.createServer(function (req, res) {
146162
const { headers } = req;

index.d.ts

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ pub struct Config {
269269
/// Unused, will warn and be ignored
270270
#[napi(js_name = "terminate_at")]
271271
pub terminate_at: Option<String>,
272+
/// Whether to disable certificate verification for this listener
273+
#[napi(js_name = "verify_upstream_tls")]
274+
pub verify_upstream_tls: Option<bool>,
272275
/// WebhookVerification configuration, the provider to use.
273276
/// See [Webhook Verification] in the ngrok docs for additional details.
274277
///

src/connect.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ macro_rules! config_common {
9292
plumb_vec!($builder, $config, deny_cidr);
9393
plumb!($builder, $config, proxy_proto);
9494
plumb!($builder, $config, forwards_to);
95+
plumb!($builder, $config, verify_upstream_tls);
9596

9697
// returns a Result, so we can't use the macro
9798
if let Some(ref v) = $config.policy {
@@ -283,6 +284,7 @@ async fn labeled_listener(session: &Session, cfg: &Config) -> Result<String> {
283284
let mut bld = session.labeled_listener();
284285
plumb!(bld, cfg, metadata);
285286
plumb!(bld, cfg, app_protocol);
287+
plumb!(bld, cfg, verify_upstream_tls);
286288
plumb_vec!(bld, cfg, label, labels, ":");
287289
Ok(bld.listen(None).await?.id())
288290
}

src/listener_builder.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ macro_rules! make_listener_builder {
6060
self
6161
}
6262

63+
/// Whether to disable certificate verification for this listener.
64+
#[napi]
65+
pub fn verify_upstream_tls(&mut self, verify_upstream_tls: bool) -> &Self {
66+
let mut builder = self.listener_builder.lock();
67+
builder.verify_upstream_tls(verify_upstream_tls);
68+
self
69+
}
70+
6371
/// Begin listening for new connections on this listener.
6472
#[napi]
6573
pub async fn listen(&self, _bind: Option<bool>) -> Result<Listener> {

src/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::{
44
time::Duration,
55
};
66

7-
use async_rustls::rustls::ClientConfig;
87
use bytes::Bytes;
98
use lazy_static::lazy_static;
109
use napi::{
@@ -28,6 +27,7 @@ use ngrok::{
2827
Session as NgrokSession,
2928
};
3029
use parking_lot::Mutex as SyncMutex;
30+
use rustls::ClientConfig;
3131
use tokio::sync::Mutex;
3232
use tracing::{
3333
debug,

0 commit comments

Comments
 (0)