module

Arcana::Signing

What a project's Key signs to prove an address is its own, and how a signature is checked. Each thing signed is a JSON object, written in Canonical form and tagged with what it is (v), so a signature made for one purpose can't pass for another.

  • Joining over the WebSocket: a client whose join frame carries its public key (key) gets back {"type":"challenge","challenge":C} and answers {"type":"prove","signature":S}, signing join_proof. That proof names the bus it was meant for (the Host the client sent), so another bus can't pass it on.
  • REST: each request carries Arcana-Key, Arcana-Time (Unix seconds), Arcana-Nonce and Arcana-Signature, signing request_proof. A bus refuses a time more than WINDOW off, or a nonce it has seen (Nonces).
  • Envelopes carry their sender's signature to the receiver (Envelope#signed), so it can check the sender itself, without trusting any bus in between (Envelope#signer).

Constants

ENVELOPE = "arcana-envelope-1"
JOIN = "arcana-join-1"
KEY_HEADER = "Arcana-Key"
NONCE_HEADER = "Arcana-Nonce"
REQUEST = "arcana-request-1"
SIGNATURE_HEADER = "Arcana-Signature"
TIME_HEADER = "Arcana-Time"
WINDOW = 60.seconds

How far a signed request's time may be from the bus's clock.

Class methods

challenge

A fresh challenge for a joining client: 32 random bytes, base64.

Source
envelope_proof(envelope : Envelope) : String

What a sender signs for an envelope: everything a bus carries unchanged. Not reply_to, which a bus sets for a request it waits on, nor ordering, which it resolves. The time is in whole Unix seconds, so it reads the same however a timestamp is written.

Source
join_proof(bus : String, address : String, challenge : String) : String

What a client signs to join as address: the bus's challenge, and bus, the Host header it sent (host:port).

Source
request_proof(method : String, bus : String, path : String, time : Int64, nonce : String, body : String | Bytes) : String

What a client signs for a REST request: its method, the bus (its Host header), its path with any query, its time and nonce, and its body's SHA-256 (hex).

Source
sign_request(key : Key, method : String, bus : String, path : String, body : String | Bytes, time : Time = Time.utc) : HTTP::Headers

The headers that sign a REST request with key. They include Host, set to bus, so the header sent is the one signed.

Source
signed_request(headers : HTTP::Headers, method : String, bus : String, path : String, body : String | Bytes, now : Time = Time.utc, window : Time::Span = WINDOW) : SignedRequest | Nil

A signed request's key, time and nonce, once its signature checks and its time is within window of now; nil when it isn't signed, and raises Error saying why when it's signed wrongly. The nonce is the caller's to check (Nonces#fresh?).

Source

Nested types