Skip to content

Commit 192110d

Browse files
committed
Merge tag 'v3.69.1' into sc
* Fix detection of encryption for all users in a room ([\matrix-org#10487](matrix-org#10487)). Fixes element-hq/element-web#24995.
2 parents 1be51f0 + af3e57f commit 192110d

File tree

4 files changed

+65
-33
lines changed

4 files changed

+65
-33
lines changed

CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
Changes in [3.69.0](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.69.0) (2023-03-28)
1+
Changes in [3.69.1](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.69.1) (2023-03-31)
22
=====================================================================================================
33

44
## 🐛 Bug Fixes
5-
* Changes for matrix-js-sdk v24.0.0
6-
* Changes for matrix-react-sdk v3.69.0
5+
* Fix detection of encryption for all users in a room ([\#10487](https://github.com/matrix-org/matrix-react-sdk/pull/10487)). Fixes vector-im/element-web#24995.
6+
7+
Changes in [3.69.0](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.69.0) (2023-03-28)
8+
=====================================================================================================
9+
10+
## 🔒 Security
11+
* Fixes for [CVE-2023-28427](https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=CVE-2023-28427) / GHSA-mwq8-fjpf-c2gr
12+
* Fixes for [CVE-2023-28103](https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=CVE-2023-28103) / GHSA-6g43-88cp-w5gv
713

814
Changes in [3.68.0](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.68.0) (2023-03-15)
915
=====================================================================================================

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "matrix-react-sdk",
3-
"version": "3.69.0",
3+
"version": "3.69.1",
44
"description": "SDK for matrix.org using React",
55
"author": "matrix.org",
66
"repository": {

src/createRoom.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,16 +398,21 @@ export default async function createRoom(opts: IOpts): Promise<string | null> {
398398
export async function canEncryptToAllUsers(client: MatrixClient, userIds: string[]): Promise<boolean> {
399399
try {
400400
const usersDeviceMap = await client.downloadKeys(userIds);
401-
// { "@user:host": { "DEVICE": {...}, ... }, ... }
402-
return Object.values(usersDeviceMap).every(
403-
(userDevices) =>
404-
// { "DEVICE": {...}, ... }
405-
Object.keys(userDevices).length > 0,
406-
);
401+
402+
// There are no devices at all.
403+
if (usersDeviceMap.size === 0) return false;
404+
405+
for (const devices of usersDeviceMap.values()) {
406+
if (devices.size === 0) {
407+
return false;
408+
}
409+
}
407410
} catch (e) {
408411
logger.error("Error determining if it's possible to encrypt to all users: ", e);
409412
return false; // assume not
410413
}
414+
415+
return true;
411416
}
412417

413418
// Similar to ensureDMExists but also adds creation content

test/createRoom-test.ts

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -147,35 +147,56 @@ describe("createRoom", () => {
147147
});
148148

149149
describe("canEncryptToAllUsers", () => {
150-
const trueUser = new Map([
151-
[
152-
"@goodUser:localhost",
153-
new Map([
154-
["DEV1", {} as unknown as DeviceInfo],
155-
["DEV2", {} as unknown as DeviceInfo],
156-
]),
157-
],
158-
]);
150+
const user1Id = "@user1:example.com";
151+
const user2Id = "@user2:example.com";
159152

160-
const falseUser = {
161-
"@badUser:localhost": {},
162-
};
153+
const devices = new Map([
154+
["DEV1", {} as unknown as DeviceInfo],
155+
["DEV2", {} as unknown as DeviceInfo],
156+
]);
163157

164158
let client: Mocked<MatrixClient>;
165-
beforeEach(() => {
166-
stubClient();
167-
client = mocked(MatrixClientPeg.get());
159+
160+
beforeAll(() => {
161+
client = mocked(stubClient());
168162
});
169163

170-
it("returns true if all devices have crypto", async () => {
171-
client.downloadKeys.mockResolvedValue(trueUser);
172-
const response = await canEncryptToAllUsers(client, ["@goodUser:localhost"]);
173-
expect(response).toBe(true);
164+
it("should return false if download keys does not return any user", async () => {
165+
client.downloadKeys.mockResolvedValue(new Map());
166+
const result = await canEncryptToAllUsers(client, [user1Id, user2Id]);
167+
expect(result).toBe(false);
174168
});
175169

176-
it("returns false if not all users have crypto", async () => {
177-
client.downloadKeys.mockResolvedValue({ ...trueUser, ...falseUser });
178-
const response = await canEncryptToAllUsers(client, ["@goodUser:localhost", "@badUser:localhost"]);
179-
expect(response).toBe(false);
170+
it("should return false if none of the users has a device", async () => {
171+
client.downloadKeys.mockResolvedValue(
172+
new Map([
173+
[user1Id, new Map()],
174+
[user2Id, new Map()],
175+
]),
176+
);
177+
const result = await canEncryptToAllUsers(client, [user1Id, user2Id]);
178+
expect(result).toBe(false);
179+
});
180+
181+
it("should return false if some of the users don't have a device", async () => {
182+
client.downloadKeys.mockResolvedValue(
183+
new Map([
184+
[user1Id, new Map()],
185+
[user2Id, devices],
186+
]),
187+
);
188+
const result = await canEncryptToAllUsers(client, [user1Id, user2Id]);
189+
expect(result).toBe(false);
190+
});
191+
192+
it("should return true if all users have a device", async () => {
193+
client.downloadKeys.mockResolvedValue(
194+
new Map([
195+
[user1Id, devices],
196+
[user2Id, devices],
197+
]),
198+
);
199+
const result = await canEncryptToAllUsers(client, [user1Id, user2Id]);
200+
expect(result).toBe(true);
180201
});
181202
});

0 commit comments

Comments
 (0)