From 14cd37ec567d3e6b8e9013d2b16faddca2c3a3a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Mon, 1 Feb 2021 13:47:22 +0100 Subject: [PATCH 1/2] Decrypt redaction events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/crypto/index.js | 22 ++++++++++++++++------ src/models/event.js | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/crypto/index.js b/src/crypto/index.js index 9b4a5bd6eec..8bf42ac75fa 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -57,6 +57,7 @@ import {IllegalMethod} from "./verification/IllegalMethod"; import {KeySignatureUploadError} from "../errors"; import {decryptAES, encryptAES} from './aes'; import {DehydrationManager} from './dehydration'; +import { MatrixEvent } from "../models/event"; const DeviceVerification = DeviceInfo.DeviceVerification; @@ -3028,19 +3029,28 @@ Crypto.prototype.encryptEvent = async function(event, room) { * finished decrypting. Rejects with an `algorithms.DecryptionError` if there * is a problem decrypting the event. */ -Crypto.prototype.decryptEvent = function(event) { +Crypto.prototype.decryptEvent = async function(event) { if (event.isRedacted()) { - return Promise.resolve({ + const redactionEvent = new MatrixEvent(event.getUnsigned().redacted_because); + const content = redactionEvent.getWireContent(); + const alg = this._getRoomDecryptor(event.getRoomId(), content.algorithm); + const decryptedEvent = await alg.decryptEvent(redactionEvent); + + return { clearEvent: { room_id: event.getRoomId(), type: "m.room.message", content: {}, + unsigned: { + redacted_because: decryptedEvent.clearEvent, + }, }, - }); + }; + } else { + const content = event.getWireContent(); + const alg = this._getRoomDecryptor(event.getRoomId(), content.algorithm); + return await alg.decryptEvent(event); } - const content = event.getWireContent(); - const alg = this._getRoomDecryptor(event.getRoomId(), content.algorithm); - return alg.decryptEvent(event); }; /** diff --git a/src/models/event.js b/src/models/event.js index 8a062caefa1..4124df7085b 100644 --- a/src/models/event.js +++ b/src/models/event.js @@ -811,6 +811,24 @@ utils.extend(MatrixEvent.prototype, { return this.getType() === "m.room.redaction"; }, + /** + * Get the (decrypted, if necessary) redaction event JSON + * if event was redacted + * + * @returns {object} The redaction event JSON, or an empty object + */ + getRedactionEvent: function() { + if (!this.isRedacted()) return null; + + if (this._clearEvent.unsigned) { + return this._clearEvent.unsigned.redacted_because; + } else if (this.event.unsigned.redacted_because) { + return this.event.unsigned.redacted_because; + } else { + return {}; + } + }, + /** * Get the push actions, if known, for this event * From 516c4644589c789886f7fa5393bf55d32db51ec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Thu, 4 Feb 2021 16:59:26 +0100 Subject: [PATCH 2/2] Call decryptEvent recursively MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/crypto/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/crypto/index.js b/src/crypto/index.js index 8bf42ac75fa..5c12076c554 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -3032,9 +3032,7 @@ Crypto.prototype.encryptEvent = async function(event, room) { Crypto.prototype.decryptEvent = async function(event) { if (event.isRedacted()) { const redactionEvent = new MatrixEvent(event.getUnsigned().redacted_because); - const content = redactionEvent.getWireContent(); - const alg = this._getRoomDecryptor(event.getRoomId(), content.algorithm); - const decryptedEvent = await alg.decryptEvent(redactionEvent); + const decryptedEvent = await this.decryptEvent(redactionEvent); return { clearEvent: {