You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Merge branch 'matthew/warn-unknown-devices' into matthew/blacklist-unverified
This commit is contained in:
@@ -57,7 +57,7 @@ function OutboundSessionInfo(sessionId) {
|
||||
* @return {Boolean}
|
||||
*/
|
||||
OutboundSessionInfo.prototype.needsRotation = function(
|
||||
rotationPeriodMsgs, rotationPeriodMs
|
||||
rotationPeriodMsgs, rotationPeriodMs,
|
||||
) {
|
||||
const sessionLifetime = new Date().getTime() - this.creationTime;
|
||||
|
||||
@@ -66,7 +66,7 @@ OutboundSessionInfo.prototype.needsRotation = function(
|
||||
) {
|
||||
console.log(
|
||||
"Rotating megolm session after " + this.useCount +
|
||||
" messages, " + sessionLifetime + "ms"
|
||||
" messages, " + sessionLifetime + "ms",
|
||||
);
|
||||
return true;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ OutboundSessionInfo.prototype.needsRotation = function(
|
||||
* in devicesInRoom.
|
||||
*/
|
||||
OutboundSessionInfo.prototype.sharedWithTooManyDevices = function(
|
||||
devicesInRoom
|
||||
devicesInRoom,
|
||||
) {
|
||||
for (const userId in this.sharedWithDevices) {
|
||||
if (!this.sharedWithDevices.hasOwnProperty(userId)) {
|
||||
@@ -106,7 +106,7 @@ OutboundSessionInfo.prototype.sharedWithTooManyDevices = function(
|
||||
if (!devicesInRoom[userId].hasOwnProperty(deviceId)) {
|
||||
console.log(
|
||||
"Starting new session because we shared with " +
|
||||
userId + ":" + deviceId
|
||||
userId + ":" + deviceId,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
@@ -220,7 +220,7 @@ MegolmEncryption.prototype._ensureOutboundSession = function(devicesInRoom) {
|
||||
}
|
||||
|
||||
return self._shareKeyWithDevices(
|
||||
session, shareMap
|
||||
session, shareMap,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ MegolmEncryption.prototype._prepareNewSession = function() {
|
||||
|
||||
this._olmDevice.addInboundGroupSession(
|
||||
this._roomId, this._olmDevice.deviceCurve25519Key, session_id,
|
||||
key.key, {ed25519: this._olmDevice.deviceEd25519Key}
|
||||
key.key, {ed25519: this._olmDevice.deviceEd25519Key},
|
||||
);
|
||||
|
||||
return new OutboundSessionInfo(session_id);
|
||||
@@ -285,7 +285,7 @@ MegolmEncryption.prototype._shareKeyWithDevices = function(session, devicesByUse
|
||||
const contentMap = {};
|
||||
|
||||
return olmlib.ensureOlmSessionsForDevices(
|
||||
this._olmDevice, this._baseApis, devicesByUser
|
||||
this._olmDevice, this._baseApis, devicesByUser,
|
||||
).then(function(devicemap) {
|
||||
let haveTargets = false;
|
||||
|
||||
@@ -318,7 +318,7 @@ MegolmEncryption.prototype._shareKeyWithDevices = function(session, devicesByUse
|
||||
}
|
||||
|
||||
console.log(
|
||||
"sharing keys with device " + userId + ":" + deviceId
|
||||
"sharing keys with device " + userId + ":" + deviceId,
|
||||
);
|
||||
|
||||
const encryptedContent = {
|
||||
@@ -334,7 +334,7 @@ MegolmEncryption.prototype._shareKeyWithDevices = function(session, devicesByUse
|
||||
self._olmDevice,
|
||||
userId,
|
||||
deviceInfo,
|
||||
payload
|
||||
payload,
|
||||
);
|
||||
|
||||
if (!contentMap[userId]) {
|
||||
@@ -401,7 +401,7 @@ MegolmEncryption.prototype.encryptMessage = function(room, eventType, content) {
|
||||
};
|
||||
|
||||
const ciphertext = self._olmDevice.encryptGroupMessage(
|
||||
session.sessionId, JSON.stringify(payloadJson)
|
||||
session.sessionId, JSON.stringify(payloadJson),
|
||||
);
|
||||
|
||||
const encryptedContent = {
|
||||
@@ -434,10 +434,6 @@ MegolmEncryption.prototype._checkForUnknownDevices = function(devicesInRoom) {
|
||||
Object.keys(devicesInRoom[userId]).forEach((deviceId)=>{
|
||||
const device = devicesInRoom[userId][deviceId];
|
||||
if (device.isUnverified() && !device.isKnown()) {
|
||||
// mark the devices as known to the user, given we're about to
|
||||
// yell at them.
|
||||
this._crypto.setDeviceVerification(userId, device.deviceId,
|
||||
undefined, undefined, true);
|
||||
if (!unknownDevices[userId]) {
|
||||
unknownDevices[userId] = {};
|
||||
}
|
||||
@@ -473,11 +469,13 @@ MegolmEncryption.prototype._getDevicesInRoom = function(room) {
|
||||
// with them, which means that they will have announced any new devices via
|
||||
// an m.new_device.
|
||||
//
|
||||
// XXX: what if the cache is stale, and the user left the room we had in common
|
||||
// and then added new devices before joining this one? --Matthew
|
||||
// XXX: what if the cache is stale, and the user left the room we had in
|
||||
// common and then added new devices before joining this one? --Matthew
|
||||
//
|
||||
// yup, see https://github.com/vector-im/riot-web/issues/2305 --richvdh
|
||||
var self = this;
|
||||
return self._crypto.downloadKeys(roomMembers, false).then(function(devices) {
|
||||
// remove any blocked (aka blacklisted) devices
|
||||
// remove any blocked devices
|
||||
for (const userId in devices) {
|
||||
if (!devices.hasOwnProperty(userId)) {
|
||||
continue;
|
||||
@@ -541,7 +539,7 @@ MegolmDecryption.prototype.decryptEvent = function(event) {
|
||||
let res;
|
||||
try {
|
||||
res = this._olmDevice.decryptGroupMessage(
|
||||
event.getRoomId(), content.sender_key, content.session_id, content.ciphertext
|
||||
event.getRoomId(), content.sender_key, content.session_id, content.ciphertext,
|
||||
);
|
||||
} catch (e) {
|
||||
if (e.message === 'OLM.UNKNOWN_MESSAGE_INDEX') {
|
||||
@@ -554,7 +552,7 @@ MegolmDecryption.prototype.decryptEvent = function(event) {
|
||||
// We've got a message for a session we don't have.
|
||||
this._addEventToPendingList(event);
|
||||
throw new base.DecryptionError(
|
||||
"The sender's device has not sent us the keys for this message."
|
||||
"The sender's device has not sent us the keys for this message.",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -565,7 +563,7 @@ MegolmDecryption.prototype.decryptEvent = function(event) {
|
||||
// room, so neither the sender nor a MITM can lie about the room_id).
|
||||
if (payload.room_id !== event.getRoomId()) {
|
||||
throw new base.DecryptionError(
|
||||
"Message intended for room " + payload.room_id
|
||||
"Message intended for room " + payload.room_id,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -609,7 +607,7 @@ MegolmDecryption.prototype.onRoomKeyEvent = function(event) {
|
||||
|
||||
this._olmDevice.addInboundGroupSession(
|
||||
content.room_id, event.getSenderKey(), content.session_id,
|
||||
content.session_key, event.getKeysClaimed()
|
||||
content.session_key, event.getKeysClaimed(),
|
||||
);
|
||||
|
||||
// have another go at decrypting events sent with this session.
|
||||
@@ -656,5 +654,5 @@ MegolmDecryption.prototype._retryDecryption = function(senderKey, sessionId) {
|
||||
};
|
||||
|
||||
base.registerAlgorithm(
|
||||
olmlib.MEGOLM_ALGORITHM, MegolmEncryption, MegolmDecryption
|
||||
olmlib.MEGOLM_ALGORITHM, MegolmEncryption, MegolmDecryption,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user