Skip to main content

HTTP Message Signatures (RFC 9421)

HTTP APIs that accept RFC 9421 request signatures, with the caller choosing the signature label, covered components, and an HMAC-SHA256 or RSA PKCS#1 v1.5 SHA-256 credential.

RFC 9421 HMAC-SHA256RFC 9421 RSASSA-PKCS1-v1_5 SHA-256✓ header signing— query / presign✓ WASMdocs.rs/reqsign-http-message-signatures ↗

Adds Signature-Input and Signature request headers. The caller supplies any Content-Digest. expires_in adds a checked expires parameter; it does not select query authentication.

Get started​

cargo add reqsign --features http-message-signatures

RFC 9421 leaves the signature label and covered components to the application, so there is no default signer. Assemble the policy explicitly:

use http::header::HeaderName;
use reqsign::http_message_signatures::{
Component, Credential, RequestSigner, StaticCredentialProvider,
};
use reqsign::{Signer, default_context};

let ctx = default_context();
let request_signer = RequestSigner::new(
"sig1",
[
Component::Method,
Component::Authority,
Component::Path,
Component::Header(HeaderName::from_static("content-digest")),
],
)?;
let signer = Signer::new(
ctx,
StaticCredentialProvider::new(Credential::hmac_sha256("my-key", b"shared secret")?),
request_signer,
);

let mut parts = http::Request::builder()
.method("POST")
.uri("https://example.com/upload?part=1")
.header("content-digest", "sha-256=:...:")
.body(())?
.into_parts()
.0;

signer.sign(&mut parts, None).await?;

Scope​

This first version signs request heads with HMAC-SHA256 or RSASSA-PKCS1-v1_5 SHA-256. It supports ordinary request fields and the @method, @target-uri, @authority, @scheme, @path, and @query derived components. Percent escapes, query order, and repeated query parameters are preserved.

The signer requires an absolute HTTP or HTTPS URI. @target-uri is rebuilt from the scheme, the authority exactly as written, and the origin-form path/query, with an empty path normalized to /. A present Host header must be unique and byte-identical to the URI authority; case-only or explicit/default-port differences are rejected because an HTTP/1.1 origin-form receiver could reconstruct a different target URI. Origin-form request targets without an absolute URI are not supported.

Verification, response signing, multiple signatures in one call, component parameters, @request-target, and body I/O are out of scope. To cover a body, compute a Content-Digest before signing and include it in the component list.

HMAC uses raw shared-key bytes. RSA accepts unencrypted PKCS#1 or PKCS#8 PEM and uses the context's CryptoProvider. The RustCrypto provider supports RSA on native targets but returns ConfigInvalid for it on wasm32-unknown-unknown. The HMAC path runs on wasm32-unknown-unknown when hosted by a JavaScript runtime through wasm-bindgen, such as a browser or Node. Jiff reads the clock from that host; a bare WASM runtime without a JavaScript clock is unsupported.

Credentials

Default credential chain

The default signer tries these sources in order and uses the first one that yields a credential — no configuration needed when any of them is present:

  1. Caller-supplied HMAC or RSA credential

Credential providers

Available ProvideCredential implementations. Construct any of them directly, reorder them, or compose them into your own chain — see Loading credentials: