diff --git a/spec/unit/rust-crypto/rust-crypto.spec.ts b/spec/unit/rust-crypto/rust-crypto.spec.ts index 36387e6cfc..48be04ea37 100644 --- a/spec/unit/rust-crypto/rust-crypto.spec.ts +++ b/spec/unit/rust-crypto/rust-crypto.spec.ts @@ -77,6 +77,7 @@ import encryptAESSecretStorageItem from "../../../src/utils/encryptAESSecretStor import { type CryptoStore, type SecretStorePrivateKeys } from "../../../src/crypto/store/base"; import { CryptoEvent } from "../../../src/crypto-api/index.ts"; import { RustBackupManager } from "../../../src/rust-crypto/backup.ts"; +import { flushPromises } from "../../test-utils/flushPromises.ts"; const TEST_USER = "@alice:example.com"; const TEST_DEVICE_ID = "TEST_DEVICE"; @@ -1139,6 +1140,11 @@ describe("RustCrypto", () => { RustSdkCryptoJs.ShieldStateCode.VerificationViolation, EventShieldReason.VERIFICATION_VIOLATION, ], + [ + "Mismatched sender", + RustSdkCryptoJs.ShieldStateCode.MismatchedSender, + EventShieldReason.MISMATCHED_SENDER, + ], ])("gets the right shield reason (%s)", async (rustReason, rustCode, expectedReason) => { // suppress the warning from the unknown shield reason jest.spyOn(console, "warn").mockImplementation(() => {}); @@ -2302,6 +2308,8 @@ describe("RustCrypto", () => { }); const rustCrypto = await makeTestRustCrypto(makeMatrixHttpApi(), undefined, undefined, secretStorage); + await flushPromises(); + // We have a key backup expect(await rustCrypto.getActiveSessionBackupVersion()).not.toBeNull(); diff --git a/src/crypto-api/index.ts b/src/crypto-api/index.ts index 173ff31764..a7acbf90af 100644 --- a/src/crypto-api/index.ts +++ b/src/crypto-api/index.ts @@ -1355,6 +1355,12 @@ export enum EventShieldReason { * The sender was previously verified but changed their identity. */ VERIFICATION_VIOLATION, + + /** + * The `sender` field on the event does not match the owner of the device + * that established the Megolm session. + */ + MISMATCHED_SENDER, } /** The result of a call to {@link CryptoApi.getOwnDeviceKeys} */ diff --git a/src/rust-crypto/rust-crypto.ts b/src/rust-crypto/rust-crypto.ts index 9cb8522d38..863a0e8e93 100644 --- a/src/rust-crypto/rust-crypto.ts +++ b/src/rust-crypto/rust-crypto.ts @@ -2277,6 +2277,12 @@ function rustEncryptionInfoToJsEncryptionInfo( case RustSdkCryptoJs.ShieldStateCode.VerificationViolation: shieldReason = EventShieldReason.VERIFICATION_VIOLATION; break; + case RustSdkCryptoJs.ShieldStateCode.MismatchedSender: + shieldReason = EventShieldReason.MISMATCHED_SENDER; + break; + default: + shieldReason = EventShieldReason.UNKNOWN; + break; } return { shieldColour, shieldReason };