diff --git a/doc/bin/relay/auth.md b/doc/bin/relay/auth.md index c1a26abec30..f1029eea5dc 100644 --- a/doc/bin/relay/auth.md +++ b/doc/bin/relay/auth.md @@ -419,10 +419,12 @@ subscribe = [] ## Auth server -Upgrade auth servers before relays when adopting the `webtransport` transport value. +Upgrade auth servers before relays when adopting the `webtransport` or `tls` transport value. WebTransport sessions report `webtransport`; native QUIC sessions report `quic`. -Older auth servers reject the new value. Updated Rust and JavaScript auth parsers -map future transport names to `unknown`, which your policy should handle explicitly. +`tls://` sessions report `tls`; plaintext `tcp://` sessions report `tcp`. +An auth server built before `tls` existed does not fail to parse it: the Rust and JavaScript +parsers read an unrecognized transport name as `unknown`, so admission then depends on how your +policy treats `unknown`. Update any policy keyed on `tcp` for stream links to handle `tls` too. `moq auth serve` is the reference auth server, answering the contract above. @@ -517,8 +519,10 @@ so count sessions only on the others. See The plaintext TCP and Unix-socket listeners are admitted exactly like QUIC: the path and query ride the `SETUP` (`tcp://127.0.0.1:4444/room?jwt=...`) and -reach the auth server with `transport` set to `tcp` or `unix`. A Unix socket -can also require a specific uid, gid, or pid: +reach the auth server with `transport` set to `tcp` or `unix`. A `tls://` link +(below) reports `tls`, so a policy keyed on `transport == "tcp"` for cluster +links over TLS now sees `"tls"`. A Unix socket can also require a specific uid, +gid, or pid: ```toml [listen.unix] diff --git a/go/wrapper/server.go b/go/wrapper/server.go index dcb355d28af..38e8c68e802 100644 --- a/go/wrapper/server.go +++ b/go/wrapper/server.go @@ -19,6 +19,8 @@ const ( TransportWebSocket = ffi.MoqTransportWebSocket // TransportTCP is a session that arrived over a plaintext TCP connection. TransportTCP = ffi.MoqTransportTcp + // TransportTLS is a session that arrived over a TCP connection inside TLS (a tls:// link). + TransportTLS = ffi.MoqTransportTls // TransportUnix is a session that arrived over a Unix domain socket. TransportUnix = ffi.MoqTransportUnix // TransportWebTransport is a session that arrived over WebTransport (HTTP/3). diff --git a/js/auth/api/index.api.md b/js/auth/api/index.api.md index 9502497ca68..8016375aae4 100644 --- a/js/auth/api/index.api.md +++ b/js/auth/api/index.api.md @@ -639,6 +639,7 @@ export const RequestSchema: ZodMiniDiscriminatedUnion<[ZodMiniObject<{ rtmp: "rtmp"; srt: "srt"; tcp: "tcp"; + tls: "tls"; unix: "unix"; unknown: "unknown"; webrtc: "webrtc"; @@ -680,6 +681,7 @@ export const RequestSchema: ZodMiniDiscriminatedUnion<[ZodMiniObject<{ rtmp: "rtmp"; srt: "srt"; tcp: "tcp"; + tls: "tls"; unix: "unix"; unknown: "unknown"; webrtc: "webrtc"; @@ -721,6 +723,7 @@ export const RequestSchema: ZodMiniDiscriminatedUnion<[ZodMiniObject<{ rtmp: "rtmp"; srt: "srt"; tcp: "tcp"; + tls: "tls"; unix: "unix"; unknown: "unknown"; webrtc: "webrtc"; @@ -768,6 +771,7 @@ export const RequestSchema: ZodMiniDiscriminatedUnion<[ZodMiniObject<{ rtmp: "rtmp"; srt: "srt"; tcp: "tcp"; + tls: "tls"; unix: "unix"; unknown: "unknown"; webrtc: "webrtc"; @@ -828,6 +832,7 @@ export const TransportSchema: ZodMiniPipe, ZodMiniCatch { expect(request.reason).toBe("invalid"); }); + test("parse the stream link transports from Rust", () => { + for (const transport of ["tcp", "tls"] as const) { + expect(RequestSchema.parse({ ...JSON.parse(RUST_REQUEST), transport }).transport).toBe(transport); + } + }); + test("parse gateway transports and stable end reasons from Rust", () => { for (const transport of ["rtmp", "srt", "webrtc"] as const) { for (const reason of ["narrowed", "shutdown"]) { diff --git a/js/net/src/connection/connect.ts b/js/net/src/connection/connect.ts index d1bd432a38e..6ac55bc4e37 100644 --- a/js/net/src/connection/connect.ts +++ b/js/net/src/connection/connect.ts @@ -545,8 +545,7 @@ async function dialRace( protocols: offered.alpns, versions: Object.fromEntries(offered.alpns.map((alpn) => [alpn, QMUX[alpn] ?? null])), config: { - maxStreamsBidi: maxStreams, - maxStreamsUni: maxStreams, + maxStreams, receiveWindow: BigInt(props.websocket?.receiveWindow ?? DEFAULT_RECEIVE_WINDOW), streamReceiveWindow: BigInt( props.websocket?.streamReceiveWindow ?? DEFAULT_STREAM_RECEIVE_WINDOW, diff --git a/js/net/src/integration.test.ts b/js/net/src/integration.test.ts index d6ac7f8b6a0..f72cd5edba6 100644 --- a/js/net/src/integration.test.ts +++ b/js/net/src/integration.test.ts @@ -2979,9 +2979,10 @@ test.each([Lite.ALPN_06, Lite.ALPN_07_WIP, Ietf.ALPN.DRAFT_22])( 30_000, ); -// A qmux session pair negotiating `protocol` over an in-memory socket, each side granting the other -// `maxStreamsUni` unidirectional streams. -function qmuxPair(protocol: string, maxStreamsUni: bigint): { client: Qmux; server: Qmux } { +// A qmux session pair negotiating `protocol` over an in-memory socket, the client letting the server +// open `maxStreams` streams of each kind. The client opens every bidirectional stream, so a small limit +// bounds only the server's group streams. +function qmuxPair(protocol: string, maxStreams: bigint): { client: Qmux; server: Qmux } { const socket = (readable: ReadableStream, writable: WritableStream) => { const closed = Promise.withResolvers<{ closeCode: number; reason: string }>(); return { @@ -2996,9 +2997,8 @@ function qmuxPair(protocol: string, maxStreamsUni: bigint): { client: Qmux; serv new TransformStream({ transform: (chunk, c) => c.enqueue(chunk.slice()) }); const up = pipe(); const down = pipe(); - const config = { idleTimeout: null, maxStreamsUni }; - const client = new Qmux(socket(down.readable, up.writable), { config }); - const server = Qmux.accept(socket(up.readable, down.writable), { config }); + const client = new Qmux(socket(down.readable, up.writable), { config: { idleTimeout: null, maxStreams } }); + const server = Qmux.accept(socket(up.readable, down.writable), { config: { idleTimeout: null } }); return { client, server }; } diff --git a/js/net/src/open.test.ts b/js/net/src/open.test.ts index c4513f1f187..e235009ee3f 100644 --- a/js/net/src/open.test.ts +++ b/js/net/src/open.test.ts @@ -10,8 +10,8 @@ import { Writer } from "./stream.ts"; const version = Version.DRAFT_07; const never = new Promise(() => {}); -// A qmux session pair over an in-memory socket, the server granting `maxStreamsUni`. -function qmuxPair(maxStreamsUni?: bigint): { client: WebTransport; server: WebTransport } { +// A qmux session pair over an in-memory socket, the server granting `maxStreams`. +function qmuxPair(maxStreams?: bigint): { client: WebTransport; server: WebTransport } { const socket = (readable: ReadableStream, writable: WritableStream) => { const closed = Promise.withResolvers<{ closeCode: number; reason: string }>(); return { @@ -28,7 +28,7 @@ function qmuxPair(maxStreamsUni?: bigint): { client: WebTransport; server: WebTr const down = pipe(); const config = { idleTimeout: null }; const client = new Qmux(socket(down.readable, up.writable), { config }); - const server = Qmux.accept(socket(up.readable, down.writable), { config: { ...config, maxStreamsUni } }); + const server = Qmux.accept(socket(up.readable, down.writable), { config: { ...config, maxStreams } }); return { client, server }; } diff --git a/js/qmux/api/index.api.md b/js/qmux/api/index.api.md index eda6aa58d5a..9d8e34afb17 100644 --- a/js/qmux/api/index.api.md +++ b/js/qmux/api/index.api.md @@ -16,8 +16,7 @@ export interface Config { idleTimeout?: Duration | null; maxDatagramFrameSize?: bigint | null; maxRecordSize?: bigint; - maxStreamsBidi?: bigint; - maxStreamsUni?: bigint; + maxStreams?: bigint; receiveWindow?: bigint; streamReceiveWindow?: bigint; } diff --git a/js/qmux/src/session.test.ts b/js/qmux/src/session.test.ts index eebe9c0c3e1..3684998b6d9 100644 --- a/js/qmux/src/session.test.ts +++ b/js/qmux/src/session.test.ts @@ -628,7 +628,7 @@ describe("Session integration (scripted peer)", () => { // The peer may open any index under its credit, implicitly opening every // lower one. Tracking each skipped index would let one tiny frame make us // allocate (and loop) once per stream below it. - const { session, peer } = connect({ maxStreamsUni: 1n << 40n }); + const { session, peer } = connect({ maxStreams: 1n << 40n }); peer.send({ type: "transport_parameters", params: peerParams() }); await session.ready; @@ -922,8 +922,10 @@ describe("Session integration (scripted peer)", () => { { receiveWindow: null }, { receiveWindow: "64" }, { streamReceiveWindow: 64 }, - { maxStreamsBidi: null }, - { maxStreamsUni: 1 }, + { maxStreams: null }, + { maxStreams: 1 }, + { maxStreamsBidi: 1n }, + { maxStreamsUni: 1n }, { maxRecordSize: null }, { maxDatagramFrameSize: 64 }, { maxData: 64n }, @@ -957,6 +959,20 @@ describe("Session integration (scripted peer)", () => { session.close(); }); + test("one maxStreams is advertised for both directions", async () => { + const { session, peer } = connect({ maxStreams: 7n }); + await started(peer); + await waitFor(() => peer.has("transport_parameters")); + const frame = peer + .received() + .find( + (frame): frame is Frame.TransportParameters => frame.type === "transport_parameters", + ) as Frame.TransportParameters; + expect(frame.params.initialMaxStreamsBidi).toBe(7n); + expect(frame.params.initialMaxStreamsUni).toBe(7n); + session.close(); + }); + test("disabled config uses null and invalid durations fail before opening", () => { // A plain number is the old millisecond config, refused rather than misread. for (const value of [ @@ -979,7 +995,7 @@ describe("Session integration (scripted peer)", () => { test("config values that don't fit a varint are refused up front", () => { (globalThis as { WebSocketStream?: unknown }).WebSocketStream = FakePeer; expect(() => new Session("https://example/test", { config: { receiveWindow: -1n } })).toThrow("VarInt"); - expect(() => new Session("https://example/test", { config: { maxStreamsBidi: VarInt.MAX + 1n } })).toThrow( + expect(() => new Session("https://example/test", { config: { maxStreams: VarInt.MAX + 1n } })).toThrow( "VarInt", ); }); @@ -1853,7 +1869,7 @@ describe("Session integration (scripted peer)", () => { // immediately observable. This is the reproduction from issue #299: the peer // sends a full stream plus FIN while the application never reads the acceptor. const { session, peer } = connect({ - maxStreamsUni: 1n, + maxStreams: 1n, receiveWindow: 100n, streamReceiveWindow: 100n, }); @@ -1891,7 +1907,7 @@ describe("Session integration (scripted peer)", () => { }); test("accepted active streams do not recycle stream-count credit", async () => { - const { session, peer } = connect({ maxStreamsUni: 1n }); + const { session, peer } = connect({ maxStreams: 1n }); peer.send({ type: "transport_parameters", params: peerParams() }); await session.ready; @@ -1916,7 +1932,7 @@ describe("Session integration (scripted peer)", () => { const id = Stream.Id.create(0n, Stream.Dir.Bi, true); async function accept() { - const { session, peer } = connect({ maxStreamsBidi: 1n }); + const { session, peer } = connect({ maxStreams: 1n }); peer.send({ type: "transport_parameters", params: peerParams() }); await session.ready; peer.send({ type: "stream", id, data: new Uint8Array([1]), fin: false }); @@ -2028,7 +2044,7 @@ describe("Session integration (scripted peer)", () => { // slot returns as soon as both halves are done on the wire. describe("a refused peer stream returns its stream-count credit", () => { test("uni, once the peer finishes it", async () => { - const { session, peer } = connect({ maxStreamsUni: 1n }); + const { session, peer } = connect({ maxStreams: 1n }); peer.send({ type: "transport_parameters", params: peerParams() }); await session.ready; await session.incomingUnidirectionalStreams.cancel(); @@ -2040,7 +2056,7 @@ describe("Session integration (scripted peer)", () => { }); test("bidi, resetting our send half, once the peer finishes its own", async () => { - const { session, peer } = connect({ maxStreamsBidi: 1n }); + const { session, peer } = connect({ maxStreams: 1n }); peer.send({ type: "transport_parameters", params: peerParams() }); await session.ready; await session.incomingBidirectionalStreams.cancel(); diff --git a/js/qmux/src/session.ts b/js/qmux/src/session.ts index e6c4b6b6253..3be3e589e9f 100644 --- a/js/qmux/src/session.ts +++ b/js/qmux/src/session.ts @@ -29,10 +29,8 @@ export type SendStreamOptions = WebTransportSendStreamOptions & { /** Configuration for a QMux session. */ export interface Config { - /** Max concurrent bidirectional streams the peer can open. */ - maxStreamsBidi?: bigint; - /** Max concurrent unidirectional streams the peer can open. */ - maxStreamsUni?: bigint; + /** Max concurrent streams the peer can open, in each direction. */ + maxStreams?: bigint; /** Connection-level receive window in bytes. */ receiveWindow?: bigint; /** Receive window in bytes for every stream. */ @@ -54,8 +52,7 @@ export interface Config { } const DEFAULT_CONFIG: Required = { - maxStreamsBidi: 100n, - maxStreamsUni: 100n, + maxStreams: 100n, receiveWindow: 1_048_576n, streamReceiveWindow: 262_144n, idleTimeout: Duration.secs(30), @@ -104,8 +101,8 @@ function configToTransportParams(config: Required): TransportParams { initialMaxStreamDataBidiLocal: config.streamReceiveWindow, initialMaxStreamDataBidiRemote: config.streamReceiveWindow, initialMaxStreamDataUni: config.streamReceiveWindow, - initialMaxStreamsBidi: config.maxStreamsBidi, - initialMaxStreamsUni: config.maxStreamsUni, + initialMaxStreamsBidi: config.maxStreams, + initialMaxStreamsUni: config.maxStreams, // Clamp to maxRecordSize so we never advertise a datagram larger than our // record layer accepts. maxDatagramFrameSize: @@ -783,8 +780,8 @@ export class Session implements WebTransport { // Receive limits are version-independent. const notify = () => this.#scheduler?.notify(); this.#recvData = new Window(this.#ourParams.initialMaxData, notify); - this.#recvBiLimit = new StreamLimit(this.#config.maxStreamsBidi, notify); - this.#recvUniLimit = new StreamLimit(this.#config.maxStreamsUni, notify); + this.#recvBiLimit = new StreamLimit(this.#config.maxStreams, notify); + this.#recvUniLimit = new StreamLimit(this.#config.maxStreams, notify); const ready = Promise.withResolvers(); this.ready = ready.promise; diff --git a/quest/m2/README.md b/quest/m2/README.md index be85fd75f4e..75b8bdec7aa 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -41,8 +41,7 @@ removal, a rename, or a wire, catalog, or format change that is free until demos return to their earlier format. - **Unused API.** [One sweep per area](/quest/m2/unused-api/README.md), each item re-checked for a downstream caller first. -- **Relay and transports.** [Congestion names](/quest/m2/congestion-names.md) - and [transport names](/quest/m2/transport-names.md). +- **Relay and transports.** [Congestion names](/quest/m2/congestion-names.md). - **Auth and crypto.** [Claims](/quest/m2/auth-claims.md). End-to-end encryption [is its own unpublished crate again](/quest/m2/e2ee-crate.md); its [finished format](/quest/m3/e2ee-format.md) follows in m3. diff --git a/quest/m2/transport-names.md b/quest/m2/transport-names.md deleted file mode 100644 index 8d9a7b3e4fd..00000000000 --- a/quest/m2/transport-names.md +++ /dev/null @@ -1,82 +0,0 @@ -# [S] A TLS stream link reports tls, and @moq/qmux has one stream limit - -## Goal - -A session over `tls://` reports its transport as `tls`, in -`moq_tokio::Transport`, in `moq_auth::Transport`, in the auth request an -endpoint receives, and in the bindings, so an auth server, a log line, and -the relay's own checks can tell an encrypted stream link from plaintext -`tcp://`. `@moq/qmux` takes one `maxStreams`, applied to each direction, as -Rust's `Limits::max_streams` and `@moq/net`'s `websocket.maxStreams` already -do. - -## Plan - -Decided 2026-11-16 (maintainer, /quest-plan of the pre-cut audit): - -- ✅ Add `Tls` to both `Transport` enums and report it for `tls://` - (rejected: only fixing the moq-tokio doc that says "plaintext"). Both - enums are non-exhaustive, so the variant is additive in Rust, but - changing what an existing link reports moves every policy and metric - keyed on `"tcp"`. That is cheapest before the name is announced. -- ✅ `@moq/qmux` takes a single `maxStreams` (rejected: also nesting its - windows under `limits` to mirror Rust; keeping the bidirectional and - unidirectional pair). -- LAN discovery stays in moq-tokio: the audit proposed moving - `moq_tokio::mdns` into moq-relay, and the maintainer did not take it. - Don't reopen it without a new reason, such as a measured build cost. - -Facts found by the audit: - -- `moq_tokio::Transport::Tcp` is documented "A plaintext TCP connection - using qmux framing" (`rs/moq-tokio/src/transport.rs:11-12`), yet a - `tls://` dial returns it (`rs/moq-tokio/src/client.rs:496-506`) and the - accept side reports it for every stream link - (`rs/moq-tokio/src/server.rs:1298`). `moq_auth::Transport::Tcp` says - "plaintext or TLS" (`rs/moq-auth/src/request.rs:186-187`). -- The relay maps one enum onto the other (`rs/moq-relay/src/auth.rs:1288`), - so an auth endpoint sees `"tcp"` for an mTLS cluster link unless a client - certificate happens to be attached. `moq`'s `is_public_transport` - (`rs/moq-cli/src/main.rs:226-231`) treats `Tcp` as always public. -- The strings are a contract: `Transport::as_str` - (`rs/moq-tokio/src/transport.rs:22-33`), the serde names in moq-auth - (`rs/moq-auth/src/request.rs:212`), `js/auth/src/contract.ts:35`, and - `MoqTransport` in moq-ffi (`rs/moq-ffi/src/server.rs:449`). -- `@moq/qmux`'s `Config` has `maxStreamsBidi` and `maxStreamsUni` - (`js/qmux/src/session.ts:33-35`, `js/qmux/api/index.api.md:19-20`). Its - one consumer sets both from one number - (`js/net/src/connection/connect.ts:549-560`), and Rust has one - `Limits::max_streams` (`rs/moq-quic/src/limits.rs:21`). - The package moves into this repository at this cut, so the rename rides - a break it already has. -- `ws://` and `wss://` share `WebSocket` in the same way. Not picked: a - WebSocket's TLS belongs to the HTTP server in front of it, which the relay - often cannot see. - -For the PR: - -- Add `Tls`, spelled `"tls"`, to `moq_tokio::Transport` and - `moq_auth::Transport`. Report it from the `tls://` dial and from the TLS - branch of the stream acceptor. Fix the `Tcp` docs to say plaintext in both - crates. Extend the relay's mapping and `is_public_transport` (a TLS link - is public the same way plaintext TCP is; say so in its doc). -- Mirror it in `@moq/auth`'s contract enum and in `MoqTransport` with every - wrapper. `MoqTransport` carries an `Unknown` variant (the open-set rule in - `rs/moq-ffi/AGENTS.md`), so `Tls` joins as a named variant before the cut. -- Grep for consumers of the `"tcp"` string: relay metrics labels - (`rs/moq-relay/src/internal.rs` uses `"tcp"` for the listener, which - stays, since the listener is one TCP port), stats labels, `doc/bin/relay`, - and `doc/concept/transport.md`. The auth docs get a line: a server keying - policy on `transport == "tcp"` for cluster links over TLS now sees `"tls"`. -- `@moq/qmux`: one `maxStreams?: bigint` on `Config` and its default; delete - the pair; `@moq/net` passes it once. Update `js/qmux/api/index.api.md`, - the README, and the migration note. -- Tests: a `tls://` session reports `tls` on both ends and in the auth - request; a `tcp://` session still reports `tcp`; `@moq/qmux` advertises - the one limit for both directions. - -Public API: additive in Rust (`Transport::Tls` on two non-exhaustive -enums) and a new binding selector; breaking for `@moq/qmux` -(`maxStreamsBidi` and `maxStreamsUni` become `maxStreams`). Behaviour: the -transport string for `tls://` changes from `tcp` to `tls` in auth requests -and logs. Wire: none. diff --git a/rs/moq-auth/src/request.rs b/rs/moq-auth/src/request.rs index 09250e8ba22..133b363f54f 100644 --- a/rs/moq-auth/src/request.rs +++ b/rs/moq-auth/src/request.rs @@ -197,7 +197,7 @@ pub enum Transport { Quic, /// A WebSocket connection using qmux framing. WebSocket, - /// A TCP connection using qmux framing, plaintext or TLS. + /// A plaintext TCP connection using qmux framing. Tcp, /// A Unix domain socket using qmux framing. Unix, @@ -212,6 +212,8 @@ pub enum Transport { WebRtc, /// A WebTransport connection over HTTP/3. WebTransport, + /// A TCP connection using qmux framing inside TLS, a `tls://` stream link. + Tls, /// A transport name this auth server does not recognize. #[serde(other)] Unknown, @@ -224,6 +226,7 @@ impl Transport { Self::Quic => "quic", Self::WebSocket => "websocket", Self::Tcp => "tcp", + Self::Tls => "tls", Self::Unix => "unix", Self::Http => "http", Self::Rtmp => "rtmp", @@ -445,6 +448,16 @@ mod tests { } } + #[test] + fn stream_link_transports_keep_their_own_names() { + for (transport, text) in [(Transport::Tcp, "tcp"), (Transport::Tls, "tls")] { + let request = Request::new("relay-1", transport, "/room"); + let json = serde_json::to_value(&request).unwrap(); + assert_eq!(json["transport"], text); + assert_eq!(serde_json::from_value::(json).unwrap(), request); + } + } + #[test] fn a_unix_session_has_no_addresses() { let request = Request::new("relay-1", Transport::Unix, ""); diff --git a/rs/moq-cli/src/main.rs b/rs/moq-cli/src/main.rs index 55346288adf..d0d17423e17 100644 --- a/rs/moq-cli/src/main.rs +++ b/rs/moq-cli/src/main.rs @@ -233,10 +233,11 @@ impl Serving { } } -/// Whether ordinary clients may use this transport on the shared LAN server. +/// Whether ordinary clients may use this transport on the shared LAN server. A TLS stream link is +/// public the same way plaintext TCP is. fn is_public_transport(transport: moq_tokio::Transport, public_quic: bool) -> bool { match transport { - moq_tokio::Transport::Tcp | moq_tokio::Transport::Unix => true, + moq_tokio::Transport::Tcp | moq_tokio::Transport::Tls | moq_tokio::Transport::Unix => true, _ => public_quic, } } @@ -1744,6 +1745,7 @@ mod tests { #[test] fn explicit_stream_listeners_are_public_without_exposing_mesh_quic() { assert!(is_public_transport(moq_tokio::Transport::Tcp, false)); + assert!(is_public_transport(moq_tokio::Transport::Tls, false)); assert!(is_public_transport(moq_tokio::Transport::Unix, false)); assert!(!is_public_transport(moq_tokio::Transport::Quic, false)); assert!(is_public_transport(moq_tokio::Transport::Quic, true)); diff --git a/rs/moq-ffi/src/server.rs b/rs/moq-ffi/src/server.rs index dc4297998a2..3810f4859c0 100644 --- a/rs/moq-ffi/src/server.rs +++ b/rs/moq-ffi/src/server.rs @@ -439,6 +439,8 @@ pub enum MoqTransport { WebTransport, /// A transport this version of the bindings cannot name yet. Unknown, + /// A TCP connection using qmux framing inside TLS, a `tls://` stream link. + Tls, } impl From for MoqTransport { @@ -447,6 +449,7 @@ impl From for MoqTransport { moq_tokio::Transport::Quic => Self::Quic, moq_tokio::Transport::WebSocket => Self::WebSocket, moq_tokio::Transport::Tcp => Self::Tcp, + moq_tokio::Transport::Tls => Self::Tls, moq_tokio::Transport::Unix => Self::Unix, moq_tokio::Transport::WebTransport => Self::WebTransport, _ => Self::Unknown, @@ -465,6 +468,7 @@ mod transport_tests { (Transport::Quic, MoqTransport::Quic), (Transport::WebSocket, MoqTransport::WebSocket), (Transport::Tcp, MoqTransport::Tcp), + (Transport::Tls, MoqTransport::Tls), (Transport::Unix, MoqTransport::Unix), (Transport::WebTransport, MoqTransport::WebTransport), ] { diff --git a/rs/moq-relay/src/auth.rs b/rs/moq-relay/src/auth.rs index f083af1c14c..d8665c67bb0 100644 --- a/rs/moq-relay/src/auth.rs +++ b/rs/moq-relay/src/auth.rs @@ -1109,6 +1109,7 @@ fn transport(transport: moq_tokio::Transport) -> moq_auth::Transport { moq_tokio::Transport::WebTransport => moq_auth::Transport::WebTransport, moq_tokio::Transport::WebSocket => moq_auth::Transport::WebSocket, moq_tokio::Transport::Tcp => moq_auth::Transport::Tcp, + moq_tokio::Transport::Tls => moq_auth::Transport::Tls, moq_tokio::Transport::Unix => moq_auth::Transport::Unix, // A transport added to moq-tokio before this mapping learns it still reaches // the decider, named as one it does not recognize. @@ -1359,7 +1360,7 @@ mod tests { #[test] fn every_transport_has_an_auth_name() { use moq_tokio::Transport as T; - for transport in [T::Quic, T::WebTransport, T::WebSocket, T::Tcp, T::Unix] { + for transport in [T::Quic, T::WebTransport, T::WebSocket, T::Tcp, T::Tls, T::Unix] { assert_eq!(super::transport(transport).as_str(), transport.as_str()); } } diff --git a/rs/moq-relay/tests/integration/auth_lifetime.rs b/rs/moq-relay/tests/integration/auth_lifetime.rs index be74b112849..fa0f003fe79 100644 --- a/rs/moq-relay/tests/integration/auth_lifetime.rs +++ b/rs/moq-relay/tests/integration/auth_lifetime.rs @@ -476,6 +476,7 @@ async fn admits_and_reports_the_session() { let connect = seen.iter().find(|r| r.event == Event::Connect).expect("a connect"); assert_eq!(connect.node, "test-relay"); assert_eq!(connect.transport, moq_auth::Transport::Tcp); + assert_eq!(pub_session.transport(), Some(moq_tokio::Transport::Tcp)); assert_eq!(connect.path, "/room"); assert_eq!(connect.query.as_deref(), Some("jwt=token")); assert!(connect.remote.is_some_and(|addr| addr.ip().is_loopback())); @@ -488,6 +489,29 @@ async fn admits_and_reports_the_session() { relay.abort(); } +/// A `tls://` session reaches the auth server as `tls`, and both ends of it report `tls`, so +/// a policy keyed on `tcp` sees only the plaintext link. +#[tokio::test] +async fn reports_a_tls_session_as_tls() { + let script = Script::new(grant(Duration::from_secs(3600))); + let mut config = moq_tokio::listen::Config::default(); + config.tcp.tls = Some(true); + config.tls.generate = vec!["localhost".into()]; + let cluster = crate::spawn_cluster(cluster::Options::default()); + let (port, relay) = spawn_relay_config(build_auth(script.spawn().await), cluster, config).await; + let (pub_session, sub_session) = connect_and_round_trip(&room_url("tls", port)).await; + + let seen = script.seen.lock().unwrap().clone(); + let connect = seen.iter().find(|r| r.event == Event::Connect).expect("a connect"); + assert_eq!(connect.transport, moq_auth::Transport::Tls); + assert_eq!(pub_session.transport(), Some(moq_tokio::Transport::Tls)); + assert_eq!(sub_session.transport(), Some(moq_tokio::Transport::Tls)); + + drop(pub_session); + drop(sub_session); + relay.abort(); +} + /// Write all of `data` to a raw qmux stream. async fn write_all(send: &mut qmux::SendStream, mut data: &[u8]) { use moq_net::transport::poll::SendStream as _; diff --git a/rs/moq-tokio/src/client.rs b/rs/moq-tokio/src/client.rs index d525ad164ce..b4e50de11c8 100644 --- a/rs/moq-tokio/src/client.rs +++ b/rs/moq-tokio/src/client.rs @@ -490,7 +490,7 @@ impl Client { ) .await?; let session = connect_session(&moq, session).await?; - return Ok(Dialed::new(session, crate::Transport::Tcp)); + return Ok(Dialed::new(session, crate::Transport::Tls)); } // Unix domain socket (qmux, no TLS). Same-host only; the server can diff --git a/rs/moq-tokio/src/server.rs b/rs/moq-tokio/src/server.rs index 1a604e20c76..9e70fcbd32d 100644 --- a/rs/moq-tokio/src/server.rs +++ b/rs/moq-tokio/src/server.rs @@ -1273,7 +1273,7 @@ impl Incoming { .zip(session.peer_certificates()) .map(|(tls, chain)| tls.peer(chain.to_vec())); Self { - transport: Transport::Tcp, + transport: if tls.is_some() { Transport::Tls } else { Transport::Tcp }, url: None, link: Link { remote, diff --git a/rs/moq-tokio/src/tcp.rs b/rs/moq-tokio/src/tcp.rs index 0a1ceb7661e..db3bdc97c04 100644 --- a/rs/moq-tokio/src/tcp.rs +++ b/rs/moq-tokio/src/tcp.rs @@ -616,7 +616,7 @@ mod tests { let url: Url = format!("tls://localhost:{port}/room?jwt=credential").parse().unwrap(); let accept = tokio::spawn(async move { let request = server.accept().await.unwrap(); - assert_eq!(request.transport(), crate::Transport::Tcp); + assert_eq!(request.transport(), crate::Transport::Tls); assert_eq!(request.path(), "/room"); assert_eq!(request.query(), Some("jwt=credential")); let session = request.ok().await.unwrap(); @@ -637,10 +637,11 @@ mod tests { matches!(untrusted, Ok(Err(_))), "an untrusted certificate must be refused" ); - let _session = kio::clock::timeout(Duration::from_secs(5), dial(true).established()) + let session = kio::clock::timeout(Duration::from_secs(5), dial(true).established()) .await .expect("trusted dial timed out") .expect("trusted dial failed"); + assert_eq!(session.transport(), Some(crate::Transport::Tls)); let (_server, _accepted) = kio::clock::timeout(Duration::from_secs(5), accept) .await .expect("accept timed out") diff --git a/rs/moq-tokio/src/transport.rs b/rs/moq-tokio/src/transport.rs index 45340e38a4e..bf2cc4532a8 100644 --- a/rs/moq-tokio/src/transport.rs +++ b/rs/moq-tokio/src/transport.rs @@ -14,6 +14,8 @@ pub enum Transport { Unix, /// WebTransport over HTTP/3 on QUIC. WebTransport, + /// A TCP connection using qmux framing inside TLS, a `tls://` stream link. + Tls, } impl Transport { @@ -25,6 +27,7 @@ impl Transport { Self::Tcp => "tcp", Self::Unix => "unix", Self::WebTransport => "webtransport", + Self::Tls => "tls", } } }