From 1b77ee0ef43df1b3e9ca5f06e6f4ac4cce2f4716 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 29 Aug 2018 18:06:45 +0100 Subject: [PATCH] Pass through function to discard megolm session To make debugging crypto slightly faster --- src/client.js | 15 +++++++++++++++ src/crypto/algorithms/megolm.js | 11 +++++++++++ src/crypto/index.js | 17 +++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/src/client.js b/src/client.js index 1f3a48130..d345d9a44 100644 --- a/src/client.js +++ b/src/client.js @@ -702,6 +702,21 @@ MatrixClient.prototype.isRoomEncrypted = function(roomId) { return this._roomList.isRoomEncrypted(roomId); }; +/** + * Forces the current outbound group session to be discarded such + * that another one will be created next time an event is sent. + * + * @param roomId The ID of the room to discard the session for + * + * This should not normally be necessary. + */ +MatrixClient.prototype.forceDiscardSession = function(roomId) { + if (!this._crypto) { + throw new Error("End-to-End encryption disabled"); + } + return this._crypto.forceDiscardSession(roomId); +}; + /** * Get a list containing all of the room keys * diff --git a/src/crypto/algorithms/megolm.js b/src/crypto/algorithms/megolm.js index a4eb32ab0..46ae3398e 100644 --- a/src/crypto/algorithms/megolm.js +++ b/src/crypto/algorithms/megolm.js @@ -1,5 +1,6 @@ /* Copyright 2015, 2016 OpenMarket Ltd +Copyright 2018 New Vector Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -496,6 +497,16 @@ MegolmEncryption.prototype.encryptMessage = function(room, eventType, content) { }); }; +/** + * Forces the current outbound group session to be discarded such + * that another one will be created next time an event is sent. + * + * This should not normally be necessary. + */ +MegolmEncryption.prototype.forceDiscardSession = function() { + this._setupPromise = this._setupPromise.then(() => null); +}; + /** * Checks the devices we're about to send to and see if any are entirely * unknown to the user. If so, warn the user, and mark them as known to diff --git a/src/crypto/index.js b/src/crypto/index.js index 4f6dbd24e..a8f4207c1 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -621,6 +621,23 @@ Crypto.prototype.getEventSenderDeviceInfo = function(event) { return device; }; +/** + * Forces the current outbound group session to be discarded such + * that another one will be created next time an event is sent. + * + * @param roomId The ID of the room to discard the session for + * + * This should not normally be necessary. + */ +Crypto.prototype.forceDiscardSession = function(roomId) { + const alg = this._roomEncryptors[roomId]; + if (alg === undefined) throw new Error("Room not encrypted"); + if (alg.forceDiscardSession === undefined) { + throw new Error("Room encryption algorithm doesn't support session discarding"); + } + alg.forceDiscardSession(); +}; + /** * Configure a room to use encryption (ie, save a flag in the sessionstore). *