Repository navigation
Conversation
…t helpers New module src/keri/core/httpsig.ts builds the RFC 9421 §2.5 signature base exactly: @method, @authority, @path, @query and @status derived components, the req parameter for request components in a response, the key parameter for dictionary field members, lowercased field names with trimmed and combined values, and @signature-params serialized as a structured-field inner list. Unsupported components or parameters, missing fields and duplicate components throw HttpSigError instead of being skipped. contentDigest() emits sha-256 (or sha-512) Content-Digest values; verifyContentDigest() checks sha-256 and sha-512 members. The legacy Signify header scheme in httping.ts and authing.ts is unchanged. Refs WebOfTrust#230 Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Re-signs RFC 9421 test-request with the published B.1.4 Ed25519 key and matches the RFC's signature base and Signature value byte for byte. Also reproduces the §2.4 reqres base, the §2.1 and §2.1.2 field examples, and RFC 9530 digest values, and covers every refusal path. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Verbatim copies of bakobo/fiki vectors/keri/ (branch keri-profile-vectors, keri_vectors_format 1). keripy carries identical copies. The JSON is kept out of prettier so the files stay byte-identical to the generator's. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…tureBase SignedHeaderAuthenticator.verifyHeaders built the legacy base inline. Move that code, unchanged, into httping.ts so the RFC 9421 profile's legacy verifier and the authenticator share one copy. No behaviour change. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…usal codes HttpSigError gains an optional code naming the profile section 9 refusal a failure corresponds to (missing-component, duplicate-component, unsupported-component, malformed-signature-input, malformed-digest), and the order-insensitive component identity used for duplicate detection is exported as componentIdentity. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Add httpsigning.ts: signRequest/signResponse for canonical mode (AID keyid, created, 128-bit nonce, alg ed25519, RFC 8941 byte-sequence Signature, sha-256 Content-Digest), verifyRequest/verifyResponse with legacy/canonical detection, the minimum covered sets, keyid resolution by derivation code through a resolver callback, freshness, and HttpSigRefusal carrying the profile's neutral code with section 9 precedence. Legacy messages verify exactly as SignedHeaderAuthenticator does. Every case in the shared fiki vectors runs: requests, responses and the RFC 9421 B.2.6 example verify and are reproduced byte for byte by the signer, each refusal gets its exact code, and the legacy set still verifies. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…tors do not mode-mismatch and unsupported-signer have no fiki case, so pin them here, along with the unsigned-401 rule, a response signed by an unexpected AID, the @authority policy, the deferred body check, the injectable clock, and the signer's default covered set, nonce and alg. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Add HttpSigAuthenticator, which signs requests and verifies KERIA's
responses under the KERI profile of RFC 9421, and AuthMode.RFC9421 to
select it. In that mode SignifyClient.fetch no longer sends
Signify-Resource or Signify-Timestamp, an unsigned 401 is reported as
unauthenticated, and a refused response is never retried in legacy mode.
createSignedRequest takes an optional { authMode }, defaulting to
canonical only for a client that uses AuthMode.RFC9421, and refuses to
sign canonically for anything but a single-key AID.
The default stays AuthMode.SignedHeaders until a KERIA release verifies
canonical mode.
Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
A mock KERIA verifies each canonical request with verifyRequest and answers in the mode under test, covering: legacy default, opt-in, query and body coverage, no Signify-* headers, mode-mismatch on a legacy reply without fallback, the unsigned-401 rule, a replaced response body, and createSignedRequest in both modes. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…ed body check R4 is now a single effective signer: exactly one current key must satisfy the signing threshold alone (effectiveKeyIndex), so Signify's passcode-rotated state, keys [new, prior-next] with threshold ['1','0'], is accepted and its first key signs. keyStateResolver applies it, and createSignedRequest signs with that key. Legacy mode looks Signify-Resource up through the resolver's optional legacy lookup, which keyStateResolver provides as the first current key with no R4 rule, as KERIA does. A deferred body check is visible: HttpSigVerified carries bodyOwed, verifyRequest and verifyResponse set it when no body is given, and checkBody returns the result with it cleared. checkPolicy refuses, as a caller error, a request set below the minimum, a non-positive maxAge or skew, and requireAuthority without authorities. Authorities compare with :80 and :443 removed. unauthenticated joins the section 9 codes. A response's own Content-Length no longer makes content-digest required, since a HEAD response announces a length it does not send, and a request Content-Length that is not a plain decimal counts as a body. verifyResponse infers the request's mode from its own Signature header, so mode-mismatch holds in both directions by default. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…f37a0 Replaces the five vector files verbatim with keri_vectors_format 2, generated for the profile before its version 1, and updates the provenance README. The harness builds key state from each key's key_state and reduces it through keyStateResolver, checking effective_key rather than trusting it. A null body is handed over as deferred, so bodyOwed is asserted and checkBody completes the check. Case policies supply authorities and the expected response keyid, and the signer skips the requests header's verify_only cases. Every section 9 code now has a case, including both mode-mismatch directions, which fiki does not verify and signify-ts does. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
The five files are verbatim from bakobo/fiki c6ec3b5, the merge of fiki PR WebOfTrust#4. Only the headers differ from 34f37a0: the profile block now names version 1 and its published URL, body_rule states that the request's headers do not count for the response minimum, and keys_rule requires a zero pad byte. No case changed (1, 20, 4, 52 and 4 cases). Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
verifyContentDigest returned a mismatch at the first recognized member that differed, so a malformed member after it was never seen and the field was reported as digest-mismatch instead of malformed-digest. The profile's refusal order puts malformed-digest first, and keripy and fiki (c6ec3b5) parse the whole field before comparing. parseContentDigest and matchContentDigest split the two steps so that a caller holding several digests can parse all of them first. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…alone Profile version 1 §3 settles what "the request had a body" means for the response minimum: the request's content was non-empty. Its headers do not count, since both sides hold the whole request by the time a response is signed or verified. The header rule (Content-Length above zero, or any Transfer-Encoding) stays where it belongs, in the header-time check of a request. signify-ts had read the request's headers as well, so a request whose headers announced a body it did not carry obliged the response to cover "content-digest";req, which keripy and fiki do not. The new tests take a request in each direction: headers announcing an empty body, and a body with no length headers. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
signResponse, verifyResponse and responseComponents now require the request record to carry the content that was sent: empty bytes, '' or null when there was none. A body left undefined, which meant not known, is a caller error rather than a request assumed empty, since an unknown body could silently drop "content-digest";req from the response minimum. This mirrors keripy's refusal of a None or Deferred request body. When a response covers "content-digest";req, the request's Content-Digest is now recomputed over that content, by the verifier and by the signer, as keripy and fiki do. Every covered digest is parsed before any is compared, and the request's is compared at header time even when the response body is deferred. HttpSigAuthenticator.verify passes the exact bytes prepare signed, and refuses a Request it did not prepare instead of treating it as bodiless. The legacy vector responses do not record their request's content; their harness now says empty, which legacy mode ignores. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Profile version 1 §9 places the check that a response is signed by the AID the client expects after malformed-key and before resolution, which is where resolveKeyid already runs it. The test fixes it: a malformed unexpected keyid is malformed-key, and a well-formed unexpected one is unknown-key without its key state ever being consulted, even when that state would be refused under R4. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…ized @path and @query came from WHATWG new URL(), which removes dot segments (%2e included), turns "\" into "/", and re-encodes ' { } and the like. A signature over https://x.example/b therefore verified against https://x.example/a/%2e%2e/b. Profile §2 requires the path as sent, encoded and unnormalized. rawTarget() now splits the path and query out of the URL string itself, for signing and verifying alike. fetch() sends the WHATWG serialization, which a Request's url already is, so HttpSigAuthenticator and createSignedRequest sign what goes on the wire; a test pins that, and signRequest's url documentation says so for direct callers. Legacy mode keeps its WHATWG pathname, unchanged. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
For a relative URL, @authority was the Host header lowercased, with the default port left on, so a request signed over https://api.example/p did not verify at /p with Host api.example:443. The Host branch now uses the same normalizeAuthority as the served-authority comparison (lowercase, :80 and :443 removed, since Host carries no scheme). normalizeAuthority and requestAuthority move to httpsig.ts, and httpsigning's authorityOf is built on them rather than repeating the URL test. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…n question A legacy request is verified and returned before any policy runs, so a verifier with requireAuthority set still accepts legacy requests, which cover no authority. Whether it should refuse them is a question the profile did not yet answer; the behaviour is left as it is, and a TODO marks the spot. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…question A covered @authority is compared with the served authorities only when requireAuthority is set, not when a policy lists @authority in its request set instead. Whether the second should imply the comparison is a question the profile did not yet answer; the behaviour is left as it is, and a TODO marks the spot. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
verifyLegacy called Verfer.verify bare. A secp256k1 key cannot reach it: no Verfer can hold one, and keyStateResolver already refuses such a key as unsupported-algorithm, which a test now pins. But the same call throws a plain TypeError for a signature the key cannot check, such as a 114-byte Ed448 indexed signature under an Ed25519 key, and that escaped as a non-refusal. It is now refused as signature-mismatch: legacy carries no alg to refuse it on earlier, so it is a signature that does not verify (profile §9). Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…eated HttpSigAuthenticator passed its clock's value straight through as created, so a clock returning fractional seconds made every prepare fail, since created is an RFC 9421 Integer. The value is now floored, and the option documents that the clock returns seconds, not milliseconds. Response freshness reads the clock as before. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…st set httpsig.ts now exports one each of what httpsigning.ts had copied: the padding-tolerant Byte Sequence decode (byteSequenceBytes), the absolute-URL test (isAbsoluteUrl, whose third copy went with the @authority fix), and the request-derived component set (HTTPSIG_REQUEST_DERIVED). Callers keep their own refusal codes. No behaviour changes. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
verifyResponse parsed the response's Content-Digest to report a malformed one early, then parsed it again in checkBody when the body was supplied. The parsed digests now go straight to the body stage. checkBody itself is unchanged for callers who defer the body. HttpSigAuthenticator.verify teed the response with clone() to read its body, which buffers it twice. It now reads the body once and returns a Response rebuilt over the same bytes with the same status, status text and headers (null body for 204, 205 and 304, which cannot carry one). The original response is consumed; a caller that catches a refusal no longer has an unread body on it, which nothing here relied on. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Profile 1.1 section 9 makes a well-formed B keyid whose key is a small-order Ed25519 point malformed-key, refused before the signature is checked: under such a key a fixed signature verifies over any message. resolveKeyid now checks the key against the same blocklist as libsodium's has_small_order and fiki (the points of order dividing 8 and the non-canonical y = p and p + 1, sign bit masked). Before, the identity-point keyid in the shared vectors reached the signature check and was refused as signature-mismatch. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Profile 1.1 sections 8 and 9 say a response whose Signature header is present but empty is unsigned, so a 401 carrying one answers a canonical request as unauthenticated and any other status as missing-signature. verifyResponse tested only for an absent header, so an empty one went on to mode detection and was refused as malformed-signature. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
The header-time body test of profile section 3 counts a Content-Length that is not a plain decimal as a body. hasBody trimmed the value with String.prototype.trim, which also strips a no-break space, so "0 " read as zero and a request whose headers announce a body was accepted without a covered content-digest. Only SP and HTAB are trimmed now (RFC 9421 section 2.1), as keripy and fiki do. The shared vectors pin this as refusals:content-length-with-a-no-break-space. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…le 1.1 Profile 1.1 section 8 has a legacy verifier look Signify-Resource up and use that controller's single effective signer under R4: the one current key that satisfies the signing threshold alone. keyStateResolver's legacy lookup took the first current key whatever the threshold said, which let one member of a 2-of-3 group act as the group, and kept a key rotated to weight 0 authenticating. It now applies effectiveKeyIndex, as the canonical lookup does, and refuses a state without a single effective signer as unsupported-signer. For every Signify controller, including after a passcode rotation (threshold ['1','0']), that is still the first key, so the traffic legacy mode exists for keeps verifying. The legacy lookup still never applies section 7 R1's derivation-code rules: Signify-Resource is looked up, never decoded as a key. A resolver without a legacy lookup is used as given, which section 8 allows. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…g it A policy could list @authority in its request set without requireAuthority. A verifier under it required @authority to be covered but never compared the covered value with the authorities it serves, so a request signed for one service replayed to another; profile section 3 says a verifier that requires @authority must compare it. checkPolicy now refuses that policy as a caller error, as keripy's Policy raises ValueError, and points at requireAuthority and authorities. This settles the open question marked earlier on this branch and removes its TODO. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
A legacy request is verified without the canonical policy, so a verifier with requireAuthority still accepts it, though legacy covers no authority. Profile 1.1 section 8 is silent on requireAuthority for legacy traffic and makes accept_legacy the switch that turns legacy off, and keripy's verifyRequest returns a legacy request before its policy runs. This keeps that behaviour, replaces the TODO marked earlier on this branch with a comment citing the profile, and pins it in a test: a verifier that must have @authority compared sets acceptLegacy to false as well. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Re-copies test/vectors/keri-rfc9421/*.json byte for byte from bakobo/fiki e8e553f (tag keri-profile-v1.1), which pins version 1.1 of the profile in keri_vectors_format 7. legacy.json gains four cases fiki generated from controllers with more than one current key: a 2-of-3 group refused as unsupported-signer, a passcode-rotated controller accepted, and a controller with threshold ['0','1'] accepted from its second key and refused from its first. refusals.json gains, among others, the small-order B keyid, the empty Signature on a 401 and the Content-Length with a no-break space, which the preceding commits make pass. The harness checks format 7 and profile "1.1" with its tag URL, and runs each generated legacy case through keyStateResolver's legacy lookup over the case's key_state: it checks the effective key against effective_key and expects the case's error, or acceptance when it has none. The README cites the tag and commit. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Move to the profile's version 1.2 and its shared vectors, copied byte-identical from bakobo/fiki 63821f7 (tag keri-profile-v1.2, keri_vectors_format 8). Legacy mode accepts a signature that verifies under any current key that alone satisfies the signing threshold, so an AID made with two keys under threshold 1, which createSignedRequest signs with its first key, verifies again. keyStateResolver's legacy lookup returns those keys, and a state with none is unsupported-signer. Canonical mode keeps its single effective signer. A B keyid's key, a key resolved from key state, and so an expected AID, must be a point of Ed25519's prime-order subgroup, checked with @noble/curves rather than a small-order blocklist; a mixed-order key is malformed-key. A keyid is an AID under keripy's PreDex codes, Ed448 (1AAD, 1AAE) included, and a B keyid is checked before the expected keyid is compared. Refusals follow the profile's numbered order in section 9. A Decimal created or expires and an empty Signature-Input are malformed-signature-input. Request content no header announced is refused at the body stage, after the signature and freshness checks. A legacy Signature-Input covering a non-String is malformed-signature-input rather than a crash. @authority drops only the default port of the scheme the request was sent with; a Host header keeps its port, is trimmed of SP and HTAB only, and must be a valid authority. Served authorities are compared lowercased, without stripping ports. The verifier's clock must be a finite number and is rounded down to whole seconds. Headers from another realm or a polyfill are read as Headers rather than as an empty record. Comments cite the profile's 1.2 sections, and the module links the tagged profile once. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Replace `export *` of httpsig.ts and httpsigning.ts with the signing and verification entry points, HttpSigError and HttpSigRefusal, the refusal codes and policy constants, keyStateResolver, responseComponents, checkBody, signatureBase, contentDigest and verifyContentDigest, and their argument and result types. The parsing and canonicalization helpers stay module-internal, so they are not a semver commitment. Nothing in signify-ts imported them from the root. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
A covered component such as "bad name" is not an RFC 9110 token, so Headers.get threw a TypeError and the refusal escaped the profile's codes. No Headers can hold such a field, so it is absent, and the request is refused as missing-component, as it already was for headers passed as a plain record. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
The digest table was a plain object, so a Content-Digest member named "constructor" found Object.prototype's constructor and the header was taken to carry a recognized algorithm. It is a Map now, and a header with no sha-256 or sha-512 member is malformed-digest. No other lookup in httpsig.ts or httpsigning.ts is keyed by peer input. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…ssing-component The absent field was compared with the expected AID first, so the response was refused as unknown-key. The profile's legacy order puts missing-component first, as verifyRequest already does. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
…formed-signature The legacy parser accepts kind="RAW" and leaves each member a string, so verification read .raw from a string, threw, and reported signature-mismatch. Mode detection and legacy verification now refuse any member that is not a Siger or Cigar; such a header is neither form of profile section 8 and is malformed-signature, as keripy reports. Signed-off-by: Daniel Hardman <daniel.hardman@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #429 +/- ##
=======================================
Coverage 97.46% 97.46%
=======================================
Files 1 1
Lines 79 79
Branches 28 28
=======================================
Hits 77 77
Misses 2 2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NOTE TO MAINTAINERS: Opened as a draft so it can be referenced. Nothing changes for existing callers. Canonical mode is opt-in, and it only works against a KERIA that has its companion PR (WebOfTrust/keria#473). Same reviewer-brief format as the keripy PR (WebOfTrust/keripy#1769), posted by hand.
Reviewer brief
Asks of you: one API call and one behaviour call.
What it does. Adds
AuthMode.RFC9421, an opt-in canonical mode forSignifyClientandcreateSignedRequest. It signs requests as plain RFC 9421 under the KERI profile of RFC 9421 (https://github.com/bakobo/fiki/blob/keri-profile-v1.2/docs/keri-profile.md). That means committing to the body through RFC 9530Content-Digest, covering@pathand@queryas sent, and verifying that each response is signed by the agent and bound to the request it answers.AuthMode.SignedHeaders, today's scheme, stays the default, and its output is byte-identical to main.API call. The new code is
src/keri/core/httpsig.ts(RFC 9421 signature base and RFC 9530 digests) andsrc/keri/core/httpsigning.ts(the profile's sign and verify). The package root exports a deliberate subset rather thanexport *: the four sign/verify entry points,checkBody,keyStateResolver, the refusal codes and the argument and result types. Is that the surface you want, or would you rather keep it internal until KERIA ships its side?Behaviour call. When
createSignedRequestsigns for a managed AID in canonical mode, it uses the AID's single effective signer: the one key that satisfies the signing threshold on its own. An AID with no such key, such as a 2-of-3 group, can't sign in canonical mode and gets an error at signing time. Legacy mode is unchanged and still signs with the first key. OK?Depends on: nothing to build. To use canonical mode against a real agent, you need KERIA with WebOfTrust/keria#473.
Compatibility: additive. The default mode, ESSR and existing tests are untouched.
@noble/curves, already a dependency, provides the Ed25519 subgroup check.You can skip:
test/vectors/keri-rfc9421/, which are shared conformance vectors copied byte for byte. keripy and KERIA run the same files.Worth reading:
verifyResponseinhttpsigning.ts, and theRFC9421branch of the authenticator inclienting.ts.Full description
In canonical mode the client signs
@method,@authority,@path,@queryand, when there's a body,content-digest, withcreatedand the controller's AID askeyid. It verifies the agent's response over its status, its own content, and the request it answers, so a response can't be replayed as the answer to a different request. A refusal is never retried in legacy mode, because falling back on failure would let anyone in the path force the weaker mode.Verification reports one refusal code per message, in the profile's order. Those are the same codes keripy raises, so a client and a server agree on why a message failed. The vectors pin each code. Several disagreements between this implementation and keripy were found that way and settled in the profile before this PR.
Headersobjects from a polyfill or another realm are read through their methods rather than treated as empty, and header records are read withoutString.trim, so a no-break space isn't stripped where RFC 9421 wouldn't strip it.