Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/verification-workers/src/index-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ const generateHTML = (status?: boolean) => `<!DOCTYPE html>
HTTP Message Signatures are a mechanism to create, encode, and verify signatures over components of an HTTP message.
They are standardised by the IETF in <a href="https://datatracker.ietf.org/doc/html/rfc9421">RFC 9421</a>.

This website validates the presence of such signature as defined in <a href="https://github.com/thibmeu/http-message-signatures-directory">draft-meunier-webbotauth-httpsig-protocol</a>.
This website validates the presence of such signature as defined in <a href="https://datatracker.ietf.org/doc/draft-ietf-webbotauth-httpsig-protocol/">draft-ietf-webbotauth-httpsig-protocol</a>.
It accepts the dictionary form of the Signature-Agent header, and the legacy string form for migration.
</p>
<p>
This website checks for an Ed25519 signature on incoming request. They should be signed by a test public key defined in <a href="https://datatracker.ietf.org/doc/html/rfc9421#name-example-ed25519-test-key">Appendix B.1.4 of RFC 9421</a>.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"name": "dictionary Signature-Agent (E.2.1)",
"signature_agent": "sig2=\"https://signature-agent.test\"",
"signature_input": "sig2=(\"@authority\" \"signature-agent\";key=\"sig2\");created=1735689600;keyid=\"poqkLGiymh_W0uP6PZFw-dvez3QJT5SolqXBCW38r0U\";alg=\"ed25519\";expires=4889289600;nonce=\"n9p433xm+NJ3ph3upfBIGmsuwHw387YV7Q/F+6BSpGCVjYCqQw6rznNA8PVVLySrAWsv0hQtFioQb6E1YsauiA==\";tag=\"web-bot-auth\"",
"signature": "sig2=:CGokAoY/FrPpyuzTe1Fb2kLTAH9Idw6qSFd1+D77r1firsMRCxeuLu5e6O+ek3zQgDMAzjiXtLVfqE00xnABCQ==:"
},
{
"name": "legacy Signature-Agent (E.2.2)",
"signature_agent": "\"https://signature-agent.test\"",
"signature_input": "sig2=(\"@authority\" \"signature-agent\");created=1735689600;keyid=\"poqkLGiymh_W0uP6PZFw-dvez3QJT5SolqXBCW38r0U\";alg=\"ed25519\";expires=1735693200;nonce=\"e8N7S2MFd/qrd6T2R3tdfAuuANngKI7LFtKYI/vowzk4lAZYadIX6wW25MwG7DCT9RUKAJ0qVkU0mEeLElW1qg==\";tag=\"web-bot-auth\"",
"signature": "sig2=:jdq0SqOwHdyHr9+r5jw3iYZH6aNGKijYp/EstF4RQTQdi5N5YYKrD+mCT1HA1nZDsi6nJKuHxUi/5Syp3rLWBA==:"
}
]
35 changes: 35 additions & 0 deletions examples/verification-workers/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { sign } from "web-bot-auth";
import { signerFromJWK } from "web-bot-auth/crypto";
import worker from "../src/index";
import jwk from "../../rfc9421-keys/ed25519.json" with { type: "json" };
import draftVectors from "./draft-ietf-webbotauth-httpsig-protocol-01.json" with { type: "json" };

// For now, you'll need to do something like this to get a correctly-typed
// `Request` to pass to `worker.fetch()`.
Expand Down Expand Up @@ -73,6 +74,7 @@ async function fetchValidator(body: Record<string, string>): Promise<Response> {
afterEach(() => {
vi.unstubAllGlobals();
vi.restoreAllMocks();
vi.useRealTimers();
});

describe("/ endpoint", () => {
Expand Down Expand Up @@ -273,6 +275,39 @@ describe("/v0/api/verify endpoint", () => {
);
});

// Ed25519 vectors from draft-ietf-webbotauth-httpsig-protocol-01,
// Appendix E.2.1 (dictionary Signature-Agent) and E.2.2 (legacy sf-string).
// They are signed outside this repo, so they catch a signature base that
// sign() and verify() would otherwise agree on.
it.each(draftVectors)("accepts the draft $name vector", async (vector) => {
vi.useFakeTimers({ toFake: ["Date"] });
vi.setSystemTime(new Date("2025-01-01T00:01:00Z"));
const uri =
"https://signature-agent.test/.well-known/http-message-signatures-directory";
const directory = await worker.fetch(
new IncomingRequest(uri),
env,
createExecutionContext()
);
const fetch = vi.fn(async () => directory.clone());
vi.stubGlobal("fetch", fetch);

const request = new IncomingRequest(`${sampleURL}/v0/api/verify`, {
headers: {
"Signature-Agent": vector.signature_agent,
"Signature-Input": vector.signature_input,
Signature: vector.signature,
},
});
const response = await worker.fetch(request, env, createExecutionContext());

expect(await response.text()).toBe("valid");
expect(fetch).toHaveBeenCalledWith(
uri,
expect.objectContaining({ redirect: "manual" })
);
});

it("rejects a well-known JWK whose kid is not its thumbprint", async () => {
const uri = `${signatureAgentOrigin}/.well-known/http-message-signatures-directory`;
const request = new IncomingRequest(`${sampleURL}/v0/api/verify`, {
Expand Down