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
11 changes: 11 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,17 @@ making them also list it under "Enrolled executor DIDs" protected nothing.
executor-initiated pushes (task consent, disclosure step-up) with sign-in
pins — those arrive from no origin and keep the enrolled set alone.

**An RP step-up is answered by the identity that signed in.** The control
plane addresses the approve-request to the session's subject and accepts an
answer only from it. A site signed in to as a per-site persona has the persona
as its subject, so `handleApproveSessionStepUp` decides the identity the way
sign-in does (`stepUpIdentity` → `decideSiteIdentity`, never the picker) and
the offscreen signs the approve-response as that persona through the VTA
(`personaTaskSigner`; `vault/sign-trust-task` signs this type for
`assertionMethod`). **What breaks it:** signing every step-up with the holder
key (a persona session's step-up is then refused "addressed to …, not this
wallet"), or letting the page name the entry.

**What is deliberately NOT signed by a channel:** `provision/integration`,
which signs its own document with an `authentication`-purpose proof in
`provision/request.ts` and sends outside the channels. Routing it through one
Expand Down
9 changes: 6 additions & 3 deletions packages/core/src/rp-login/step-up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
// holder's signature over the RP's challenge is the one thing only the wallet
// can contribute.

import type { SigningIdentity } from "../siop/self-issued.js";
import { VtaClientError } from "../vta/errors.js";
import type { TrustTask } from "../vta/protocol.js";
import type { ChannelSigner } from "../vta/trust-task.js";
import {
buildStepUpApproval,
verifyStepUpApproveRequest,
Expand All @@ -34,8 +34,11 @@ export interface RpStepUpRequestArgs {
/** The RP's signed `approve-request/0.5`, exactly as the page received it
* in the RP's `auth/step-up/start/0.2` reply. Untrusted until verified. */
approveRequest: Record<string, unknown> | undefined;
/** The wallet's signing identity — the DID the RP session authenticated as. */
signing: SigningIdentity;
/** The DID the RP session authenticated as, and how to sign as it: the
* wallet's own key, or a persona's `TaskSigner` (signed through the VTA)
* when the site was signed in to as that persona. The approve-request must
* be addressed to, and name as its subject, this `did`. */
signing: ChannelSigner;
/** The RP's DID: the approve-request must be signed by it, and the
* approve-response is addressed to it. */
rpDid: string;
Expand Down
17 changes: 8 additions & 9 deletions packages/core/src/vta/step-up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
// Everything a human is shown, and everything the wallet signs over, comes out
// of the verified payload.

import { signTrustTask } from "../trust-tasks/sign.js";
import { verifyTrustTaskProof } from "../trust-tasks/verify.js";
import type { SigningIdentity } from "../siop/self-issued.js";
import type { TrustTask } from "./protocol.js";
import { asTaskSigner, type ChannelSigner } from "./trust-task.js";

import { TYPE_URI as MSG_APPROVE_RESPONSE } from "../specs/auth/step-up/approve-response/0.7/payload.js";
import { TYPE_URI as APPROVE_REQUEST } from "../specs/auth/step-up/approve-request/0.5/payload.js";
Expand Down Expand Up @@ -173,10 +172,12 @@ export interface StepUpApproveResponsePayload {
}

export interface BuildStepUpApprovalArgs {
/** The wallet's Ed25519 signing identity — its `did` is the response
* `subject`/`issuer` and its `kid` the proof's `verificationMethod`. It
* MUST be the DID the RP session authenticated as. */
signing: SigningIdentity;
/** Who answers — its `did` is the response `issuer`. It MUST be the DID
* the RP session authenticated as: the wallet's own key, or, for a site
* signed in to as a persona, a `TaskSigner` that signs through the VTA
* (which holds that persona's key and signs this type for
* `assertionMethod`, by the same rule as below). */
signing: ChannelSigner;
/** The RP's DID — bound in-band as `recipient` so the signed proof commits
* to this audience (SPEC §4.8.2). */
rpDid: string;
Expand Down Expand Up @@ -216,9 +217,7 @@ export async function buildStepUpApproval(
payload,
};

await signTrustTask({
envelope: document as unknown as Record<string, unknown> & { proof?: unknown },
signing: args.signing,
await asTaskSigner(args.signing).sign(document as TrustTask<unknown>, {
proofPurpose: "assertionMethod",
});
return document;
Expand Down
53 changes: 53 additions & 0 deletions packages/core/tests/rp-login.step-up.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,56 @@ test("performRpStepUp: a refused approve-request never reaches the human", async
assert.match(res.error, /not an executor/);
assert.equal(prompted, false);
});

// ── A persona session: the step-up is answered as the persona ──────────────
//
// A site signed in to as a per-site persona has that persona as the session's
// subject; the control plane addresses the approve-request to it and accepts
// an answer only from it. Its key lives at the VTA, so the wallet answers
// through a `TaskSigner` — stood in for here by one over a local key, which
// records the purpose it was asked for.

function personaSigner(persona, asked) {
return {
did: persona.did,
sign: async (envelope, opts) => {
asked.push(opts?.proofPurpose);
await signTrustTask({ envelope, signing: persona, proofPurpose: opts.proofPurpose });
},
};
}

test("performRpStepUp: a persona session is answered by the persona, for assertionMethod", async () => {
const persona = generateSigningIdentity();
const asked = [];
const res = await performRpStepUp({
...args(persona, await approveRequest(persona)),
signing: personaSigner(persona, asked),
requestConsent: async () => true,
});

assert.equal(res.ok, true, res.ok ? undefined : res.error);
assert.deepEqual(asked, ["assertionMethod"]);
const doc = res.approveResponse;
assert.equal(doc.issuer, persona.did);
assert.equal(doc.payload.subject, persona.did);
const proof = await verifyTrustTaskProof(doc, { expectedProofPurpose: "assertionMethod" });
assert.equal(proof.verified, true, proof.reason);
assert.equal(proof.signer, persona.did);
});

test("performRpStepUp: the wallet's own key cannot answer a persona session's step-up", async () => {
const persona = generateSigningIdentity();
const holder = generateSigningIdentity();
let prompted = false;
const res = await performRpStepUp({
...args(holder, await approveRequest(persona)),
requestConsent: async () => {
prompted = true;
return true;
},
});
assert.equal(res.ok, false);
assert.match(res.error, /not this wallet/);
assert.equal(prompted, false);
});
33 changes: 33 additions & 0 deletions packages/extension/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,31 @@ async function resolveLoginIdentity(
return { ok: true, entryId: bound.entryId, did: chosen.selectedDid, bound: true };
}

/**
* The identity a session step-up at `origin` is answered as: the persona the
* origin is bound to (its vault entry), else the wallet's own key.
*
* The same `decideSiteIdentity` sign-in uses, so the step-up is signed by the
* DID the session authenticated as. It never raises the picker: `ask` — no
* persona and no recorded choice — is the wallet's own key, which is what a
* sign-in that predates personas used.
*/
async function stepUpIdentity(
origin: string,
): Promise<{ ok: true; entryId?: string } | { ok: false; error: string }> {
const listed = await handleVaultList({
type: RUNTIME_VAULT_LIST,
filter: { secretKind: PROFILE_SECRET_KIND, targetOriginPrefix: origin },
});
if (!listed.ok) return { ok: false, error: listed.error };
const decision = decideSiteIdentity(
listed.result.entries,
origin,
await prefersHolderIdentity(origin),
);
return decision.kind === "persona" ? { ok: true, entryId: decision.entryId } : { ok: true };
}

async function handleLoginDidcomm(
req: RuntimeLoginDidcommRequest,
): Promise<RuntimeLoginResponse> {
Expand Down Expand Up @@ -2068,6 +2093,12 @@ async function handleApproveSessionStepUp(
if (bindingRefusal) return { ok: false, error: bindingRefusal };
const active = await readActiveConnection();
if (!active.ok) return { ok: false, error: active.error };
// The session's subject is whoever signed in: the persona this origin is
// bound to, when it has one. The step-up must be answered by that same
// identity, so it is decided the way sign-in decides it — without a
// picker, which belongs to sign-in alone.
const identity = await stepUpIdentity(req.origin);
if (!identity.ok) return { ok: false, error: identity.error };
await ensureOffscreenDocument();
const offscreenRequest: OffscreenApproveSessionStepUpRequest = {
target: OFFSCREEN_TARGET,
Expand All @@ -2078,6 +2109,8 @@ async function handleApproveSessionStepUp(
// The sign-in that pinned this origin is what enrolls its RP as the
// step-up's executor; the binding check above has just matched it.
...(pin ? { signedInRpDid: pin.rpDid } : {}),
...(identity.entryId ? { entryId: identity.entryId } : {}),
...(active.conn.restBaseUrl ? { restBaseUrl: active.conn.restBaseUrl } : {}),
};
return (await chrome.runtime.sendMessage(
offscreenRequest,
Expand Down
8 changes: 8 additions & 0 deletions packages/extension/src/bridge-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2142,6 +2142,14 @@ export interface OffscreenApproveSessionStepUpRequest {
* by the background, never by the page; the offscreen counts it as an
* enrolled executor for this step-up (`rpStepUpExecutorDids`). */
signedInRpDid?: string;
/** The vault entry (persona) this origin signs in as, when it has one —
* decided by the background exactly as sign-in decides it, never named by
* the page. The approve-response is then signed as that persona, through
* the VTA, because that persona is the session's subject. Absent: the
* wallet's own key signs, as it signed the login. */
entryId?: string;
/** The active connection's REST base URL, for the persona's VTA signing. */
restBaseUrl?: string;
}

/** offscreen → background: raise the step-up consent prompt for a VERIFIED
Expand Down
7 changes: 6 additions & 1 deletion packages/extension/src/offscreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4888,8 +4888,13 @@ async function doApproveSessionStepUp(
// Same IndexedDB-backed holder the popup/background use, so the DID is
// identical to the base-login path being elevated.
const sw = createStopwatch();
const { signing } = await loadHolder(req.vtaDid);
const { signing: holderSigning } = await loadHolder(req.vtaDid);
sw.mark("load holder");
// Answer as the identity that signed in: a persona signs through the VTA,
// the only place its key exists; otherwise the wallet's own key.
const signing = req.entryId
? await personaTaskSigner(req.vtaDid, req.restBaseUrl, req.entryId)
: holderSigning;

// The flow itself — verify → consent → sign, in that enforced order — lives
// in core (`performRpStepUp`), where it is unit tested. This function
Expand Down