From 0016d8e744a1c345af8494745f805b2d38d2405e Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 19 May 2020 11:36:44 +0100 Subject: [PATCH] Add e2ee_default_for_private_rooms to control default e2ee behaviour Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/views/dialogs/CreateRoomDialog.js | 3 ++- src/components/views/dialogs/InviteDialog.js | 5 ++--- src/components/views/right_panel/UserInfo.js | 4 ++-- src/createRoom.js | 7 ++++++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/components/views/dialogs/CreateRoomDialog.js b/src/components/views/dialogs/CreateRoomDialog.js index fb08afa5f7..df5f559e3b 100644 --- a/src/components/views/dialogs/CreateRoomDialog.js +++ b/src/components/views/dialogs/CreateRoomDialog.js @@ -25,6 +25,7 @@ import { _t } from '../../../languageHandler'; import {MatrixClientPeg} from '../../../MatrixClientPeg'; import {Key} from "../../../Keyboard"; import SettingsStore from "../../../settings/SettingsStore"; +import {privateShouldBeEncrypted} from "../../../createRoom"; export default createReactClass({ displayName: 'CreateRoomDialog', @@ -37,7 +38,7 @@ export default createReactClass({ const config = SdkConfig.get(); return { isPublic: this.props.defaultPublic || false, - isEncrypted: true, + isEncrypted: privateShouldBeEncrypted(), name: "", topic: "", alias: "", diff --git a/src/components/views/dialogs/InviteDialog.js b/src/components/views/dialogs/InviteDialog.js index 7cbbf8ba64..6b7d2ff69d 100644 --- a/src/components/views/dialogs/InviteDialog.js +++ b/src/components/views/dialogs/InviteDialog.js @@ -31,9 +31,8 @@ import dis from "../../../dispatcher"; import IdentityAuthClient from "../../../IdentityAuthClient"; import Modal from "../../../Modal"; import {humanizeTime} from "../../../utils/humanize"; -import createRoom, {canEncryptToAllUsers} from "../../../createRoom"; +import createRoom, {canEncryptToAllUsers, privateShouldBeEncrypted} from "../../../createRoom"; import {inviteMultipleToRoom} from "../../../RoomInvite"; -import SettingsStore from '../../../settings/SettingsStore'; import RoomListStore, {TAG_DM} from "../../../stores/RoomListStore"; import {Key} from "../../../Keyboard"; @@ -574,7 +573,7 @@ export default class InviteDialog extends React.PureComponent { const createRoomOptions = {inlineErrors: true}; - if (SettingsStore.getValue("feature_cross_signing")) { + if (privateShouldBeEncrypted()) { // Check whether all users have uploaded device keys before. // If so, enable encryption in the new room. const has3PidMembers = targets.some(t => t instanceof ThreepidMember); diff --git a/src/components/views/right_panel/UserInfo.js b/src/components/views/right_panel/UserInfo.js index 478dc90418..68139e5726 100644 --- a/src/components/views/right_panel/UserInfo.js +++ b/src/components/views/right_panel/UserInfo.js @@ -25,7 +25,7 @@ import dis from '../../../dispatcher'; import Modal from '../../../Modal'; import * as sdk from '../../../index'; import { _t } from '../../../languageHandler'; -import createRoom from '../../../createRoom'; +import createRoom, {privateShouldBeEncrypted} from '../../../createRoom'; import DMRoomMap from '../../../utils/DMRoomMap'; import AccessibleButton from '../elements/AccessibleButton'; import SdkConfig from '../../../SdkConfig'; @@ -111,7 +111,7 @@ async function openDMForUser(matrixClient, userId) { dmUserId: userId, }; - if (SettingsStore.getValue("feature_cross_signing")) { + if (privateShouldBeEncrypted()) { // Check whether all users have uploaded device keys before. // If so, enable encryption in the new room. const usersToDevicesMap = await matrixClient.downloadKeys([userId]); diff --git a/src/createRoom.js b/src/createRoom.js index a39d2c2216..2573c438c2 100644 --- a/src/createRoom.js +++ b/src/createRoom.js @@ -24,6 +24,7 @@ import * as Rooms from "./Rooms"; import DMRoomMap from "./utils/DMRoomMap"; import {getAddressType} from "./UserAddress"; import SettingsStore from "./settings/SettingsStore"; +import SdkConfig from "./SdkConfig"; /** * Create a new room, and switch to it. @@ -227,7 +228,7 @@ export async function ensureDMExists(client, userId) { roomId = existingDMRoom.roomId; } else { let encryption; - if (SettingsStore.getValue("feature_cross_signing")) { + if (privateShouldBeEncrypted()) { encryption = canEncryptToAllUsers(client, [userId]); } roomId = await createRoom({encryption, dmUserId: userId, spinner: false, andView: false}); @@ -235,3 +236,7 @@ export async function ensureDMExists(client, userId) { } return roomId; } + +export function privateShouldBeEncrypted() { + return SettingsStore.getValue("feature_cross_signing") && SdkConfig.get().e2ee_default_for_private_rooms !== false; +}