This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add labs option to exclude unverified devices
Add a labs option which will, when set, switch into the "invisible crypto" mode of refusing to send keys to, or decrypt messages from, devices that have not been signed by their owner.
- Loading branch information
Showing
6 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Copyright 2024 New Vector Ltd. | ||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only | ||
Please see LICENSE files in the repository root for full details. | ||
*/ | ||
|
||
import { AllDevicesIsolationMode, OnlySignedDevicesIsolationMode } from "matrix-js-sdk/src/crypto-api"; | ||
import { MatrixClient } from "matrix-js-sdk/src/matrix"; | ||
|
||
import SettingController from "./SettingController"; | ||
import { MatrixClientPeg } from "../../MatrixClientPeg"; | ||
import { SettingLevel } from "../SettingLevel"; | ||
|
||
/** | ||
* A controller for the "exclude_insecure_devices" setting, which will | ||
* update the crypto stack's device isolation mode on change. | ||
*/ | ||
export default class DeviceIsolationModeController extends SettingController { | ||
public onChange(level: SettingLevel, roomId: string, newValue: any): void { | ||
setDeviceIsolationMode(MatrixClientPeg.safeGet(), newValue); | ||
} | ||
} | ||
|
||
/** | ||
* Set the crypto stack's device isolation mode based on the current value of the | ||
* "exclude_insecure_devices" setting. | ||
* | ||
* @param client - MatrixClient to update to the new setting. | ||
* @param settingValue - value of the "exclude_insecure_devices" setting. | ||
*/ | ||
export function setDeviceIsolationMode(client: MatrixClient, settingValue: boolean): void { | ||
client | ||
.getCrypto() | ||
?.setDeviceIsolationMode( | ||
settingValue ? new OnlySignedDevicesIsolationMode() : new AllDevicesIsolationMode(true), | ||
); | ||
} |
33 changes: 33 additions & 0 deletions
33
test/settings/controllers/DeviceIsolationModeController-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Copyright 2024 New Vector Ltd. | ||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only | ||
Please see LICENSE files in the repository root for full details. | ||
*/ | ||
|
||
import { AllDevicesIsolationMode, OnlySignedDevicesIsolationMode } from "matrix-js-sdk/src/crypto-api"; | ||
|
||
import { stubClient } from "../../test-utils"; | ||
import DeviceIsolationModeController from "../../../src/settings/controllers/DeviceIsolationModeController.ts"; | ||
import { SettingLevel } from "../../../src/settings/SettingLevel"; | ||
|
||
describe("DeviceIsolationModeController", () => { | ||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe("tracks enabling and disabling", () => { | ||
it("on sets signed device isolation mode", () => { | ||
const cli = stubClient(); | ||
const controller = new DeviceIsolationModeController(); | ||
controller.onChange(SettingLevel.DEVICE, "", true); | ||
expect(cli.getCrypto()?.setDeviceIsolationMode).toHaveBeenCalledWith(new OnlySignedDevicesIsolationMode()); | ||
}); | ||
|
||
it("off sets all device isolation mode", () => { | ||
const cli = stubClient(); | ||
const controller = new DeviceIsolationModeController(); | ||
controller.onChange(SettingLevel.DEVICE, "", false); | ||
expect(cli.getCrypto()?.setDeviceIsolationMode).toHaveBeenCalledWith(new AllDevicesIsolationMode(true)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters