Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

kernel: pin the publisher property, and record what per-publisher relays cost (#457)

nyblnetecac1909c8f9
diff --git a/kernel/src/sync/online.ts b/kernel/src/sync/online.ts
index c2b3e0fe..2856edda 100644
--- a/kernel/src/sync/online.ts
+++ b/kernel/src/sync/online.ts
@@ -151,7 +151,19 @@ export async function mintCollab(): Promise<CollabCreds> {
/** The relay host: the localStorage dev override (e.g. ws://localhost:8787),
* else the host the app configured (a fork running its own relay), else the
- * platform default. Rigs that never call configureApp() get the default. */
+ * platform default. Rigs that never call configureApp() get the default.
+ *
+ * A file's collab capability is complete only WITHIN the publisher that
+ * minted it. `CollabCreds` carries the room and the key and no host, which
+ * was total while every build had one relay; with per-publisher relays, the
+ * same file opened in another publisher's build joins that publisher's
+ * relay, where the room id is a valid commitment and is simply created
+ * fresh. Both sides are live, on two relays, and never meet — a silent
+ * split, not a leak (the relay is blind and the payloads are E2EE). This is
+ * accepted and consistent with the update channel refusing another
+ * publisher's manifests: a fork is its own trust domain. Cross-publisher
+ * collaboration would need the host stamped into `collab` — an additive
+ * format change, and its own serialized kernel PR. */
export function syncHost(): string {
let configured: string | undefined
try { configured = appConfig().syncHost } catch { /* not configured: platform default */ }
diff --git a/scripts/test-release-channel.mjs b/scripts/test-release-channel.mjs
index 0caf44ed..9f1041dd 100644
--- a/scripts/test-release-channel.mjs
+++ b/scripts/test-release-channel.mjs
@@ -285,5 +285,73 @@ await throws(
'the untouched shell gets PAST the integrity check (and then needs a browser)',
)
+// ---- 4. the publisher is a build-time choice, and it is honoured -------------
+//
+// `AppConfig.publicKeyJwk` lets a fork that runs its own signed channel verify
+// against ITS key instead of the platform key embedded in update.ts. The
+// property that makes that safe — "refuses another PUBLISHER" — was untested:
+// every case above configures the app WITHOUT the field, so a refactor that
+// quietly stopped reading it would make every fork accept upstream signatures,
+// and nothing here would move. Three cases, because either direction alone can
+// be passed by a verifier that refuses everything, or one that accepts
+// everything.
+//
+// The "fork" is a second throwaway keypair. Its manifest is the SAME payload,
+// re-signed — so the only thing that differs between accepted and refused is
+// which publisher signed it.
+console.log('\n--- publisher: the configured key is the one that counts ---')
+const { releaseSigner } = await import('./lib/release-sign.ts')
+const fork = await releaseSigner()
+const forkManifest = await fork.envelope(payload)
+
+// direction 1: an UPSTREAM build (no override) refuses a fork-signed manifest.
+serve({ [MANIFEST_URL]: forkManifest })
+{
+ const r = await kernelUpdate.checkForUpdates(MANIFEST_URL)
+ ok(r.status === 'error' && /signature is INVALID/i.test(r.message),
+ `an upstream build REFUSES a manifest signed by another publisher (${r.status})`)
+}
+
+// now build "as the fork": same app, its own publisher.
+kernelApp.configureApp({
+ appId: app.appId,
+ appName: app.label,
+ manifestUrl: MANIFEST_URL,
+ publicKeyJwk: fork.jwk,
+})
+
+// positive control: the fork build ACCEPTS its own publisher. Without this the
+// case below would pass for a verifier that refuses everything.
+{
+ const r = await kernelUpdate.checkForUpdates(MANIFEST_URL)
+ ok(r.status === 'update' && r.release.version === payload.version,
+ `a fork build ACCEPTS its own publisher's manifest and offers v${payload.version}`)
+}
+
+// direction 2: the fork build REFUSES the upstream (platform) publisher — the
+// case the field exists for. A refactor that ignored publicKeyJwk fails HERE.
+serve({ [MANIFEST_URL]: manifestRaw })
+{
+ const r = await kernelUpdate.checkForUpdates(MANIFEST_URL)
+ ok(r.status === 'error' && /signature is INVALID/i.test(r.message),
+ `a fork build REFUSES the platform publisher's manifest (${r.status})`)
+}
+
+// And no app IN THIS REPO sets either field. They are for a downstream build;
+// an upstream app setting one is a deliberate act that deserves a review, not
+// something that slips in. Read from source so the assertion is about what
+// ships, not about what this rig configured.
+{
+ const apps = ['slides', 'spaces', 'dash', 'type']
+ const offenders = apps.filter((a) => {
+ const p = join(root, a, 'src/main.ts')
+ if (!existsSync(p)) return false
+ const block = readFileSync(p, 'utf8').match(/configureApp\(\{[\s\S]*?\}\)/)?.[0] ?? ''
+ return /\b(publicKeyJwk|syncHost)\b/.test(block)
+ })
+ ok(offenders.length === 0,
+ `no in-repo app sets publicKeyJwk or syncHost${offenders.length ? ` — ${offenders.join(', ')} does` : ''}`)
+}
+
console.log(`\n${checks - failures}/${checks} checks passed`)
if (failures) process.exit(1)