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
96 changes: 6 additions & 90 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1526,97 +1526,18 @@ Reject trailing unexpected bytes.

---

# 40. VPN modes
# 40. Userspace transport

Implement in phases.

## Phase 1: Tailcat-compatible transport

Support:

```bash
qcat serve
qcat forward
qcat socks
```

This proves:

* PQ handshake
* DERP bootstrap
* WireGuard PSK integration
* NAT traversal
* authentication
* Secure Enclave bridge

before adding system routing.

## Phase 2: point-to-point TUN

Add:

```bash
qcat up outpost
```

Result:

```text
client server

100.100.x.2/32 100.100.x.1/32
│ │
TUN TUN
│ │
└────── WireGuard ──────────┘
```

Use a private ULA IPv6 prefix or another explicitly configured range rather than colliding with real Tailscale addressing.

Prefer IPv6 internally because point-to-point address management is simpler.

Example:

```text
fd7a:7163:6174::/48
```

but choose the final prefix deliberately before release.
Quantumcat uses Tailcat’s userspace network stack for TCP and UDP services,
SSH, Mosh, and SOCKS5. Applications reach a published service through a
local forward, proxy, or SSH ProxyCommand.

---

# 41. Routing

Initial `qcat up` should only install a host route to the remote Quantumcat peer.

Example:

```text
qcat up outpost
```

creates:

```text
fdxx::1 -> qcat tunnel
```

Do not initially implement:

```text
0.0.0.0/0
::/0
LAN subnet routing
DNS interception
```

Later:

```bash
qcat up outpost --route 10.0.0.0/24
```

can enable subnet routing.
Peer IPv6 addresses in `fd7a:7163:6174::/48` belong to the userspace network
stack. The operating system keeps its existing interfaces and routes.

---

Expand All @@ -1637,7 +1558,6 @@ qcat serve
qcat connect
qcat forward
qcat socks
qcat up
qcat down
qcat status
qcat debug
Expand All @@ -1653,10 +1573,6 @@ qcat identity init --name macbook
qcat peer add outpost outpost.qpeer
```

```bash
qcat up outpost
```

```bash
qcat forward outpost 2222:localhost:22
```
Expand Down
4 changes: 2 additions & 2 deletions PROTOCOL.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ the transcript hash to identify the session. Type 4 is an authenticated
acknowledgement, replacing the design's optional Error message. This handles
lost finishes without premature client peer installation. Repeated finishes
resend the acknowledgement without reinstalling a peer.
Acceptance is committed only after transport and any TUN route installation
succeed. Installation failure erases the pending keys and acknowledgement state;
Acceptance is committed only after transport installation
succeeds. Installation failure erases the pending keys and acknowledgement state;
repeated finishes cannot turn a failed installation into a successful handshake.

The server installs the peer after ClientFinish verification; the client waits
Expand Down
25 changes: 8 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ QuantumCat (`qcat`) combines WireGuard, Tailscale's networking stack, and DERP r
- ML-DSA-87 device authentication
- Fresh ML-KEM-1024 exchange for each connection's WireGuard PSK
- Secure Enclave-backed identities on supported Macs
- TCP, UDP, SSH, Mosh, SOCKS5, and IPv6 TUN modes
- SSH, Mosh, SOCKS5, and TCP/UDP forwarding
- macOS, Linux, and FreeBSD builds

> [!WARNING]
Expand Down Expand Up @@ -227,9 +227,8 @@ Set-ID invocations (different real/effective user or group IDs) cannot start a
helper. Ordinary root invocations, including `sudo`, ignore both environment
overrides and disable the shared-directory exception. Root will not run a helper
from a normal user-owned Homebrew keg, even if the helper file itself is root-owned.
For privileged TUN use with Secure Enclave, install `qcat` and its helper into a
separate root-owned, non-group/other-writable installation rather than changing
ownership of Homebrew's prefix. Identity and peer-store symlink and permission
For a root-run service, install the helper in a root-owned installation with
write access restricted to root. Identity and peer-store symlink and permission
checks are unchanged.

Secure Enclave long-lived private keys remain non-exportable. Helper-path checks
Expand Down Expand Up @@ -288,19 +287,11 @@ These run unprivileged for forwarding mode and do not expose public TCP/UDP list

The repository contains ready-to-adapt examples under [`deploy/`](deploy/).

## IP mode
## Migrating from OS TUN mode

QuantumCat can also create an OS TUN interface and assign private IPv6 host routes between authenticated peers:

```sh
# Server
sudo qcat --config /etc/qcat serve --tun --export /tmp/outpost.qpeer

# Client
sudo qcat --config /path/to/client-config up outpost
```

IP mode installs peer host routes only. It does not install a default route, subnet route, or DNS configuration.
`qcat serve --tun` and `qcat up` have been removed. For SSH, publish port 22 with `qcat serve --tcp 22=127.0.0.1:22`
and use `qcat connect PEER 22` as the SSH ProxyCommand. For other services,
use TCP/UDP forwarding or SOCKS5. These modes reuse existing pairings.

## Status and shutdown

Expand Down Expand Up @@ -333,7 +324,7 @@ automatically. To stamp a tag into a local build, set `VERSION`:
make build VERSION=v0.1.0
```

Use `--verbose` on `serve`, `forward`, `socks`, `connect`, `up`, or `mosh` to
Use `--verbose` on `serve`, `forward`, `socks`, `connect`, or `mosh` to
write transport diagnostics, including `portmapper:` messages, to stderr.
Place it before positional arguments, for example
`qcat serve --verbose --tcp 22=127.0.0.1:22` or
Expand Down
55 changes: 3 additions & 52 deletions cmd/qcat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ import (
"github.com/ekarulf/quantumcat/internal/protocol"
"github.com/ekarulf/quantumcat/internal/proxy"
"github.com/ekarulf/quantumcat/internal/transport"
"github.com/ekarulf/quantumcat/internal/tunnel"
"github.com/ekarulf/quantumcat/internal/version"
"github.com/tailscale/tailcat"
_ "tailscale.com/feature/condregister/portmapper"
"tailscale.com/tailcfg"
"tailscale.com/types/key"
"tailscale.com/types/logger"
"tailscale.com/wgengine/filter"
)
Expand All @@ -47,16 +45,14 @@ qcat [--config DIR] socks [--listen 127.0.0.1:1080] PEER
qcat [--config DIR] connect PEER PORT
qcat [--config DIR] mosh [--ssh-host HOST] [--server-port PORT] [--tunnel-port PORT]
[--local-port 0] [--mosh-server PATH] PEER [-- COMMAND...]
qcat [--config DIR] up PEER
qcat [--config DIR] serve --tun [--export FILE.qpeer]
qcat [--config DIR] status
qcat [--config DIR] down [PEER|serve]
qcat debug
qcat version

Pair identity show output out of band; serve --export includes public reachability.
Flags for each command precede positional arguments. Ctrl-C closes the tunnel.
Use --verbose on serve, forward, socks, connect, up, or mosh for transport logs on stderr.
Use --verbose on serve, forward, socks, connect, or mosh for transport logs on stderr.
`

// help prefixes the usage text with the running build, so a bug report that
Expand Down Expand Up @@ -121,7 +117,7 @@ func run(ctx context.Context, args []string) error {
return serve(ctx, s, args[1:])
case "mosh":
return mosh(ctx, s, args[1:])
case "forward", "socks", "connect", "up":
case "forward", "socks", "connect":
return client(ctx, s, args[0], args[1:])
case "status":
if len(args) != 1 {
Expand Down Expand Up @@ -241,7 +237,6 @@ func serve(ctx context.Context, s config.Store, args []string) error {
region := f.Int("region", 0, "DERP region ID")
dm := f.String("derp-map", "", "DERP map URL")
export := f.String("export", "", "new public .qpeer file")
tunMode := f.Bool("tun", false, "use an OS TUN with authenticated peer host routes")
if err := f.Parse(args); err != nil {
return err
}
Expand Down Expand Up @@ -281,12 +276,9 @@ func serve(ctx context.Context, s config.Store, args []string) error {
}
allowed[target] = true
}
if len(allowed) == 0 && len(udpTargets) == 0 && !*tunMode {
if len(allowed) == 0 && len(udpTargets) == 0 {
return errors.New("specify at least one --tcp, --udp or --allow-target")
}
if *tunMode && (len(allowed) > 0 || len(udpTargets) > 0) {
return errors.New("--tun cannot be combined with forwarding services")
}
i, _, meta, close, err := s.Identity(ctx)
if err != nil {
return err
Expand Down Expand Up @@ -317,19 +309,6 @@ func serve(ctx context.Context, s config.Store, args []string) error {
}
}
})
if *tunMode {
tun, err := tunnel.Open()
if err != nil {
return err
}
defer tun.Close()
if err = tun.Configure(tailcat.NodeAddress(meta.Node.Public())); err != nil {
return err
}
server.TUN = tun.Device
server.OnTunnelPeer = func(k key.NodePublic, add bool) error { return tun.Peer(tailcat.NodeAddress(k), add) }
fmt.Fprintln(os.Stderr, "TUN", tun.Name, tailcat.NodeAddress(meta.Node.Public()))
}
server.RegionID = tailcfg.DERPRegionID(*region)
server.DERPMapURL = *dm
server.Logf = transportLogf(*verbose)
Expand Down Expand Up @@ -457,21 +436,6 @@ func client(ctx context.Context, s config.Store, command string, args []string)
}
defer c.Close()
c.Logf = transportLogf(*verbose)
var tun *tunnel.Tunnel
if command == "up" {
if len(args) != 1 {
return errors.New("up requires PEER")
}
tun, err = tunnel.Open()
if err != nil {
return err
}
defer tun.Close()
c.TUN = tun.Device
if err = tun.Configure(tailcat.NodeAddress(c.PublicKey())); err != nil {
return err
}
}
if _, err = c.Ping(ctx); err != nil {
return err
}
Expand Down Expand Up @@ -503,19 +467,6 @@ func client(ctx context.Context, s config.Store, command string, args []string)
if *udp {
return forwardUDP(ctx, c, udpListen, udpPort, *udpIdle)
}
if command == "up" {
ci, err := tailcat.ParseAddr(p.Endpoint)
if err != nil {
return err
}
addr := tailcat.NodeAddress(ci.ServerPublic.NodePublic)
if err = tun.Peer(addr, true); err != nil {
return err
}
fmt.Fprintln(os.Stderr, "TUN", tun.Name, "local", tailcat.NodeAddress(c.PublicKey()), "remote", addr)
<-ctx.Done()
return nil
}
if command == "connect" {
if len(args) != 2 {
return errors.New("connect requires PEER PORT")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.27.4

require (
github.com/tailscale/tailcat v0.7.1-0.20261105151022-e00cdde6ff78
github.com/tailscale/wireguard-go v0.0.0-20260928213353-e61b6b78110b
go4.org/mem v0.0.0-20240501181205-ae6ca9944745
tailscale.com v1.105.0-pre.0.20261013225543-fb79793d99f5
)
Expand Down Expand Up @@ -40,6 +39,7 @@ require (
github.com/tailscale/hujson v0.0.0-20260727124030-b80ff77dac4f // indirect
github.com/tailscale/peercred v0.0.0-20250107143737-35a0c7bd7edc // indirect
github.com/tailscale/web-client-prebuilt v0.0.0-20260917222731-e0ed2d0d0fea // indirect
github.com/tailscale/wireguard-go v0.0.0-20260928213353-e61b6b78110b // indirect
github.com/x448/float16 v0.8.4 // indirect
go4.org/netipx v0.0.0-20260823151212-3075585bcbeb // indirect
golang.org/x/crypto v0.57.0 // indirect
Expand Down
12 changes: 3 additions & 9 deletions internal/transport/renew_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,7 @@ func TestTCPStreamSurvivesRenewalAndLostAcknowledgement(t *testing.T) {
}
}
}
var routeAdds, commits atomic.Int32
server.OnTunnelPeer = func(_ key.NodePublic, add bool) error {
if add {
routeAdds.Add(1)
}
return nil
}
var commits atomic.Int32
var droppedAck, freshPSK atomic.Bool
var previous tailcat.PresharedKey // Accessed only by serialized bootstrap worker.
original := server.Bootstrap
Expand Down Expand Up @@ -253,8 +247,8 @@ func TestTCPStreamSurvivesRenewalAndLostAcknowledgement(t *testing.T) {
if commits.Load() < 3 || !droppedAck.Load() || !freshPSK.Load() {
t.Fatalf("renewal scenarios missing: commits=%d ackLoss=%v freshPSK=%v", commits.Load(), droppedAck.Load(), freshPSK.Load())
}
if routeAdds.Load() != 1 || c.PublicKey() != node || conn.LocalAddr().String() != addr {
t.Fatal("renewal recreated transport identity or route")
if c.PublicKey() != node || conn.LocalAddr().String() != addr {
t.Fatal("renewal changed the transport identity or local address")
}
newHandshake := false
for _, peer := range c.Status().Peer {
Expand Down
Loading
Loading