Skip to content

Prepare for forthcoming matrix-sdk-crypto-wasm release, and add new ShieldStateCode.MismatchedSender #4916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions spec/unit/rust-crypto/rust-crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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(() => {});
Expand Down Expand Up @@ -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();

Expand Down
6 changes: 6 additions & 0 deletions src/crypto-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand Down
6 changes: 6 additions & 0 deletions src/rust-crypto/rust-crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,12 @@
case RustSdkCryptoJs.ShieldStateCode.VerificationViolation:
shieldReason = EventShieldReason.VERIFICATION_VIOLATION;
break;
case RustSdkCryptoJs.ShieldStateCode.MismatchedSender:

Check failure on line 2280 in src/rust-crypto/rust-crypto.ts

View workflow job for this annotation

GitHub Actions / ESLint

Property 'MismatchedSender' does not exist on type 'typeof ShieldStateCode'.

Check failure on line 2280 in src/rust-crypto/rust-crypto.ts

View workflow job for this annotation

GitHub Actions / Node.js example

Property 'MismatchedSender' does not exist on type 'typeof ShieldStateCode'.

Check failure on line 2280 in src/rust-crypto/rust-crypto.ts

View workflow job for this annotation

GitHub Actions / Analyse Dead Code

Property 'MismatchedSender' does not exist on type 'typeof ShieldStateCode'.

Check failure on line 2280 in src/rust-crypto/rust-crypto.ts

View workflow job for this annotation

GitHub Actions / JSDoc Checker

Property 'MismatchedSender' does not exist on type 'typeof ShieldStateCode'.

Check failure on line 2280 in src/rust-crypto/rust-crypto.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Property 'MismatchedSender' does not exist on type 'typeof ShieldStateCode'.

Check failure on line 2280 in src/rust-crypto/rust-crypto.ts

View workflow job for this annotation

GitHub Actions / Workflow Lint

Property 'MismatchedSender' does not exist on type 'typeof ShieldStateCode'.

Check failure on line 2280 in src/rust-crypto/rust-crypto.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

Property 'MismatchedSender' does not exist on type 'typeof ShieldStateCode'.

Check failure on line 2280 in src/rust-crypto/rust-crypto.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node 22)

Property 'MismatchedSender' does not exist on type 'typeof ShieldStateCode'.

Check failure on line 2280 in src/rust-crypto/rust-crypto.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

Property 'MismatchedSender' does not exist on type 'typeof ShieldStateCode'.

Check failure on line 2280 in src/rust-crypto/rust-crypto.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node lts/*)

Property 'MismatchedSender' does not exist on type 'typeof ShieldStateCode'.
shieldReason = EventShieldReason.MISMATCHED_SENDER;
break;
default:
shieldReason = EventShieldReason.UNKNOWN;
break;
}

return { shieldColour, shieldReason };
Expand Down
Loading