Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ CLANG=clang-22 CLANGXX=clang++-22 .github/scripts/cross-openbsd.sh arm64 out/rap
The forwarding **target is pinned on the server** — clients cannot choose a
destination. The server loads a **rule table** mapping endpoints to targets, and
the rule authorities also define the allowed TLS SNI hostnames. Connections with
missing or non-matching SNI are rejected during the TLS handshake; accepted
CONNECT-UDP requests are then matched on `:authority` + path (the query string
is ignored, so generic MASQUE clients that carry `target_host`/`target_port` in
the query still interoperate; the server ignores those and uses the rule's
target).
non-matching SNI are rejected during the TLS handshake. Connections without SNI
are accepted, so IP-literal endpoints can use certificates with IP subject
alternative names (including Let's Encrypt IP certificates). Clients still verify
the certificate against the endpoint's IP address; no `--insecure` is needed.
All CONNECT-UDP requests, with or without SNI, are matched on `:authority` + path
(the query string is ignored, so generic MASQUE clients that carry
`target_host`/`target_port` in the query still interoperate; the server ignores
those and uses the rule's target).

The **client is a local UDP proxy**: it binds a UDP socket and tunnels every
datagram received there through the proxy, opening one CONNECT-UDP flow per local
Expand Down Expand Up @@ -491,19 +494,19 @@ cleartext cover identity; it only needs a valid certificate for the ECH
with the server's fresh `retry_configs`. A cert covering both names handles both
paths.

The server rejects ClientHellos whose SNI does not match any configured rule
authority host. With ECH accepted, this check is applied to the decrypted inner
SNI; rejected ECH fallbacks and ordinary non-ECH handshakes are checked against
the cleartext SNI.
The server rejects ClientHellos whose SNI is present but does not match any
configured rule authority host. Missing SNI is allowed for IP-literal endpoints.
With ECH accepted, this check is applied to the decrypted inner SNI; rejected ECH
fallbacks and ordinary non-ECH handshakes are checked against the cleartext SNI.

Both ends log whether ECH was accepted on each connection (`ech=true`).

### Access control

By default the proxy performs **no client authentication**: any peer that can
reach it, complete TLS with a configured SNI host, and send a CONNECT-UDP request
matching a rule's authority + path is granted a tunnel. (The client still
authenticates the *server* via TLS unless `--insecure`.)
reach it, complete TLS (with a configured SNI host or no SNI), and send a
CONNECT-UDP request matching a rule's authority + path is granted a tunnel. (The
client still authenticates the *server* via TLS unless `--insecure`.)

A secret can be embedded in a rule's endpoint **path** as a lightweight
shared-secret gate. The server matches on the path component (the query string is
Expand Down
61 changes: 61 additions & 0 deletions src/e2e_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,67 @@ async fn ech_accepted_over_quic() {
assert_eq!(server_hs.server_name.as_deref(), Some(HOST));
}

#[tokio::test(flavor = "multi_thread")]
async fn missing_sni_is_accepted_with_ip_certificate() {
let fx = Fixture::new("no-sni");
// The SNI allowlist must not reject a client that sends no SNI at all.
let server = fx.server(HOST);
let addr = server.local_addr().unwrap();
let accept = tokio::spawn(async move {
for _ in 0..2 {
let conn = server.accept().await.unwrap().await.unwrap();
assert_eq!(handshake_data(&conn).server_name, None);
conn.closed().await;
}
});

let client = client_endpoint(false);
for ip in ["127.0.0.1", "::1"] {
// Production ClientTls omits SNI for IP literals and verifies IP SANs.
let conn = tokio::time::timeout(
Duration::from_secs(5),
client
.connect_with(fx.client_config(false), addr, ip)
.unwrap(),
)
.await
.expect("IP-literal handshake must not time out")
.expect("IP-literal handshake without SNI must succeed");
conn.close(0u32.into(), b"");
}
accept.await.unwrap();
}

#[tokio::test(flavor = "multi_thread")]
async fn missing_sni_does_not_bypass_certificate_verification() {
let fx = Fixture::new("no-sni-verify");
let server = fx.server(HOST);
let addr = server.local_addr().unwrap();
tokio::spawn(async move {
while let Some(incoming) = server.accept().await {
let _ = incoming.await;
}
});

let other = Fixture::new("no-sni-verify-other");
let client = client_endpoint(false);
for (config, ip) in [
(fx.client_config(false), "127.0.0.2"),
(other.client_config(false), "127.0.0.1"),
] {
let res = tokio::time::timeout(
Duration::from_secs(5),
client.connect_with(config, addr, ip).unwrap(),
)
.await
.expect("certificate rejection must not time out");
assert!(
res.is_err(),
"a mismatched IP SAN or untrusted certificate must still fail"
);
}
}

#[tokio::test(flavor = "multi_thread")]
async fn unmatched_sni_is_rejected() {
let fx = Fixture::new("sni");
Expand Down
2 changes: 2 additions & 0 deletions src/ech_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ pub(crate) fn self_signed() -> (
let san = SubjectAlternativeName::new()
.dns("secret.internal")
.dns("public.example.com")
.ip("127.0.0.1")
.ip("::1")
.build(&b.x509v3_context(None, None))
.unwrap();
b.append_extension(san).unwrap();
Expand Down
10 changes: 5 additions & 5 deletions src/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,14 @@ pub(crate) fn install_ech_keys(builder: &mut SslContextBuilder, ech: &EchKeySet)
Ok(())
}

/// Reject handshakes whose ClientHello SNI is missing or not one of the
/// configured proxy endpoint hosts. With ECH accepted, BoringSSL exposes the
/// protected inner SNI here; without ECH this checks the ordinary SNI.
/// Reject handshakes whose ClientHello SNI is present but not one of the
/// configured proxy endpoint hosts. Clients connecting to an IP literal omit
/// SNI and authenticate the server using its certificate's IP SAN instead.
/// With ECH accepted, BoringSSL exposes the protected inner SNI here.
pub(crate) fn install_sni_guard(builder: &mut SslContextBuilder, allowed_hosts: Vec<String>) {
builder.set_select_certificate_callback(move |client_hello| {
let Some(sni) = client_hello.servername(NameType::HOST_NAME) else {
log::debug!("rejecting TLS ClientHello without SNI");
return Err(SelectCertError::ERROR);
return Ok(());
};
if allowed_hosts.iter().any(|h| h.eq_ignore_ascii_case(sni)) {
return Ok(());
Expand Down
Loading