You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Assume per-user deviceID uniqueness in encryptAndSendKeysToDevices (#2136)
* Segment recorded device info by user ID when tracking key shares. Fixes #2135. * address review feedback * fix userIdDeviceInfo Co-authored-by: Denis Kasak <dkasak@termina.org.uk> Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -592,7 +592,8 @@ class MegolmEncryption extends EncryptionAlgorithm {
|
|||||||
payload: IPayload,
|
payload: IPayload,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const contentMap: Record<string, Record<string, IEncryptedContent>> = {};
|
const contentMap: Record<string, Record<string, IEncryptedContent>> = {};
|
||||||
const deviceInfoByDeviceId = new Map<string, DeviceInfo>();
|
// Map from userId to a map of deviceId to deviceInfo
|
||||||
|
const deviceInfoByUserIdAndDeviceId = new Map<string, Map<string, DeviceInfo>>();
|
||||||
|
|
||||||
const promises: Promise<unknown>[] = [];
|
const promises: Promise<unknown>[] = [];
|
||||||
for (let i = 0; i < userDeviceMap.length; i++) {
|
for (let i = 0; i < userDeviceMap.length; i++) {
|
||||||
@@ -605,7 +606,18 @@ class MegolmEncryption extends EncryptionAlgorithm {
|
|||||||
const userId = val.userId;
|
const userId = val.userId;
|
||||||
const deviceInfo = val.deviceInfo;
|
const deviceInfo = val.deviceInfo;
|
||||||
const deviceId = deviceInfo.deviceId;
|
const deviceId = deviceInfo.deviceId;
|
||||||
deviceInfoByDeviceId.set(deviceId, deviceInfo);
|
|
||||||
|
// Assign to temp value to make type-checking happy
|
||||||
|
let userIdDeviceInfo = deviceInfoByUserIdAndDeviceId.get(userId);
|
||||||
|
|
||||||
|
if (userIdDeviceInfo === undefined) {
|
||||||
|
userIdDeviceInfo = new Map<string, DeviceInfo>();
|
||||||
|
|
||||||
|
deviceInfoByUserIdAndDeviceId.set(userId, userIdDeviceInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
// We hold by reference, this updates deviceInfoByUserIdAndDeviceId[userId]
|
||||||
|
userIdDeviceInfo.set(deviceId, deviceInfo);
|
||||||
|
|
||||||
if (!contentMap[userId]) {
|
if (!contentMap[userId]) {
|
||||||
contentMap[userId] = {};
|
contentMap[userId] = {};
|
||||||
@@ -660,7 +672,7 @@ class MegolmEncryption extends EncryptionAlgorithm {
|
|||||||
session.markSharedWithDevice(
|
session.markSharedWithDevice(
|
||||||
userId,
|
userId,
|
||||||
deviceId,
|
deviceId,
|
||||||
deviceInfoByDeviceId.get(deviceId).getIdentityKey(),
|
deviceInfoByUserIdAndDeviceId.get(userId).get(deviceId).getIdentityKey(),
|
||||||
chainIndex,
|
chainIndex,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user