diff --git a/src/crypto/algorithms/megolm.js b/src/crypto/algorithms/megolm.js index c9792b38e..b4a78334a 100644 --- a/src/crypto/algorithms/megolm.js +++ b/src/crypto/algorithms/megolm.js @@ -433,7 +433,15 @@ MegolmEncryption.prototype.reshareKeyWithDevice = async function( } // The chain index of the key we previously sent this device + if (obSessionInfo.sharedWithDevices[userId] === undefined) { + logger.debug("Session ID " + sessionId + " never shared with user " + userId); + return; + } const sentChainIndex = obSessionInfo.sharedWithDevices[userId][device.deviceId]; + if (sentChainIndex === undefined) { + logger.debug("Session ID " + sessionId + " never shared with device " + userId + ":" + device.deviceId); + return; + } // get the key from the inbound session: the outbound one will already // have been ratcheted to the next chain index. diff --git a/src/crypto/index.js b/src/crypto/index.js index 54c6bb16a..7c0ac003a 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -1196,7 +1196,7 @@ Crypto.prototype._onToDeviceBadEncrypted = async function(event) { // We send this first such that, as long as the toDevice messages arrive in the // same order we sent them, the other end will get this first, set up the new session, // then get the keyshare request and send the key over this new session (because it - // it the session it has most recently received a message on). + // is the session it has most recently received a message on). const encryptedContent = { algorithm: olmlib.OLM_ALGORITHM, sender_key: this._olmDevice.deviceCurve25519Key,