encryption: Send the group session key before ratcheting it.

This commit is contained in:
poljar (Damir Jelić) 2018-05-12 11:45:31 +02:00
parent 5f3842e4fa
commit 2bf9766276
2 changed files with 11 additions and 14 deletions

View file

@ -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):

View file

@ -510,19 +510,16 @@ class MatrixServer:
W.prnt("", "matrix: Encrypting message")
payload_dict, session_is_new = self.olm.group_encrypt(
room_id,
plaintext_dict
)
if session_is_new:
to_device_dict = self.olm.share_group_session(
payload_dict, to_device_dict = self.olm.group_encrypt(
room_id,
plaintext_dict,
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(