Skip to content

Verify and sign RFC 9421 requests and responses, still accepting today's Signify signatures - #473

Draft
dhh1128 wants to merge 44 commits into
WebOfTrust:mainfrom
dhh1128:feat/rfc9421-canonical
Draft

dhh1128 wants to merge 44 commits into
WebOfTrust:mainfrom
dhh1128:feat/rfc9421-canonical

Conversation

@dhh1128

@dhh1128 dhh1128 commented Nov 13, 2026

Copy link
Copy Markdown

NOTE TO MAINTAINERS: Opened as a draft so it can be referenced. It can't pass CI yet, because it needs keri's new keri.end.httpsigning module in a 1.2.x release (WebOfTrust/keripy#1769). It uses the same reviewer-brief format as that PR, posted by hand.


Reviewer brief

Asks of you: one behaviour call, and patience until the keri pin can move.

What it does. KERIA verifies and signs RFC 9421 requests and responses through keripy's keri.end.httpsigning. That's the KERI profile of RFC 9421 (https://github.com/bakobo/fiki/blob/keri-profile-v1.2/docs/keri-profile.md): plain RFC 9421 with an AID as keyid, committing to the body through Content-Digest and covering the query string as sent. KERIA keeps accepting today's Signify signatures ("legacy mode") and answers each request in the mode it arrived in. So existing Signify clients see no change, and a client that opts into canonical mode gets canonical responses.

Behaviour call. On PUT /agent/{caid}, a failed request signature now returns 401 where main returns 403. A canonical client treats any unsigned refusal other than 401 as a protocol error, so this keeps passcode-rotation failures reportable as authentication failures. signify-ts only checks res.ok there, so no current client notices. OK?

Configuration, all optional: KERIA_ACCEPT_LEGACY (default true), KERIA_SIGNATURE_MAX_AGE (300), KERIA_SIGNATURE_SKEW (60), and KERIA_SIGNATURE_AUTHORITIES. When the last one is set, canonical requests must sign for one of the listed hosts, which stops a request signed for one service from replaying to another. KERIA refuses to start with a bad value, or with a setting below the profile's minimum.

Depends on: keripy's keri.end.httpsigning (WebOfTrust/keripy#1769) in a 1.2.x release. pyproject.toml still pins keri==1.2.14 until that release exists. Every test here ran against 1.2.14 with that module added.
Compatibility: legacy traffic is verified as before, except that the legacy key rule now follows the controller's signing threshold. That's the same change and the same question as in the keripy PR. Every Signify controller is unaffected.
You can skip: tests/vectors/keri-rfc9421/, which are shared conformance vectors copied byte for byte.
Worth reading: src/keria/core/authing.py (the authenticator and middleware) and docs/protocol.md's new section on request signing.

Full description

The server needs the request target exactly as sent, because @path and @query are signed that way and a normalizing server would accept a request the signer never signed. KERIA's hio server doesn't expose it, so KERIA adds RAW_URI to the WSGI environ. A canonical request whose signed path differs from the path falcon routes on is refused.

Bodies are checked against their Content-Digest before any handler reads them. Responses to canonical requests are signed over the status, their own content, and the request they answer, including its body digest. That means a response can't be replayed as the answer to a different request. Responses with no content on the wire, such as a HEAD, 204 or 304, are signed as bodiless. A generator-streamed response is buffered before it's signed.

PUT /agent/{caid} verifies the request against the controller's key state as the pending rotation would leave it, and reads the clock once for both checks, so a request near its freshness limit can't leave the agent half-rotated.

The same conformance vectors run in keripy, signify-ts and here, so the three implementations can't drift apart without a test failing.

At DEBUG the logger read req.stream and reset only env['wsgi.input'].
Falcon had already bound req.stream to the original input, so every
later reader, the resource included, saw an empty body. Reset
req.stream and drop the cached bounded stream as well.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
hio percent-decodes the request path and re-encodes it with quote() to
build PATH_INFO, so the app never sees the path the client sent. RFC
9421's @path is that path, percent-encoding included. RawUriServer
subclasses hio's server to add the request target to the environ as
RAW_URI, the name gunicorn uses, and rawPath() reads the path from it,
falling back to req.path when a server does not set it.
createHttpServer now builds a RawUriServer.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
SignedHeaderAuthenticator now accepts two modes and picks one from the
form of the Signature header. Legacy mode, today's scheme, runs exactly
the code it ran before. Canonical mode is RFC 9421 as written under
the KERI profile, verified with keripy's keri.end.httpsigning:

- the agent is found from the keyid parameter, the Client AID, and the
  signature verified against its key state as the agent holds it;
- @method, @path (the raw path, from RAW_URI), @query and, when there is
  a body, content-digest must be covered;
- created and expires are checked against max_age and skew;
- the body is read, its Content-Digest recomputed, and the stream reset
  before the request reaches a resource.

Responses to canonical requests are signed over @status, content-digest
and the request's method, path, query and content-digest marked req. A
streamed body is buffered so it can be covered. Every refusal is still
a bare 401.

New KERIAServerConfig settings, each with an environment variable:
acceptLegacy (KERIA_ACCEPT_LEGACY, default true), signatureMaxAge
(KERIA_SIGNATURE_MAX_AGE, 300), signatureSkew (KERIA_SIGNATURE_SKEW,
60) and signatureAuthorities (KERIA_SIGNATURE_AUTHORITIES, none; when
set, @authority is required and must name one of them).

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Copies the KERI profile vectors verbatim from fiki (530cd8c, format 1)
into tests/vectors/keri-rfc9421 and runs them through KERIA's
authenticator: every accepted request, every request refusal by its
error code, the responses reproduced byte for byte from KERIA's view
of the request, and the legacy signatures. Adds round trips through
the falcon middleware, RAW_URI handling, body digest and freshness
refusals, and body re-reading after the request logger.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Replaces the placeholder section of protocol.md with the two modes KERIA
accepts, links RFC 9421 and RFC 9530, points at the shared test vectors,
and lists the new configuration settings.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…ssing

A subclass bound at import broke test_createHttpServer, which replaces
hio.core.http.Server at call time and expects createHttpServer to build
whatever that name holds. exposeRawUri() wraps buildEnviron on the
instance instead, so createHttpServer keeps looking the class up when
it runs, and it leaves a server without a WSGI environ alone.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Wrapping buildEnviron on the instance made a reference cycle, server to
wrapper to bound method to server, so a server that was never closed
kept its listening socket until the cyclic collector ran.
test_setup_no_http leaves port 5678 bound that way and test_setup then
failed to bind it. rawUriServerType() makes, and caches, a subclass of
whatever hio.core.http.Server is when createHttpServer runs, which has
no cycle and still lets tests replace that name.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
verifyRequest now requires the body. KERIA passes Deferred, so the
signature is checked on the headers before the body is read, and keeps
the Verified that checkBody returns. The middleware refuses any request
whose verification still owes its body check, so one cannot reach a
resource (profile draft 6, section 5).

The response is bound to Verified.request instead of a Requestage rebuilt
here. Routing uses peekMode instead of catching detectMode's error. With
no agent for the keyid, resolver None gives the malformed-key and
unknown-key ordering the hand-built resolver did, and @authority comes
from Host through keripy's normalizeAuthority, which drops :80 and :443
whatever the scheme, replacing KERIA's own port stripping.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
KERIAServerConfig builds its canonical-mode Policy when it is created, so
a max age or skew that is not a positive integer, or authorities given as
one string, stops KERIA at startup instead of failing requests later.
The profile does not allow a policy below its minimum set (draft 6,
section 3). Authorities are normalized by the Policy itself.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
… rotation

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…limits

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Copies fiki's vectors at 34f37a0 (keri_vectors_format 2, profile draft
6) verbatim. Vector keys are now served from their key_state, so the
passcode-rotated controller verifies and the multi-key states are
refused as unsupported-signer by KERIA's own resolver. A case's
authorities policy is applied, and a URL without a host goes to the
case's Host field.

Runs 20 requests, 37 request refusals (also through the middleware), 4
responses and 4 legacy cases.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
keripy's verifyResponse and signResponse now refuse a request record whose
body is None or Deferred. KERIA's own record already
carries the bytes, since checkBody fills them in before signResponse sees
it; only the tests' hand-built records passed None.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
KERIA kept its own copy of the legacy signature-base builder, which keripy's
keri.end.httpsigning now carries as verifyLegacy with the same base and the
same refusal messages. The signer lookup moves to
KeverResolver.legacy, which takes the first current key of Signify-Resource's
KEL exactly as before (profile section 8).

The header-presence checks and the agent lookup stay in KERIA, so every
refusal keeps its order and message and tests/core/test_authing.py passes
unchanged. Two malformed inputs change outcome: a Signature with no member
for the input's label, and a legacy header that fails to parse,
could escape the middleware as KeyError or TypeError (a 500), and are now
401 refusals.

Legacy response signing already goes through keripy's ending.siginput and
ending.signature; httpsigning adds no legacy signer, so it is unchanged.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Re-copied verbatim from fiki c6ec3b5, the merge of bakobo/fiki#4, so KERIA
carries the same files as keripy. Against the earlier
copy from 34f37a0 only header text differs: the profile is cited as version
1, and policy.body_rule and keys_rule are reworded. No case changed:
requests 20, responses 4, refusals 52, legacy 4, rfc9421 1.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Name the profile canonical mode follows, pinned to the fiki commit the
vectors come from, and say that a response covers "content-digest";req when
the request's content was non-empty, whatever its headers claimed (profile
draft 7, section 3).

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
The contact image endpoint sets rep.stream to Organizer.getImg, a
generator with no read(), so signing a canonical response to it raised
AttributeError. Read a file-like stream, join an iterable one.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
A canonical-mode client verifies a response from Signature,
Signature-Input and Content-Digest. The CORS expose list had the first
two but not the third, so in a browser the digest read as absent and
every response with a covered body failed verification.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
The endpoint applied the controller's rotation and only then verified
the request, so a refused request (stale created, legacy mode off, a
missing signature, the wrong key) left the agent's copy of the KEL
rotated with the salt and key updates undone. It now verifies first,
against the key state the pending rotation would establish, through a
read-only overlay on the agent's kevers, and verifies again against
the state as applied. inboundCanonical and inboundLegacy are split into
side-effect-free verify methods and the request mutations they did.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Only 'true' and '1' turned legacy mode on, so any other spelling,
including 'yes', 'TRUE ' or a typo, silently turned it off and refused
every legacy client. Accept true/1/yes/on and false/0/no/off in any case
with surrounding whitespace, and stop at startup naming the variable on
anything else.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
'a.example; b.example' configured ' b.example', and a trailing ';'
configured an empty authority, neither of which any request's
@authority can match. The other ';' lists (KERIA_CURLS and the rest)
keep upstream's parsing.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Helpers.server built a plain hio http.Server, so a test going through it
saw PATH_INFO re-encoded by hio and no RAW_URI. It now uses
createHttpServer, as KERIA does. A new test sends canonical requests for
paths with %7E and ':' over a real socket: KERIA's server verifies them
and signs a response bound to the path as sent, and a plain hio server
refuses them.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
inboundCanonical always completes the body check before it returns, so
AuthenticationMiddleware.bodyOwed could only be true for a subclass that
overrode it, and its test existed only to build such a subclass. The
invariant lives where checkBody is called; a test now pins that a
resource sees bodyOwed False and that a swapped body is refused, unsigned,
before any resource runs.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
The middleware, AgentResourceEnd's pre-rotation check and its
post-rotation check each peeked at the Signature header's mode; it is
now computed once and kept on request.context. KERIAServerConfig keeps
the Policy it validates at startup, and the admin server's
authenticator uses that one instead of building a second. keripy's
signatureKeyid and verifyRequest still parse the header themselves,
which KERIA cannot share without a keripy API change.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
The vector files keep fiki's own header text, since they are copied verbatim.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
keri_vectors_format 7 targets version 1.1 of the KERI profile. Its four
generated legacy cases, from controllers with more than one current key,
now run through the authenticator's legacy path against the key state each
states. The request builder also passes Content-Length through as hio's
environ does, as sent rather than parsed, so the no-break-space case is
refused here as it is behind KERIA's server.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
hio parses a request target that begins with "//" as an authority and
routes on what follows it, while @path is the target as sent. Such a
request verified against one path and was served by the resource at
another. With RAW_URI present, a canonical request is now refused unless
its path as sent, unquoted, equals the PATH_INFO falcon routes on.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
PUT /agent/{caid} verifies its request before applying the rotation and
again after it, and each verification read the clock. A signature that
aged out of its window between the two passed the first and failed the
second, leaving the KEL rotated and the rest of the update undone. The
authenticator now reads the clock once per request and keeps the time on
request.context.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
PUT /agent/{caid} parses its body to find the rotation it verifies the
request against, so that body reached JSON and KERI event parsing before
any check. The endpoint now checks the body against Content-Digest
first, and refuses a body without one unless the request is on the
legacy path, which covers no body. Coverage of content-digest is still
checked when the request is verified.

test_agent_resource exercises the body checks, which now follow
authentication, so it gives the endpoint a mock authenticator.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
PUT /agent/{caid} answered a request that failed verification with an
unsigned 403. A canonical client reports every unsigned response other
than a 401 as missing-signature, so a refused passcode rotation looked
like a protocol error rather than an authentication failure. The route
now answers 401, as every other refusal does. Its 404 for an unknown
controller and 400 for a malformed body stay, and protocol.md now says
so.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
An entry such as https://keria.example.com was accepted, could never
equal a request's @authority, and so refused every canonical request at
run time. Each configured authority is now checked when the server
configuration is built, and one with a scheme, user information, path,
query, fragment or bad port stops KERIA at startup, as a bad
KERIA_ACCEPT_LEGACY value already does. Case is left to the policy,
which lowercases authorities.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
The comment in AgentResourceEnd.on_put and the verifyPending docstring
now say that the request is verified with the key state the pending
rotation would give caid substituted for its current state.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…ernals

protocol.md said the Signature-Input member is labelled signify. That is
Signify's label; the profile lets a client choose any single label and
KERIA accepts it. readBody and the request logger clear falcon 4.0's
private bounded_stream cache, which now says so where it is done.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…reshold

Version 1.2 of the KERI profile, section 8: a legacy signature is not
indexed, so it is accepted when it verifies under any current key of
Signify-Resource's key state that alone satisfies the signing threshold.
keripy's KeverResolver.legacy now returns those keys and verifyLegacy
tries each, so an AID made with two keys under threshold 1, which
signify-ts's createSignedRequest signs with its first key, verifies
again. A 2-of-3 group is still unsupported-signer, and a key with no
weight still fails as signature-mismatch.

A missing Signature-Input, Signature or Signify-Resource, and a
Signify-Resource KERIA serves no agent for, are now the profile's
section 9 codes (missing-signature-input, missing-signature,
missing-component, unknown-key) with the messages KERIA has always
given; all remain kering.AuthNError subclasses.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
… default port

Version 1.2 of the KERI profile, section 2: @authority drops the default
port of the scheme the request was sent with, and a verifier that has
only Host and no scheme keeps whatever port Host carries. keripy used to
drop :80 and :443 whatever the scheme; it now takes the scheme, and
KERIA passes falcon's request.scheme, so Host keria.example.com:443 is
keria.example.com over https and keeps its port over http. Configured
signatureAuthorities are compared as @authority is built.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Version 1.2 of the KERI profile takes a B keyid's key from its prefix
and never asks a resolver, so such a request now verifies even when
KERIA holds no agent for it, where it used to be refused as unknown-key
for want of key state. KERIA has no one to act for then, so it refuses
the verified request as unknown-key rather than hand a resource an
empty agent.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Copies bakobo/fiki's vectors/keri at 63821f7a (keri_vectors_format 8,
tagged keri-profile-v1.2) and runs them through KERIA's authenticator.
The generated legacy cases now carry sufficient_keys and may have no
key state; test_vector_legacy_sufficient_keys serves each from its
key_state, or serves no agent when it is null. A B keyid absent from the
key table verifies from its prefix, and test_b_keyid_without_an_agent
pins that KERIA still refuses it when it serves no agent for it.
falconRequest now hands Host over as sent, since falcon's test environ
strips it, and test_canonical_authority_from_host_drops_default_port
checks the default port against the scheme the request arrived over.

One refusal case differs here by design: hio reads a request body only
when a header announces it and always supplies CONTENT_LENGTH, so
unannounced-body-and-stale reaches KERIA announced and is refused at the
covered list as insufficient-coverage (KERIA_CODES).

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
protocol.md now cites keri-profile-v1.2, says legacy mode accepts a
signature under any current key that alone satisfies the threshold, that
signatureAuthorities does not apply to legacy requests, how @authority is
built from Host and the request's scheme, and that unpadded base64 is
accepted in Signature and Content-Digest.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
The comparison of @path with the path falcon routes on ran before the
request was verified, so a request with no Signature, or from a keyid
KERIA serves no agent for, was refused as signature-mismatch rather than
by its own earlier code. It now runs after the signature is verified,
which is step 19 of the profile's section 9 order, and wins over the
freshness checks of steps 20 and 21.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
For HEAD, and for a 1xx, 204 or 304 status, falcon drops the body the
resource gave it, but KERIA digested and signed that body, so the
Content-Digest it sent did not match the empty content and the client
refused the response as digest-mismatch. The profile takes a response's
body to be the content sent (section 3), so these responses are now
signed over empty content.

Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
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