From 2894e253a2085a163e1644c64b3f7fead8d9dab6 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Thu, 10 Aug 2017 15:01:56 +0100 Subject: [PATCH] Make OlmDevice.addInboundGroupSession async --- src/crypto/OlmDevice.js | 2 +- src/crypto/algorithms/megolm.js | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/crypto/OlmDevice.js b/src/crypto/OlmDevice.js index 6594106d6..4f292d4c5 100644 --- a/src/crypto/OlmDevice.js +++ b/src/crypto/OlmDevice.js @@ -686,7 +686,7 @@ OlmDevice.prototype._getInboundGroupSession = function( * @param {boolean} exportFormat true if the megolm keys are in export format * (ie, they lack an ed25519 signature) */ -OlmDevice.prototype.addInboundGroupSession = function( +OlmDevice.prototype.addInboundGroupSession = async function( roomId, senderKey, forwardingCurve25519KeyChain, sessionId, sessionKey, keysClaimed, exportFormat, diff --git a/src/crypto/algorithms/megolm.js b/src/crypto/algorithms/megolm.js index 0ba1e2dec..66fddeefe 100644 --- a/src/crypto/algorithms/megolm.js +++ b/src/crypto/algorithms/megolm.js @@ -249,7 +249,7 @@ MegolmEncryption.prototype._prepareNewSession = async function() { const sessionId = this._olmDevice.createOutboundGroupSession(); const key = this._olmDevice.getOutboundGroupSessionKey(sessionId); - this._olmDevice.addInboundGroupSession( + await this._olmDevice.addInboundGroupSession( this._roomId, this._olmDevice.deviceCurve25519Key, [], sessionId, key.key, {ed25519: this._olmDevice.deviceEd25519Key}, ); @@ -706,18 +706,20 @@ MegolmDecryption.prototype.onRoomKeyEvent = function(event) { content.room_id, senderKey, forwardingKeyChain, sessionId, content.session_key, keysClaimed, exportFormat, - ); + ).then(() => { + // cancel any outstanding room key requests for this session + this._crypto.cancelRoomKeyRequest({ + algorithm: content.algorithm, + room_id: content.room_id, + session_id: content.session_id, + sender_key: senderKey, + }); - // cancel any outstanding room key requests for this session - this._crypto.cancelRoomKeyRequest({ - algorithm: content.algorithm, - room_id: content.room_id, - session_id: content.session_id, - sender_key: senderKey, + // have another go at decrypting events sent with this session. + this._retryDecryption(senderKey, sessionId); + }).catch((e) => { + console.error(`Error handling m.room_key_event: ${e}`); }); - - // have another go at decrypting events sent with this session. - this._retryDecryption(senderKey, sessionId); }; /**