1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +03:00

support for unpacking megolm keys

This is incredibly hacky at the moment, pending the arrival of ephemeral
events, but it kinda works.
This commit is contained in:
Richard van der Hoff
2016-08-19 16:08:43 +01:00
parent e4bfb3ca32
commit 1159e0911f
5 changed files with 93 additions and 15 deletions

View File

@@ -377,14 +377,13 @@ MatrixClient.prototype.isEventSenderVerified = function(event) {
return false;
}
var cryptoContent = event.getWireContent();
var sender_key = cryptoContent.sender_key;
var sender_key = event.getSenderKey();
if (!sender_key) {
return false;
}
var algorithm = cryptoContent.algorithm;
var algorithm = event.getWireContent().algorithm;
return this._crypto.isSenderKeyVerified(
event.getSender(), algorithm, sender_key
@@ -418,6 +417,20 @@ function onCryptoEvent(client, event) {
}
}
/**
* handle a room key event
*
* @private
*
* @param {MatrixEvent} event
*/
MatrixClient.prototype._onRoomKeyEvent = function(event) {
if (!this._crypto) {
return;
}
this._crypto.onRoomKeyEvent(event);
};
/**
* Enable end-to-end encryption for a room.
* @param {string} roomId The room ID to enable encryption in.
@@ -2628,7 +2641,15 @@ function _PojoToMatrixEventMapper(client) {
if (plainOldJsObject.type === "m.room.encrypted") {
clearData = _decryptMessage(client, plainOldJsObject);
}
return new MatrixEvent(plainOldJsObject, clearData);
var matrixEvent = new MatrixEvent(plainOldJsObject, clearData);
// XXXX massive hack to deal with the fact that megolm keys are in the
// room for now, and we need to handle them before attempting to
// decrypt the following megolm messages.
if (matrixEvent.getType() == "m.room_key") {
client._onRoomKeyEvent(matrixEvent);
}
return matrixEvent;
}
return mapper;
}