Skip to main content

Crate m4a_seam

Crate m4a_seam 

Source
Expand description

The seam between a product server and the messenger server.

One small crate used by BOTH sides so the wire cannot drift: the product server signs, the messenger core verifies. No I/O, no database.

§Assertion v1

Header value: v1.<base64url(json)>.<hex hmac-sha256>. The JSON carries nick, cred_ref, authenticated (1), paid (0 or 1), iat, exp (unix seconds) and nonce. The HMAC key is the raw UTF-8 of the shared secret. The HMAC input is this UTF-8 text, every line ending in a newline:

v1
<METHOD>
<path and query as the receiver sees it>
<nick>
1
<0 or 1>
<cred_ref>
<iat>
<exp>
<nonce>

The verifier rebuilds the text from the parsed JSON, so the JSON values are exactly what was signed.

§Events

JSON bodies with id and type (credential.revoked, account.deleted, nick.changed); the signature header carries the hex HMAC-SHA256 of the raw body bytes under the same secret.

Modules§

keyproof
Proof-of-possession login: an identity is an ed25519 key pair held by the CLIENT; it proves itself by signing a server challenge. No password, no shared secret, nothing an agent can read.

Structs§

Assertion
What an assertion states about the caller.
Event
One event with its idempotency id.
LiveNick
NonceCache
Remembers nonces until their assertion expires.
Reconcile
Startup reconciliation: the product’s snapshot of live credentials, so the messenger can catch up on credential.revoked / account.deleted events it never received. Posted to /account-source/v1/reconcile with the same body signature as events.

Enums§

EventKind
Lifecycle events, product -> messenger.
SeamError
Why verification failed.

Constants§

ANON_READ_HEADER
Marker a product puts on an unauthenticated, read-only forward (no assertion). The core honours it only when anonymous read is switched on (M4A_ANON_READ=on), only for GET, and only for the paths of anon_read_path_ok.
ASSERTION_TTL_S
Lifetime of an assertion the signer makes, in seconds.
DEFAULT_ASSERTION_HEADER
Default header carrying the assertion. Products may configure another name.
DEFAULT_EVENT_SIG_HEADER
Default header carrying the event body signature.
LINK_TOKEN_HEADER
Header carrying the barrier token on private links (product -> edge, product -> core). Every receiver of a link checks it inside, on top of the transport (WireGuard or a unix socket) that already protects the link.
VECTORS
Shared accept/reject vectors for assertion v1 (JSON; see the file).

Functions§

anon_read_path_ok
Anonymous read allowlist: GETs that answer from public, world-readable data only. path may carry a query string and the /_matrix prefix.
link_path_is_open
Paths that stay reachable without the barrier token because they are public protocol surfaces (federation peers, key documents, discovery, health).
link_token_ok
Constant-time comparison of a presented barrier token with the expected one.
sign_assertion
Make the header value for one request. path is the path and query as the receiver will see it.
sign_body
Hex HMAC-SHA256 of a raw event body.
verify_assertion
Verify a header value against any of secrets (current first). now_ms and skew_ms bound [iat, exp]. Replay is the caller’s concern (NonceCache).
verify_body
True when sig_hex is valid for body under any of secrets.