diff --git a/.changeset/pr-1457-agentic.md b/.changeset/pr-1457-agentic.md new file mode 100644 index 0000000000..40257b0a12 --- /dev/null +++ b/.changeset/pr-1457-agentic.md @@ -0,0 +1,8 @@ +--- +"@agentproto/secrets": major +"@agentproto/pair-client": minor +"@agentproto/runtime": minor +"@agentproto/cli": minor +--- + +Widen the daemon identity fingerprint from 64 to 128 bits and default `pairing.pairPage` to the new per-daemon `{fingerprint}.agentproto.cloud` pair page (`DEFAULT_PAIR_PAGE`); offer URLs now require the 32-hex fingerprint id. diff --git a/docs/cli/concepts/pairing.md b/docs/cli/concepts/pairing.md index dc6c1999f6..a3f0c54c5d 100644 --- a/docs/cli/concepts/pairing.md +++ b/docs/cli/concepts/pairing.md @@ -69,8 +69,11 @@ A daemon's persistent identity, stored `~/.agentproto/identity.json` (mode - an **Ed25519** keypair for authenticity (the daemon signs the handshake transcript so the client can prove it reached the daemon it scanned). -The **fingerprint** is `sha256(x25519 pub)[:16]` — the same construction as a -seal key id — and is what a human confirms at offer and accept time. +The **fingerprint** is the first 32 lowercase hex chars (128 bits) of +`sha256(x25519 pub)`, and is what a human confirms at offer and accept time. +It also names the daemon's browser origin (`.agentproto.cloud`), +so it is sized so nobody can grind a key whose fingerprint lands on another +daemon's origin. A seal key id is its first 16 hex chars. ### 2. Handshake — `pair/v2` (`@agentproto/secrets/pairing`) @@ -156,7 +159,7 @@ rate limiting, single-use tokens, constant-time token compare. Self-hostable via handshake, pins the daemon's keys, and persists the pairing. - `pair offer --qr` shows the same offer as a phone link: the web pair page with the offer in its URL fragment - (`https://cli.agentproto.sh/pair#v=2&rv=…`). A fragment never reaches a + (`https://.agentproto.cloud/pair#v=2&rv=…`). A fragment never reaches a server. The page runs the client handshake in the browser with `@agentproto/pair-client` (WebCrypto, WebSocket, IndexedDB), which speaks the same wire protocol as `pair accept`, so the daemon can't tell the two @@ -270,33 +273,37 @@ all of that to the page's **origin**. If every daemon's pages shared one origin, a script on that origin could read every pairing's credential and reach every daemon's UI, and a bug in one daemon's app would reach the others. -So the page setting takes a template with `{fp}` in the hostname, filled with -the daemon's identity fingerprint: +So the pair page is a template with `{fp}` in the hostname, filled with the +daemon's identity fingerprint. The default is: ```text -https://{fp}.agentproto.cloud/pair → https://a1b2c3d4e5f60718.agentproto.cloud/pair#v=2&… +https://{fp}.agentproto.cloud/pair → https://a1b2c3d4e5f607189c3e5d7f1a2b4c6d.agentproto.cloud/pair#v=2&… ``` Each daemon then gets its own origin. The browser keeps its credential, storage, service worker and UI apart from every other pairing, with no shared state to leak. - Rules: `{fp}` is only allowed in the hostname. The fingerprint must be a - valid DNS label (it's 16 lowercase hex chars). -- The page checks it's on the right origin with - `expectedPairHost(template, fingerprint)`, compared against - `location.host`, and refuses an offer meant for another daemon. -- **The default is still** `https://cli.agentproto.sh/pair`. The per-daemon - domain (`PAIR_WEB_URL_TEMPLATE_CLOUD`, `https://{fp}.agentproto.cloud/pair`) - becomes the default once its DNS is live. Until then, opt in with - `pairing.pairPage` in `config.json` or `pair offer --qr --pair-page <…>` - (the flag wins). - -**Self-hosting the pair page.** The page is a static bundle (no server-side -code, and the offer stays in the URL fragment). Serve it from your own host and -point `pairing.pairPage` at it: -- a single origin, `"https://pair.example.com/pair"`, or + valid DNS label (it's 32 lowercase hex chars). +- The page refuses an offer whose daemon fingerprint isn't its own origin's + first label, before any network I/O, and stores only that daemon's + credential (AIP-59 §5.8). `expectedPairHost(template, fingerprint)` gives a + page the host to compare with `location.host`. +- **The default is** `https://{fp}.agentproto.cloud/pair` + (`PAIR_WEB_URL_TEMPLATE_CLOUD`): one static page (`packages/pair-page`) + served on every `.agentproto.cloud` by a Cloudflare Worker, + which answers 404 for any host whose first label isn't a fingerprint. + Change it with `pairing.pairPage` in `config.json` or + `pair offer --qr --pair-page <…>` (the flag wins). + +**Self-hosting the pair page.** The page is a static bundle +(`packages/pair-page`: no server-side code, and the offer stays in the URL +fragment). Serve it from your own host and point `pairing.pairPage` at it: - one origin per daemon, `"https://{fp}.pair.example.com/pair"`, which needs a - wildcard DNS record and TLS certificate. + wildcard DNS record and TLS certificate (recommended), or +- a single shared origin, `"https://pair.example.com/pair"`. Every paired + daemon's UI then shares that origin with every other pairing's credential + (AIP-59 §5.8), so tell your users. The page only needs to reach the rendezvous broker named in the offer. diff --git a/docs/cli/reference/config-schema.md b/docs/cli/reference/config-schema.md index ed31ce9df7..69b51f921d 100644 --- a/docs/cli/reference/config-schema.md +++ b/docs/cli/reference/config-schema.md @@ -69,11 +69,12 @@ agentproto config set daemon.port 18791 // Mirrors tunnel.autoconnect. Default true when a rendezvous is set. "autoconnect": true, // Web pair page for `pair offer --qr` (the offer rides in its URL - // fragment). A plain http(s) URL, or a template with {fp} in the HOSTNAME - // (the daemon fingerprint) for one browser origin per daemon. - // Absent → https://cli.agentproto.sh/pair. `--pair-page` overrides it. + // fragment). A template with {fp} in the HOSTNAME (the daemon + // fingerprint) for one browser origin per daemon, or a plain http(s) URL + // (one shared origin). Absent → https://{fp}.agentproto.cloud/pair. + // `--pair-page` overrides it. // See concepts/pairing.md ("The phone pair page"). - "pairPage": "https://{fp}.agentproto.cloud/pair" + "pairPage": "https://{fp}.pair.example.com/pair" }, // Global and per-adapter defaults auto-applied to every `agent_start` diff --git a/docs/cli/verbs/pair.md b/docs/cli/verbs/pair.md index e73d8f1737..13fab0cf78 100644 --- a/docs/cli/verbs/pair.md +++ b/docs/cli/verbs/pair.md @@ -42,9 +42,9 @@ agentproto pair offer ``` ```text -Pairing offer (daemon a1b2c3d4e5f60718) — expires 2026-07-13T19:20:00.000Z +Pairing offer (daemon a1b2c3d4e5f607189c3e5d7f1a2b4c6d) — expires 2026-07-13T19:20:00.000Z - agentproto://pair?v=2&rv=…&id=a1b2c3d4e5f60718&pk=…&sk=…&s=…&exp=… + agentproto://pair?v=2&rv=…&id=a1b2c3d4e5f607189c3e5d7f1a2b4c6d&pk=…&sk=…&s=…&exp=… █▀▀▀▀▀█ ▀▀ █ █▀▀▀▀▀█ (QR of the URL — omit with --no-qr) … @@ -65,27 +65,29 @@ This window can close. - `--no-qr` prints the URL only (also the fallback when the optional `qrcode-terminal` renderer isn't installed). - `--qr` pairs a **phone browser** instead of another CLI: it prints, and draws - as the QR, the web pair page with the offer in its fragment — - `https://cli.agentproto.sh/pair#v=2&rv=…&id=…&pk=…&sk=…&s=…&exp=…` (the query - string of the `agentproto://` URL, verbatim, after the `#`). A URL fragment + as the QR, the web pair page with the offer in its fragment. By default + that page is the daemon's own origin, + `https://.agentproto.cloud/pair#v=2&rv=…&id=…&pk=…&sk=…&s=…&exp=…` + (the query string of the `agentproto://` URL, verbatim, after the `#`). A URL fragment is never sent to a server, so the page's host never sees the token. The page runs the same handshake in the browser (`@agentproto/pair-client`) and shows the daemon's name and fingerprint to confirm. The `agentproto://` URL is still printed for `pair accept`, and either form is accepted by both clients. - `--pair-page ` (with `--qr`) picks the pair page for this offer. It overrides `pairing.pairPage` in config, and the default is - `https://cli.agentproto.sh/pair`. It accepts two forms: - - A **plain URL**, used as is, e.g. a local `http://localhost:3000/pair`. + `https://{fp}.agentproto.cloud/pair`. It accepts two forms: - A **template** with `{fp}` in the **hostname**, filled with the daemon's - identity fingerprint (lowercase hex): + identity fingerprint (lowercase hex), e.g. a self-hosted page: ```bash - agentproto pair offer --qr --pair-page 'https://{fp}.agentproto.cloud/pair' - # → https://a1b2c3d4e5f60718.agentproto.cloud/pair#v=2&… + agentproto pair offer --qr --pair-page 'https://{fp}.pair.example.com/pair' + # → https://a1b2c3d4e5f607189c3e5d7f1a2b4c6d.pair.example.com/pair#v=2&… ``` - That gives each daemon its own browser origin (see + That gives each daemon its own browser origin, like the default (see [concepts/pairing.md](../concepts/pairing.md#the-phone-pair-page-one-origin-per-daemon)). + - A **plain URL**, used as is, e.g. a local `http://localhost:3000/pair`. + Every daemon paired through it shares one origin. `{fp}` anywhere else (path, query, port, userinfo) is rejected, as is any other `{…}`. The page setting is checked before the offer is minted. - `--json` emits `{ url, fingerprint, rendezvous, rendezvousIsHostedDefault, @@ -97,18 +99,18 @@ agentproto pair offer --qr ``` ```text -Pairing offer (daemon a1b2c3d4e5f60718) — expires 2026-07-13T19:20:00.000Z +Pairing offer (daemon a1b2c3d4e5f607189c3e5d7f1a2b4c6d) — expires 2026-07-13T19:20:00.000Z - agentproto://pair?v=2&rv=…&id=a1b2c3d4e5f60718&pk=…&sk=…&s=…&exp=… + agentproto://pair?v=2&rv=…&id=a1b2c3d4e5f607189c3e5d7f1a2b4c6d&pk=…&sk=…&s=…&exp=… Scan with a phone (opens the pair page in the browser): - https://cli.agentproto.sh/pair#v=2&rv=…&id=a1b2c3d4e5f60718&pk=…&sk=…&s=…&exp=… + https://a1b2c3d4e5f607189c3e5d7f1a2b4c6d.agentproto.cloud/pair#v=2&rv=…&id=a1b2c3d4e5f607189c3e5d7f1a2b4c6d&pk=…&sk=…&s=…&exp=… █▀▀▀▀▀█ ▀▀ █ █▀▀▀▀▀█ (QR of the pair-page link) … -Confirm the page shows daemon a1b2c3d4e5f60718 before you accept. +Confirm the page shows daemon a1b2c3d4e5f607189c3e5d7f1a2b4c6d before you accept. **Routing precedence:** `--rendezvous` → `pairing.rendezvous` in config → the hosted default. To point elsewhere, self-host the broker @@ -133,7 +135,7 @@ agentproto pair accept "agentproto://pair?v=2&…" --name my-laptop ``` ```text -✓ Paired with daemon a1b2c3d4e5f60718 +✓ Paired with daemon a1b2c3d4e5f607189c3e5d7f1a2b4c6d name: my-laptop rendezvous: wss://rendezvous.example/v1 diff --git a/packages/cli/src/__tests__/pair-offer-qr.test.ts b/packages/cli/src/__tests__/pair-offer-qr.test.ts index b558c4b4fd..cbb7416989 100644 --- a/packages/cli/src/__tests__/pair-offer-qr.test.ts +++ b/packages/cli/src/__tests__/pair-offer-qr.test.ts @@ -23,7 +23,7 @@ const { loadConfig } = await import("@agentproto/runtime/config") const config = vi.mocked(loadConfig) const OFFER = - "agentproto://pair?v=2&rv=wss%3A%2F%2Frdv.agentproto.sh%2Fv1&id=a1b2c3d4e5f60718&pk=AAA&sk=BBB&s=sec_ret-1&exp=1900000000" + "agentproto://pair?v=2&rv=wss%3A%2F%2Frdv.agentproto.sh%2Fv1&id=a1b2c3d4e5f607189c3e5d7f1a2b4c6d&pk=AAA&sk=BBB&s=sec_ret-1&exp=1900000000" const QUERY = OFFER.slice(OFFER.indexOf("?") + 1) describe("agentproto pair offer --qr", () => { @@ -47,7 +47,7 @@ describe("agentproto pair offer --qr", () => { discoverDaemon.mockResolvedValue({ found: { url: "http://127.0.0.1:18790", token: "tok" }, stale: [] }) httpPostJson.mockResolvedValue({ url: OFFER, - fingerprint: "a1b2c3d4e5f60718", + fingerprint: "a1b2c3d4e5f607189c3e5d7f1a2b4c6d", rendezvous: "wss://rdv.agentproto.sh/v1", rendezvousIsHostedDefault: true, expiresAt: "2030-03-17T17:46:40.000Z", @@ -59,13 +59,14 @@ describe("agentproto pair offer --qr", () => { it("renders the web pair page with the offer in the fragment", async () => { expect(await runPair(["offer", "--qr"])).toBe(0) - const web = `https://cli.agentproto.sh/pair#${QUERY}` + // Default: the daemon's own origin on agentproto.cloud (AIP-59 §5.8). + const web = `https://a1b2c3d4e5f607189c3e5d7f1a2b4c6d.agentproto.cloud/pair#${QUERY}` expect(qr).toHaveBeenCalledTimes(1) expect(qr).toHaveBeenCalledWith(web) const text = out.join("") expect(text).toContain(web) expect(text).toContain(OFFER) // the CLI form is still printed - expect(text).toContain("a1b2c3d4e5f60718") + expect(text).toContain("a1b2c3d4e5f607189c3e5d7f1a2b4c6d") }) it("--pair-page points the link at another page; --json adds webUrl", async () => { @@ -79,7 +80,7 @@ describe("agentproto pair offer --qr", () => { it("without --qr, the offer and its QR are unchanged", async () => { expect(await runPair(["offer"])).toBe(0) expect(qr).toHaveBeenCalledWith(OFFER) - expect(out.join("")).not.toContain("cli.agentproto.sh") + expect(out.join("")).not.toContain("/pair#") out.length = 0 expect(await runPair(["offer", "--json"])).toBe(0) @@ -95,13 +96,13 @@ describe("agentproto pair offer --qr", () => { it("--pair-page takes a {fp} template: one origin per daemon", async () => { expect(await runPair(["offer", "--qr", "--pair-page", "https://{fp}.agentproto.cloud/pair", "--json"])).toBe(0) - expect(JSON.parse(out.join("")).webUrl).toBe(`https://a1b2c3d4e5f60718.agentproto.cloud/pair#${QUERY}`) + expect(JSON.parse(out.join("")).webUrl).toBe(`https://a1b2c3d4e5f607189c3e5d7f1a2b4c6d.agentproto.cloud/pair#${QUERY}`) }) it("config pairing.pairPage is used with --qr, and --pair-page overrides it", async () => { config.mockResolvedValue({ pairing: { pairPage: "https://{fp}.agentproto.cloud/pair" } }) expect(await runPair(["offer", "--qr"])).toBe(0) - expect(qr).toHaveBeenCalledWith(`https://a1b2c3d4e5f60718.agentproto.cloud/pair#${QUERY}`) + expect(qr).toHaveBeenCalledWith(`https://a1b2c3d4e5f607189c3e5d7f1a2b4c6d.agentproto.cloud/pair#${QUERY}`) qr.mockClear() expect(await runPair(["offer", "--qr", "--pair-page", "https://pair.example.com/pair"])).toBe(0) @@ -128,8 +129,12 @@ describe("agentproto pair offer --qr", () => { expect(httpPostJson).not.toHaveBeenCalled() }) - it("the default page is unchanged", async () => { + it("defaults to the per-daemon page; a plain URL still selects one shared page", async () => { expect(await runPair(["offer", "--qr", "--json"])).toBe(0) + expect(JSON.parse(out.join("")).webUrl).toBe(`https://a1b2c3d4e5f607189c3e5d7f1a2b4c6d.agentproto.cloud/pair#${QUERY}`) + + out.length = 0 + expect(await runPair(["offer", "--qr", "--json", "--pair-page", "https://cli.agentproto.sh/pair"])).toBe(0) expect(JSON.parse(out.join("")).webUrl).toBe(`https://cli.agentproto.sh/pair#${QUERY}`) }) }) diff --git a/packages/cli/src/commands/pair.ts b/packages/cli/src/commands/pair.ts index 0b0d12f518..abc4953389 100644 --- a/packages/cli/src/commands/pair.ts +++ b/packages/cli/src/commands/pair.ts @@ -4,7 +4,7 @@ * offer [--ttl 10m] [--rendezvous wss://…] [--no-qr | --qr [--pair-page ]] * daemon side: mint an offer URL (+ QR) and start listening on the * rendezvous. `--qr` renders the phone link instead: the web pair page - * with the offer in its fragment (`https://cli.agentproto.sh/pair#…`). + * with the offer in its fragment (`https://.agentproto.cloud/pair#…`). * accept "" [--name