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

Merge pull request #182 from matrix-org/rav/single_key_message

Put all of the megolm keys in one room message
This commit is contained in:
Richard van der Hoff
2016-08-24 11:48:54 +01:00
committed by GitHub

View File

@@ -87,8 +87,6 @@ MegolmEncryption.prototype._ensureOutboundSession = function(room) {
}); });
var self = this; var self = this;
var txnBase = '' + (new Date().getTime()) + '.';
var txnCtr = 0;
// TODO: we need to give the user a chance to block any devices or users // TODO: we need to give the user a chance to block any devices or users
// before we send them the keys; it's too late to download them here. // before we send them the keys; it's too late to download them here.
@@ -97,7 +95,12 @@ MegolmEncryption.prototype._ensureOutboundSession = function(room) {
).then(function(res) { ).then(function(res) {
return self._crypto.ensureOlmSessionsForUsers(roomMembers); return self._crypto.ensureOlmSessionsForUsers(roomMembers);
}).then(function(devicemap) { }).then(function(devicemap) {
var promises = []; // TODO: send OOB messages. for now, send an in-band message. Each
// encrypted copy of the key takes up about 1K, so we'll only manage
// about 60 copies before we hit the event size limit; but ultimately the
// OOB messaging API will solve that problem for us.
var participantKeys = [];
for (var userId in devicemap) { for (var userId in devicemap) {
if (!devicemap.hasOwnProperty(userId)) { if (!devicemap.hasOwnProperty(userId)) {
continue; continue;
@@ -111,22 +114,18 @@ MegolmEncryption.prototype._ensureOutboundSession = function(room) {
} }
var deviceInfo = devices[deviceId].device; var deviceInfo = devices[deviceId].device;
participantKeys.push(deviceInfo.getIdentityKey());
}
}
var encryptedContent = olmlib.encryptMessageForDevices( var encryptedContent = olmlib.encryptMessageForDevices(
self._deviceId, self._deviceId,
self._olmDevice, self._olmDevice,
[deviceInfo.getIdentityKey()], participantKeys,
payload payload
); );
var txnId = txnBase + (txnCtr++); var txnId = '' + (new Date().getTime());
// TODO: send an OOB message. for now, send an in-band message.
// TODO: aggregate the messages into batches. If we make a
// separate request for each message, we will get rate-limited.
// On the other hand, we can't just send them in one big batch,
// because we'll hit the event size limit.
var path = utils.encodeUri( var path = utils.encodeUri(
"/rooms/$roomId/send/m.room.encrypted/$txnId", { "/rooms/$roomId/send/m.room.encrypted/$txnId", {
$roomId: self._roomId, $roomId: self._roomId,
@@ -135,14 +134,9 @@ MegolmEncryption.prototype._ensureOutboundSession = function(room) {
); );
// TODO: retries // TODO: retries
var promise = self._baseApis._http.authedRequest( return self._baseApis._http.authedRequest(
undefined, "PUT", path, undefined, encryptedContent undefined, "PUT", path, undefined, encryptedContent
); );
promises.push(promise);
}
}
return q.all(promises);
}).then(function() { }).then(function() {
// don't set this until the keys are sent successfully; if we get an // don't set this until the keys are sent successfully; if we get an
// error, the user can restart by resending the message. // error, the user can restart by resending the message.