Expand description
Dual-stack HTTP message signatures for ActivityPub.
Provides signing and verification for both:
- Cavage draft-12 — the de-facto Fediverse standard (Mastodon, Pleroma, Lemmy, Misskey, …)
- RFC 9421 — the finalized IETF HTTP Message Signatures standard (Mastodon 4.5+ accepts both)
Algorithms supported out of the box:
rsa-sha256(2048–8192-bit modulus) — legacy main-key format, required for interop with current Mastodon;RsaBitsexposes the conventional 2048 and 4096 presets for generation, andRsaSigningKey::from_pkcs8_deraccepts any byte-aligned width in the full rangeed25519— FEP-521a Multikey, recommended for new deployments
All cryptographic primitives are backed by aws-lc-rs, a memory-safe,
constant-time, FIPS 140-3 validated library maintained by AWS. This crate
is therefore not affected by RUSTSEC-2023-0071 (Marvin Attack) that
impacts the pure-Rust rsa crate.
The crate is HTTP-framework agnostic: it operates on http::Request
values and leaves transport to the caller.
§Example — Cavage signing
let key = SigningKey::generate_ed25519();
let body: Vec<u8> = br#"{"type":"Follow"}"#.to_vec();
let mut req = Request::builder()
.method(Method::POST)
.uri("https://example.com/inbox")
.header("host", "example.com")
.header("date", "Sun, 05 Jan 2014 21:31:40 GMT")
.header("digest", sha256_digest_header(&body))
.header("content-type", "application/activity+json")
.body(body)
.unwrap();
let signer = CavageSigner::new(&key, "https://example.com/users/alice#main-key");
signer.sign(&mut req).unwrap();
assert!(req.headers().contains_key("signature"));Structs§
- Cavage
Header Params - Parsed
Signature:header parameters. - Cavage
Header Set - Which headers to include in the signature base string, in order.
- Cavage
Signer - A request signer that attaches a Cavage
Signature:header to anhttp::Request. - Cavage
Verified - Successful verification report.
- Ed25519
Public Key - A verifying half of an Ed25519 key pair.
- Ed25519
Signing Key - An Ed25519 key pair capable of producing signatures.
- Multikey
- A FEP-521a Multikey, pairing the decoded
VerifyingKeywith the original base58-btc encoded string. - Rfc9421
Signer - A request signer that produces RFC 9421
Signature-Input:andSignature:headers. - Rfc9421
Verified - Successful RFC 9421 verification report.
- RsaPublic
Key - The verifying half of an RSA key pair.
- RsaSigning
Key - An RSA key pair capable of producing PKCS#1 v1.5 SHA-256 signatures.
- Signature
Input - One entry of the
Signature-Input:dictionary: the ordered component list plus parameters. - Verify
Policy - Tunables governing which signed requests are accepted at verification time.
Enums§
- Algorithm
- Algorithm identifier for a signing / verifying key.
- Component
- A single component in an RFC 9421 signature base.
- Digest
Algorithm - A hash algorithm registered with the IANA Hash Algorithm Names
registry and accepted by RFC 9530
Content-Digest. - Error
- Enumeration of every failure mode that this crate can surface.
- RsaBits
- Supported RSA key sizes. Fediverse actors use 2048 by default; Mastodon allows 4096 and other implementations occasionally go higher.
- Signing
Key - A key capable of producing detached signatures.
- Verified
- Report summarising a successful verification.
- Verifying
Key - A key capable of verifying detached signatures.
Constants§
- CAVAGE_
REQUIRED_ HEADERS - Minimum Cavage header set every compliant verifier should enforce.
- CONTENT_
DIGEST_ HEADER - Name of the
Content-Digest:HTTP header. - DEFAULT_
HEADER_ SET - The default header set signed on outbound POST requests.
- REDACTED_
HEADERS_ DEFAULT - Headers whose values
Verified::signature_base_redactedreplaces with a placeholder. - RFC9421_
DEFAULT_ COMPONENTS - Default component sequence emitted by
Rfc9421Signer::new. - RFC9421_
REQUIRED_ COMPONENTS - Minimum RFC 9421 covered-component set every compliant verifier should enforce for POST requests.
- SHA256_
DIGEST_ PREFIX - Prefix emitted in the legacy
Digest:header for SHA-256. - SIGNATURE_
HEADER - Name of the
Signature:HTTP header. - SIGNATURE_
INPUT_ HEADER - Name of the
Signature-Input:HTTP header.
Functions§
- cavage_
verify - Verifies a Cavage-signed request against a key returned by
resolve_key(key_id). - cavage_
verify_ with_ policy - Verifies a Cavage-signed request with replay-protection.
- content_
digest_ header - Computes the conventional Mastodon-compatible single-algorithm
Content-Digest:value carrying only asha-256entry. - content_
digest_ header_ with - Computes a multi-algorithm
Content-Digest:value carrying one dictionary entry per requested algorithm, in the order they are supplied. - parse_
signature_ dict - Parses the raw
Signature:header into an ordered list of(label, signature-bytes)pairs. - parse_
signature_ input_ dict - Parses the raw
Signature-Input:header into a sequence of (label,SignatureInput) pairs, preserving insertion order. - rfc9421_
verify - Verifies an RFC 9421-signed request against a key returned by
resolve_key(key_id). - rfc9421_
verify_ with_ policy - Verifies an RFC 9421-signed request with replay-protection.
- serialise_
signature_ dict - Serialises a list of
(label, bytes)pairs into aSignature:-compatible value. - serialise_
signature_ input_ dict - Serialises a
(label, SignatureInput)sequence into a single header value suitable for inserting into anhttp::Request. - sha256_
digest_ header - Computes the legacy
Digest:header value forbody. - verify
- Verifies a signed HTTP request, autodetecting the signature flavour.
- verify_
any_ content_ digest_ header - Verifies that the
Content-Digest:header carries at least one matching entry across the supplied accepted algorithms. - verify_
content_ digest_ header - Verifies that the
Content-Digest:header carries asha-256entry matchingbody. - verify_
digest_ header - Verifies that the
Digest:header value matches the computed digest ofbody. - verify_
with_ policy - Verifies a signed HTTP request with replay-protection, picking the correct flavour automatically.