#matrix #chat #messaging #ruma #cryptography

ruma-signatures

Digital signatures according to the Matrix specification

9 releases (5 breaking)

✓ Uses Rust 2018 edition

0.6.0-dev.1 Mar 30, 2020
0.5.0 Jul 12, 2019
0.5.0-dev.1 Mar 30, 2020
0.4.2 Apr 12, 2019
0.1.0 Dec 12, 2016

#112 in Cryptography

Download history 13/week @ 2019-12-15 13/week @ 2019-12-22 4/week @ 2019-12-29 6/week @ 2020-01-05 11/week @ 2020-01-12 37/week @ 2020-01-19 2/week @ 2020-01-26 6/week @ 2020-02-02 12/week @ 2020-02-09 12/week @ 2020-02-16 57/week @ 2020-02-23 6/week @ 2020-03-01 23/week @ 2020-03-08 12/week @ 2020-03-15 37/week @ 2020-03-22 35/week @ 2020-03-29

76 downloads per month

MIT license

55KB
849 lines

ruma-signatures

ruma-signatures provides functionality for creating digital signatures according to the Matrix specification.

Documentation

ruma-signatures has comprehensive documentation available on docs.rs.

Minimum Rust version

ruma-client-api is only guaranteed to work on the latest stable version of Rust.

This support policy is inherited from the dependency on ring.

License

MIT


lib.rs:

Crate ruma_signatures implements digital signatures according to the Matrix specification.

Digital signatures are used by Matrix homeservers to verify the authenticity of events in the Matrix system, as well as requests between homeservers for federation. Each homeserver has one or more signing key pairs (sometimes referred to as "verify keys") which it uses to sign all events and federation requests. Matrix clients and other Matrix homeservers can ask the homeserver for its public keys and use those keys to verify the signed data.

Each signing key pair has an identifier, which consists of the name of the digital signature algorithm it uses and a "version" string, separated by a colon. The version is an arbitrary identifier used to distinguish key pairs using the same algorithm from the same homeserver.

Arbitrary JSON objects can be signed as well as JSON representations of Matrix events. In both cases, the signatures are stored within the JSON object itself under a signatures key. Events are also required to contain hashes of their content, which are similarly stored within the hashed JSON object under a hashes key.

In JSON representations, both signatures and hashes appear as Base64-encoded strings, using the standard character set, without padding.

Signing and hashing

To sign an arbitrary JSON object, use the sign_json function. See the documentation of this function for more details and a full example of use.

Signing an event uses a more complicated process than signing arbitrary JSON, because events can be redacted, and signatures need to remain valid even if data is removed from an event later. Homeservers are required to generate hashes of event contents as well as signing events before exchanging them with other homeservers. Although the algorithm for hashing and signing an event is more complicated than for signing arbitrary JSON, the interface to a user of ruma-signatures is the same. To hash and sign an event, use the hash_and_sign_event function. See the documentation of this function for more details and a full example of use.

Verifying signatures and hashes

When a homeserver receives data from another homeserver via the federation, it's necessary to verify the authenticity and integrity of the data by verifying their signatures.

To verify a signature on arbitrary JSON, use the verify_json function. To verify the signatures and hashes on an event, use the verify_event function. See the documentation for these respective functions for more details and full examples of use.

Dependencies

~6.5MB
~200K SLoC