quicmux
quicmux multiplexes Unix and TCP sockets over QUIC (RFC 9000). The client and server correlate their listening and connecting sockets using a routing label specified in the command line arguments; it's a number 0-255 that is used once per circuit, upon establishment.
In other words, say for some reason you have one UDP connection to talk to some server with, then with quicmux you can make local mirroring sockets of any of the stream sockets that server can reach, including but not limited to the server's SSH daemon, or a SOCKS proxy. So like OpenSSH's port (and unix socket!) forwarding, but over QUIC.
- client listens on one or more local Unix/TCP sockets. Every accepted
connection gets its own QUIC connection to the server.
- server listens on one or more UDP addresses. Every accepted QUIC
connection is connected to the Unix/TCP target selected by its routing
label.
The QUIC protocol demultiplexes connections by Connection ID, which is why a single UDP socket
can carry many independent connections.
I pretty much oneshotted this with help of an LLM (well, "help", they did 99%),
hence the llmao prefix.
Homepage: https://sr.ht/~nullenenenen/llmao-quicmux/.
Mailing list: ~nullenenenen/llmao-quicmux@lists.sr.ht.
Known bugs
quicmux is surprisingly hard to type except, perhaps, for people who have never typed the word quick.
Requirements
Go 1.26.0 or newer. This is the floor imposed by the current dependencies
(github.com/quic-go/quic-go v0.64.1 requires Go 1.26.0); older toolchains
will refuse to build the module.
Install
CGO_ENABLED=0 go install nontrivialpursuit.org/llmao-quicmux/quicmux@latest
Or from a checkout:
CGO_ENABLED=0 go install ./quicmux
CGO_ENABLED=0 is recommended: quicmux does not use cgo, and this avoids
requiring a C compiler.
Build
CGO_ENABLED=0 go build \
-buildvcs=true -tags=release -buildmode=exe -pgo=auto \
-ldflags="-s -w" -trimpath \
-o bin/quicmux ./quicmux
Authentication: mutual certificate pinning, no PKI
Both sides authenticate each other: the server proves its identity to the
client, and the client proves its identity to the server. There is no CA, no
PKI, and no certificate files. Each side pins the peer's certificate hash.
Each side has an Ed25519 key. The key is either:
- supplied as base58 in
QUICMUX_KEY, or
- generated at startup and printed to stderr (not saved; persisting it is the
operator's job). This output is unconditional and not affected by
QUICMUX_LOG_LEVEL.
The self-signed certificate is derived deterministically from the key: fixed
template, fixed serial, fixed validity, Ed25519 signatures. The same key
always yields the same certificate and therefore the same SHA-256 pin. The
local certpin is printed at startup in every case, regardless of the log
level.
Generate a key and its pin:
quicmux gen-key
# QUICMUX_KEY=<base58>
# certpin=sha256:<base58>
Given an existing key in QUICMUX_KEY, print its certificate pin:
QUICMUX_KEY=<base58> quicmux show-cert
# sha256:<base58>
Configure the peer's pin with --certpin sha256:<base58> or
QUICMUX_CERTPIN. If both are set they must match. The certificate CN/SAN and
the TLS server name are always quicmux.
If a side generates an ephemeral key, its pin changes on every restart, so the
peer's --certpin must be updated accordingly. Set QUICMUX_KEY to the
printed value to keep the pin stable.
Server
QUICMUX_KEY=<server-key> quicmux server \
--quic-listen 0.0.0.0:4433 \
--connect-to 0:unix:/run/sshd.sock \
--connect-to 1:tcp:127.0.0.1:22 \
--certpin sha256:<client-pin>
--quic-listen is repeatable.
--quic-freebind-listen is repeatable and enables Linux IP_FREEBIND /
IPV6_FREEBIND, allowing the socket to bind to a non-local address.
--connect-to is repeatable and takes label:unix:/path or
label:tcp:host:port. The label is a decimal integer 0-255 and must be
unique on the server.
Client
QUICMUX_KEY=<client-key> quicmux client \
--quic-connect 203.0.113.1:4433 \
--listen 0:unix:/run/quicmux.sock \
--listen 1:tcp:127.0.0.1:2222 \
--certpin sha256:<server-pin>
--listen is repeatable and accepts label:unix:/path or
label:tcp:host:port. The label must be unique on the client.
- Unix listeners default to mode
0660 (QUICMUX_UNIX_MODE).
--quic-connect is the server's UDP address.
Routing labels
A routing label selects which server-side --connect-to target a local
connection uses. The client sends the label as the first byte of the QUIC
stream, before any application data. The server reads it after the handshake
completes and dials the matching target. An unknown label closes the QUIC
connection with an application error.
The label is carried in the stream, not in the QUIC Connection ID. QUIC CIDs
are chosen by the receiver and identify a connection, not a service, so they
cannot be used for this.
Labels are decimal integers 0-255. They are local to each daemon: the client
and server must agree on the mapping, but the numbers themselves carry no
meaning. A client listener and a server target with the same label are
connected. For example:
# server
--connect-to 1:unix:/run/sshd.sock
--connect-to 2:tcp:127.0.0.1:5432
# client
--listen 1:tcp:127.0.0.1:2222
--listen 2:tcp:127.0.0.1:15432
The label is chosen by the client, so the certificate pin authorizes the client
for every configured target. If different clients should reach different
targets, enforce that outside quicmux or run separate server instances.
Environment
| Variable |
Default |
Notes |
QUICMUX_KEY |
generated |
base58 Ed25519 seed (32 bytes) or private key (64 bytes); printed if unset |
QUICMUX_CERTPIN |
required unless --certpin |
sha256:<base58> |
QUICMUX_LOG_LEVEL |
info |
debug, info, warn, error |
QUICMUX_LOG_FORMAT |
text |
text or json |
QUICMUX_HANDSHAKE_IDLE_TIMEOUT |
10s |
|
QUICMUX_MAX_IDLE_TIMEOUT |
90s |
negotiated as min of both peers |
QUICMUX_KEEPALIVE_PERIOD |
30s |
keeps idle connections and NAT mappings alive |
QUICMUX_CONNECT_TIMEOUT |
15s |
client QUIC dial |
QUICMUX_DRAIN_TIMEOUT |
5s |
wait for peer close before closing the QUIC connection |
QUICMUX_TARGET_DIAL_TIMEOUT |
10s |
server --connect-to dial |
QUICMUX_STREAM_ACCEPT_TIMEOUT |
10s |
server stream accept and routing label read |
QUICMUX_INITIAL_STREAM_RECEIVE_WINDOW |
64KiB |
small by design |
QUICMUX_MAX_STREAM_RECEIVE_WINDOW |
256KiB |
raise for bulk transfers |
QUICMUX_INITIAL_CONNECTION_RECEIVE_WINDOW |
128KiB |
|
QUICMUX_MAX_CONNECTION_RECEIVE_WINDOW |
1MiB |
|
QUICMUX_SOCKET_RCVBUF |
512KiB |
|
QUICMUX_SOCKET_SNDBUF |
512KiB |
|
QUICMUX_INITIAL_PACKET_SIZE |
1280 |
|
QUICMUX_DISABLE_PMTUD |
false |
|
QUICMUX_ALLOW_0RTT |
false |
see below |
QUICMUX_0RTT_BUFFER_LIMIT |
64KiB |
replay buffer per connection |
QUICMUX_SESSION_CACHE_SIZE |
64 |
TLS session tickets for 0-RTT |
QUICMUX_MAX_INCOMING_STREAMS |
1 |
one stream per QUIC connection |
QUICMUX_MAX_INCOMING_UNI_STREAMS |
-1 |
none |
QUICMUX_UDP_LOCAL_ADDR |
empty |
client UDP bind address |
QUICMUX_UNIX_MODE |
0660 |
client Unix listener mode |
Sizes accept KiB, MiB, GiB, KB, MB, GB, or plain bytes.
0-RTT
0-RTT is off by default. It is useful when the client daemon opens many
short-lived connections to the same server and the extra handshake RTT
matters: request/response protocols, short-lived tunnels, and similar
latency-sensitive workloads. When enabled with QUICMUX_ALLOW_0RTT=true, the
client keeps TLS session tickets in memory and uses DialEarly for new local
connections. The server uses ListenEarly, accepts the 0-RTT stream, but
waits for the handshake to complete (and the client certificate pin to be
verified) before dialing the target. If the server rejects 0-RTT, the client
transparently moves to the post-handshake connection and replays the bytes
recorded before the handshake completed.
The security impact is real: 0-RTT data is replayable by an attacker who can
capture it, and it is sent before the server has authenticated the client.
For arbitrary TCP targets, a replayed first flight can duplicate commands or
data. Enable it only when the target tolerates replay and when the latency
win is worth it.
Design notes
- One QUIC connection per local connection, one bidirectional stream per QUIC
connection. The first byte of the stream is the routing label.
- The server accepts the stream first, reads the routing label, then dials the
matching
--connect-to destination, so a connection that never opens a
stream does not create an outbound connection.
- EOF on one direction half-closes the other side. A real error closes both.
- After the last stream data and FIN, the server waits for the client to close
(or
QUICMUX_DRAIN_TIMEOUT) before closing the QUIC connection, because
CloseWithError does not retransmit stream data.
- With 0-RTT enabled, the server never dials the target until the handshake
completes, so unauthenticated 0-RTT data cannot trigger a target connection.
- Certificates are deterministic: fixed template, fixed serial, fixed
validity, Ed25519 signatures. The same key always yields the same pin.
Tests
Unit and integration tests (in-process, no external tools):
make test
# or: CGO_ENABLED=0 go test ./...
End-to-end tests (real binaries, real sockets, Go):
make test-e2e
test-e2e builds quicmux and runs the tests in e2e/, which are behind
the e2e build tag so that make test stays fast. The tests start the
daemons as subprocesses, implement the tunneled TCP/Unix applications
in-process, and parse the daemons' listening log lines for their ephemeral
addresses. Coverage:
- TCP and Unix listeners, with TCP and Unix targets
- payloads larger than the flow-control windows
- half-close (the target answers only after it sees EOF)
- concurrent connections
- multiple client listeners
- routing labels, including an unknown label
- certificate pin mismatch in both directions
- target dial failure
- 0-RTT, including fallback after a server restart invalidates the ticket
License
GPL-3.0-or-later. See LICENSE.
Third-party components and their licenses are listed in
THIRD_PARTY_NOTICES.md.
Copyright (C) 2026 Wicher Minnaard nullenenenen@gavagai.eu