From 2bf9766276a3d26d41b1ff61e4e35fd541771eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?poljar=20=28Damir=20Jeli=C4=87=29?= Date: Sat, 12 May 2018 11:45:31 +0200 Subject: [PATCH] encryption: Send the group session key before ratcheting it. --- matrix/encryption.py | 10 +++++----- matrix/server.py | 15 ++++++--------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/matrix/encryption.py b/matrix/encryption.py index 0663b2f..ea731d0 100644 --- a/matrix/encryption.py +++ b/matrix/encryption.py @@ -313,14 +313,14 @@ class Olm(): except OlmSessionError: return None - def group_encrypt(self, room_id, plaintext_dict): - # type: (str, Dict[str, str]) -> Dict[str, str], Bool - is_new = False + def group_encrypt(self, room_id, plaintext_dict, own_id, users): + # type: (str, Dict[str, str]) -> Dict[str, str], Optional[Dict[Any, Any]] plaintext_dict["room_id"] = room_id + to_device_dict = None if room_id not in self.outbound_group_sessions: self.create_outbound_group_session(room_id) - is_new = True + to_device_dict = self.share_group_session(room_id, own_id, users) session = self.outbound_group_sessions[room_id] @@ -334,7 +334,7 @@ class Olm(): "device_id": self.device_id } - return payload_dict, is_new + return payload_dict, to_device_dict @encrypt_enabled def group_decrypt(self, room_id, session_id, ciphertext): diff --git a/matrix/server.py b/matrix/server.py index 21918e4..897e89f 100644 --- a/matrix/server.py +++ b/matrix/server.py @@ -510,19 +510,16 @@ class MatrixServer: W.prnt("", "matrix: Encrypting message") - payload_dict, session_is_new = self.olm.group_encrypt( + payload_dict, to_device_dict = self.olm.group_encrypt( room_id, - plaintext_dict + plaintext_dict, + self.user_id, + room.users.keys() ) - if session_is_new: - to_device_dict = self.olm.share_group_session( - room_id, - self.user_id, - room.users.keys() - ) - message = MatrixToDeviceMessage(self.client, to_device_dict) + if to_device_dict: W.prnt("", "matrix: Megolm session missing for room.") + message = MatrixToDeviceMessage(self.client, to_device_dict) self.send_queue.append(message) message = MatrixEncryptedMessage(