Skip to content

feat: serve push/* over TSP, through the same intake as DIDComm and HTTPS - #34

Merged
stormer78 merged 8 commits into
mainfrom
feat/tsp-transport
Sep 26, 2026
Merged

stormer78 merged 8 commits into
mainfrom
feat/tsp-transport

Conversation

@stormer78

Copy link
Copy Markdown
Contributor

Merges after #32. This branch is based on fix/didcomm-signed-controller-ops; until #32 lands, the diff here includes its commits.

What

TSP is the gateway's third transport, served on the same terms as DIDComm and HTTPS. Every remote API is a Trust Task, and it doesn't depend on the transport.

  • One listener, two protocols. The mediator allows one websocket per DID. So the existing affinidi-messaging-didcomm-service listener now runs with Protocols::BOTH via start_with_tsp, and TSP frames come off the same socket (tsp feature on the service and on affinidi-tdk 0.18, as in VTI).
  • A thin adapter (src/tsp.rs). It opens the TSP binding envelope (trust_tasks_tsp::ENVELOPE_TYPE), hands the document to intake::receive and wraps the reply in the envelope. It adds no authorisation of its own.
  • The sender VID is a claim. It is treated the same way as DIDComm's from: a VID that differs from the issuer the proof establishes gets identityMismatch.
  • Bare payloads are refused. A Trust Task sent over TSP without the envelope is answered with malformedRequest and not executed. A payload that isn't a Trust Task at all gets no answer.
  • Relationships. The gateway accepts a peer's relationship invite, which grants nothing. The service records control messages and answers §7.3 cancellations itself. Relationship state lives in memory, so after a restart a peer invites again.
  • Advertisement. At startup the gateway resolves its own DID. It warns if the DID document has no TSPTransport service naming the mediator in its identity file, and the warning includes the entry to add. The push-gateway DID template in VTI doesn't emit this entry yet.

Tests

  • The document suite now runs over TSP as well as DIDComm and HTTPS: accepted, wrong issuer, unsigned, stale, assertionMethod, replay, and the no-DID gateway.
  • Identity mismatch is tested on both transports that name a sender (TSP, DIDComm).
  • A document accepted on any transport is a replay on every other.
  • A bare TSP payload is refused.
  • Unit tests cover reading TSPTransport from a DID document.

cargo test --workspace, cargo clippy --all-targets -- -D warnings, cargo fmt --check and cargo deny check pass locally.

The HTTPS adapter authenticates `push/provision` and `push/wake` by a
signature over the request body. The DIDComm adapter authorised them on
the envelope's `from`, so the two transports did not ask the caller for
the same evidence. They now do: over DIDComm the Trust Task document
carries an `eddsa-jcs-2022` Data Integrity proof, and the caller is the
document's `issuer` once that proof binds it to one of the issuer's own
keys (src/proof.rs):

- the proof is `eddsa-jcs-2022` with `proofPurpose: assertionMethod`;
- the DID of `proof.verificationMethod` is the `issuer`;
- the issuer's DID document lists that method, its `controller` is the
  issuer, and it is referenced (or embedded) under `assertionMethod`;
- the signature verifies over the raw document without `proof`.

`push/provision` then requires that issuer to be the handle's
controller VTA and `push/wake` requires it to be on the allowlist,
through the unchanged dispatch core.

The envelope sender is never authorising on its own. A document with no
proof reaches the core as anonymous, so `push/register` works as before
and provision/wake answer `proofRequired`. When the envelope does name a
sender it must be the proven issuer (`identityMismatch` otherwise), and a
document addressed to another `recipient` gets `wrongRecipient`.

Proof DIDs resolve through a resolver built from the same tuning and
host policy as the listener's, since inbound documents choose them.

BREAKING CHANGE: a controller VTA or trigger that sends
`push/provision` / `push/wake` over DIDComm without a document proof is
now refused with `proofRequired`. vta-service's `provision_gateway`
(trust_tasks/device.rs) and `trigger_gateway_wake`
(trust_tasks/step_up.rs) send them unsigned today and need to attach a
proof with the VTA's assertionMethod key (`attach_proof_in_place`) before
this ships. The HTTPS path is unchanged.

Signed-off-by: Glenn Gore <glenn.g@affinidi.com>
…ue and id

`push/provision` and `push/wake` are the caller's own operational
messages, not attestations. Per VTI-KEY-106 they are signed with the
caller's operational key under `proofPurpose: authentication`, and the
verification method must be listed under `authentication` in the
issuer's DID document. An `assertionMethod` proof — reserved for
attestation artefacts — is now refused. The exact
verificationMethod/controller/issuer binding is unchanged.

An `authentication` proof carries no challenge, so the document itself
binds it to one delivery (VTI-KEY-107):

- `recipient` is required on a signed document (and must be this
  gateway, as before);
- `issuedAt` is required and must lie within the acceptance window —
  at most 5 minutes old, at most 60 s in the future (VTI-OPS-024,
  `FreshnessPolicy::consequential`);
- the document `id` is claimed in a replay record held in `AppState`
  and retained for exactly that window (VTI-OPS-026). A second delivery
  of an accepted document is answered with the first response and not
  executed again; a different document under an accepted id gets
  `idConflict`; an unavailable record fails closed.

BREAKING CHANGE: the VTA must sign these messages with its operational
key under `authentication`, and include `recipient`, `issuedAt` and a
unique `id`. No dual acceptance of `assertionMethod`.

Signed-off-by: Glenn Gore <glenn.g@affinidi.com>
…ed document

Follow-ups to the document admission added in the previous commit:

- An already-expired document (`expiresAt` in the past, `issuedAt` in
  the window) was accepted, and because its record was retained only
  until `expiresAt` it re-executed on every delivery. `validate_basic`
  now refuses `expiresAt <= now` before anything is claimed.
- The record was claimed before authorisation, so any self-signed
  did:key could create entries and push legitimate ones out of the
  bounded record, making them replayable. The claim now runs inside the
  dispatch core (`AdmitOnce`), after the per-DID rate limit and after the
  controller/allowlist check (`Store::check_controller` for provision).
  A refused caller leaves no entry.
- The record (`src/replay.rs`, `ReplayRecord`) is keyed by (issuer, id)
  and partitioned per issuer: one issuer cannot evict another's entries
  or take an id another will use. At its bounds (8192 per issuer, 65536
  total) it refuses instead of evicting.
- A transient push failure releases the claim, so a retry of the same
  document is attempted instead of answered with the failure.
- Retention now runs to the last instant the window accepts the document
  (`issuedAt + max_age + skew`, or `expiresAt` if sooner) plus 1 s.
  Previously it stopped `skew` short of that.
- The proof's verification method is refused when `revoked` is set or
  `expires` has passed (or does not parse), and a resolved DID document
  over 64 KiB is refused.

Signed-off-by: Glenn Gore <glenn.g@affinidi.com>
`push/register` is anonymous and names its controller freely, so anyone
can become the "authorised" controller of handles naming DIDs they hold
and send them signed provisions. A handful of such controllers could fill
the replay record's global bound, after which every issuer was refused.
A registration-time proof from the controller would not prevent it (the
attacker is that controller), so the record's budgets now carry it:

- a provision that re-applies the stored allowlist changes nothing and
  is answered without spending a record (`Store::allowlist_is`);
- records are charged to the handle as well as the issuer, and one handle
  holds at most 512 in the window, shared by its controller and every
  trigger acting on it;
- at the global soft bound (65536) an issuer is admitted only while it
  holds less than its fair share (soft bound / issuers holding records),
  so invented controllers cannot lock out one that is not flooding; a
  hard bound of twice the soft bound caps memory;
- one controller DID holds at most 4096 live handles
  (`GATEWAY_MAX_HANDLES_PER_CONTROLLER`), and an unprovisioned handle is
  swept after 1 h instead of 24 h.

The reviewer's probe is a regression test (three self-registered
controllers flooding fresh provisions; a legitimate wake is still
admitted), with tests for the no-op provision, the per-handle budget,
the fair share and the per-controller cap. The README specifies who can
spend the record.

Signed-off-by: Glenn Gore <glenn.g@affinidi.com>
`push/register` is anonymous and names its `controllerVtaDid`, so any DID
a caller holds could be made the controller of a handle. The gateway now
serves only the controller VTAs its operator lists in
`GATEWAY_ALLOWED_CONTROLLERS` (comma/space separated DIDs, exact match):

- a registration naming an unlisted controller is refused with
  `permissionDenied`, before a sender is selected or anything stored;
- a provision by a controller no longer on the list is refused the same
  way, without spending a replay record (covers handles restored from a
  snapshot taken under a wider list);
- unset or empty lists nothing, so every registration is refused, and
  startup logs an error saying so;
- `*` alone is an explicit open mode: any controller may register, a
  startup warning is logged, and the per-controller, per-handle and
  fair-share limits all still apply;
- a malformed list (a non-DID entry, a fragment, a pattern, or `*`
  mixed with DIDs) stops startup. Patterns are deliberately not
  supported: one would admit every DID anyone can mint under it.

BREAKING CHANGE: a gateway must be configured with the VTAs it serves;
without `GATEWAY_ALLOWED_CONTROLLERS` it refuses every registration. The
`test-wake` helpers register under a throwaway controller and so need a
local gateway in open mode.

Signed-off-by: Glenn Gore <glenn.g@affinidi.com>
…ntroller-ops

Signed-off-by: Glenn Gore <glenn.g@affinidi.com>
…transport

push/provision and push/wake are Trust Tasks, so they are authorised by the
document's own proof whichever transport carried them. Every adapter now
hands the document to one intake (src/intake.rs): an eddsa-jcs-2022
authentication proof bound to the issuer, the issuer an allowed controller,
recipient = this gateway's DID, issuedAt inside the acceptance window, and a
replay record keyed on (proven issuer, id), bounded and fail-closed, shared
by the transports.

- HTTPS POST /trust-tasks now authenticates by the document proof, as the
  VTA push engine's REST transport sends it. The X-TT-Did/X-TT-Signature
  body signature (src/auth.rs) is removed.
- DIDComm is a thin adapter; the envelope sender is only a claim that must
  agree with the proven issuer.
- Proof verification uses trust-tasks-proof 0.23's ProofPurposeResolver and
  PurposeBound; only `authentication` is accepted.
- A gateway without an identity has no DID to be addressed to and serves
  push/register only.
- test-wake helpers sign their documents.
- Dependencies: trust-tasks-rs 0.23.2, trust-tasks-proof 0.23.2,
  affinidi-tdk 0.18, affinidi-messaging-didcomm-service 0.13 (messaging-sdk
  0.28), affinidi-secrets-resolver 0.5.12.

Signed-off-by: Glenn Gore <glenn.g@affinidi.com>
…TTPS

The gateway's mediator listener now multiplexes TSP with DIDComm on its one
websocket (affinidi-messaging-didcomm-service `tsp`, Protocols::BOTH). A new
TSP adapter (src/tsp.rs) opens the TSP binding envelope, hands the document
to intake::receive with the authenticated sender VID as the transport's
claim, and returns the reply in the envelope. It adds no authorisation: a
sender VID that differs from the proven issuer is identityMismatch, as a
DIDComm `from` is. Relationship invites are accepted; they grant nothing.

At startup the gateway resolves its own DID and warns when the document has
no TSPTransport service naming its mediator.

The document suite now runs over TSP too (accepted, wrong issuer, unsigned,
stale, assertionMethod, replay), a document accepted on any transport is a
replay on every other, and a bare TSP payload is refused with
malformedRequest.

Signed-off-by: Glenn Gore <glenn.g@affinidi.com>
@stormer78
stormer78 merged commit f28ebd2 into main Sep 26, 2026
3 checks passed
@stormer78
stormer78 deleted the feat/tsp-transport branch September 26, 2026 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant