fiki (Rust)
The Rust implementation of fiki. Requires Rust 1.75 or newer.
Dependencies, and why this port has some
The Go and JavaScript ports have none. This one cannot: Rust's standard library has no cryptography at all, so Ed25519 and SHA-2 have to come from somewhere. It takes ed25519-dalek, sha2, and rand_core, and nothing else — the RFC 8941 subset is still hand-rolled in src/sfv.rs, base64 is thirty lines in src/keys.rs rather than a fourth crate, and the base58btc decoder aid_from needs is hand-written in src/formats.rs for the same reason.
That asymmetry is recorded in this.i @2tt6fmc0 rather than left for a reader who expected fiki's zero-dependency claim to be universal.
Signing a request
let key = from_seed?; // or Key::generate()
println!; // register this once with whoever you call
let headers = sign_request?;
By default the signature binds the method, the host, the path, the query string, and a digest of the body. Pass the body wherever you pass the URL: fiki covers a body it is given, or refuses to sign — but it cannot cover one it never sees.
Verifying a request
let verdict = verify_request?;
max_age is a decision the caller states one way or the other: MaxAge::seconds(n) for that many seconds of tolerance, or MaxAge::Unchecked to decline. Left at MaxAge::Unstated, which is what ..Default::default() gives it, verify_request and verify_response refuse the call as Kind::InvalidArgument. Both defaults would be wrong — a number guesses at somebody else's clock skew and replay window, and skipping the check silently is the thing the field exists to prevent. An expires the signer declared is enforced either way. A MaxAge::Seconds or skew you do give must be positive; zero or less is Kind::InvalidArgument. skew: None takes DEFAULT_SKEW, five seconds.
authorities is a decision of the same kind, and is checked when verify_request runs because ..Default::default() cannot make a field mandatory: Authorities::served([...]) names the hosts this verifier answers for, Authorities::Unchecked declines the check, and leaving it Unstated is Kind::InvalidArgument. minimum defaults to Minimum::Default, which applies DEFAULT_MINIMUM (method, authority, path and query, plus the body's digest whenever there is a body, with created and keyid required); Minimum::Off is the explicit opt-out and Minimum::of(..) a minimum of your own, no smaller than REQUEST_MINIMUM: Minimum::of(REQUEST_MINIMUM) is the KERI profile's.
headers holds one string per field name. A field your framework hands over as several lines, as an http::HeaderMap does through get_all, is joined with ", " (a comma and one space) before the call, set-cookie included: that is the value RFC 9421 section 2.1 signs, and what fiki-py and fiki-js do with a list (this.i @4un2vx4l).
verdict.keyid is the keyid exactly as it appeared on the wire, or None when the signature had none. verdict.aid is the identity that vouched for the key: the AID of a raw key, the keyid a resolver vouched for, or the AID of expected_aid.
Other spellings of a key
aid_from converts a public key given as raw base64url (a JWK's x), a base58btc did:key, a did:peer:0, or an ssh-ed25519 line into the AID to register, and Key::from_openssh signs with an unencrypted OpenSSH private key (this.i @0mvgkwnl). Call aid_from when you load registrations rather than per request. Both refuse anything ambiguous as Kind::MalformedKey, with no detail and a message that never quotes the input, since what is passed by mistake can be a private key; the user guide lists what that covers.
let aid = aid_from?;
let key = from_openssh?;
The crate runs every case under vectors/keys/ and satisfies key_vectors_format 1, exported as KEY_VECTORS_FORMAT beside VECTORS_FORMAT and KERI_VECTORS_FORMAT.
Responses, KERI identifiers, and resolvers
The crate implements the KERI profile of RFC 9421 and runs every file under vectors/keri/. That adds sign_response and verify_response, whose expected_keyid (ExpectedKeyid::is(aid) or ExpectedKeyid::Unchecked) is a required decision; a caller-chosen keyid on SignOptions; a Resolver for keyids that are not keys, such as a transferable KERI AID, which is authoritative; and the profile's minimum covered sets, REQUEST_MINIMUM and RESPONSE_MINIMUM. The user guide shows each in Rust, and cargo run --example guide runs every Rust sample in it.
What fiki refuses before it reads anything
Signature, Signature-Input and Content-Digest are each read only up to MAX_FIELD_BYTES (8192 bytes), measured before parsing, and only up to MAX_DICTIONARY_MEMBERS (16) members, MAX_INNER_LIST_ITEMS (64) items in an inner list, and MAX_PARAMETERS (16) parameters on an item. A header over any of them is that header's malformed kind. A URL whose port is not a number from 0 to 65535 is a SignatureMismatch when a covered component needs it, because no signature base can be built from it.
Mistakes in a call are Kind::InvalidArgument rather than a refusal of the message (this.i @5zrf8gjk, @2n99rej7): a method that is not an HTTP token, a bad port when signing, a label that is not an RFC 8941 key, a keyid, nonce or tag outside printable ASCII, a component name that is not a field name, a created or expires outside 0 to 999999999999999, and a supplied Content-Digest the body does not match.
Two things measured rather than assumed
Key's Debug prints the AID and nothing else, so a seed cannot reach a log line by way of a derived impl.
A public key is refused as MalformedKey before any signature is checked unless it is the canonical encoding of an on-curve point of large order — whether it arrives as an AID, a keyid, or from a resolver (this.i @2t8xctts, @34qlc8r3). That is measured rather than inherited from ed25519-dalek 2.x, whose VerifyingKey::from_bytes reduces a y at or above the field prime and so accepts a second spelling of some keys, and accepts small-order points under which a signature proves nothing about who made it; tests/profile.rs pins every class on every path.