Enable encryption in DMs with device keys

When the cross-signing lab is enabled, this changes DMs to use encryption as
long as all invited users have uploaded device keys (which we're using as a
proxy for "has some client that understands E2E").

Fixes https://github.com/vector-im/riot-web/issues/12005
This commit is contained in:
J. Ryan Stinnett 2020-01-23 16:00:55 +00:00
parent 2b16b650fe
commit 1e25b32ba3
2 changed files with 42 additions and 6 deletions

View file

@ -82,7 +82,7 @@ const _getE2EStatus = (cli, userId, devices) => {
return "warning";
};
function openDMForUser(matrixClient, userId) {
async function openDMForUser(matrixClient, userId) {
const dmRooms = DMRoomMap.shared().getDMRoomsForUserId(userId);
const lastActiveRoom = dmRooms.reduce((lastActiveRoom, roomId) => {
const room = matrixClient.getRoom(roomId);
@ -100,9 +100,27 @@ function openDMForUser(matrixClient, userId) {
action: 'view_room',
room_id: lastActiveRoom.roomId,
});
} else {
createRoom({dmUserId: userId});
return;
}
const createRoomOptions = {
dmUserId: userId,
};
if (SettingsStore.isFeatureEnabled("feature_cross_signing")) {
// Check whether all users have uploaded device keys before.
// If so, enable encryption in the new room.
const usersToDevicesMap = await matrixClient.downloadKeys([userId]);
const allHaveDeviceKeys = Object.values(usersToDevicesMap).every(devices => {
// `devices` is an object of the form { deviceId: deviceInfo, ... }.
return Object.keys(devices).length > 0;
});
if (allHaveDeviceKeys) {
createRoomOptions.encryption = true;
}
}
createRoom(createRoomOptions);
}
function useIsEncrypted(cli, room) {