diff --git a/README.md b/README.md index f7280d5..4d63ba6 100644 --- a/README.md +++ b/README.md @@ -6,397 +6,258 @@

-**A small, post-quantum point-to-point VPN for connecting devices without a coordination server.** +**QuantumCat connects your laptop privately to another computer.** Pair it with +your home server, for example, and you can log in or use a service on that +server without opening a port on your router. -QuantumCat (`qcat`) combines WireGuard, Tailscale's networking stack, and DERP relay support with post-quantum device authentication and session key establishment. +QuantumCat looks for a fast, direct connection between the two computers. When +the network blocks a direct connection, a relay carries the encrypted traffic. -- No Tailscale account or control plane -- Direct peer-to-peer paths when available, DERP relay when needed -- ML-DSA-87 device authentication -- Fresh ML-KEM-1024 exchange for each connection's WireGuard PSK -- Secure Enclave-backed identities on supported Macs -- SSH, Mosh, SOCKS5, and TCP/UDP forwarding -- macOS, Linux, and FreeBSD builds +QuantumCat uses modern post-quantum cryptography to verify both devices and +protect their connection. On supported Macs, the Secure Enclave lets the Mac +prove its identity without exposing its private identity key, even to QuantumCat. > [!WARNING] -> QuantumCat is an early implementation of [DESIGN.md](DESIGN.md), not a security-audited release. The bootstrap protocol should receive independent cryptographic review before it protects sensitive production traffic. +> QuantumCat is experimental. Its connection protocol needs independent security +> review before use with sensitive production traffic. -## What does it look like? - -Pair two devices once, then use normal tools through the encrypted tunnel. - -### SSH - -On your laptop: - -```sh -qcat identity init --name laptop > laptop.qpeer -``` - -On the server: - -```sh -qcat identity init --name outpost -qcat peer add laptop laptop.qpeer -qcat serve --tcp 22=127.0.0.1:22 --export outpost.qpeer -``` - -Back on the laptop: - -```sh -qcat peer add outpost outpost.qpeer -qcat connect outpost 22 -``` - -Or make it transparent to OpenSSH: - -```sshconfig -Host outpost - HostName outpost - User alice - ProxyCommand /Users/alice/.local/bin/qcat connect outpost 22 -``` - -Then: - -```sh -ssh outpost -``` - -No DNS record named `outpost` is required. SSH still performs its normal host-key and user authentication inside the QuantumCat tunnel. - -### Mosh - -Publish SSH plus the normal Mosh UDP range on the server: - -```sh -qcat serve \ - --tcp 22=127.0.0.1:22 \ - --udp 60000:61000=127.0.0.1:60000 \ - --export outpost.qpeer -``` - -Then connect from the client: - -```sh -qcat mosh outpost -``` - -`qcat mosh` bootstraps through SSH, creates the UDP forwarding path, and launches `mosh-client`. - -### SOCKS5 proxy - -Allow a destination on the server: - -```sh -qcat serve --allow-target example.com:443 --export outpost.qpeer -``` - -Run a local SOCKS5 proxy on the client: - -```sh -qcat socks --listen 127.0.0.1:1080 outpost -curl --socks5-hostname 127.0.0.1:1080 https://example.com/ -``` - -DNS resolution happens on the remote side. - -### UDP forwarding - -Publish a UDP service on the server: - -```sh -qcat serve --udp 60001=127.0.0.1:60001 --export outpost.qpeer -``` +## Install -Forward a client-side loopback port to it: +Homebrew provides `qcat` for Apple Silicon with macOS 26+ and for x86-64 or ARM64 Linux. ```sh -qcat forward --udp outpost 60001:60001 +brew install ekarulf/tap/qcat ``` -No public UDP listener is created on the server. - -## How it works - -QuantumCat deliberately separates **identity**, **reachability**, and **transport**. - -1. Each device has a long-lived ML-DSA identity. -2. Devices exchange public `.qpeer` descriptors through an authenticated out-of-band channel. -3. A fresh ML-KEM exchange authenticates the peer and derives a new WireGuard PSK. -4. Tailscale's `magicsock` machinery discovers direct paths and falls back to DERP when necessary. -5. Application traffic runs inside WireGuard. - -The DERP relay is not trusted for authentication or session confidentiality. +FreeBSD amd64 users can install a release archive. Archives are also available +for macOS and Linux. Install the same version on both devices. -Persistent identity compromise does not by itself reveal old session PSKs. +
+Install from a release archive -For the full protocol and threat-model details, see: - -- [DESIGN.md](DESIGN.md) — architecture and rationale -- [PROTOCOL.md](PROTOCOL.md) — wire protocol and bootstrap details -- [third_party/tailcat/QUANTUMCAT.md](third_party/tailcat/QUANTUMCAT.md) — networking changes used by QuantumCat - -## Install - -Download the archive and `SHA256SUMS` from [GitHub Releases](https://github.com/ekarulf/quantumcat/releases). - -Current build targets: +Download your archive and the matching `SHA256SUMS` from [GitHub Releases](https://github.com/ekarulf/quantumcat/releases). | Platform | Archive | | --- | --- | -| Apple Silicon macOS 26+ | `qcat-darwin-arm64.tar.gz` | +| Apple Silicon, macOS 26+ | `qcat-darwin-arm64.tar.gz` | | Linux x86-64 | `qcat-linux-amd64.tar.gz` | | Linux ARM64 | `qcat-linux-arm64.tar.gz` | | FreeBSD amd64 | `qcat-freebsd-amd64.tar.gz` | -Verify the archive before extracting it. `SHA256SUMS` lists every archive, so -select the line for the one you downloaded: +In the download directory, use `shasum` to verify the macOS archive. ```sh -# macOS -grep qcat-darwin-arm64.tar.gz SHA256SUMS | shasum -a 256 -c - -# Linux / FreeBSD -grep qcat-linux-amd64.tar.gz SHA256SUMS | sha256sum -c +archive=qcat-darwin-arm64.tar.gz +awk -v file="$archive" '$2 == file' SHA256SUMS | shasum -a 256 -c ``` -Both print `OK` and exit 0. A mismatch, or a filename that matches no line, -exits non-zero. +On Linux or FreeBSD, set `archive` to the filename for your platform and check it with `sha256sum`. -Then install `qcat` somewhere on your `PATH`, for example: +```sh +archive=qcat-linux-amd64.tar.gz +awk -v file="$archive" '$2 == file' SHA256SUMS | sha256sum -c +``` + +After the check prints `OK`, extract the archive and install the binary. Make +sure `$HOME/.local/bin` is on your `PATH`. ```sh +tar -xzf "$archive" +cd "${archive%.tar.gz}" mkdir -p "$HOME/.local/bin" install -m 755 qcat "$HOME/.local/bin/qcat" ``` -On macOS, install `qcat-se` outside your `PATH`: +On macOS, install the Secure Enclave helper from the same directory. ```sh mkdir -p "$HOME/.local/libexec/qcat" install -m 755 qcat-se "$HOME/.local/libexec/qcat/qcat-se" ``` -macOS binaries are currently ad-hoc signed rather than Developer ID signed/notarized. Checksums protect against accidental corruption; they are not publisher signatures. +Release checksums detect corruption. The macOS binaries are ad-hoc signed and +lack Developer ID signing and notarization. -### Homebrew and other package layouts +
-For a Homebrew formula, install the two binaries separately: +
+macOS helper discovery and permissions -```ruby -bin.install "qcat" -libexec.install "qcat-se" -``` +Homebrew installs `qcat-se` in the formula's private `libexec`. Restart running +qcat services after an upgrade, before `brew cleanup` removes the old version. -Homebrew keeps `libexec` private to the formula instead of linking it into the -global `bin` or `sbin`. Prefer it to `sbin`, which Homebrew links and which may -already be on the user's `PATH`. No wrapper or environment variable is needed. - -`qcat` resolves its own executable first, so a Homebrew `bin/qcat` or -`opt/quantumcat/bin/qcat` symlink finds the helper in the same versioned keg. -That location is pinned at process startup; restart running services after an -upgrade, before Homebrew removes their old keg. -When `qcat` is in a `bin` or `sbin` directory, discovery checks these paths in -order under that installation prefix: - -1. `libexec/qcat/qcat-se` -2. `libexec/qcat-se` -3. `sbin/qcat-se` -4. `qcat-se` beside `qcat` (also the only default for other executable locations) - -Adjacent release-archive and `make helper` layouts remain supported. The helper -is never searched for on `PATH`. A missing candidate allows the next layout; -an existing but unsafe or broken candidate is an error rather than a fallback. -For a custom location, an unprivileged process may set an absolute -`QCAT_ENCLAVE_HELPER` path (`QCAT_SE_HELPER` remains a legacy alias). - -Helper symlinks are allowed only after validating every traversed directory and -link and the final executable. The canonical target is then executed. The helper -must be a regular executable owned by root or the current user, never writable -by group or others. Directory and link ownership must also be trusted. - -For an ordinary unprivileged invocation, group-writable directories shared by -the resolved `qcat` and helper paths are allowed to accommodate Homebrew's -admin-group-managed prefixes. This explicitly trusts that installation's group -to replace both binaries, including helpers started by an already-running -`qcat`. Helper-only group-writable directories and non-sticky world-writable -directories are rejected. These are POSIX owner/mode checks, not an ACL audit. - -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 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 -protect which code can invoke signing operations and use the process's OS -privileges; they do not change that key-storage design. - -## Pairing - -Configuration defaults to: - -```text -~/.config/qcat -``` +For custom installs, qcat resolves its own executable at startup. If it lives +in `bin` or `sbin`, qcat searches the same prefix for `libexec/qcat/qcat-se`, +then `libexec/qcat-se`, then `sbin/qcat-se`. It also checks +beside the executable. It does not search `PATH` for the helper. An unprivileged process can select an absolute path with +`QCAT_ENCLAVE_HELPER` (legacy alias `QCAT_SE_HELPER`). Discovery skips missing +candidates and stops on an unsafe or broken one. -Create a device identity: +The helper must be a regular executable owned by root or the current user. +Only its owner may have write permission. It also checks directory and symlink ownership and +permissions along the resolved path. For unprivileged installs it permits group-writable +directories shared by qcat and its helper, so the installation group is trusted +to replace both. These checks use POSIX mode bits. Root requires a root-owned +installation and ignores helper overrides. Set-ID processes cannot launch the helper. -```sh -qcat identity init --name laptop > laptop.qpeer -``` +
+ +## Pairing and first SSH connection -Only exchange `.qpeer` files. **Never copy `identity.json` between machines.** +This example connects a laptop to a server called `my-server` with SSH listening +on `127.0.0.1:22`. The name is a local alias. Each device keeps its own +`identity.json`. Exchange only the public `.qpeer` files over an authenticated +channel. Before importing a file, compare its full `PeerID` with the sender's +`qcat identity show` output out of band. Importing a peer on the server +authorizes it to use the services you publish. -Import a peer: +**On the laptop**, create an identity and send `laptop.qpeer` to the server. ```sh -qcat peer add outpost outpost.qpeer +qcat identity init --name laptop > laptop.qpeer ``` -Inspect or revoke peers: +**On the server**, create its identity, import the laptop, and publish SSH. ```sh -qcat peer list -qcat peer show outpost -qcat peer remove outpost +qcat identity init --name my-server +qcat peer add laptop laptop.qpeer +qcat serve --tcp 22=127.0.0.1:22 --export my-server.qpeer ``` -Removing a server locally stops running `connect`, `forward`, `socks`, and -`mosh` clients paired with it. They check the pinned server identity every -second, before sending bootstrap messages, and when bootstrap completes. -A missing, unreadable, or replaced descriptor cancels the session within one -polling interval plus local scheduling and filesystem latency. Connecting to a -replacement server requires a new command. To revoke a client's authorization -on a remote server, remove the client from that server's pairing store. +Leave `qcat serve` running and send `my-server.qpeer` back to the laptop. The +file exported by `serve` includes the endpoint the laptop needs to connect. -Importing a peer grants authorization, so transfer peer descriptors over an authenticated channel and compare full PeerIDs out of band. - -## Running a persistent server - -A typical SSH + Mosh server looks like this: +**Back on the laptop**, import the server and connect. Replace `alice` with +your SSH username on the server. ```sh -qcat serve \ - --tcp 22=127.0.0.1:22 \ - --udp 60000:61000=127.0.0.1:60000 +qcat peer add my-server my-server.qpeer +ssh -o 'ProxyCommand=qcat connect my-server %p' alice@my-server ``` -QuantumCat includes service templates for: +SSH still checks the server's host key and authenticates your login. To use +`ssh my-server` and `qcat mosh my-server`, save the alias in `~/.ssh/config`. -- macOS `launchd` -- Linux `systemd --user` -- FreeBSD `rc.d` +```sshconfig +Host my-server + User alice + ProxyCommand qcat connect my-server %p +``` -These run unprivileged for forwarding mode and do not expose public TCP/UDP listeners for the forwarded services. +## Mosh, forwarding, and SOCKS5 -The repository contains ready-to-adapt examples under [`deploy/`](deploy/). +For each service you want, add its flags to the server's `qcat serve` command. Keep +`--tcp 22=127.0.0.1:22` for SSH. Use `--export` only when writing a new +descriptor file. -## Migrating from OS TUN mode +| Use | Additional server flags | Laptop command | +| --- | --- | --- | +| Mosh | `--udp 60000:61000=127.0.0.1:60000` | `qcat mosh my-server` | +| HTTP on server port 8080 | `--allow-target 127.0.0.1:8080` | `qcat forward my-server 18080:127.0.0.1:8080` | +| DNS over UDP on server port 53 | `--udp 1053=127.0.0.1:53` | `qcat forward --udp my-server 1053:1053` | +| SOCKS5 for `example.com:443` | `--allow-target example.com:443` | `qcat socks --listen 127.0.0.1:1080 my-server` | -`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. +Mosh uses the SSH alias above to start `mosh-server` on the server, then runs +`mosh-client` on the laptop. Install Mosh on both. -## Status and shutdown +The HTTP example is reachable at `http://127.0.0.1:18080/` on the laptop, and +the DNS forward listens on `127.0.0.1:1053`. Any local process can use a +forwarding or SOCKS5 listener while it is open. To use SOCKS5 with DNS +resolution on the server, run the following in a second terminal. ```sh -qcat status -qcat down outpost -qcat down serve +curl --socks5-hostname 127.0.0.1:1080 https://example.com/ ``` -`qcat status` prints JSON keyed by running session. Each entry in a session's `Peer` map -has a `Path` field for the tunnel's current send path. +## Operating a server -| Path | Meaning | -| --- | --- | -| `direct` | qcat has selected the UDP endpoint in `CurAddr`. | -| `derp` | qcat selects the DERP fallback for the next send, even if the peer is idle. It may also try UDP during path discovery. | -| `peer-relay` | The transport reports a selected UDP peer relay in `PeerRelay`. | -| `unknown` | The snapshot has too little information to identify a path, for example before the first send. | - -`CurAddr` is an empty string when there is no selected direct endpoint. -`Relay` identifies the peer's home DERP region even when its path is direct. -`LastHandshake` records the last successful WireGuard handshake. A session with no -running backend reports `null`. If no sessions are running, the result is `{}`. - -Client connections periodically re-authenticate with a fresh signed ML-KEM exchange and refresh paths after sleep or network changes. -Renewal requires the bootstrap DERP relay even when application traffic is direct. -If the relay stays unavailable through the one-hour server lease, the server -removes the tunnel. A healthy direct path does not extend that lease. Recovery -can bootstrap through DERP again; existing application flows may need restarting. +For a persistent SSH and Mosh server, adapt the service template for +[macOS launchd](deploy/macos/com.quantumcat.server.plist), +[Linux systemd --user](deploy/systemd/qcat.service), or +[FreeBSD rc.d](deploy/freebsd/qcat). The forwarding process runs unprivileged. -## Build from source +### Peers and revocation -Requires Go 1.27.4 or newer. +The default configuration directory is `~/.config/qcat`. On Linux and FreeBSD, +a backup of this directory includes the device's private identity key. ```sh -make build +qcat peer list +qcat peer show laptop ``` -`qcat version` reports the build. Release archives from GitHub Releases name -their tag; anything built from a checkout reports `devel` plus the commit hash, -commit time, and whether the tree was modified, which the Go toolchain records -automatically. To stamp a tag into a local build, set `VERSION`: +Run `qcat peer remove laptop` **on the server** to revoke the laptop's access and +close its tunnels. Removing `my-server` on the laptop stops local clients paired +with that server. + +### Status and shutdown ```sh -make build VERSION=v0.1.0 +qcat status # show locally managed sessions as JSON +qcat down my-server # stop managed client sessions for my-server +qcat down serve # stop the local server ``` -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 -`qcat connect --verbose outpost 22`. Logging stays quiet by default. - -On supported Apple Silicon Macs: +On current `main`, each entry in the session's `Peer` map reports its send path. -```sh -make helper -./bin/qcat debug -``` +| `Path` | Meaning | +| --- | --- | +| `direct` | The selected UDP endpoint is in `CurAddr`. | +| `derp` | The next send uses DERP. Path discovery may also try UDP. | +| `peer-relay` | The selected UDP relay is in `PeerRelay`. | +| `unknown` | There is too little information to identify the path yet. | + +`Relay` names the peer's home DERP region even on a direct path. `LastHandshake` +records the last successful WireGuard handshake. A session with no running +backend reports `null`. An empty result (`{}`) means there are no managed sessions. + +For transport logs on stderr, add `--verbose` before positional arguments, +for example `qcat connect --verbose my-server 22`. Clients need DERP to renew +even on direct paths. If renewal fails for the full one-hour lease, the server +removes the tunnel and existing application connections may need restarting. + +### Upgrading older installations + +Both ends need compatible bootstrap versions. If your identity predates +identity-file version 3, reinitialize it and re-pair the devices. +Former `qcat up` and `serve --tun` users can reuse compatible pairings with +SSH, forwarding, or SOCKS5. + +## Technical details + +- **Network paths.** The devices first contact each other through a DERP relay. + Tailscale's `magicsock` tests UDP paths so traffic can move to a direct link. + WireGuard encrypts application traffic on either path. The relay can see + connection metadata but cannot read the traffic. Pairing requires no + Tailscale account or coordination server. +- **Post-quantum cryptography.** Each device signs the handshake with its + ML-DSA-87 identity key. A fresh ML-KEM-1024 exchange supplies the secret + used to derive a WireGuard preshared key for the session. +- **Key storage.** On Apple silicon Macs running macOS 26 or later, QuantumCat + defaults to the Secure Enclave for identity signing and for the client's + temporary ML-KEM private key. Linux and FreeBSD use software-backed keys. + +See the [wire protocol](PROTOCOL.md) for the handshake and renewal sequence, +the [design and threat model](DESIGN.md) for what a relay can observe, and the +[Tailcat integration notes](third_party/tailcat/QUANTUMCAT.md) for transport changes. -macOS defaults to Secure Enclave identities and ephemeral KEM keys. Linux and FreeBSD use software-backed keys. On macOS, capability failures are errors rather than silent downgrade to software keys. +## Build from source -Run the test suite with: +Use Go 1.27.4 or newer. On a supported Mac, also run `make helper` to build the +Swift helper beside `bin/qcat`. Run `./bin/qcat debug` to check its capabilities. ```sh +make build +./bin/qcat version make test go vet ./... ``` -## Security model, in one paragraph - -QuantumCat trusts explicitly paired device identities, not relay infrastructure. ML-DSA authenticates the devices; fresh ML-KEM material is mixed into each WireGuard session as a PSK; WireGuard protects application traffic; DERP may relay packets but cannot authenticate as a peer or decrypt the session. Peer removal revokes authorization and active sessions are torn down shortly afterward. Private identity material stays local to each machine. On Linux and FreeBSD the software identity is stored in the config directory, so backing up that directory also backs up the private identity. A `qcat forward` or `qcat socks` listener grants tunnel access to every local process and should not be left running on a multi-user host. - -For the details and caveats, read [DESIGN.md](DESIGN.md) and [PROTOCOL.md](PROTOCOL.md). - -Before publishing a release, validate the packaged Secure Enclave helper on -Apple Silicon using the [release checklist](docs/RELEASING.md). - -## Project status - -QuantumCat is experimental. The implementation includes automated tests for authentication tampering, replay, identity/source binding, PSK freshness, forwarding policy, revocation, TCP/UDP transport, fragmentation, storage permissions, and local runtime control, but that is not a substitute for independent review. - -Current `main` intentionally breaks compatibility with earlier builds: it uses -Go's standard-library ML-DSA/ML-KEM implementations, SHA-384 bootstrap -primitives, SHA-512/256 PeerIDs, identity-file version 3, and a nonce-blinded -client peer tag in place of the transmitted client PeerID. Reinitialize -identities and re-pair peers when upgrading. - -PeerIDs stay stable locally; they are simply no longer sent over the DERP -bootstrap path, so a relay operator that does not already know a client's PeerID -cannot use it to link separate client instances. An operator that *does* know a -candidate PeerID can still recompute the tag and test it, and the client's source -IP remains visible regardless. This is metadata hygiene, not anonymity — see -[DESIGN.md](DESIGN.md) §22.8 for what it does and does not provide. - -Contributions, testing on real networks, protocol review, and security analysis are welcome. +Local builds report `devel` and the commit. Use `make build VERSION=vX.Y.Z` +to stamp a release version. -## License +## Further reading -See [LICENSE](LICENSE). +- [Release checklist](docs/RELEASING.md) — validation of the packaged helper on Apple Silicon. +- [Apache 2.0 license](LICENSE).