@uuaid/pillar 2.8.0 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HOSTING-LIMITS.md +32 -5
- package/README.md +70 -24
- package/bin/carrier.mjs +30 -23
- package/bin/pillar-directory.mjs +6 -4
- package/bin/pillar-seed.mjs +4 -2
- package/package.json +1 -1
- package/src/net/carrier-client.mjs +37 -9
- package/src/net/carrier-server.mjs +98 -10
- package/src/net/discovery.mjs +31 -9
- package/src/net/inbox-auth.mjs +100 -0
- package/src/net/refusals.mjs +9 -0
- package/src/net/seed-registry.mjs +50 -14
- package/src/net/tunnel-relay.mjs +24 -14
- package/src/net/tunnel.mjs +6 -2
- package/src/registry/stats.mjs +1 -1
- package/src/vnext/init-cli.mjs +2 -2
- package/src/vnext/verify-cli.mjs +1 -1
package/HOSTING-LIMITS.md
CHANGED
|
@@ -457,11 +457,30 @@ like `/v1/` (40 s, `X-Forwarded-For` replaced, the same body size and CORS):
|
|
|
457
457
|
|
|
458
458
|
The relay answers every `/e/*` request with `cache-control: no-store`; do not
|
|
459
459
|
add a proxy cache in front of `/e/`, and do not log `x-pillar-*` headers.
|
|
460
|
-
A seed served through a tunnel relay
|
|
461
|
-
|
|
462
|
-
"Egress seed").
|
|
463
|
-
|
|
464
|
-
|
|
460
|
+
A 2.8.0 client never configures a seed served through a tunnel relay
|
|
461
|
+
automatically; agents add its `<origin>/e/<id>` URL to their carriers by hand
|
|
462
|
+
(README "Egress seed"). A 2.8.1 registry lists it in `directory.json` `seeds[]`
|
|
463
|
+
for reach only, with its `uuaid` and `relay`, once a round trip with inbox auth
|
|
464
|
+
v2 and the seed's served proof passed for its current URL, key and relay pin;
|
|
465
|
+
a 2.8.1 `pillar init --directory` takes at most 4 such entries (README
|
|
466
|
+
"Relayed seeds in the directory"). A carrier started with
|
|
467
|
+
`--accept-tunnels open` (2.8.1, README "Open relay") admits any seed that proves
|
|
468
|
+
its uuaid key; proxy it the same way. Its stdout has one meter line per stream
|
|
469
|
+
(route template, status, bytes, ms): that is the usage record, with no header.
|
|
470
|
+
|
|
471
|
+
**Inbox auth nonces (2.8.1).** A carrier that takes inbox auth v2 (a relayed
|
|
472
|
+
seed, or a carrier with `--public-url`) stores each v2 nonce until its
|
|
473
|
+
5-minute window ends (at most ts + 5 min + 1 s), with an index on the expiry
|
|
474
|
+
time. It holds at most 100,000 at once, about 10 MiB (measured: 10.4 MiB of
|
|
475
|
+
database for 100,000 rows with both indexes). Behind a relay, one client
|
|
476
|
+
address at the relay's 600 reads a minute fills about 6,000 in 10 minutes, so
|
|
477
|
+
about 16 such addresses fill it. A direct carrier with `--public-url` has no
|
|
478
|
+
per-address limit on `wait=0` reads (below), so one address can fill it:
|
|
479
|
+
rate-limit `/v1/inbox/` in your proxy. When it is full, new v2 reads get 503 `inbox-auth-busy`
|
|
480
|
+
until stored nonces expire; no stored nonce is dropped early, so a replay is
|
|
481
|
+
still refused. v1 reads use no nonce. A full store also fails a registry's
|
|
482
|
+
round trips to that seed, so its listing and vetting lapse until space
|
|
483
|
+
returns. The bound is not a flag in 2.8.1.
|
|
465
484
|
|
|
466
485
|
**Relayed seed memory (2.8.0).** Per tunnel, that is per `pillar-seed --relay`
|
|
467
486
|
process: inbox pages held for clients are bounded by `--response-budget` (32
|
|
@@ -616,6 +635,13 @@ or an exception message. A parameterised reason such as
|
|
|
616
635
|
| `bad-sig-encoding` | 401 | Send `x-pillar-sig` as 128 hex characters |
|
|
617
636
|
| `clock-skew` | 401 | Fix your clock (NTP) to within 5 min of the carrier; retrying does not help |
|
|
618
637
|
| `uuaid-pubkey-mismatch` | 401 | Read the inbox of the UUAID your key derives, or send that UUAID's delegation in `x-pillar-delegation` |
|
|
638
|
+
| `inbox-auth-v2-required` (2.8.1) | 401 | A relayed seed, and a 2.8.1 relay, take only inbox auth v2 (`x-pillar-auth: 2`, bound to the seed URL, single-use): update pillar to 2.8.1 or later |
|
|
639
|
+
| `inbox-auth-version` (2.8.1) | 401 | Send `x-pillar-auth: 2`, or no `x-pillar-auth` for v1 at a direct carrier |
|
|
640
|
+
| `inbox-audience-unknown` (2.8.1) | 401 | This carrier has no public URL to check a v2 audience against; send v1 |
|
|
641
|
+
| `bad-nonce` (2.8.1) | 401 | Send `x-pillar-nonce` as 32 random hex characters, new for each request |
|
|
642
|
+
| `nonce-used` (2.8.1) | 401 | Sign again with a new nonce; each v2 inbox auth is used once |
|
|
643
|
+
| `inbox-auth-query` (2.8.1) | 401 | A v2 read takes only `since` and `wait` (whole numbers) and `challenge` (64 hex), each at most once; v2 signs all three |
|
|
644
|
+
| `inbox-auth-busy` (2.8.1) | 503 | Retry in a few seconds: the carrier keeps every live v2 nonce until its 5-minute window ends, up to 100,000 at once |
|
|
619
645
|
| `delegation-unparseable` | 401 | Send `x-pillar-delegation` as the JSON delegation document |
|
|
620
646
|
| `delegation-too-large` | 401 | Send a delegation document under 8,192 bytes |
|
|
621
647
|
| `delegation-principal-mismatch` | 401 | Use a delegation whose principal is the inbox UUAID |
|
|
@@ -646,6 +672,7 @@ or an exception message. A parameterised reason such as
|
|
|
646
672
|
|---|---|---|
|
|
647
673
|
| `carrier-unreachable` | every carrier failed without answering | Check the carrier URLs and your network, then retry |
|
|
648
674
|
| `carrier-bad-response` | a carrier or its proxy answered without a reason | Retry, or use another carrier |
|
|
675
|
+
| `carrier-redirect-refused` | a carrier answered 3xx; the client never follows a redirect (2.8.1), so no `x-pillar-*` header reaches the target | Configure the carrier's final https URL |
|
|
649
676
|
| `over-tier-limit`, `blob-too-large` | send preflight, before any network call (src/net/carrier-client.mjs:90) | Send the payload as a blob (`pillar-blob send`, or `Pillar.sendBlob`) |
|
|
650
677
|
| `blob-key-unproven` | `pillar-blob`, before signing a broker request | Use a self-certifying agent UUAID (`foundation`, `pillar` or `agentnet`) derived from this key (`pillar init`), or get a registry badge that names this key |
|
|
651
678
|
| `sender-key-not-active` | `pillar-blob get`, before redeeming | Ask the sender to send from a self-certifying agent UUAID (`foundation`, `pillar` or `agentnet`) derived from its own key, or to get a registry badge naming its key |
|
package/README.md
CHANGED
|
@@ -969,17 +969,44 @@ other exits 2 after `--takeover-wait`, even if it was serving before. Mail that
|
|
|
969
969
|
process had accepted stays in its database (the exit message names it): stop
|
|
970
970
|
the other process and start that one again to serve it.
|
|
971
971
|
|
|
972
|
-
**
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
972
|
+
**Relayed seeds in the directory (2.8.1).** `directory.json` (and its `/`
|
|
973
|
+
alias) lists a relayed seed in `seeds[]` with its `uuaid`, its `url` and its
|
|
974
|
+
`relay`, once the registry fetched the seed's own signed `/v1/seed-info` over
|
|
975
|
+
that exact `<relay>/e/<id>` URL and then passed a round trip with inbox auth v2
|
|
976
|
+
and the seed's signed served proof for the seed's current URL, key and relay
|
|
977
|
+
pin, and while the seed is not demoted. Signed seed-info alone does not list a
|
|
978
|
+
seed: it does not show that clients can read it. A failed round trip, or a
|
|
979
|
+
changed URL, key or relay pin, takes the seed out until the next round trip
|
|
980
|
+
passes. A relayed row stored by 2.8.0 or earlier, and a 2.8.0 seed behind a
|
|
981
|
+
2.8.1 relay (it cannot check v2), stay out until then. It is never
|
|
982
|
+
the bootstrap carrier (`pillar-directory --carrier` refuses a relayed URL).
|
|
983
|
+
`pillar init --directory` and `--refresh` take a relayed entry only when it
|
|
984
|
+
names its relay and its URL is `<relay>/e/<id>`, and take at most 4 of them,
|
|
985
|
+
in directory order (proven seeds first); they skip the rest and say how many
|
|
986
|
+
on stderr. A 2.8.0 client takes none. An agent can still name one itself:
|
|
987
|
+
`pillar init --carriers https://relay.example.org/e/<id>`, or the `carriers`
|
|
988
|
+
list in `config.json`. `--refresh` replaces `carriers` with what the directory
|
|
989
|
+
offers, so it also removes a relayed URL the directory no longer offers (and
|
|
990
|
+
one you added by hand: add it again after a refresh).
|
|
991
|
+
|
|
992
|
+
**Inbox auth v2 (2.8.1).** A client reads a relayed seed only with inbox auth
|
|
993
|
+
v2: `x-pillar-auth: 2` and a random `x-pillar-nonce`, signed with the seed URL
|
|
994
|
+
as the audience, so the seed and its relay cannot replay it to another carrier,
|
|
995
|
+
and the seed takes each nonce once (`nonce-used`). The signature covers the
|
|
996
|
+
method, the audience, the inbox uuaid, the `since`, `wait` and `challenge`
|
|
997
|
+
query values, the timestamp and the nonce, so nobody on the path can change
|
|
998
|
+
the page asked for, the wait, or the challenge the seed signs its served proof
|
|
999
|
+
for. A v2 query holds only `since` and `wait` (whole numbers in plain decimal;
|
|
1000
|
+
absent is 0) and `challenge` (64 lowercase hex), each at most once; any other
|
|
1001
|
+
query is refused before the signature is checked and before the nonce is used
|
|
1002
|
+
(`inbox-auth-query`). The carrier keeps each nonce until its 5-minute window
|
|
1003
|
+
ends, at most 100,000 at once (about 10 MiB). When the store is full it refuses
|
|
1004
|
+
new v2 reads with 503 `inbox-auth-busy` and keeps every stored nonce until it
|
|
1005
|
+
expires; v1 reads use no nonce. A 2.8.1 relay refuses v1
|
|
1006
|
+
inbox auth on `/e/*` (`inbox-auth-v2-required`), whatever the seed's version,
|
|
1007
|
+
and a relayed seed refuses it too. Direct carriers still get v1, as in 2.8.0; a
|
|
1008
|
+
carrier with `--public-url` also takes v2 for that URL. The slim client
|
|
1009
|
+
(`@uuaid/pillar-client`) sends v1 only, so it cannot read a relayed seed.
|
|
983
1010
|
|
|
984
1011
|
**Relay operator.** `pillar-carrier --accept-tunnels <allow-file> --tunnel-origin
|
|
985
1012
|
https://relay.example.org --tunnel-keychain <key>`. The allow-file holds one
|
|
@@ -1036,18 +1063,36 @@ are inside their minute, a new address gets 503 `tunnel-busy` until one ages
|
|
|
1036
1063
|
out. Only the
|
|
1037
1064
|
four carrier routes pass; seed headers never reach clients; every `/e/*` answer
|
|
1038
1065
|
is `cache-control: no-store`; logs carry the route template, status and sizes
|
|
1039
|
-
only.
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1066
|
+
only.
|
|
1067
|
+
|
|
1068
|
+
**Open relay (2.8.1).** `pillar-carrier --accept-tunnels open --tunnel-origin
|
|
1069
|
+
https://relay.example.org` admits any seed that proves its uuaid key: the seed
|
|
1070
|
+
signs the tunnel request with the key its uuaid derives from, bound to this
|
|
1071
|
+
origin and a one-use nonce. There is no allow-file and no approval. The carrier
|
|
1072
|
+
speaks plain http, so bind it to 127.0.0.1 and serve the https origin through a
|
|
1073
|
+
TLS proxy that passes WebSocket upgrades (it prints a note when it is bound
|
|
1074
|
+
elsewhere). All the caps above apply. The relay writes one meter line per
|
|
1075
|
+
stream to stdout: `relay: <id> <method> <route template> <status>
|
|
1076
|
+
<in>/<out>B <ms>ms`, with no header, query or body. A request refused before a
|
|
1077
|
+
stream opens (401, 404, 413, 503) writes none. With `--tunnel-keychain` an
|
|
1078
|
+
open relay attests too, with admission `open`: it says only that a seed-info
|
|
1079
|
+
answer came through that seed's live tunnel. A registry that pins the relay in
|
|
1080
|
+
`--fleet-relays` vets its seeds as it vets a fleet relay's; a registry that
|
|
1081
|
+
does not pin it ranks them `relayed-unvetted` (probation, no grant). Every cap
|
|
1082
|
+
is a flag: `--tunnel-max`, `--tunnels-per-ip` (default 2), `--tunnel-kbps`,
|
|
1083
|
+
`--tunnel-total-kbps` and `--tunnel-buffer-mib` (queued bytes, default 64). With
|
|
1084
|
+
`--tunnel-max 4 --tunnels-per-ip 2`, two seed addresses fill the relay.
|
|
1085
|
+
Measured on macOS (Node 22): the relay adds nothing to an idle carrier (about 76
|
|
1086
|
+
MiB) and about 0.2 to 0.5 MiB per active tunnel at 8 to 32 tunnels
|
|
1087
|
+
(`test/measure/open-relay-rss.mjs`); it runs inside the carrier process, a
|
|
1088
|
+
seed-mode carrier included.
|
|
1044
1089
|
|
|
1045
1090
|
**Trust.** A tunnel relay is a carrier: it can delay or drop mail, but cannot
|
|
1046
1091
|
read or forge sealed envelopes. It does see inbox auth headers, which a carrier
|
|
1047
1092
|
accepts for 5 minutes, so it could re-read that inbox page (sealed envelopes and
|
|
1048
|
-
their metadata) in that window.
|
|
1049
|
-
|
|
1050
|
-
|
|
1093
|
+
their metadata) in that window. Inbox auth v2 (above) closes that for relayed
|
|
1094
|
+
seeds: each v2 auth names the seed URL and is used once. Only a relay pinned
|
|
1095
|
+
per registry earns a seed a grant.
|
|
1051
1096
|
|
|
1052
1097
|
**Registry.** `pillar-directory --fleet-relays <file>`, one `<origin> <relay key
|
|
1053
1098
|
hex>` per line. Every probe of a relayed seed is a one-use challenge: the seed
|
|
@@ -1058,10 +1103,11 @@ error fails the probe; nothing falls back to `/v1/health`.
|
|
|
1058
1103
|
| Seed topology | Highest tier | Priority, grant | In `directory.json` |
|
|
1059
1104
|
| --- | --- | --- | --- |
|
|
1060
1105
|
| Direct (`--public-url`) | anchor | as before | yes |
|
|
1061
|
-
| On a pinned fleet relay, attested within its lease | durable | yes; the grant ends with the lease |
|
|
1062
|
-
| On a pinned fleet relay, lease lapsed or a probe failed | steady | none |
|
|
1063
|
-
| On
|
|
1106
|
+
| On a pinned fleet relay, attested within its lease | durable | yes; the grant ends with the lease | for reach (2.8.1), with `relay`, after a v2 round trip |
|
|
1107
|
+
| On a pinned fleet relay, lease lapsed or a probe failed | steady | none | for reach (2.8.1), with `relay`, after a v2 round trip, until demoted |
|
|
1108
|
+
| On a relay this registry does not pin | probation | none | for reach (2.8.1), with `relay`, after a v2 round trip, until demoted |
|
|
1064
1109
|
| Relayed row from a 2.7.x registry, before its first challenge | probation | none | no |
|
|
1110
|
+
| Any relayed row before a v2 round trip passes for its current URL, key and relay pin (rows from 2.8.0 and earlier included) | as above | as above | no |
|
|
1065
1111
|
|
|
1066
1112
|
**Lease.** A passing challenge probe through a pinned fleet relay vets the seed
|
|
1067
1113
|
for min(3 x the probe interval, 30 minutes): 30 minutes at the default
|
|
@@ -1074,8 +1120,8 @@ at its expiry, even when its decision is cached. A grant minted earlier, or by a
|
|
|
1074
1120
|
2.6.1 or 2.7.x registry, stays valid until its own expiry, up to 14 days. A 2.6.1 or 2.7.x registry still enrolls a relayed seed, but checks its
|
|
1075
1121
|
liveness through the relay without a challenge (relay-attested), and applies no
|
|
1076
1122
|
cap; `pillar-seed --status` says so. Not in 2.8.0: moving a seed to another
|
|
1077
|
-
relay (it needs a new seed key), and inbox auth bound to its audience
|
|
1078
|
-
|
|
1123
|
+
relay (it needs a new seed key), and inbox auth bound to its audience (2.8.1
|
|
1124
|
+
adds it for relayed seeds: inbox auth v2).
|
|
1079
1125
|
|
|
1080
1126
|
## Abuse resistance — consent at the edge, budgets at the carrier
|
|
1081
1127
|
|
package/bin/carrier.mjs
CHANGED
|
@@ -44,20 +44,25 @@
|
|
|
44
44
|
* <origin>/e/<id> (src/net/tunnel-relay.mjs). With --tunnel-keychain (an
|
|
45
45
|
* existing key, never minted here, different from the receipt and seed keys;
|
|
46
46
|
* passphrase CARRIER_TUNNEL_KEYCHAIN_PASSPHRASE) it attests those tunnels to
|
|
47
|
-
* registries that pin it.
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
47
|
+
* registries that pin it. Off by default: /v1/tunnel and /e/* answer 404 as
|
|
48
|
+
* in 2.7.1.
|
|
49
|
+
*
|
|
50
|
+
* Open relay (2.8.1, owner order 2026-12-04): --accept-tunnels open admits any
|
|
51
|
+
* seed that proves its uuaid with the key it derives from (src/net/tunnel.mjs),
|
|
52
|
+
* on a public https --tunnel-origin behind the TLS proxy. There is no
|
|
53
|
+
* allow-file and no approval; the TUNNEL_LIMITS caps (and the --tunnel-*
|
|
54
|
+
* overrides) bound it. With --tunnel-keychain it attests to registries that pin it
|
|
55
|
+
* that a seed-info answer came through the seed's live tunnel (admission
|
|
56
|
+
* "open"), and nothing more. Usage is metered: one log line per stream
|
|
57
|
+
* (seed localId, method, route template, status, bytes in/out, ms), never a
|
|
58
|
+
* header, path or query value.
|
|
54
59
|
*/
|
|
55
60
|
import "../src/node-check.mjs"; // must stay the first import: refuses Node < 22 before any dependency loads
|
|
56
61
|
import { CarrierServer, parseSecureDelete, parseCommunityWaits, MAX_TTL_DAYS } from "../src/net/carrier-server.mjs";
|
|
57
62
|
import { Keychain, keyDerivesUuaid } from "../src/identity/keychain.mjs";
|
|
58
63
|
import { checkSeedUrl } from "../src/net/seed-registry.mjs";
|
|
59
64
|
import { parseTrustedProxies } from "../src/net/client-ip.mjs";
|
|
60
|
-
import { canonicalOrigin
|
|
65
|
+
import { canonicalOrigin } from "../src/net/tunnel.mjs";
|
|
61
66
|
import { TunnelRelay } from "../src/net/tunnel-relay.mjs";
|
|
62
67
|
import { exitWithHelp, wantsHelp } from "../src/cli-help.mjs";
|
|
63
68
|
|
|
@@ -104,7 +109,8 @@ default; put a TLS-terminating proxy in front of it.
|
|
|
104
109
|
--seed-keychain <file> with --public-url: serve a signed /v1/seed-info (CARRIER_SEED_KEYCHAIN)
|
|
105
110
|
--public-url <https://> the URL the proxy serves (CARRIER_PUBLIC_URL)
|
|
106
111
|
--accept-tunnels <file> relay seeds whose uuaid is in this allow-file (CARRIER_ACCEPT_TUNNELS;
|
|
107
|
-
default off). "open" admits any seed
|
|
112
|
+
default off). "open" admits any seed that proves its uuaid key
|
|
113
|
+
(2.8.1: a public open relay; caps and per-stream meter apply)
|
|
108
114
|
--tunnel-origin <https://> the public origin seeds are served at, as <origin>/e/<id>
|
|
109
115
|
(CARRIER_TUNNEL_ORIGIN)
|
|
110
116
|
--tunnel-keychain <file> attest tunnels to registries with this existing key
|
|
@@ -112,6 +118,9 @@ default; put a TLS-terminating proxy in front of it.
|
|
|
112
118
|
--tunnel-max <n> most tunnels at once (CARRIER_TUNNEL_MAX, default 32)
|
|
113
119
|
--tunnel-kbps <n> per-tunnel KiB/s each way (CARRIER_TUNNEL_KBPS, default 256)
|
|
114
120
|
--tunnel-total-kbps <n> all tunnels, KiB/s each way (CARRIER_TUNNEL_TOTAL_KBPS, default 8192)
|
|
121
|
+
--tunnels-per-ip <n> most tunnels from one seed address (CARRIER_TUNNELS_PER_IP, default 2)
|
|
122
|
+
--tunnel-buffer-mib <n> request and answer bytes the relay queues for all streams, MiB
|
|
123
|
+
(CARRIER_TUNNEL_BUFFER_MIB, default 64)
|
|
115
124
|
-h, --help print this help and exit
|
|
116
125
|
|
|
117
126
|
The carrier never mints a key. See the header of bin/carrier.mjs for details.`;
|
|
@@ -208,7 +217,7 @@ if (wantSeedKey) {
|
|
|
208
217
|
}
|
|
209
218
|
}
|
|
210
219
|
|
|
211
|
-
// Relay (2.8.0): off unless --accept-tunnels names an allow-file
|
|
220
|
+
// Relay (2.8.0): off unless --accept-tunnels names an allow-file, or "open" (2.8.1: any seed).
|
|
212
221
|
const tunnelOpt = (flag, env) => { const v = args[flag] ?? process.env[env]; return v === "" ? null : (v ?? null); };
|
|
213
222
|
const acceptTunnels = tunnelOpt("accept-tunnels", "CARRIER_ACCEPT_TUNNELS");
|
|
214
223
|
const tunnelOriginText = tunnelOpt("tunnel-origin", "CARRIER_TUNNEL_ORIGIN");
|
|
@@ -220,6 +229,9 @@ for (const [flag, env, key, scale] of [
|
|
|
220
229
|
["tunnel-max", "CARRIER_TUNNEL_MAX", "maxTunnels", 1],
|
|
221
230
|
["tunnel-kbps", "CARRIER_TUNNEL_KBPS", "tunnelBytesPerSec", 1024],
|
|
222
231
|
["tunnel-total-kbps", "CARRIER_TUNNEL_TOTAL_KBPS", "totalBytesPerSec", 1024],
|
|
232
|
+
// 2.8.1: every relay cap is a runtime flag, so a small host runs lower caps.
|
|
233
|
+
["tunnels-per-ip", "CARRIER_TUNNELS_PER_IP", "tunnelsPerIp", 1],
|
|
234
|
+
["tunnel-buffer-mib", "CARRIER_TUNNEL_BUFFER_MIB", "totalBufferedBytes", 1024 * 1024],
|
|
223
235
|
]) {
|
|
224
236
|
const v = tunnelOpt(flag, env);
|
|
225
237
|
if (v === null) continue;
|
|
@@ -235,16 +247,16 @@ if (acceptTunnels === null) {
|
|
|
235
247
|
refuse("--tunnel-origin, --tunnel-keychain and the --tunnel-* limits need --accept-tunnels");
|
|
236
248
|
}
|
|
237
249
|
} else {
|
|
238
|
-
if (typeof acceptTunnels !== "string") refuse("--accept-tunnels needs an allow-file path
|
|
250
|
+
if (typeof acceptTunnels !== "string") refuse("--accept-tunnels needs an allow-file path, or open");
|
|
239
251
|
if (typeof tunnelOriginText !== "string") refuse("--accept-tunnels needs --tunnel-origin <https://origin>: the public origin seeds are served at");
|
|
240
252
|
const c = canonicalOrigin(tunnelOriginText);
|
|
241
253
|
if (!c.ok) refuse(`--tunnel-origin is not a relay origin (${c.reason}); the value is not shown`);
|
|
242
254
|
tunnelOrigin = c.origin;
|
|
243
255
|
if (acceptTunnels === "open") {
|
|
244
|
-
//
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
256
|
+
// 2.8.1 (owner order 2026-12-04): open admission on a public origin. The
|
|
257
|
+
// 2.8.0 loopback-only lock (RedTeam 085b71 C5) is lifted on purpose. With
|
|
258
|
+
// --tunnel-keychain an open relay attests "came through this live tunnel"
|
|
259
|
+
// (admission "open", V1 via Lead 3f4436), nothing more.
|
|
248
260
|
}
|
|
249
261
|
if (tunnelKeychainPath !== null) {
|
|
250
262
|
if (typeof tunnelKeychainPath !== "string") refuse("--tunnel-keychain needs a path to a keychain file");
|
|
@@ -277,21 +289,16 @@ try {
|
|
|
277
289
|
refuse(e.message);
|
|
278
290
|
}
|
|
279
291
|
const addr = await server.listen(port, host);
|
|
280
|
-
if (acceptTunnels === "open" && !tunnelLoopback(addr.address)) {
|
|
281
|
-
// The address the socket really holds, not the flag (RedTeam 085b71 C5).
|
|
282
|
-
await server.close();
|
|
283
|
-
refuse(`--accept-tunnels open is for loopback tests, but the carrier is bound to ${addr.address}`);
|
|
284
|
-
}
|
|
285
292
|
console.log(`carrier listening on ${addr.address}:${addr.port}`);
|
|
286
293
|
console.log(` db: ${dbPath}`);
|
|
287
294
|
console.log(` ttl: ${ttlDays} days`);
|
|
288
295
|
console.log(` tiers: ${tierIssuers.length ? `${tierIssuers.length} trusted issuer(s)` : "disabled (community budgets for all)"}`);
|
|
289
296
|
console.log(` secure-delete: ${secureDelete ? "on (expired envelopes are zeroed; WAL truncated after each expiry pass)" : "off (expired envelope bytes stay on disk until reused)"}`);
|
|
290
297
|
console.log(` seed: ${seedKeychain ? `${seedKeychain._identity.uuaid} at ${publicUrl} (signed /v1/seed-info)` : "off (no seed keychain; /v1/seed-info is 404)"}`);
|
|
291
|
-
if (acceptTunnels === "open") {
|
|
292
|
-
console.error(`carrier:
|
|
298
|
+
if (acceptTunnels === "open" && !tunnelLoopback(addr.address)) {
|
|
299
|
+
console.error(`carrier: note: bound to ${addr.address}, not loopback. The carrier speaks plain http; serve ${tunnelOrigin} through a TLS proxy.`);
|
|
293
300
|
}
|
|
294
|
-
console.log(` tunnels: ${!tunnelRelay ? "off (/v1/tunnel and /e/* are 404)" : acceptTunnels === "open" ? `open
|
|
301
|
+
console.log(` tunnels: ${!tunnelRelay ? "off (/v1/tunnel and /e/* are 404)" : acceptTunnels === "open" ? `open (any seed that proves its uuaid key; caps on; one meter line per stream), serving ${tunnelOrigin}/e/<id>${tunnelKeychain ? `, attesting as ${tunnelKeychain._identity.publicKeyHex.slice(0, 16)}… (admission open)` : ", not attesting"}` : `allow-file ${acceptTunnels} (${tunnelRelay.allow.set.size} seed${tunnelRelay.allow.set.size === 1 ? "" : "s"}), serving ${tunnelOrigin}/e/<id>${tunnelKeychain ? `, attesting as ${tunnelKeychain._identity.publicKeyHex.slice(0, 16)}…` : ", not attesting"}`}`);
|
|
295
302
|
console.log(` receipts: ${server.receiptCarrier ? `signed as ${server.receiptCarrier} (uuaid.carrier-receipt.v1)` : "off (no receipt keychain)"}`);
|
|
296
303
|
|
|
297
304
|
// Vacuum expired envelopes hourly.
|
package/bin/pillar-directory.mjs
CHANGED
|
@@ -68,7 +68,8 @@ The first start mints the registry key in --home.
|
|
|
68
68
|
--trusted-proxy <ips> whose X-Forwarded-For counts (DIRECTORY_TRUSTED_PROXIES)
|
|
69
69
|
--probe-minutes <n> seed probe interval (DIRECTORY_PROBE_MINUTES, default 10)
|
|
70
70
|
--fleet-relays <file> relay origins and keys this registry pins, one "<origin> <key hex>"
|
|
71
|
-
per line; only seeds on these are
|
|
71
|
+
per line; only seeds on these are vetted and granted (2.8.1 lists
|
|
72
|
+
a relayed seed on any relay for reach, after a v2 round trip)
|
|
72
73
|
(DIRECTORY_FLEET_RELAYS; default none)
|
|
73
74
|
-h, --help print this help and exit
|
|
74
75
|
|
|
@@ -100,7 +101,7 @@ const carrier = opts.carrier ?? null;
|
|
|
100
101
|
// 2.8.0 (RedTeam 22f6c3 Q2): directory.json never names a relayed seed URL
|
|
101
102
|
// (<relay origin>/e/<id>) as its bootstrap carrier.
|
|
102
103
|
if (typeof carrier === "string" && isRelayedSeedUrl(carrier)) {
|
|
103
|
-
console.error("pillar-directory: --carrier/DIRECTORY_CARRIER is a relayed seed URL (<origin>/e/<id>); 2.8.
|
|
104
|
+
console.error("pillar-directory: --carrier/DIRECTORY_CARRIER is a relayed seed URL (<origin>/e/<id>); the bootstrap carrier is never a relayed seed (2.8.1 lists relayed seeds in seeds[] with their relay, for reach only). Name a direct carrier; clients reach a relayed seed with pillar init --carriers <url>.");
|
|
104
105
|
process.exit(2);
|
|
105
106
|
}
|
|
106
107
|
const agentsPath = opts.agents ?? null;
|
|
@@ -115,8 +116,9 @@ const probeIntervalMs = opts["probe-interval-ms"];
|
|
|
115
116
|
const effectiveProbeMs = probeIntervalMs ?? probeMinutes * 60_000;
|
|
116
117
|
const allowPrivateUrls = opts["allow-private-urls"];
|
|
117
118
|
// Fleet relays (2.8.0): the relay origins and attestation keys this registry pins.
|
|
118
|
-
// A relayed seed is
|
|
119
|
-
//
|
|
119
|
+
// A relayed seed is vetted and granted only on one of these. None by default.
|
|
120
|
+
// 2.8.1: a relayed seed on any relay is listed for reach (no vetting, no grant)
|
|
121
|
+
// once a round trip with inbox auth v2 passed for its current pin.
|
|
120
122
|
const fleetRelaysPath = opts["fleet-relays"] ?? null;
|
|
121
123
|
let fleetRelays = new Map();
|
|
122
124
|
if (fleetRelaysPath !== null) {
|
package/bin/pillar-seed.mjs
CHANGED
|
@@ -46,7 +46,9 @@
|
|
|
46
46
|
* A machine with outbound-only network (a cloud VM, a laptop behind NAT) runs
|
|
47
47
|
* a seed with --relay <origin> instead: the seed stays on 127.0.0.1, opens one
|
|
48
48
|
* outbound WebSocket to that relay carrier, and is served at
|
|
49
|
-
* <origin>/e/<id>. The relay must list this seed's uuaid on its allow-file
|
|
49
|
+
* <origin>/e/<id>. The relay must list this seed's uuaid on its allow-file
|
|
50
|
+
* (2.8.1: an open relay, --accept-tunnels open, admits any seed that proves
|
|
51
|
+
* its uuaid key).
|
|
50
52
|
* See src/net/tunnel-client.mjs and the README "Egress seed" section.
|
|
51
53
|
*/
|
|
52
54
|
import "../src/node-check.mjs"; // must stay the first import: refuses Node < 22 before any dependency loads
|
|
@@ -441,7 +443,7 @@ async function printStanding(registry, uuaid, publicKeyHex) {
|
|
|
441
443
|
else if (!s.demoted) console.log(` next: top of the ladder`);
|
|
442
444
|
// 2.8.0: the topology this registry has pinned for the seed.
|
|
443
445
|
if (s.topology) {
|
|
444
|
-
console.log(` topology: ${s.topology}${s.relay ? ` via ${s.relay}` : ""}${s.vettedUntil ? `, vetted until ${s.vettedUntil}` : ""}${s.listed === false ? (s.relay ? " (not in directory.json:
|
|
446
|
+
console.log(` topology: ${s.topology}${s.relay ? ` via ${s.relay}` : ""}${s.vettedUntil ? `, vetted until ${s.vettedUntil}` : ""}${s.listed === false ? (s.relay ? " (not in directory.json yet: a relayed seed is listed once a round trip with inbox auth v2 passes through its relay; until then clients reach it only by pillar init --carriers <url>)" : " (not listed in directory.json)") : ""}`);
|
|
445
447
|
} else {
|
|
446
448
|
const via = relayShapeOrigin(s.url, publicKeyHex);
|
|
447
449
|
if (via) console.log(` topology: relayed via ${via}; this registry predates 2.8.0, so its liveness checks are relay-attested`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uuaid/pillar",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.1",
|
|
4
4
|
"description": "Pillar (Protocol for Inter-agent Linked Ledger And Relay) — the secure delivery layer of UACP, the Universal Agent Communication Protocol. UACP = UUAID (identity) + Envelope (signed, encrypted container) + Pillar (relay, mailbox, routing, store-and-forward). Reference implementation of the UACP delivery layer; includes VDA-1 (IAASO-3901, in ballot) delivery attestation and a blind escrow for the Zilligon ZGN / EVM rails.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -8,6 +8,17 @@
|
|
|
8
8
|
import { envelopeBodyBytes, preflightBodyBytes } from "../blob/blob.mjs";
|
|
9
9
|
import { seedTier } from "./seed-tier.mjs";
|
|
10
10
|
import { carrierFix, REFUSAL_FIXES } from "./refusals.mjs";
|
|
11
|
+
import { isRelayedSeedUrl } from "./tunnel.mjs";
|
|
12
|
+
import { signInboxAuthV1, signInboxAuthV2 } from "./inbox-auth.mjs";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A 3xx answer under `redirect: "manual"` (2.8.1). Node's fetch hands back the
|
|
16
|
+
* 3xx itself; a browser-style runtime hands back an opaque redirect (status 0).
|
|
17
|
+
* Either way the client stops here and sends nothing to the target.
|
|
18
|
+
*/
|
|
19
|
+
function isRedirect(res) {
|
|
20
|
+
return res.type === "opaqueredirect" || (res.status >= 300 && res.status < 400);
|
|
21
|
+
}
|
|
11
22
|
import { setTimeout as sleepTimer } from "node:timers/promises";
|
|
12
23
|
|
|
13
24
|
/**
|
|
@@ -115,6 +126,9 @@ export class CarrierClient {
|
|
|
115
126
|
try {
|
|
116
127
|
const res = await fetch(`${base}/v1/envelopes`, {
|
|
117
128
|
method: "POST",
|
|
129
|
+
// 2.8.1: never follow a redirect. A 307/308 would replay the body and
|
|
130
|
+
// the x-pillar-* headers to whatever host the answer names.
|
|
131
|
+
redirect: "manual",
|
|
118
132
|
headers: {
|
|
119
133
|
"content-type": "application/json",
|
|
120
134
|
...(this.tierGrantB64 ? { "x-pillar-tier-grant": this.tierGrantB64 } : {}),
|
|
@@ -122,6 +136,10 @@ export class CarrierClient {
|
|
|
122
136
|
body: JSON.stringify(envelope),
|
|
123
137
|
signal: AbortSignal.timeout(timeoutMs),
|
|
124
138
|
});
|
|
139
|
+
if (isRedirect(res)) {
|
|
140
|
+
await res.body?.cancel().catch(() => {});
|
|
141
|
+
return { carrier: base, ok: false, status: res.status, error: `${res.status} carrier-redirect-refused`, reason: "carrier-redirect-refused", fix: carrierFix("carrier-redirect-refused") };
|
|
142
|
+
}
|
|
125
143
|
const raw = await res.text();
|
|
126
144
|
let body = {};
|
|
127
145
|
try { body = raw ? JSON.parse(raw) : {}; } catch (_error) {}
|
|
@@ -162,19 +180,29 @@ export class CarrierClient {
|
|
|
162
180
|
* Signed request; carrier verifies our key before serving.
|
|
163
181
|
*/
|
|
164
182
|
async fetchInbox(base, { since = 0, waitS = 0, timeoutMs = 40000, signal = null } = {}) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
},
|
|
183
|
+
// 2.8.1 (Lead 5e8cf6): a relayed seed URL gets inbox auth v2, bound to
|
|
184
|
+
// that URL and single-use, so neither the seed nor its relay can replay it
|
|
185
|
+
// to another carrier. A direct carrier gets v1, as in 2.8.0.
|
|
186
|
+
const headers = isRelayedSeedUrl(base)
|
|
187
|
+
? signInboxAuthV2(this.keychain, { audience: base, uuaid: this.uuaid, since, wait: waitS })
|
|
188
|
+
: signInboxAuthV1(this.keychain, { uuaid: this.uuaid, since });
|
|
189
|
+
const res = await fetch(`${String(base).replace(/\/+$/, "")}/v1/inbox/${encodeURIComponent(this.uuaid)}?since=${since}&wait=${waitS}`, {
|
|
190
|
+
headers,
|
|
174
191
|
// `signal` lets a caller cancel a long-poll early (peekCarrierInbox stops
|
|
175
192
|
// the other carriers once one has mail).
|
|
176
193
|
signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]) : AbortSignal.timeout(timeoutMs),
|
|
194
|
+
// 2.8.1: never follow a redirect; the signed inbox headers would go to
|
|
195
|
+
// the host the answer names, and stay replayable there for 5 minutes.
|
|
196
|
+
redirect: "manual",
|
|
177
197
|
});
|
|
198
|
+
if (isRedirect(res)) {
|
|
199
|
+
await res.body?.cancel().catch(() => {});
|
|
200
|
+
const e = new Error(`inbox fetch ${base}: ${res.status} carrier-redirect-refused`);
|
|
201
|
+
e.code = "carrier-redirect-refused";
|
|
202
|
+
e.fix = carrierFix(e.code);
|
|
203
|
+
e.status = res.status; e.carrier = base;
|
|
204
|
+
throw e;
|
|
205
|
+
}
|
|
178
206
|
if (res.status !== 200) {
|
|
179
207
|
const body = await res.json().catch(() => ({}));
|
|
180
208
|
const e = new Error(`inbox fetch ${base}: ${res.status} ${body.error ?? ""}`);
|
|
@@ -30,6 +30,11 @@
|
|
|
30
30
|
* x-pillar-delegation: (optional) JSON delegation document letting a
|
|
31
31
|
* delegate key read <uuaid>'s inbox; must be signed by <uuaid> and
|
|
32
32
|
* cover kind "inbox" (or "*")
|
|
33
|
+
* 2.8.1 inbox auth v2 (src/net/inbox-auth.mjs): x-pillar-auth: 2 and
|
|
34
|
+
* x-pillar-nonce; the signature covers this server's public URL as the
|
|
35
|
+
* audience and the since, wait and challenge values, and the nonce is
|
|
36
|
+
* used once (at most MAX_INBOX_AUTH_NONCES kept; full: 503
|
|
37
|
+
* inbox-auth-busy). A relayed seed takes v2 only.
|
|
33
38
|
* - carrier derives UUAID from pubkey; must equal <uuaid> (self-authenticating,
|
|
34
39
|
* zero registration) unless a valid inbox delegation is presented
|
|
35
40
|
* - long-polls up to `wait` seconds (max 30)
|
|
@@ -75,8 +80,20 @@ import { withCarrierFix } from "./refusals.mjs"; // additive `fix` on refusals;
|
|
|
75
80
|
import { carrierReceiptSigningString, carrierReceiptShapeOk, carrierUuaidFromKey } from "./carrier-receipt.mjs";
|
|
76
81
|
import { rekeyToSenderUnique } from "../sqlite-rekey.mjs";
|
|
77
82
|
import { CHALLENGE_RE, makeServedProof } from "./tunnel.mjs";
|
|
83
|
+
import { NONCE_RE, canonicalInboxQuery, inboxAuthV2Bytes } from "./inbox-auth.mjs";
|
|
78
84
|
|
|
79
85
|
const MAX_WAIT_S = 30;
|
|
86
|
+
/**
|
|
87
|
+
* Inbox auth v2 nonces kept at once (2.8.1, RedTeam 57c79a item 3). A nonce is
|
|
88
|
+
* kept until its request's time window ends: at most ts + 5 min + 1 s, so up to
|
|
89
|
+
* about 10 minutes for a ts 5 minutes ahead. One client address at a relay's
|
|
90
|
+
* 600 reads a minute fills 6,000 rows in that time; 100,000 rows hold about 16
|
|
91
|
+
* such addresses, about 10 MiB on disk (measured 10.4 MiB with both indexes).
|
|
92
|
+
* A direct carrier with a public URL has no per-address limit on wait=0
|
|
93
|
+
* reads, so one address can fill it there. Full: new v2 reads get 503
|
|
94
|
+
* inbox-auth-busy, and no live marker is dropped early.
|
|
95
|
+
*/
|
|
96
|
+
const MAX_INBOX_AUTH_NONCES = 100_000;
|
|
80
97
|
/** Most rows in one inbox page. */
|
|
81
98
|
export const INBOX_PAGE_ROWS = 200;
|
|
82
99
|
/**
|
|
@@ -225,7 +242,7 @@ const ENVELOPES_COLUMNS = `
|
|
|
225
242
|
const ENVELOPES_INDEX = "create index if not exists idx_envelopes_recipient on envelopes(recipient, seq);";
|
|
226
243
|
|
|
227
244
|
export class CarrierServer {
|
|
228
|
-
constructor({ dbPath = "carrier.db", ttlDays = 14, cryptoInventory, trustedTierIssuers = [], keychain = null, publicUrl = null, secureDelete = true, receiptKeychain = null, communityInboxWaits = COMMUNITY_CONCURRENT_WAITS, trustedProxies = DEFAULT_TRUSTED_PROXIES, relayOrigin = null, tunnelRelay = null, responseBudget = null } = {}) {
|
|
245
|
+
constructor({ dbPath = "carrier.db", ttlDays = 14, cryptoInventory, trustedTierIssuers = [], keychain = null, publicUrl = null, secureDelete = true, receiptKeychain = null, communityInboxWaits = COMMUNITY_CONCURRENT_WAITS, trustedProxies = DEFAULT_TRUSTED_PROXIES, relayOrigin = null, tunnelRelay = null, responseBudget = null, maxInboxAuthNonces = MAX_INBOX_AUTH_NONCES, clock = () => Date.now() } = {}) {
|
|
229
246
|
// Every row's retain_until is created_at + ttlDays, so the TTL must be a
|
|
230
247
|
// real positive duration (a NaN here used to surface only as a vacuum crash).
|
|
231
248
|
if (typeof ttlDays !== "number" || !Number.isFinite(ttlDays) || ttlDays <= 0) {
|
|
@@ -258,7 +275,18 @@ export class CarrierServer {
|
|
|
258
275
|
k text primary key,
|
|
259
276
|
v text not null
|
|
260
277
|
);
|
|
278
|
+
-- 2.8.1: inbox auth v2 nonces, each usable once until its ts window ends.
|
|
279
|
+
create table if not exists inbox_auth_nonces (
|
|
280
|
+
nonce text primary key,
|
|
281
|
+
expires integer not null
|
|
282
|
+
);
|
|
283
|
+
create index if not exists idx_inbox_auth_nonces_expires on inbox_auth_nonces(expires);
|
|
261
284
|
`);
|
|
285
|
+
if (!Number.isSafeInteger(maxInboxAuthNonces) || maxInboxAuthNonces < 1) throw new Error("maxInboxAuthNonces must be a whole number of at least 1");
|
|
286
|
+
this.maxInboxAuthNonces = maxInboxAuthNonces;
|
|
287
|
+
this.clock = clock;
|
|
288
|
+
this._noncePrunedAt = -Infinity;
|
|
289
|
+
this._nonceCount = this.db.prepare("select count(*) as n from inbox_auth_nonces").get().n;
|
|
262
290
|
// Migration for stores created before carrier receipts: add the per-row
|
|
263
291
|
// retention deadline and canonical envelope hash. Existing rows get
|
|
264
292
|
// retain_until = created_at + ttlDays (what the old vacuum would have
|
|
@@ -717,7 +745,16 @@ export class CarrierServer {
|
|
|
717
745
|
});
|
|
718
746
|
}
|
|
719
747
|
|
|
720
|
-
|
|
748
|
+
/**
|
|
749
|
+
* Inbox auth, v1 or v2 (src/net/inbox-auth.mjs). v2 (x-pillar-auth: 2) is
|
|
750
|
+
* checked against this server's own audience (its public URL) and its
|
|
751
|
+
* nonce is consumed only after the signature verifies. A relayed seed
|
|
752
|
+
* (relayOrigin set) takes v2 only (2.8.1, Lead 5e8cf6).
|
|
753
|
+
*/
|
|
754
|
+
_verifyInboxAuth(req, uuaid, sincePath, query = null) {
|
|
755
|
+
const version = req.headers["x-pillar-auth"];
|
|
756
|
+
if (version !== undefined && version !== "2") return { ok: false, reason: "inbox-auth-version" };
|
|
757
|
+
if (version === undefined && this.relayOrigin) return { ok: false, reason: "inbox-auth-v2-required" };
|
|
721
758
|
const pubkey = req.headers["x-pillar-pubkey"];
|
|
722
759
|
const ts = req.headers["x-pillar-ts"];
|
|
723
760
|
const sig = req.headers["x-pillar-sig"];
|
|
@@ -725,7 +762,7 @@ export class CarrierServer {
|
|
|
725
762
|
if (!/^[0-9a-f]{64}$/i.test(pubkey)) return { ok: false, reason: "bad-pubkey" };
|
|
726
763
|
if (!/^[0-9a-f]{128}$/i.test(sig)) return { ok: false, reason: "bad-sig-encoding" };
|
|
727
764
|
const tsNum = Number(ts);
|
|
728
|
-
if (!Number.isFinite(tsNum) || Math.abs(Date.now() - tsNum) > MAX_SKEW_MS) {
|
|
765
|
+
if (!Number.isFinite(tsNum) || Math.abs((typeof this.clock === "function" ? this.clock() : Date.now()) - tsNum) > MAX_SKEW_MS) {
|
|
729
766
|
return { ok: false, reason: "clock-skew" };
|
|
730
767
|
}
|
|
731
768
|
// Self-authenticating: UUAID must derive from the presented pubkey.
|
|
@@ -740,12 +777,61 @@ export class CarrierServer {
|
|
|
740
777
|
}
|
|
741
778
|
// Either the principal's own key or an authorized delegate key: in both
|
|
742
779
|
// cases it must have signed THIS request.
|
|
743
|
-
|
|
780
|
+
let message;
|
|
781
|
+
let nonce = null;
|
|
782
|
+
let v2 = null;
|
|
783
|
+
if (version === "2") {
|
|
784
|
+
if (!this.publicUrl) return { ok: false, reason: "inbox-audience-unknown" };
|
|
785
|
+
nonce = req.headers["x-pillar-nonce"];
|
|
786
|
+
if (typeof nonce !== "string" || !NONCE_RE.test(nonce)) return { ok: false, reason: "bad-nonce" };
|
|
787
|
+
if (!/^[0-9]{1,16}$/.test(ts)) return { ok: false, reason: "clock-skew" };
|
|
788
|
+
// Every query value that changes the read is signed; the handler acts on
|
|
789
|
+
// these values only (RedTeam 57c79a item 1).
|
|
790
|
+
v2 = query ? canonicalInboxQuery(query) : { ok: false };
|
|
791
|
+
if (!v2.ok) return { ok: false, reason: "inbox-auth-query" }; // @rule inbox.v2-canonical-query
|
|
792
|
+
message = inboxAuthV2Bytes({ audience: this.publicUrl, uuaid, since: v2.since, wait: v2.wait, challenge: v2.challenge, ts: Number(ts), nonce });
|
|
793
|
+
} else {
|
|
794
|
+
message = Buffer.from(`${sincePath}\n${ts}`, "utf-8");
|
|
795
|
+
}
|
|
744
796
|
let verified = false;
|
|
745
797
|
try { verified = Keychain.verifyDetached(pubkey, message, Buffer.from(sig, "hex")); }
|
|
746
798
|
catch (_e) { return { ok: false, reason: "verify-threw" }; }
|
|
747
799
|
if (!verified) return { ok: false, reason: "bad-signature" };
|
|
748
|
-
|
|
800
|
+
if (nonce !== null) {
|
|
801
|
+
const used = this._consumeNonce(nonce, Number(ts));
|
|
802
|
+
if (used === "full") return { ok: false, status: 503, reason: "inbox-auth-busy" };
|
|
803
|
+
if (!used) return { ok: false, reason: "nonce-used" };
|
|
804
|
+
}
|
|
805
|
+
return { ok: true, ...(v2 ? { v2: { since: v2.since, wait: v2.wait, challenge: v2.challenge } } : {}) };
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* Use a v2 nonce once: true the first time, false after, "full" when the
|
|
810
|
+
* store holds maxInboxAuthNonces live markers. The insert is one statement,
|
|
811
|
+
* so two requests with one nonce cannot both pass. A marker is kept until
|
|
812
|
+
* its request's ts window has ended (expires = ts + 5 min + 1 s); only
|
|
813
|
+
* markers past that are pruned, by the expiry index, and a request with such
|
|
814
|
+
* an old ts is refused by the clock check first. A live marker is never
|
|
815
|
+
* dropped to make room (RedTeam 57c79a item 3).
|
|
816
|
+
*/
|
|
817
|
+
_consumeNonce(nonce, ts) {
|
|
818
|
+
const now = this.clock();
|
|
819
|
+
const prune = () => {
|
|
820
|
+
this._nonceCount -= this.db.prepare("delete from inbox_auth_nonces where expires < ?").run(now).changes;
|
|
821
|
+
this._noncePrunedAt = now;
|
|
822
|
+
};
|
|
823
|
+
if (now - this._noncePrunedAt > 10_000) prune();
|
|
824
|
+
if (this.db.prepare("select 1 from inbox_auth_nonces where nonce = ?").get(nonce)) return false;
|
|
825
|
+
if (this._nonceCount >= this.maxInboxAuthNonces) prune();
|
|
826
|
+
if (this._nonceCount >= this.maxInboxAuthNonces) return "full"; // @rule inbox.nonce-store-cap
|
|
827
|
+
try {
|
|
828
|
+
this.db.prepare("insert into inbox_auth_nonces (nonce, expires) values (?, ?)").run(nonce, ts + MAX_SKEW_MS + 1000);
|
|
829
|
+
this._nonceCount++;
|
|
830
|
+
return true;
|
|
831
|
+
} catch (e) {
|
|
832
|
+
if (String(e?.code).startsWith("SQLITE_CONSTRAINT")) return false;
|
|
833
|
+
throw e;
|
|
834
|
+
}
|
|
749
835
|
}
|
|
750
836
|
|
|
751
837
|
/**
|
|
@@ -787,11 +873,14 @@ export class CarrierServer {
|
|
|
787
873
|
}
|
|
788
874
|
|
|
789
875
|
async _handleInbox(req, res, uuaid, url) {
|
|
790
|
-
|
|
791
|
-
|
|
876
|
+
let since = Number(url.searchParams.get("since") ?? 0);
|
|
877
|
+
let wait = Math.min(Number(url.searchParams.get("wait") ?? 0), MAX_WAIT_S);
|
|
878
|
+
let challenge = url.searchParams.get("challenge");
|
|
792
879
|
const sincePath = `GET /v1/inbox/${uuaid}?since=${since}`;
|
|
793
|
-
const auth = this._verifyInboxAuth(req, uuaid, sincePath);
|
|
794
|
-
if (!auth.ok) return this._json(res, 401, { error: auth.reason });
|
|
880
|
+
const auth = this._verifyInboxAuth(req, uuaid, sincePath, url.searchParams);
|
|
881
|
+
if (!auth.ok) return this._json(res, auth.status ?? 401, { error: auth.reason });
|
|
882
|
+
// v2: the read uses exactly the signed values (RedTeam 57c79a item 1).
|
|
883
|
+
if (auth.v2) { since = auth.v2.since; wait = Math.min(auth.v2.wait, MAX_WAIT_S); challenge = auth.v2.challenge; } // the same values as the raw query when canonical; kept so no other read of the query can drift
|
|
795
884
|
|
|
796
885
|
// F2: cap concurrent long-polls so sleeping connections cannot pin the
|
|
797
886
|
// event loop / fd table. The grant is resolved against the PRINCIPAL
|
|
@@ -881,7 +970,6 @@ export class CarrierServer {
|
|
|
881
970
|
// 2.8.0 served proof (RedTeam 085b71 C4): a seed asked with a one-use
|
|
882
971
|
// challenge signs the digest of this exact page, on this authenticated
|
|
883
972
|
// read, so a relay cannot answer a registry's round trip by itself.
|
|
884
|
-
const challenge = url.searchParams.get("challenge");
|
|
885
973
|
const proof = this.keychain?._identity && challenge !== null && CHALLENGE_RE.test(challenge) && Number.isSafeInteger(since)
|
|
886
974
|
? makeServedProof(this.keychain, { inbox: uuaid, since, challenge, envelopes })
|
|
887
975
|
: undefined;
|
package/src/net/discovery.mjs
CHANGED
|
@@ -3,17 +3,32 @@
|
|
|
3
3
|
* --directory`, `--refresh`, `--force --directory`).
|
|
4
4
|
*
|
|
5
5
|
* 2.8.0 (RedTeam 22f6c3 Q2): no relayed seed URL (`<relay origin>/e/<id>`,
|
|
6
|
-
* src/net/tunnel.mjs)
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* and
|
|
6
|
+
* src/net/tunnel.mjs) was configured automatically, because inbox auth sent
|
|
7
|
+
* through a relay could be replayed for 5 minutes.
|
|
8
|
+
*
|
|
9
|
+
* 2.8.1 (Lead 5e8cf6, owner order 2026-12-04): a client sends a relayed seed
|
|
10
|
+
* only inbox auth v2, bound to that seed URL and single-use
|
|
11
|
+
* (src/net/inbox-auth.mjs), so a relayed seed is taken from a directory when
|
|
12
|
+
* its entry names its relay and its URL is `<relay>/e/<id>` (the registry
|
|
13
|
+
* lists it only after a round trip with inbox auth v2 and the seed's served
|
|
14
|
+
* proof passed for its current URL, key and relay pin; RedTeam 57c79a). At
|
|
15
|
+
* most MAX_RELAYED_FROM_DIRECTORY are taken, in directory order, so a
|
|
16
|
+
* directory full of relayed seeds cannot fan one client's mail out to all of
|
|
17
|
+
* them. The bootstrap carrier is never a relayed seed. A relayed-shape URL
|
|
18
|
+
* with no `relay`, or `relay` on a URL of another shape, is skipped. Direct
|
|
19
|
+
* carrier and seed entries are taken exactly as before.
|
|
13
20
|
*/
|
|
14
21
|
import { readFileSync } from "node:fs";
|
|
15
22
|
import { isRelayedSeedUrl } from "./tunnel.mjs";
|
|
16
23
|
|
|
24
|
+
export const MAX_RELAYED_FROM_DIRECTORY = 4;
|
|
25
|
+
|
|
26
|
+
/** A directory seed entry that names its relay, at exactly `<relay>/e/<id>`. */
|
|
27
|
+
function provenRelayed(s) {
|
|
28
|
+
if (typeof s?.relay !== "string" || typeof s?.url !== "string") return false;
|
|
29
|
+
return isRelayedSeedUrl(s.url) && s.url.replace(/\/+$/, "").startsWith(`${s.relay.replace(/\/+$/, "")}/e/`);
|
|
30
|
+
}
|
|
31
|
+
|
|
17
32
|
/**
|
|
18
33
|
* @param {object} d a directory document ({ carrier, seeds: [{ url, relay? }] })
|
|
19
34
|
* @returns {{ carriers: string[], skippedRelayed: number }}
|
|
@@ -22,13 +37,20 @@ import { isRelayedSeedUrl } from "./tunnel.mjs";
|
|
|
22
37
|
export function directoryCarriers(d) {
|
|
23
38
|
const carriers = [];
|
|
24
39
|
let skippedRelayed = 0;
|
|
40
|
+
let relayedTaken = 0;
|
|
25
41
|
let carrier = d?.carrier;
|
|
26
42
|
if (carrier && isRelayedSeedUrl(carrier)) { carrier = null; skippedRelayed++; } // @rule discovery.carrier-not-relayed
|
|
27
43
|
if (carrier) carriers.push(carrier);
|
|
28
44
|
for (const s of Array.isArray(d?.seeds) ? d.seeds : []) {
|
|
29
45
|
let url = s?.url;
|
|
30
|
-
|
|
31
|
-
if (url &&
|
|
46
|
+
let relayed = false;
|
|
47
|
+
if (url && s?.relay !== undefined) {
|
|
48
|
+
relayed = provenRelayed(s);
|
|
49
|
+
if (!relayed) { url = null; skippedRelayed++; } // @rule discovery.seed-relay-metadata
|
|
50
|
+
}
|
|
51
|
+
if (url && !relayed && isRelayedSeedUrl(url)) { url = null; skippedRelayed++; } // @rule discovery.seed-relayed-shape
|
|
52
|
+
if (url && relayed && relayedTaken >= MAX_RELAYED_FROM_DIRECTORY) { url = null; skippedRelayed++; } // @rule discovery.relayed-cap
|
|
53
|
+
if (url && relayed) relayedTaken++;
|
|
32
54
|
if (url) carriers.push(url);
|
|
33
55
|
}
|
|
34
56
|
return { carriers, skippedRelayed };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inbox auth v2 (2.8.1, Lead 5e8cf6; scope fixed per RedTeam 57c79a item 1):
|
|
3
|
+
* bound to its audience, to every query value that changes the read, and
|
|
4
|
+
* single-use.
|
|
5
|
+
*
|
|
6
|
+
* v1 (`x-pillar-sig` over "GET /v1/inbox/<uuaid>?since=<n>\n<ts>") names no
|
|
7
|
+
* carrier and can be sent again for 5 minutes, so whoever receives it (a seed,
|
|
8
|
+
* or the relay in front of one) could read the same inbox at the client's
|
|
9
|
+
* other carriers. v2 signs, as JCS:
|
|
10
|
+
*
|
|
11
|
+
* { t: "pillar-inbox-auth/2", method: "GET", audience, inbox, since, wait,
|
|
12
|
+
* challenge, ts, nonce }
|
|
13
|
+
*
|
|
14
|
+
* audience the carrier base URL the client sends to, as configured, with
|
|
15
|
+
* no trailing slash (a relayed seed: <relay origin>/e/<id>)
|
|
16
|
+
* inbox the inbox uuaid in the path
|
|
17
|
+
* since the `since` query value (a whole number; absent = 0)
|
|
18
|
+
* wait the `wait` query value in seconds (a whole number; absent = 0)
|
|
19
|
+
* challenge the `challenge` query value (64 hex) the seed signs its served
|
|
20
|
+
* proof for, or null when absent
|
|
21
|
+
* ts unix ms (the same 5-minute window as v1)
|
|
22
|
+
* nonce 32 hex characters, random per request
|
|
23
|
+
*
|
|
24
|
+
* Both sides build these values with canonicalInboxQuery, so the verifier
|
|
25
|
+
* checks the signature over exactly the values it then acts on. A v2 query
|
|
26
|
+
* with any other key, a repeated key, or a value not in canonical form is
|
|
27
|
+
* refused (`inbox-auth-query`) before the signature is checked and before
|
|
28
|
+
* the nonce is used.
|
|
29
|
+
*
|
|
30
|
+
* Headers: x-pillar-auth: 2, x-pillar-pubkey, x-pillar-ts, x-pillar-nonce,
|
|
31
|
+
* x-pillar-sig (and x-pillar-delegation, as v1). The receiver checks the
|
|
32
|
+
* signature against ITS OWN audience, then uses the nonce once
|
|
33
|
+
* (src/net/carrier-server.mjs). A second use is refused (`nonce-used`).
|
|
34
|
+
*
|
|
35
|
+
* Who sends which: a client sends v2 to a relayed seed URL and v1 to a direct
|
|
36
|
+
* carrier (as 2.8.0). A relayed seed and a 2.8.1 relay refuse v1. v1 bytes
|
|
37
|
+
* and v1 parsing are unchanged.
|
|
38
|
+
*/
|
|
39
|
+
import { randomBytes } from "node:crypto";
|
|
40
|
+
import { jcs } from "../identity/jcs.mjs";
|
|
41
|
+
|
|
42
|
+
export const INBOX_AUTH_V2 = "pillar-inbox-auth/2";
|
|
43
|
+
export const NONCE_RE = /^[0-9a-f]{32}$/;
|
|
44
|
+
const WHOLE = /^(0|[1-9][0-9]{0,14})$/;
|
|
45
|
+
const CHALLENGE = /^[0-9a-f]{64}$/;
|
|
46
|
+
const V2_QUERY_KEYS = new Set(["since", "wait", "challenge"]);
|
|
47
|
+
|
|
48
|
+
/** A carrier base URL as an audience: the configured URL without trailing slashes. */
|
|
49
|
+
export function canonicalAudience(url) {
|
|
50
|
+
return String(url).replace(/\/+$/, "");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The canonical v2 query values from URLSearchParams: { ok, since, wait,
|
|
55
|
+
* challenge } or { ok:false }. Only since, wait and challenge, each at most
|
|
56
|
+
* once; since and wait whole numbers in plain decimal; challenge 64 hex.
|
|
57
|
+
*/
|
|
58
|
+
export function canonicalInboxQuery(params) {
|
|
59
|
+
const seen = new Set();
|
|
60
|
+
for (const k of params.keys()) {
|
|
61
|
+
if (!V2_QUERY_KEYS.has(k) || seen.has(k)) return { ok: false };
|
|
62
|
+
seen.add(k);
|
|
63
|
+
}
|
|
64
|
+
const s = params.get("since") ?? "0";
|
|
65
|
+
const w = params.get("wait") ?? "0";
|
|
66
|
+
const c = params.get("challenge");
|
|
67
|
+
if (!WHOLE.test(s) || !WHOLE.test(w)) return { ok: false };
|
|
68
|
+
if (c !== null && !CHALLENGE.test(c)) return { ok: false };
|
|
69
|
+
return { ok: true, since: Number(s), wait: Number(w), challenge: c };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The query string a v2 signer sends for these values (canonical order). */
|
|
73
|
+
export function inboxQueryString({ since = 0, wait = 0, challenge = null }) {
|
|
74
|
+
return `since=${since}&wait=${wait}${challenge === null ? "" : `&challenge=${challenge}`}`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The signed bytes of a v2 inbox auth. */
|
|
78
|
+
export function inboxAuthV2Bytes({ audience, uuaid, since, wait, challenge, ts, nonce }) {
|
|
79
|
+
return Buffer.from(jcs({ t: INBOX_AUTH_V2, method: "GET", audience, inbox: uuaid, since, wait, challenge, ts, nonce }), "utf-8");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** v2 inbox auth headers for one request to `audience`, with the query it signs. */
|
|
83
|
+
export function signInboxAuthV2(keychain, { audience, uuaid, since = 0, wait = 0, challenge = null, ts = Date.now(), nonce = randomBytes(16).toString("hex") }) {
|
|
84
|
+
const q = canonicalInboxQuery(new URLSearchParams(inboxQueryString({ since, wait, challenge })));
|
|
85
|
+
if (!q.ok) throw new Error("signInboxAuthV2: since and wait must be whole numbers and challenge 64 hex or null");
|
|
86
|
+
const sig = keychain.sign(inboxAuthV2Bytes({ audience: canonicalAudience(audience), uuaid, since: q.since, wait: q.wait, challenge: q.challenge, ts, nonce })).toString("hex");
|
|
87
|
+
return {
|
|
88
|
+
"x-pillar-auth": "2",
|
|
89
|
+
"x-pillar-pubkey": keychain._identity.publicKeyHex,
|
|
90
|
+
"x-pillar-ts": String(ts),
|
|
91
|
+
"x-pillar-nonce": nonce,
|
|
92
|
+
"x-pillar-sig": sig,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** v1 inbox auth headers (2.8.0 and earlier; direct carriers only). */
|
|
97
|
+
export function signInboxAuthV1(keychain, { uuaid, since, ts = Date.now() }) {
|
|
98
|
+
const sig = keychain.sign(Buffer.from(`GET /v1/inbox/${uuaid}?since=${since}\n${ts}`, "utf-8")).toString("hex");
|
|
99
|
+
return { "x-pillar-pubkey": keychain._identity.publicKeyHex, "x-pillar-ts": String(ts), "x-pillar-sig": sig };
|
|
100
|
+
}
|
package/src/net/refusals.mjs
CHANGED
|
@@ -56,6 +56,14 @@ export const REFUSAL_FIXES = Object.freeze({
|
|
|
56
56
|
"bad-sig-encoding": "send x-pillar-sig as 128 hex characters",
|
|
57
57
|
"clock-skew": "fix your clock (NTP) to within 5 min of the carrier; retrying does not help",
|
|
58
58
|
"uuaid-pubkey-mismatch": "read the inbox of the UUAID your key derives, or send that UUAID's delegation in x-pillar-delegation",
|
|
59
|
+
// Inbox auth v2 (2.8.1, src/net/inbox-auth.mjs)
|
|
60
|
+
"inbox-auth-v2-required": "update pillar to 2.8.1 or later: a relayed seed takes only audience-bound, single-use inbox auth (x-pillar-auth: 2)",
|
|
61
|
+
"inbox-auth-version": "send x-pillar-auth: 2, or no x-pillar-auth header for v1 at a direct carrier",
|
|
62
|
+
"inbox-audience-unknown": "send v1 inbox auth to this carrier: it has no public URL to check a v2 audience against",
|
|
63
|
+
"bad-nonce": "send x-pillar-nonce as 32 random hex characters, new for each request",
|
|
64
|
+
"nonce-used": "sign the request again with a new x-pillar-nonce; each v2 inbox auth is used once",
|
|
65
|
+
"inbox-auth-query": "send only since and wait (whole numbers) and challenge (64 hex), each at most once: v2 signs them",
|
|
66
|
+
"inbox-auth-busy": "retry in a few seconds: this carrier holds as many live inbox auth nonces as it may",
|
|
59
67
|
"delegation-unparseable": "send x-pillar-delegation as the JSON delegation document",
|
|
60
68
|
"delegation-too-large": "send a delegation document under 8,192 bytes",
|
|
61
69
|
"delegation-principal-mismatch": "use a delegation whose principal is the inbox UUAID",
|
|
@@ -79,6 +87,7 @@ export const REFUSAL_FIXES = Object.freeze({
|
|
|
79
87
|
// Client side: no server gave a code
|
|
80
88
|
"carrier-unreachable": "check the carrier URLs and your network, then retry",
|
|
81
89
|
"carrier-bad-response": "retry, or use another carrier; the carrier or its proxy answered without a reason",
|
|
90
|
+
"carrier-redirect-refused": "configure the carrier's final https URL; it answered a redirect, and pillar never follows one, so its headers never reach another host",
|
|
82
91
|
"over-tier-limit": "send the payload as a blob (pillar-blob send, or Pillar.sendBlob)",
|
|
83
92
|
"blob-key-unproven": "use a self-certifying agent UUAID derived from this key (pillar init), or get a registry badge that names this key",
|
|
84
93
|
"sender-key-not-active": "ask the sender to send from a self-certifying agent UUAID derived from its own key, or to get a registry badge naming its key",
|
|
@@ -42,6 +42,7 @@ import { jcs } from "../identity/jcs.mjs";
|
|
|
42
42
|
import { Keychain } from "../identity/keychain.mjs";
|
|
43
43
|
import { makeTierGrant } from "../identity/tier.mjs";
|
|
44
44
|
import { seal } from "./envelope.mjs";
|
|
45
|
+
import { signInboxAuthV1, signInboxAuthV2 } from "./inbox-auth.mjs";
|
|
45
46
|
import { evaluateSeedTier, seedTier, GRANT_TTL_DAYS, DEMOTE_AFTER_FAILURES } from "./seed-tier.mjs";
|
|
46
47
|
import {
|
|
47
48
|
canonicalOrigin, relayShapeOrigin, relayedUrlFor, relayPathFor, decodeAttestHeader, isRelayedSeedUrl,
|
|
@@ -525,6 +526,10 @@ export class SeedRegistry {
|
|
|
525
526
|
if (!cols.includes("relay_key")) this.db.exec("alter table seeds add column relay_key text");
|
|
526
527
|
if (!cols.includes("vetted_until")) this.db.exec("alter table seeds add column vetted_until text");
|
|
527
528
|
if (!cols.includes("pin_state")) this.db.exec("alter table seeds add column pin_state text not null default 'direct'");
|
|
529
|
+
// 2.8.1 (RedTeam 57c79a item 2): the endpoint and pin (pinKey) a round trip
|
|
530
|
+
// with inbox auth v2 and a served proof last passed for. Null until one
|
|
531
|
+
// passes, also for every row stored before this column existed.
|
|
532
|
+
if (!cols.includes("v2_rt_pin")) this.db.exec("alter table seeds add column v2_rt_pin text");
|
|
528
533
|
this._migrateRelayedRows();
|
|
529
534
|
this._migrateVettingToLease();
|
|
530
535
|
this._clampStoredVetting();
|
|
@@ -591,6 +596,11 @@ export class SeedRegistry {
|
|
|
591
596
|
};
|
|
592
597
|
}
|
|
593
598
|
|
|
599
|
+
/** A relayed row's endpoint and pin, as the v2 round-trip marker records it. */
|
|
600
|
+
static pinKey(row) {
|
|
601
|
+
return JSON.stringify([row.url, row.public_key, row.relay ?? null, row.relay_key ?? null]);
|
|
602
|
+
}
|
|
603
|
+
|
|
594
604
|
get(uuaid) { return this.db.prepare("select * from seeds where uuaid = ?").get(uuaid); }
|
|
595
605
|
all() { return this.db.prepare("select * from seeds").all(); }
|
|
596
606
|
|
|
@@ -861,19 +871,23 @@ export class SeedRegistry {
|
|
|
861
871
|
// Poll from just below the receipt seq so the probe envelope is in
|
|
862
872
|
// range regardless of how much unrelated traffic the seed carries.
|
|
863
873
|
const since = Math.max(0, Number(receipt.seq) - 1);
|
|
864
|
-
const path = `GET /v1/inbox/${me.uuaid}?since=${since}`;
|
|
865
|
-
const ts = String(Date.now());
|
|
866
|
-
const sig = this.keychain.sign(Buffer.from(`${path}\n${ts}`, "utf-8")).toString("hex");
|
|
867
874
|
// 2.8.0: a one-use challenge the seed binds, with the digest of the exact
|
|
868
875
|
// page it returns, into a signed served proof (RedTeam 085b71 C4). A 2.7
|
|
869
|
-
// seed ignores it;
|
|
876
|
+
// seed ignores it; v1 inbox auth does not cover the query.
|
|
870
877
|
const rt = randomBytes(32).toString("hex");
|
|
878
|
+
// 2.8.1: a relayed seed takes only inbox auth v2, bound to its URL (the
|
|
879
|
+
// enrolled row URL, not the resolved one), to since, wait and this
|
|
880
|
+
// challenge, and single-use (RedTeam 57c79a item 1).
|
|
881
|
+
const viaV2 = isRelayedSeedUrl(row.url);
|
|
882
|
+
const authHeaders = viaV2
|
|
883
|
+
? signInboxAuthV2(this.keychain, { audience: row.url, uuaid: me.uuaid, since, wait: ROUND_TRIP_WAIT_S, challenge: rt })
|
|
884
|
+
: signInboxAuthV1(this.keychain, { uuaid: me.uuaid, since });
|
|
871
885
|
const getSignal = AbortSignal.timeout(this.probeTimeoutMs + ROUND_TRIP_WAIT_S * 1000);
|
|
872
886
|
const res = await raceSignal(
|
|
873
887
|
this.fetch(
|
|
874
888
|
`${resolved.url}/v1/inbox/${encodeURIComponent(me.uuaid)}?since=${since}&wait=${ROUND_TRIP_WAIT_S}&challenge=${rt}`,
|
|
875
889
|
{
|
|
876
|
-
headers:
|
|
890
|
+
headers: authHeaders,
|
|
877
891
|
signal: getSignal,
|
|
878
892
|
redirect: "manual",
|
|
879
893
|
...lookupOpt,
|
|
@@ -898,7 +912,8 @@ export class SeedRegistry {
|
|
|
898
912
|
});
|
|
899
913
|
if (!p.ok) return { ok: false, reason: p.reason };
|
|
900
914
|
}
|
|
901
|
-
|
|
915
|
+
// v2: this read used inbox auth v2 and the seed signed what it served.
|
|
916
|
+
return { ok: true, v2: viaV2 && needProof };
|
|
902
917
|
} catch (e) {
|
|
903
918
|
return { ok: false, reason: `probe-threw: ${e?.message ?? e}` };
|
|
904
919
|
}
|
|
@@ -918,6 +933,9 @@ export class SeedRegistry {
|
|
|
918
933
|
rt = await this.roundTripProbe(current, { now });
|
|
919
934
|
this.recordRoundTrip(row.uuaid, rt.ok);
|
|
920
935
|
if (!rt.ok && (current.pin_state ?? "direct") !== "direct") this._clearVetting(row.uuaid); // @rule reg.rt-failure-clears-vetting
|
|
936
|
+
// 2.8.1 (RedTeam 57c79a item 2): the endpoint and pin a v2 round trip
|
|
937
|
+
// last passed for; a failed round trip clears it.
|
|
938
|
+
this.db.prepare("update seeds set v2_rt_pin = ? where uuaid = ?").run(rt.ok && rt.v2 === true ? SeedRegistry.pinKey(current) : null, row.uuaid);
|
|
921
939
|
}
|
|
922
940
|
const evaluated = this.evaluate(row.uuaid, now);
|
|
923
941
|
return { uuaid: row.uuaid, url: row.url, alive, roundTrip: rt, ...evaluated };
|
|
@@ -964,10 +982,20 @@ export class SeedRegistry {
|
|
|
964
982
|
let grantExpiresMs = now + GRANT_TTL_DAYS * DAY_MS;
|
|
965
983
|
if (topology !== "direct") grantExpiresMs = Math.min(grantExpiresMs, Date.parse(row.vetted_until ?? "") || now); // @rule reg.grant-expiry-at-vetting
|
|
966
984
|
let listed = !ev.demoted;
|
|
967
|
-
// 2.8.
|
|
968
|
-
//
|
|
969
|
-
|
|
970
|
-
|
|
985
|
+
// 2.8.1 (owner order 2026-12-04): a relayed seed at exactly <relay>/e/<id>
|
|
986
|
+
// is listed with its uuaid and relay, so it can be found and reached by
|
|
987
|
+
// uuaid, once a round trip with inbox auth v2 and a served proof passed
|
|
988
|
+
// for its current endpoint and pin (RedTeam 57c79a item 2: signed
|
|
989
|
+
// seed-info alone does not show that clients can read it). Listing gives
|
|
990
|
+
// no vetting and no grant. A 2.8.1 client takes up to 4 such entries and
|
|
991
|
+
// reads them only with v2 (src/net/discovery.mjs); a 2.8.0 client takes
|
|
992
|
+
// none. A pending row, or a relayed-shape URL with no proven relay, stays
|
|
993
|
+
// unlisted.
|
|
994
|
+
let relayedOk = false;
|
|
995
|
+
relayedOk = topology.startsWith("relayed-") && typeof row.relay === "string" && row.url === relayedUrlFor(row.relay, row.public_key); // @rule reg.list-relayed-proven
|
|
996
|
+
if (row.v2_rt_pin !== SeedRegistry.pinKey(row)) relayedOk = false; // @rule reg.list-needs-v2-round-trip
|
|
997
|
+
if (topology !== "direct" && !relayedOk) listed = false; // @rule reg.list-direct-or-proven-relayed
|
|
998
|
+
if (isRelayedSeedUrl(row.url) && !relayedOk) listed = false; // @rule reg.list-no-unproven-relayed-shape
|
|
971
999
|
return { ev, rung, topology, grantTier, priority: grantTier !== null && rung.priority, listed, grantExpiresMs };
|
|
972
1000
|
}
|
|
973
1001
|
|
|
@@ -1057,10 +1085,13 @@ export class SeedRegistry {
|
|
|
1057
1085
|
* from, and handing it a host that failed its last three probes is how you
|
|
1058
1086
|
* get a first-run experience of silent message loss.
|
|
1059
1087
|
*
|
|
1060
|
-
* 2.8.
|
|
1061
|
-
*
|
|
1062
|
-
*
|
|
1063
|
-
*
|
|
1088
|
+
* 2.8.1: every seed entry names its uuaid. A relayed seed that proved itself
|
|
1089
|
+
* through its relay, and passed a round trip with inbox auth v2 for its
|
|
1090
|
+
* current pin, is listed with `relay` (its reach). A 2.8.0 client
|
|
1091
|
+
* never configures one as a carrier; a 2.8.1 client takes the first 4, in
|
|
1092
|
+
* this order, and reads them only with inbox auth v2 (src/net/discovery.mjs,
|
|
1093
|
+
* src/net/inbox-auth.mjs). The bootstrap carrier is never a relayed URL.
|
|
1094
|
+
* Served at /directory.json and /.
|
|
1064
1095
|
*/
|
|
1065
1096
|
directory({ agents = [], now = Date.now(), includeProbation = true } = {}) {
|
|
1066
1097
|
const rows = this.all()
|
|
@@ -1079,6 +1110,11 @@ export class SeedRegistry {
|
|
|
1079
1110
|
agents,
|
|
1080
1111
|
seeds: rows.map(({ r, s }) => ({
|
|
1081
1112
|
url: r.url,
|
|
1113
|
+
// 2.8.1: the seed's identity, so a seed (and an agent's reach) is found by uuaid.
|
|
1114
|
+
uuaid: r.uuaid,
|
|
1115
|
+
// 2.8.1: a relayed seed carries its relay origin; a client takes it
|
|
1116
|
+
// only with that relay named for its URL (src/net/discovery.mjs).
|
|
1117
|
+
...(s.topology === "direct" ? {} : { relay: r.relay }),
|
|
1082
1118
|
operator: r.operator ?? undefined,
|
|
1083
1119
|
region: r.region ?? undefined,
|
|
1084
1120
|
since: r.enrolled_at.slice(0, 10),
|
package/src/net/tunnel-relay.mjs
CHANGED
|
@@ -14,10 +14,11 @@
|
|
|
14
14
|
* method, route template, status, byte counts and time only; state is keyed
|
|
15
15
|
* by client IP, localId and stream id; every /e/* answer is `no-store`.
|
|
16
16
|
*
|
|
17
|
-
* With an attestation key
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* current allow-file (pillar-relay-attest/1, ./tunnel.mjs).
|
|
17
|
+
* With an attestation key, a seed-info answer to a registry's challenge
|
|
18
|
+
* carries `x-pillar-relay-attest`: the relay's signed statement that it came
|
|
19
|
+
* through this exact active tunnel of the seed, and in allow-file mode that
|
|
20
|
+
* the seed is on the current allow-file (pillar-relay-attest/1, ./tunnel.mjs).
|
|
21
|
+
* In open mode (2.8.1) its admission is "open" and it vouches for nothing else.
|
|
21
22
|
*/
|
|
22
23
|
import { createHash, randomBytes } from "node:crypto";
|
|
23
24
|
import { performance } from "node:perf_hooks";
|
|
@@ -128,7 +129,7 @@ export class TunnelRelay {
|
|
|
128
129
|
* @param {object} o
|
|
129
130
|
* origin canonical public origin of this relay
|
|
130
131
|
* admission { mode: "allow-file", path } or { mode: "open" }
|
|
131
|
-
* keychain attestation key (
|
|
132
|
+
* keychain attestation key (optional; either mode, 2.8.1)
|
|
132
133
|
* trustedProxies whose X-Forwarded-For counts (the carrier's list)
|
|
133
134
|
* limits overrides of TUNNEL_LIMITS
|
|
134
135
|
* log (line) => void; never given a header value
|
|
@@ -143,7 +144,7 @@ export class TunnelRelay {
|
|
|
143
144
|
this.origin = origin;
|
|
144
145
|
this.mode = admission.mode;
|
|
145
146
|
this.allowPath = admission.mode === "allow-file" ? admission.path : null;
|
|
146
|
-
this.keychain =
|
|
147
|
+
this.keychain = keychain; // 2.8.1: both modes attest when given a key
|
|
147
148
|
this.trustedProxies = trustedProxies;
|
|
148
149
|
this.limits = { ...TUNNEL_LIMITS, ...limits };
|
|
149
150
|
this.log = log;
|
|
@@ -402,6 +403,9 @@ export class TunnelRelay {
|
|
|
402
403
|
if (!p) return this._send(res, 404, { error: "not-found" });
|
|
403
404
|
const route = allowedRoute(req.method, p.rest);
|
|
404
405
|
if (!route) return this._send(res, 404, { error: "not-found" }); // @rule relay.route-allow-list
|
|
406
|
+
// 2.8.1 (Lead 5e8cf6): v1 inbox auth never passes a relay, whatever the
|
|
407
|
+
// seed's version: it names no carrier and could be replayed for 5 minutes.
|
|
408
|
+
if (route === "/v1/inbox/:uuaid" && req.headers["x-pillar-auth"] !== "2") return this._send(res, 401, { error: "inbox-auth-v2-required" });
|
|
405
409
|
const tunnel = this.tunnels.get(p.localId);
|
|
406
410
|
if (!tunnel) return this._send(res, 503, { error: "seed-offline" });
|
|
407
411
|
const ip = clientIpOf(req, this.trustedProxies);
|
|
@@ -680,21 +684,27 @@ export class TunnelRelay {
|
|
|
680
684
|
}
|
|
681
685
|
|
|
682
686
|
/**
|
|
683
|
-
* The attestation for a seed-info answer to a registry's challenge: only
|
|
684
|
-
*
|
|
685
|
-
*
|
|
687
|
+
* The attestation for a seed-info answer to a registry's challenge: only
|
|
688
|
+
* with a key, only for the tunnel that is active for that seed now, and in
|
|
689
|
+
* allow-file mode only while the seed is on the allow-file as it is now.
|
|
690
|
+
* In open mode (2.8.1) it says only that the answer came through this live
|
|
691
|
+
* tunnel for this seed key: admission "open", no allow-file hash.
|
|
686
692
|
*/
|
|
687
693
|
_attest(stream, now) {
|
|
688
|
-
if (!this.keychain
|
|
694
|
+
if (!this.keychain) return null;
|
|
689
695
|
if (stream.route !== "/v1/seed-info" || !CHALLENGE_RE.test(stream.challenge ?? "")) return null;
|
|
690
|
-
|
|
691
|
-
if (
|
|
696
|
+
let allowSha256 = null;
|
|
697
|
+
if (this.mode === "allow-file") {
|
|
698
|
+
const allow = this._allowNow();
|
|
699
|
+
if (!allow.set.has(stream.tunnel.uuaid)) return null; // @rule relay.attest-current-allow-file
|
|
700
|
+
allowSha256 = allow.sha;
|
|
701
|
+
}
|
|
692
702
|
if (this.tunnels.get(stream.localId) !== stream.tunnel) return null; // @rule relay.attest-active-tunnel
|
|
693
703
|
const t = stream.tunnel;
|
|
694
704
|
return encodeAttestHeader(makeRelayAttest(this.keychain, {
|
|
695
705
|
origin: this.origin, path: `/e/${t.localId}/v1/seed-info`, uuaid: t.uuaid, publicKey: t.publicKey,
|
|
696
|
-
challenge: stream.challenge, tunnelId: t.id, tunnelSince: t.since, admission:
|
|
697
|
-
allowSha256
|
|
706
|
+
challenge: stream.challenge, tunnelId: t.id, tunnelSince: t.since, admission: this.mode,
|
|
707
|
+
allowSha256, at: now,
|
|
698
708
|
}));
|
|
699
709
|
}
|
|
700
710
|
|
package/src/net/tunnel.mjs
CHANGED
|
@@ -123,6 +123,7 @@ export function allowedRoute(method, path) {
|
|
|
123
123
|
export const FORWARDED_REQUEST_HEADERS = Object.freeze([
|
|
124
124
|
"content-type", "content-length",
|
|
125
125
|
"x-pillar-pubkey", "x-pillar-ts", "x-pillar-sig", "x-pillar-delegation", "x-pillar-tier-grant",
|
|
126
|
+
"x-pillar-auth", "x-pillar-nonce", // inbox auth v2 (2.8.1)
|
|
126
127
|
]);
|
|
127
128
|
|
|
128
129
|
/** The allow-listed request headers of `headers` (a Node header object). */
|
|
@@ -236,7 +237,7 @@ export function decodeAttestHeader(value) {
|
|
|
236
237
|
/**
|
|
237
238
|
* Verify an attestation against what the registry expects: the configured
|
|
238
239
|
* key for this origin, the seed's pinned identity, the seed-info path, the
|
|
239
|
-
* challenge it just sent, allow-file admission and a fresh `at`.
|
|
240
|
+
* challenge it just sent, allow-file or open admission (2.8.1) and a fresh `at`.
|
|
240
241
|
*/
|
|
241
242
|
export function verifyRelayAttest(att, { relayKey, origin, path, uuaid, publicKey, challenge, now = Date.now() }) {
|
|
242
243
|
if (!att || att.t !== "pillar-relay-attest/1") return { ok: false, reason: "attest-missing" };
|
|
@@ -245,7 +246,10 @@ export function verifyRelayAttest(att, { relayKey, origin, path, uuaid, publicKe
|
|
|
245
246
|
if (att.path !== path) return { ok: false, reason: "attest-path" };
|
|
246
247
|
if (att.uuaid !== uuaid || String(att.publicKey).toLowerCase() !== String(publicKey).toLowerCase()) return { ok: false, reason: "attest-identity" }; // @rule reg.attest-identity
|
|
247
248
|
if (att.challenge !== challenge) return { ok: false, reason: "attest-challenge" }; // @rule reg.attest-challenge
|
|
248
|
-
|
|
249
|
+
// 2.8.1 (V1 via Lead 3f4436): an open relay attests too. "open" says only
|
|
250
|
+
// that the answer came through this relay's live tunnel for this seed key;
|
|
251
|
+
// the registry still trusts it only from a relay key it pins (--fleet-relays).
|
|
252
|
+
if (att.admission !== "allow-file" && att.admission !== "open") return { ok: false, reason: "attest-admission" }; // @rule reg.attest-admission
|
|
249
253
|
if (typeof att.tunnelId !== "string" || !/^[0-9a-f]{32}$/.test(att.tunnelId)) return { ok: false, reason: "attest-tunnel" };
|
|
250
254
|
if (!Number.isSafeInteger(att.at) || Math.abs(now - att.at) > TUNNEL_SKEW_MS) return { ok: false, reason: "attest-stale" }; // @rule reg.attest-fresh
|
|
251
255
|
if (typeof att.sig !== "string" || !SIG_RE.test(att.sig)) return { ok: false, reason: "attest-sig" };
|
package/src/registry/stats.mjs
CHANGED
|
@@ -52,7 +52,7 @@ export const TTFA_METHODS = Object.freeze(["ci-canary", "field-cohort"]);
|
|
|
52
52
|
export const TTFA_MIN_N = 10;
|
|
53
53
|
|
|
54
54
|
/** Tool stamped on B8 verdicts (same string the `pillar verify` CLI uses). */
|
|
55
|
-
export const STATS_VERDICT_TOOL = "pillar/2.8.
|
|
55
|
+
export const STATS_VERDICT_TOOL = "pillar/2.8.1";
|
|
56
56
|
|
|
57
57
|
/** Closed key set of `pillar-ttfa-report/1`. */
|
|
58
58
|
export const TTFA_REPORT_KEYS = Object.freeze([
|
package/src/vnext/init-cli.mjs
CHANGED
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
readRecoverySheetWords,
|
|
43
43
|
writeFileAtomic,
|
|
44
44
|
} from "./wave-a.mjs";
|
|
45
|
-
import { directoryCarriers, readBackCarriers, relayedCarriersIn } from "../net/discovery.mjs";
|
|
45
|
+
import { directoryCarriers, readBackCarriers, relayedCarriersIn, MAX_RELAYED_FROM_DIRECTORY } from "../net/discovery.mjs";
|
|
46
46
|
|
|
47
47
|
const INIT_VALUE_FLAGS = new Set([
|
|
48
48
|
"home",
|
|
@@ -181,7 +181,7 @@ function failInit(errOut, msg, exitCode = 1) {
|
|
|
181
181
|
*/
|
|
182
182
|
function carriersFromDirectory(d, errOut) {
|
|
183
183
|
const { carriers, skippedRelayed } = directoryCarriers(d);
|
|
184
|
-
if (skippedRelayed) errOut(`note: ${skippedRelayed} relayed seed URL(s) in the directory were not added
|
|
184
|
+
if (skippedRelayed) errOut(`note: ${skippedRelayed} relayed seed URL(s) in the directory were not added (no relay named for its URL, or past the first ${MAX_RELAYED_FROM_DIRECTORY}); name one with pillar init --carriers <url>\n`);
|
|
185
185
|
return carriers;
|
|
186
186
|
}
|
|
187
187
|
|
package/src/vnext/verify-cli.mjs
CHANGED
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
verifyStatsArtifact,
|
|
32
32
|
} from "../registry/stats.mjs";
|
|
33
33
|
|
|
34
|
-
export const VERIFY_CLI_TOOL = "pillar/2.8.
|
|
34
|
+
export const VERIFY_CLI_TOOL = "pillar/2.8.1";
|
|
35
35
|
const TYPE_SET = new Set([...VERIFY_TYPES, TTFA_VERDICT_TYPE, REGISTRY_STATS_VERDICT_TYPE]);
|
|
36
36
|
|
|
37
37
|
const VALUE_FLAGS = new Set([
|