Skip to content

Commit c5d6e35

Browse files
committed
feat(legacy crypto!): remove {get,set}GlobalErrorOnUnknownDevices
`globalErrorOnUnknownDevices` is not used in the rust-crypto. The API is marked as unstable, we can remove it.
1 parent 8fc29ae commit c5d6e35

File tree

3 files changed

+1
-125
lines changed

3 files changed

+1
-125
lines changed

spec/integ/crypto/crypto.spec.ts

+1-88
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ import {
9595
establishOlmSession,
9696
getTestOlmAccountKeys,
9797
} from "./olm-utils";
98-
import { ToDevicePayload } from "../../../src/models/ToDeviceMessage";
9998
import { AccountDataAccumulator } from "../../test-utils/AccountDataAccumulator";
10099
import { UNSIGNED_MEMBERSHIP_FIELD } from "../../../src/@types/event";
101100
import { KnownMembership } from "../../../src/@types/membership";
@@ -995,7 +994,6 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
995994
keyResponder.addDeviceKeys(testDeviceKeys);
996995

997996
await startClientAndAwaitFirstSync();
998-
aliceClient.setGlobalErrorOnUnknownDevices(false);
999997

1000998
// tell alice she is sharing a room with bob
1001999
syncResponder.sendOrQueueSyncResponse(getSyncResponse(["@bob:xyz"]));
@@ -1013,8 +1011,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
10131011
await expectSendRoomKey("@bob:xyz", testOlmAccount);
10141012
});
10151013

1016-
it("Alice sends a megolm message with GlobalErrorOnUnknownDevices=false", async () => {
1017-
aliceClient.setGlobalErrorOnUnknownDevices(false);
1014+
it("Alice sends a megolm message", async () => {
10181015
const homeserverUrl = aliceClient.getHomeserverUrl();
10191016
const keyResponder = new E2EKeyResponder(homeserverUrl);
10201017
keyResponder.addKeyReceiver("@alice:localhost", keyReceiver);
@@ -1042,7 +1039,6 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
10421039
});
10431040

10441041
it("We should start a new megolm session after forceDiscardSession", async () => {
1045-
aliceClient.setGlobalErrorOnUnknownDevices(false);
10461042
const homeserverUrl = aliceClient.getHomeserverUrl();
10471043
const keyResponder = new E2EKeyResponder(homeserverUrl);
10481044
keyResponder.addKeyReceiver("@alice:localhost", keyReceiver);
@@ -1077,87 +1073,6 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
10771073
await Promise.all([aliceClient.sendTextMessage(ROOM_ID, "test2"), p2]);
10781074
});
10791075

1080-
describe("get|setGlobalErrorOnUnknownDevices", () => {
1081-
it("should raise an error if crypto is disabled", () => {
1082-
aliceClient["cryptoBackend"] = undefined;
1083-
expect(() => aliceClient.setGlobalErrorOnUnknownDevices(true)).toThrow("encryption disabled");
1084-
expect(() => aliceClient.getGlobalErrorOnUnknownDevices()).toThrow("encryption disabled");
1085-
});
1086-
1087-
oldBackendOnly("should permit sending to unknown devices", async () => {
1088-
expect(aliceClient.getGlobalErrorOnUnknownDevices()).toBeTruthy();
1089-
1090-
expectAliceKeyQuery({ device_keys: { "@alice:localhost": {} }, failures: {} });
1091-
await startClientAndAwaitFirstSync();
1092-
const p2pSession = await establishOlmSession(aliceClient, keyReceiver, syncResponder, testOlmAccount);
1093-
1094-
syncResponder.sendOrQueueSyncResponse(getSyncResponse(["@bob:xyz"]));
1095-
await syncPromise(aliceClient);
1096-
1097-
// start out with the device unknown - the send should be rejected.
1098-
expectAliceKeyQuery(getTestKeysQueryResponse("@bob:xyz"));
1099-
expectAliceKeyQuery(getTestKeysQueryResponse("@bob:xyz"));
1100-
1101-
await aliceClient.sendTextMessage(ROOM_ID, "test").then(
1102-
() => {
1103-
throw new Error("sendTextMessage failed on an unknown device");
1104-
},
1105-
(e) => {
1106-
expect(e.name).toEqual("UnknownDeviceError");
1107-
},
1108-
);
1109-
1110-
// enable sending to unknown devices, and resend
1111-
aliceClient.setGlobalErrorOnUnknownDevices(false);
1112-
expect(aliceClient.getGlobalErrorOnUnknownDevices()).toBeFalsy();
1113-
1114-
const room = aliceClient.getRoom(ROOM_ID)!;
1115-
const pendingMsg = room.getPendingEvents()[0];
1116-
1117-
const inboundGroupSessionPromise = expectSendRoomKey("@bob:xyz", testOlmAccount, p2pSession);
1118-
1119-
await Promise.all([
1120-
aliceClient.resendEvent(pendingMsg, room),
1121-
expectSendMegolmMessage(inboundGroupSessionPromise),
1122-
]);
1123-
});
1124-
});
1125-
1126-
describe("get|setGlobalBlacklistUnverifiedDevices", () => {
1127-
it("should send a m.unverified code in toDevice messages to an unverified device when globalBlacklistUnverifiedDevices=true", async () => {
1128-
aliceClient.getCrypto()!.globalBlacklistUnverifiedDevices = true;
1129-
1130-
expectAliceKeyQuery({ device_keys: { "@alice:localhost": {} }, failures: {} });
1131-
await startClientAndAwaitFirstSync();
1132-
await establishOlmSession(aliceClient, keyReceiver, syncResponder, testOlmAccount);
1133-
1134-
// Tell alice we share a room with bob
1135-
syncResponder.sendOrQueueSyncResponse(getSyncResponse(["@bob:xyz"]));
1136-
await syncPromise(aliceClient);
1137-
1138-
// Force alice to download bob keys
1139-
expectAliceKeyQuery(getTestKeysQueryResponse("@bob:xyz"));
1140-
1141-
// Wait to receive the toDevice message and return bob device content
1142-
const toDevicePromise = new Promise<ToDevicePayload>((resolve) => {
1143-
fetchMock.putOnce(new RegExp("/sendToDevice/m.room_key.withheld/"), (url, request) => {
1144-
const content = JSON.parse(request.body as string);
1145-
resolve(content.messages["@bob:xyz"]["DEVICE_ID"]);
1146-
return {};
1147-
});
1148-
});
1149-
1150-
// Mock endpoint of message sending
1151-
fetchMock.put(new RegExp("/send/"), { event_id: "$event_id" });
1152-
1153-
await aliceClient.sendTextMessage(ROOM_ID, "test");
1154-
1155-
// Finally, check that the toDevice message has the m.unverified code
1156-
const toDeviceContent = await toDevicePromise;
1157-
expect(toDeviceContent.code).toBe("m.unverified");
1158-
});
1159-
});
1160-
11611076
describe("Session should rotate according to encryption settings", () => {
11621077
/**
11631078
* Send a message to bob and get the encrypted message
@@ -1475,7 +1390,6 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
14751390

14761391
describe("getEncryptionInfoForEvent", () => {
14771392
it("handles outgoing events", async () => {
1478-
aliceClient.setGlobalErrorOnUnknownDevices(false);
14791393
expectAliceKeyQuery({ device_keys: { "@alice:localhost": {} }, failures: {} });
14801394
await startClientAndAwaitFirstSync();
14811395

@@ -1579,7 +1493,6 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
15791493
// set up the aliceTestClient so that it is a room with no known members
15801494
expectAliceKeyQuery({ device_keys: { "@alice:localhost": {} }, failures: {} });
15811495
await startClientAndAwaitFirstSync({ lazyLoadMembers: true });
1582-
aliceClient.setGlobalErrorOnUnknownDevices(false);
15831496

15841497
syncResponder.sendOrQueueSyncResponse(getSyncResponse([]));
15851498
await syncPromise(aliceClient);

spec/integ/crypto/verification.spec.ts

-2
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,6 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st
906906
describe("Send verification request in DM", () => {
907907
beforeEach(async () => {
908908
aliceClient = await startTestClient();
909-
aliceClient.setGlobalErrorOnUnknownDevices(false);
910909

911910
e2eKeyResponder.addCrossSigningData(BOB_SIGNED_CROSS_SIGNING_KEYS_DATA);
912911
e2eKeyResponder.addDeviceKeys(BOB_SIGNED_TEST_DEVICE_DATA);
@@ -989,7 +988,6 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st
989988
testOlmAccount.create();
990989

991990
aliceClient = await startTestClient();
992-
aliceClient.setGlobalErrorOnUnknownDevices(false);
993991
syncResponder.sendOrQueueSyncResponse(getSyncResponse([BOB_TEST_USER_ID]));
994992
await syncPromise(aliceClient);
995993

src/client.ts

-35
Original file line numberDiff line numberDiff line change
@@ -1970,41 +1970,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
19701970
return this.cryptoBackend;
19711971
}
19721972

1973-
/**
1974-
* Set whether sendMessage in a room with unknown and unverified devices
1975-
* should throw an error and not send them message. This has 'Global' for
1976-
* symmetry with setGlobalBlacklistUnverifiedDevices but there is currently
1977-
* no room-level equivalent for this setting.
1978-
*
1979-
* This API is currently UNSTABLE and may change or be removed without notice.
1980-
*
1981-
* It has no effect with the Rust crypto implementation.
1982-
*
1983-
* @param value - whether error on unknown devices
1984-
*
1985-
* ```ts
1986-
* client.getCrypto().globalErrorOnUnknownDevices = value;
1987-
* ```
1988-
*/
1989-
public setGlobalErrorOnUnknownDevices(value: boolean): void {
1990-
if (!this.cryptoBackend) {
1991-
throw new Error("End-to-end encryption disabled");
1992-
}
1993-
this.cryptoBackend.globalErrorOnUnknownDevices = value;
1994-
}
1995-
1996-
/**
1997-
* @returns whether to error on unknown devices
1998-
*
1999-
* This API is currently UNSTABLE and may change or be removed without notice.
2000-
*/
2001-
public getGlobalErrorOnUnknownDevices(): boolean {
2002-
if (!this.cryptoBackend) {
2003-
throw new Error("End-to-end encryption disabled");
2004-
}
2005-
return this.cryptoBackend.globalErrorOnUnknownDevices;
2006-
}
2007-
20081973
/**
20091974
* Whether encryption is enabled for a room.
20101975
* @param roomId - the room id to query.

0 commit comments

Comments
 (0)