Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONFORMANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ model does not sanction.
| `FR-01` | `build` | With a working worker, the page loads and verifies the archive only in that worker before using its identities or guest |
| `FR-02` | `build` | A returning browser whose worker kept an earlier deploy serves this deploy from the navigation that brings its page |
| `FR-03` | `build` | A first visit's bytes are counted once the page has started, the frame's and the app's each within its own budget |
| `FR-04` | `build` | An app's workspace key opens only on a device of the Prism ID that made it, follows the ID when it joins or is recovered, and stays locked on a removed device |

## Cited authorities

Expand Down
28 changes: 28 additions & 0 deletions TEMPLATE-VERIFICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,34 @@ and end up with a second account.
| `npm run test:identity`, "a click the bar is redrawn under still opens the panel" | the frame before this fix, which opened the panel it was clicked on even after the bar was redrawn (found on holo-search: a first click right after load did nothing) | rejected: `not ok 2`, waiting for `#account-panel:popover-open`; fixed, 21 of 21 pass |
| same test, after the account panel became a centred dialog and the button reads "Continue with Windows Hello" | the same branch removed again | rejected: the button read `Create account` where `Continue with Windows Hello` was required; restored, 21 of 21 pass |

## An app's workspace key (FR-04)

An app that keeps a visitor's work in the browser asks the frame for a
workspace key, `frame.workspaceKey()`: 32 random bytes the frame seals under
the Prism ID's private boundary key (Prism ID's `sealPrivate`) and keeps in
this origin's `prism-id` store, under `workspace`. Only a device of the ID that
made it opens it. Joining an ID from another device, or recovering one from a
kit, reseals it for that ID in the same IndexedDB write that keeps the device
(`carryWorkspace`), so work made before the join is not lost. A removed device
makes a new ID and carries nothing, so the work it kept stays locked: the key
answers `removed`, and `{ replace: true }` starts a new one. After a removal
rotates the boundary key, a member device reseals the key under the new key,
which the removed device does not hold. While an app holds its key, the ID card
reads "Your ID and your work, sealed on your devices".

`frame_fr_04` (`crates/conformance/tests/frame.rs`) runs `openWorkspace` and
`carryWorkspace` in Node; `npm run test:identity` carries them across two apps
in Chromium (try-page.yml).

| Gate | Planted defect | Result |
| --- | --- | --- |
| `frame_fr_04` | `openWorkspace` no longer refuses a key kept by another ID (`if (false && kept.prism !== held.prism)`) | rejected: `AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal`, the other ID was answered `stale-key` where `removed` was required; restored, passes |
| `npm run test:identity`, "another app joins the same id" | joining keeps the device without carrying the workspace key (`await keep(Prism, next)`) | rejected: `not ok 5`, the joined app's key answered `removed`; restored, 16 of 16 pass |

The template's ratchet held: the three popovers in `frame/panels.css` now share
one surface and title rule, and the panel's relay messages parse in one place,
so this change shrinks the counted lines.

## The workspace page

The standard page became the workspace: a header row, the app's surface
Expand Down
99 changes: 54 additions & 45 deletions crates/conformance/tests/frame.rs
Original file line number Diff line number Diff line change
@@ -1,66 +1,75 @@
//! Executes the production frame regression under Node's isolated VM loader.
//! Executes the production frame regressions under Node.

use std::path::PathBuf;
use std::process::Command;

#[test]
fn frame_fr_01() {
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.ancestors()
.nth(2)
.expect("crates/conformance is two below the root")
.to_path_buf();
/// Runs a Node regression from the repository root and fails with its output unless it passes.
fn node(id: &str, args: &[&str]) {
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../..");
let result = Command::new("node")
.arg("site/worker-gate.mjs")
.args(args)
.current_dir(root)
.output()
.expect("Node executes the production frame regression");
.expect("Node runs");
let (out, err) = (
String::from_utf8_lossy(&result.stdout),
String::from_utf8_lossy(&result.stderr),
);
assert!(
result.status.success(),
"FR-01: {}\n{}",
String::from_utf8_lossy(&result.stdout),
String::from_utf8_lossy(&result.stderr)
"{id}: {out}
{err}"
);
}

/// `FR-01`: With a working worker, the page loads and verifies the archive only in that worker before using its identities or guest
#[test]
fn frame_fr_01() {
node("FR-01", &["site/worker-gate.mjs"]);
}

/// `FR-02`: A returning browser whose worker kept an earlier deploy serves this deploy from the navigation that brings its page
#[test]
fn frame_fr_02() {
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.ancestors()
.nth(2)
.expect("crates/conformance is two below the root")
.to_path_buf();
let result = Command::new("node")
.arg("site/sw-gate.mjs")
.current_dir(root)
.output()
.expect("Node executes the production service worker regression");
assert!(
result.status.success(),
"FR-02: {}\n{}",
String::from_utf8_lossy(&result.stdout),
String::from_utf8_lossy(&result.stderr)
);
node("FR-02", &["site/sw-gate.mjs"]);
}

/// `FR-03`: A first visit's bytes are counted once the page has started, the frame's and the app's each within its own budget
#[test]
fn frame_fr_03() {
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.ancestors()
.nth(2)
.expect("crates/conformance is two below the root")
.to_path_buf();
let result = Command::new("node")
.arg("bootstrap/weight-gate.mjs")
.current_dir(root)
.output()
.expect("Node executes the weight gate's regression");
assert!(
result.status.success(),
"FR-03: {}\n{}",
String::from_utf8_lossy(&result.stdout),
String::from_utf8_lossy(&result.stderr)
);
node("FR-03", &["bootstrap/weight-gate.mjs"]);
}

/// `FR-04`: An app's workspace key opens only on a device of the Prism ID that made it, follows the ID when it joins or is recovered, and stays locked on a removed device
///
/// The decisions run here; the frame's panel carries them across two apps in Chromium in
/// `identity/test.mjs` (try-page.yml).
#[test]
fn frame_fr_04() {
node("FR-04", &["--input-type=module", "-e", WORKSPACE]);
}

const WORKSPACE: &str = r#"
import assert from "node:assert/strict";
import * as Prism from "./identity/prism-id.mjs";
import { carryWorkspace, openWorkspace } from "./frame/panels.mjs";
const id = await Prism.createPrism();
const made = await openWorkspace(Prism, id, null);
assert.equal(made.key.length, 32);
const again = await openWorkspace(Prism, id, made.record);
assert.deepEqual([again.key, again.record], [made.key, null]);
const other = await Prism.createPrism();
await assert.rejects(openWorkspace(Prism, other, made.record), { code: "removed" });
assert.notDeepEqual((await openWorkspace(Prism, other, null)).key, made.key);
const carried = await carryWorkspace(Prism, made.record, id, other);
assert.deepEqual((await openWorkspace(Prism, other, carried)).key, made.key);
assert.equal(await carryWorkspace(Prism, made.record, other, id), null);
const { uri, pending } = await Prism.createLinkOffer(id, { now: Date.now() });
const offer = Prism.parseLinkUri(uri);
const device = await Prism.createDevice();
const accepted = await Prism.acceptLinkRequest(id, pending, await Prism.requestLink(device, offer), { now: Date.now(), confirmCode: await Prism.linkCode(offer.secret, device.record) });
const second = await Prism.completeLink(device, offer, accepted.response);
const rotated = await openWorkspace(Prism, await Prism.revokeDevice(accepted.session, second.device.id), made.record);
assert.deepEqual(rotated.key, made.key);
await assert.rejects(openWorkspace(Prism, second, rotated.record));
"#;
9 changes: 9 additions & 0 deletions features/suites/frame.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,12 @@ Feature: frame
And everything else counts as the app's
And the frame's bytes, the app's bytes and the requests are each held to their own budget
And a blob or data URL is not counted again

@FR-04 @build
Scenario: An app's workspace key opens only on a device of the Prism ID that made it, follows the ID when it joins or is recovered, and stays locked on a removed device
Given a Prism ID made on this device and the frame's openWorkspace and carryWorkspace
When an app asks for its workspace key, again, from another ID, after joining another ID, and after a removal rotated the ID's key
Then the first request makes 32 random bytes sealed under the ID's private boundary key, and the next opens the same bytes without sealing again
And another ID is refused as removed, and asking for a new key replaces the one it cannot open
And joining or recovering an ID reseals the key for that ID in the same write that keeps the device
And after a rotation a member device reseals the key under the new boundary key, which the removed device cannot open
14 changes: 12 additions & 2 deletions frame/frame.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,14 @@ const firstMove = () =>
// which publish.mjs writes here.
// It is fetched after the first move, checked against that hash as the page
// checks the frame, and imported; a failure is tried again the next time.
// Unpublished (a checkout, or an app that bundles its locked copy of the
// frame), it is imported from beside this file, as panels.mjs imports Prism id.
const PANELS = "/*PANELS*/";
let panelsModule = null;
let panelsSheet = null;
const loadPanels = () =>
(panelsModule ??= (async () => {
if (!/^[0-9a-f]{64}$/.test(PANELS)) throw new Error("this frame was published without its panels");
if (!/^[0-9a-f]{64}$/.test(PANELS)) return import("./panels.mjs");
const bytes = await (await fetch(new URL(`${PANELS}/prism-panels.mjs`, FRAME_HOST))).arrayBuffer();
const hex = Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", bytes)), (b) => b.toString(16).padStart(2, "0")).join("");
if (hex !== PANELS) throw new Error("the panels module is not the one this frame names");
Expand Down Expand Up @@ -846,6 +848,13 @@ class PrismFrame extends Element {
return { signature: b64u(signature), delegation: saved.delegation };
}

// This app's workspace key: 32 bytes only a device of the visitor's Prism
// id opens (panels.mjs, openWorkspace). { replace: true } starts a new one.
workspaceKey(options) {
if (!this.accountsReady) return Promise.reject(Object.assign(new Error("A Prism ID cannot work here"), { name: "IdentityError", code: "unsupported" }));
return this.accountsReady().then((accounts) => accounts.workspace(options));
}

// The Prism id icon, after full screen: a line drawing until the id is
// ready, filled once it is. The id is made, and this app's session signed,
// with nothing to click and nothing in the way, by the panels module
Expand All @@ -857,7 +866,7 @@ class PrismFrame extends Element {
const button = this.$("account");
const panel = this.$("account-panel");
this.accountWatch?.abort();
this.accountReady = null;
this.accountReady = this.accountsReady = null;
let wired = false;
if (typeof panel.showPopover !== "function" || !window.isSecureContext || !globalThis.crypto?.subtle || !globalThis.indexedDB) {
button.hidden = true;
Expand Down Expand Up @@ -891,6 +900,7 @@ class PrismFrame extends Element {
}
return this.accountReady;
};
this.accountsReady = ready;
const reach = () => ready().then((accounts) => accounts.reach(), () => {});
for (const type of ["pointerenter", "focus", "touchstart"]) button.addEventListener(type, reach, { passive: true });
// First use: the visitor's first touch, click or key anywhere makes the id.
Expand Down
58 changes: 15 additions & 43 deletions frame/panels.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@
* suggestions and the theme (its modes, the Unsplash search and the photos).
* Loaded with frame/panels.mjs after the visitor's first move, never with the
* page; a panel opened before then waits for them. */
/* The theme panel: three modes side by side, then three photos to set
* behind the page, then the photographer's credit. It opens under the theme
* button (the script sets --theme-top and --theme-right) as share does. */
.theme-panel {
/* The popovers' common surface and titles. */
.theme-panel, .trust-panel, .share-panel {
position: fixed;
inset: var(--theme-top, 3rem) var(--theme-right, 1rem) auto auto;
width: min(20rem, 100vw - 2rem);
max-height: calc(100vh - var(--theme-top, 3rem) - 1rem);
margin: 0;
padding: var(--space-3);
overflow: auto;
border: var(--border-width) solid var(--border);
border-radius: var(--radius);
background: var(--popover);
color: var(--popover-foreground);
box-shadow: var(--shadow-overlay);
transition: opacity var(--duration) var(--ease), transform var(--duration) var(--ease), overlay var(--duration) allow-discrete, display var(--duration) allow-discrete;
}
.theme-panel:not(:popover-open), .trust-panel:not(:popover-open), .share-panel:not(:popover-open) { opacity: 0; transform: translateY(-0.25rem) scale(0.98); }
:host([dark]) :is(.theme-panel, .trust-panel, .share-panel, .account-panel) { box-shadow: none; border-color: var(--border-strong); }
/* The theme panel: three modes side by side, then three photos to set
* behind the page, then the photographer's credit. It opens under the theme
* button (the script sets --theme-top and --theme-right) as share does. */
.theme-panel {
inset: var(--theme-top, 3rem) var(--theme-right, 1rem) auto auto;
width: min(20rem, 100vw - 2rem);
max-height: calc(100vh - var(--theme-top, 3rem) - 1rem);
padding: var(--space-3);
font-size: var(--text-14);
scrollbar-width: thin;
scrollbar-color: var(--border-strong) transparent;
transform-origin: top right;
transition: opacity var(--duration) var(--ease), transform var(--duration) var(--ease), overlay var(--duration) allow-discrete, display var(--duration) allow-discrete;
}
.theme-panel:not(:popover-open) { opacity: 0; transform: translateY(-0.25rem) scale(0.98); }
:host([dark]) .theme-panel { box-shadow: none; border-color: var(--border-strong); }
.theme-title, .share-title, .trust-title { font-family: var(--font-display); font-weight: 600; font-size: var(--text-16); letter-spacing: var(--tracking-display); }
.theme-title {
margin: 0 0 var(--space-3);
padding: 0 var(--space-1);
font-family: var(--font-display);
font-weight: 600;
font-size: var(--text-16);
letter-spacing: var(--tracking-display);
}
/* The modes: one slim segmented switch, as a system setting draws it. The
* mode in use is a raised chip inside a sunken track; small, fine icons. */
Expand Down Expand Up @@ -243,25 +243,14 @@
* opens under the shield (the script sets --trust-top and --trust-left),
* lifts in over one beat and closes on Escape or a click outside. */
.trust-panel {
position: fixed;
inset: var(--trust-top, 3rem) auto auto var(--trust-left, 1rem);
width: min(22rem, 100vw - 2rem);
max-height: calc(100vh - var(--trust-top, 3rem) - 1rem);
margin: 0;
padding: var(--space-2);
overflow: auto;
border: var(--border-width) solid var(--border);
border-radius: var(--radius);
background: var(--popover);
color: var(--popover-foreground);
box-shadow: var(--shadow-overlay);
font-size: var(--text-14);
line-height: 1.45;
transform-origin: top left;
transition: opacity var(--duration) var(--ease), transform var(--duration) var(--ease), overlay var(--duration) allow-discrete, display var(--duration) allow-discrete;
}
.trust-panel:not(:popover-open) { opacity: 0; transform: translateY(-0.25rem) scale(0.98); }
:host([dark]) .trust-panel { box-shadow: none; border-color: var(--border-strong); }
.trust-panel p { margin: 0; }

.trust-head {
Expand All @@ -272,7 +261,6 @@
border-bottom: var(--border-width) solid var(--border);
}
.trust-words { min-width: 0; }
.trust-title { font-family: var(--font-display); font-size: var(--text-16); font-weight: 600; letter-spacing: var(--tracking-display); }
.check { display: flex; gap: var(--space-3); padding: var(--space-2); }
.check .mark { flex: none; display: grid; place-items: center; width: 1.25rem; height: 1.3125rem; }
.check .mark svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 1.75; }
Expand Down Expand Up @@ -327,29 +315,14 @@
* a click outside, and gives focus back to the button. Light ground: the
* overlay shadow; dark ground: no shadow, a stronger hairline. */
.share-panel {
position: fixed;
inset: var(--share-top, 4rem) var(--share-right, 1rem) auto auto;
width: min(23rem, 100vw - 2rem);
max-height: calc(100vh - var(--share-top, 4rem) - 1rem);
margin: 0;
padding: var(--space-4);
overflow: auto;
border: var(--border-width) solid var(--border);
border-radius: var(--radius);
background: var(--popover);
color: var(--popover-foreground);
box-shadow: var(--shadow-overlay);
transform-origin: top right;
transition: opacity var(--duration) var(--ease), transform var(--duration) var(--ease), overlay var(--duration) allow-discrete, display var(--duration) allow-discrete;
}
.share-panel:not(:popover-open) { opacity: 0; transform: translateY(-0.25rem) scale(0.98); }
:host([dark]) .share-panel { box-shadow: none; border-color: var(--border-strong); }
.share-title {
margin: 0 0 var(--space-3);
font-family: var(--font-display);
font-weight: 600;
font-size: var(--text-16);
letter-spacing: var(--tracking-display);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
Expand Down Expand Up @@ -420,7 +393,6 @@
-webkit-backdrop-filter: blur(1rem);
backdrop-filter: blur(1rem);
}
:host([dark]) .account-panel { box-shadow: none; border-color: var(--border-strong); }
.account-panel p, .account-panel h2 { margin: 0; }
.account-close { position: absolute; top: 1rem; right: 1rem; display: grid; place-items: center; width: 2rem; height: 2rem; min-height: 0; padding: 0; border: 0; border-radius: var(--radius-control); background: none; color: var(--muted-foreground); cursor: pointer; }
.account-close:hover { background: var(--accent); color: var(--foreground); }
Expand Down
Loading
Loading