From 00ae1449974de9164f21bae7ea57fe4a01bad851 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Mon, 20 Jul 2015 10:58:20 +0100 Subject: [PATCH] Don't try to decrypt end-to-end messages if the client doesn't have end-to-end support enabled --- lib/client.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index a2eff6fa1..7c6a2ddb0 100644 --- a/lib/client.js +++ b/lib/client.js @@ -662,6 +662,12 @@ function _sendEncryptedMessage(client, roomId, e2eRoomInfo, eventType, content, } function _decryptMessage(client, event) { + if (client.sessionStore === null) { + // End to end encryption isn't enabled if we don't have a session + // store. + return _badEncryptedMessage(event, "Encryption not enabled"); + } + var content = event.getContent(); if (content.algorithm === OLM_ALGORITHM) { var sender = event.getSender(); @@ -726,12 +732,12 @@ function _decryptMessage(client, event) { user_id: event.getSender() }); } else { - return _badEncryptedMessge(event, "Bad Encrypted Message"); + return _badEncryptedMessage(event, "Bad Encrypted Message"); } } } -function _badEncryptedMessge(event, reason) { +function _badEncryptedMessage(event, reason) { return new MatrixEvent({ type: "m.room.message", // TODO: Add rest of the event keys.