Skip to content

Conversation

@Zil0
Copy link
Contributor

@Zil0 Zil0 commented Jun 13, 2018

We need to know with maximum reliability if a room is encrypted. No crypto stuff in this one.

  • 6f1b4e8 allows to send the state event to enable encryption.
  • 6278d47 allows to handle the encryption enabling state event, which allows to know when encryption gets enabled in a room we are already in.
  • fcb8040 allows to detect if a room we join is already encrypted. This is also triggered during the first sync, when we get the list of rooms we are in. The approach here is probably debatable. (edit: it really is too ugly. Maybe put the check in Room.__init__, and add a check_encryption parameter? In _mkroom we could then write Room(self, room_id, check_encryption=self.encryption). Not implementing this right away because I'm not sure this is the perfect approach either.)

Some of those things won't get triggered on low cache_level. Maybe we should add a warning somewhere?

Also, if encryption is not enabled when instantiating MatrixClient, unencrypted messages are sent to encrypted rooms just like before. Once the encryption has fully landed, maybe this stops being an expected behaviour and should be disabled by default, with some kind of explicit insecure=True flag to enable it.

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

Copy link
Collaborator

@non-Jedi non-Jedi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good in general. :)

elif etype == "m.room.guest_access":
self.guest_access = econtent["guest_access"] == "can_join"
elif etype == "m.room.encryption":
if econtent.get("algorithm") == "m.megolm.v1.aes-sha2":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the e2e implementation guide, we also need to handle events with algorithm = m.olm.v1.curve25519-aes-sha2. Not sure if that's true though, since the section right above about enabling e2e says that only m.megolm.v1.aes-sha2 is permitted. Could you clarify this please?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, i'm surprised the guide says you need to implement both. I'm not aware of any legitimate use for pure olm encryption within a room currently, other than compatibility with ~2016 vintage Matrix E2E. Pure olm is of course used for toDevice messages however.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@non-Jedi I can't find where this would be written in the guide, maybe you confused m.room.encryption and m.room.encrypted?
Olm encrypted events are indeed handled as toDevice events in later parts.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. @Zil0 got it. Exactly what happened. (wish github had a way to mark specific comment chains as resolved rather than just whole reviews...)

content={"messages": messages}
)

def get_encryption_algorithm(self, room_id):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be a generic get_state_event method instead? where URL is just built from event_type?

room = Room(self, room_id)
if self.encryption:
try:
self.api.get_encryption_algorithm(room_id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This technically needs to check whether the room was ever encrypted and whether the algorithm was valid, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, this was really bad.

@Zil0
Copy link
Contributor Author

Zil0 commented Jul 2, 2018

Done

if self._encryption:
try:
event = self.api.get_state_event(room_id, "m.room.encryption")
if event["content"]["algorithm"] == "m.megolm.v1.aes-sha2":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to check that event has a content property, and that event["property"] has an algorithm property (or else handle a KeyError exception), or is there some Python magic going on here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmmh, there are no such checks because this field is required as per https://matrix.org/speculator/spec/drafts%2Fe2e/client_server/unstable.html#id326. The SDK is generally not robust against malformed events, though your concern is still valid, especially considering how weird it is for such a method to potentially raise a KeyError. Maybe @non-Jedi has some thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the rest of the python-sdk does the same thing as this, maybe it's fine to merge as-is.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. In absence of a strong typing system, we assume JSON follows matrix spec. Think this is fine unless the "content" or "algorithm" fields are optional.

@uhoreg uhoreg mentioned this pull request Jul 13, 2018
@non-Jedi non-Jedi merged commit f894889 into matrix-org:master Jul 13, 2018
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.

4 participants