Skip to main content

Module linked_data

Module linked_data 

Source
Expand description

Linked Data Signatures: RsaSignature2017, as Mastodon makes and checks them (ActivityPub::LinkedDataSignature).

The signature sits in the document it signs, under signature, and covers two SHA-256 hashes: one of the signature’s own options (creator, created, expires) read against the identity context, and one of the document without its signature. Each hash is of the canonical N-Quads of what the JSON-LD means ([ojak_jsonld::rdf]), so a server that passes the document on — a relay, or a server forwarding a reply — cannot change what it says without the signature failing, while the signature still says who wrote it.

That cuts both ways. What verifies is the graph, not the tree: a document can be rewritten into one that reads differently to a reader of JSON keys and still verify. A caller that takes a document on the strength of this signature should read it as JSON-LD processing gives it, not as it was written; ojak’s inbox does.

Structs§

Signed
An RsaSignature2017 read and hashed, its key not yet tried.

Constants§

DEFAULT_LIFETIME_SECONDS
How long Mastodon’s signatures last.
IDENTITY_CONTEXT
What the signature’s options are read against.
RSA_SIGNATURE_2017
The one Linked Data Signature suite the fediverse uses.
SECURITY_CONTEXT
What a signed document’s @context gains, so that signature means something to a JSON-LD reader.

Functions§

creator
The key an RsaSignature2017 on document says made it: its creator.
sign
Sign document as key_id, which private_key is the key of: the document with an RsaSignature2017 made at created and good until expires (Unix seconds), and the security context added to its @context, as ActivityPub::LinkedDataSignature#sign! gives it.
verify
Check the RsaSignature2017 on document against public_key_pem, the key its creator names, at now (Unix seconds).