Add .well-known config option to force disable encryption on room creation (#11120)

* force disable encryption on room creation

* test allowChangingEncryption

* move into utils/room directory

* tests

* unit test CreateRoomDialog

* remove debug

* wait for constructor promises to settle

* test case for force_disable

* comment

* set forced value after resolving checkUserIsAllowedToChangeEncryption

* tidy and comments

* use label text in test
This commit is contained in:
Kerry
2023-06-21 21:50:01 +00:00
committed by GitHub
parent 9d9c55d92e
commit a692fe2181
9 changed files with 375 additions and 9 deletions
+47
View File
@@ -43,6 +43,7 @@ import Spinner from "./components/views/elements/Spinner";
import { ViewRoomPayload } from "./dispatcher/payloads/ViewRoomPayload";
import { findDMForUser } from "./utils/dm/findDMForUser";
import { privateShouldBeEncrypted } from "./utils/rooms";
import { shouldForceDisableEncryption } from "./utils/room/shouldForceDisableEncryption";
import { waitForMember } from "./utils/membership";
import { PreferredRoomVersions } from "./utils/PreferredRoomVersions";
import SettingsStore from "./settings/SettingsStore";
@@ -471,3 +472,49 @@ export async function ensureDMExists(client: MatrixClient, userId: string): Prom
}
return roomId;
}
interface AllowedEncryptionSetting {
/**
* True when the user is allowed to choose whether encryption is enabled
*/
allowChange: boolean;
/**
* Set when user is not allowed to choose encryption setting
* True when encryption is forced to enabled
*/
forcedValue?: boolean;
}
/**
* Check if server configuration supports the user changing encryption for a room
* First check if server features force enable encryption for the given room type
* If not, check if server .well-known forces encryption to disabled
* If either are forced, then do not allow the user to change room's encryption
* @param client
* @param chatPreset chat type
* @returns Promise<boolean>
*/
export async function checkUserIsAllowedToChangeEncryption(
client: MatrixClient,
chatPreset: Preset,
): Promise<AllowedEncryptionSetting> {
const doesServerForceEncryptionForPreset = await client.doesServerForceEncryptionForPreset(chatPreset);
const doesWellKnownForceDisableEncryption = shouldForceDisableEncryption(client);
// server is forcing encryption to ENABLED
// while .well-known config is forcing it to DISABLED
// server version config overrides wk config
if (doesServerForceEncryptionForPreset && doesWellKnownForceDisableEncryption) {
console.warn(
`Conflicting e2ee settings: server config and .well-known configuration disagree. Using server forced encryption setting for chat type ${chatPreset}`,
);
}
if (doesServerForceEncryptionForPreset) {
return { allowChange: false, forcedValue: true };
}
if (doesWellKnownForceDisableEncryption) {
return { allowChange: false, forcedValue: false };
}
return { allowChange: true };
}