Skip to content

Conversation

@Zil0
Copy link
Contributor

@Zil0 Zil0 commented Jul 30, 2018

Penultimate missing feature.

This was unexpectedly complicated to implement, as it required small changes everywhere and as the logic behind the few checks that get added is not trivial.

Some notes about the design:
- Since the SDK is mainly used by bots, device verification is disabled by default (enabling it is as painless as passing verify_devices=True when instantiating MatrixClient, though).
- Unlike in the JS SDK, there is no Event class. This means that one cannot use something like event.isVerified() after getting an event from the SDK in order to know if they should treat an event as trusted.
It could be tempting to infer that an event is trusted from the fact that it is sent in an encrypted room and that it comes from a verified device. However this would be broken because, as the decryption of events is transparent, an event received in a encrypted room could very well be unencrypted, thus not trusted.
There are a lot of possible tricks to work around this limitation. The less hacky one felt like adding a VerifiedEvent dict subclass. In order to check if an event is verified, one has to import it from matrix_client.crypto.verified_event, and add the check if isinstance(event, VerifiedEvent): .... Not perfect, but at least readable.

In order to verify or blacklist a device, it is possible to do one of the following:
- From a User object, use the devices property to get a map from device ID to Device object. Then, display the ed25519 property (the fingerprint) of a device, and turn on the blacklisted or verified property accordingly.
- When sending a message in an encrypted room where device verification in enabled, the exception E2EUnknownDevices defined in errors.py will be raised if there are new unknown devices. One can inspect the user_devices property of this exception, and will find a map from user ID to a list of Device objects. For each of those device, one of the previous properties should be set in order to be able to successfully send the message. Note that there is also an ignored property of a Device object that can be turned on, in order to send a message anyway to unverified devices.

Currently, it is impossible to verify the devices of a user if we do not share an encrypted room with them.

Signed-off-by: Valentin Deniaud <valentin.deniaud@inpt.fr>

Zil0 added 30 commits October 18, 2018 21:59
Use a thread to allow downloading the keys in a non-blocking way.
Implement sort of a queue of users who need updating, which should be
efficient (request is fired as soon as possible with as much data as
possible) and avoid races (we always have only one download in
progress).
This has the effect of tracking the device lists of users proactively.
Since device tracking is done in a separate thread, we need to be
careful not to use the same connection object between threads (in
fact the problem existed since the first persistence commit when using
MatrixClient.start_listener_thread).
@non-Jedi non-Jedi closed this Dec 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants