@uuaid/pillar 2.8.0 → 2.8.2
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 +196 -26
- package/bin/carrier.mjs +30 -23
- package/bin/pillar-directory.mjs +6 -4
- package/bin/pillar-seed.mjs +4 -2
- package/package.json +2 -1
- package/src/groups-v2-admin.mjs +3 -0
- package/src/groups-v2.mjs +198 -5
- package/src/mailbox/mailbox.mjs +30 -5
- package/src/net/carrier-client.mjs +109 -14
- 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/pillar.mjs +324 -60
- package/src/registry/stats.mjs +1 -1
- package/src/send-permit.mjs +66 -0
- package/src/vnext/init-cli.mjs +2 -2
- package/src/vnext/json-dir-mailbox.mjs +2 -0
- package/src/vnext/jsonl-mailbox.mjs +28 -2
- package/src/vnext/retired-import.mjs +4 -1
- package/src/vnext/verify-cli.mjs +1 -1
|
@@ -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" };
|