Skip to content

Commit ded8729

Browse files
authored
Update matrix-sdk-crypto-wasm to 11.0.0 (#4566)
* Update matrix-sdk-crypto-wasm to 11.0.0 * use `backend` variable to test for rust crypto * apply changes from review
1 parent cf39595 commit ded8729

File tree

5 files changed

+53
-34
lines changed

5 files changed

+53
-34
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
],
5151
"dependencies": {
5252
"@babel/runtime": "^7.12.5",
53-
"@matrix-org/matrix-sdk-crypto-wasm": "^9.0.0",
53+
"@matrix-org/matrix-sdk-crypto-wasm": "^11.0.0",
5454
"@matrix-org/olm": "3.2.15",
5555
"another-json": "^0.2.0",
5656
"bs58": "^6.0.0",

spec/integ/crypto/verification.spec.ts

+13
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import {
7878
encryptGroupSessionKey,
7979
encryptMegolmEvent,
8080
encryptSecretSend,
81+
getTestOlmAccountKeys,
8182
ToDeviceEvent,
8283
} from "./olm-utils";
8384
import { KeyBackupInfo } from "../../../src/crypto-api";
@@ -992,6 +993,18 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st
992993
aliceClient.setGlobalErrorOnUnknownDevices(false);
993994
syncResponder.sendOrQueueSyncResponse(getSyncResponse([BOB_TEST_USER_ID]));
994995
await syncPromise(aliceClient);
996+
997+
// Rust crypto requires the sender's device keys before it accepts a
998+
// verification request.
999+
if (backend === "rust-sdk") {
1000+
const crypto = aliceClient.getCrypto()!;
1001+
1002+
const bobDeviceKeys = getTestOlmAccountKeys(testOlmAccount, BOB_TEST_USER_ID, "BobDevice");
1003+
e2eKeyResponder.addDeviceKeys(bobDeviceKeys);
1004+
syncResponder.sendOrQueueSyncResponse({ device_lists: { changed: [BOB_TEST_USER_ID] } });
1005+
await syncPromise(aliceClient);
1006+
await crypto.getUserDeviceInfo([BOB_TEST_USER_ID]);
1007+
}
9951008
});
9961009

9971010
/**

spec/unit/rust-crypto/rust-crypto.spec.ts

+25-3
Original file line numberDiff line numberDiff line change
@@ -572,15 +572,37 @@ describe("RustCrypto", () => {
572572
});
573573

574574
it("emits VerificationRequestReceived on incoming m.key.verification.request", async () => {
575+
rustCrypto = await makeTestRustCrypto(
576+
new MatrixHttpApi(new TypedEventEmitter<HttpApiEvent, HttpApiEventHandlerMap>(), {
577+
baseUrl: "http://server/",
578+
prefix: "",
579+
onlyData: true,
580+
}),
581+
testData.TEST_USER_ID,
582+
);
583+
584+
fetchMock.post("path:/_matrix/client/v3/keys/upload", { one_time_key_counts: {} });
585+
fetchMock.post("path:/_matrix/client/v3/keys/query", {
586+
device_keys: {
587+
[testData.TEST_USER_ID]: {
588+
[testData.TEST_DEVICE_ID]: testData.SIGNED_TEST_DEVICE_DATA,
589+
},
590+
},
591+
});
592+
593+
// wait until we know about the other device
594+
rustCrypto.onSyncCompleted({});
595+
await rustCrypto.getUserDeviceInfo([testData.TEST_USER_ID]);
596+
575597
const toDeviceEvent = {
576598
type: "m.key.verification.request",
577599
content: {
578-
from_device: "testDeviceId",
600+
from_device: testData.TEST_DEVICE_ID,
579601
methods: ["m.sas.v1"],
580602
transaction_id: "testTxn",
581603
timestamp: Date.now() - 1000,
582604
},
583-
sender: "@user:id",
605+
sender: testData.TEST_USER_ID,
584606
};
585607

586608
const onEvent = jest.fn();
@@ -1015,7 +1037,7 @@ describe("RustCrypto", () => {
10151037
["Not encrypted.", RustSdkCryptoJs.ShieldStateCode.SentInClear, EventShieldReason.SENT_IN_CLEAR],
10161038
[
10171039
"Encrypted by a previously-verified user who is no longer verified.",
1018-
RustSdkCryptoJs.ShieldStateCode.PreviouslyVerified,
1040+
RustSdkCryptoJs.ShieldStateCode.VerificationViolation,
10191041
EventShieldReason.VERIFICATION_VIOLATION,
10201042
],
10211043
])("gets the right shield reason (%s)", async (rustReason, rustCode, expectedReason) => {

src/rust-crypto/rust-crypto.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
653653
* Implementation of {@link CryptoApi#getUserVerificationStatus}.
654654
*/
655655
public async getUserVerificationStatus(userId: string): Promise<UserVerificationStatus> {
656-
const userIdentity: RustSdkCryptoJs.UserIdentity | RustSdkCryptoJs.OwnUserIdentity | undefined =
656+
const userIdentity: RustSdkCryptoJs.OtherUserIdentity | RustSdkCryptoJs.OwnUserIdentity | undefined =
657657
await this.getOlmMachineOrThrow().getIdentity(new RustSdkCryptoJs.UserId(userId));
658658
if (userIdentity === undefined) {
659659
return new UserVerificationStatus(false, false, false);
@@ -662,7 +662,9 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
662662
const verified = userIdentity.isVerified();
663663
const wasVerified = userIdentity.wasPreviouslyVerified();
664664
const needsUserApproval =
665-
userIdentity instanceof RustSdkCryptoJs.UserIdentity ? userIdentity.identityNeedsUserApproval() : false;
665+
userIdentity instanceof RustSdkCryptoJs.OtherUserIdentity
666+
? userIdentity.identityNeedsUserApproval()
667+
: false;
666668
userIdentity.free();
667669
return new UserVerificationStatus(verified, wasVerified, false, needsUserApproval);
668670
}
@@ -671,7 +673,7 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
671673
* Implementation of {@link CryptoApi#pinCurrentUserIdentity}.
672674
*/
673675
public async pinCurrentUserIdentity(userId: string): Promise<void> {
674-
const userIdentity: RustSdkCryptoJs.UserIdentity | RustSdkCryptoJs.OwnUserIdentity | undefined =
676+
const userIdentity: RustSdkCryptoJs.OtherUserIdentity | RustSdkCryptoJs.OwnUserIdentity | undefined =
675677
await this.getOlmMachineOrThrow().getIdentity(new RustSdkCryptoJs.UserId(userId));
676678

677679
if (userIdentity === undefined) {
@@ -1020,7 +1022,7 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
10201022
* Implementation of {@link CryptoApi#requestVerificationDM}
10211023
*/
10221024
public async requestVerificationDM(userId: string, roomId: string): Promise<VerificationRequest> {
1023-
const userIdentity: RustSdkCryptoJs.UserIdentity | undefined = await this.olmMachine.getIdentity(
1025+
const userIdentity: RustSdkCryptoJs.OtherUserIdentity | undefined = await this.olmMachine.getIdentity(
10241026
new RustSdkCryptoJs.UserId(userId),
10251027
);
10261028

@@ -2035,7 +2037,7 @@ class EventDecryptor {
20352037
errorDetails,
20362038
);
20372039

2038-
case RustSdkCryptoJs.DecryptionErrorCode.SenderIdentityPreviouslyVerified:
2040+
case RustSdkCryptoJs.DecryptionErrorCode.SenderIdentityVerificationViolation:
20392041
// We're refusing to decrypt due to not trusting the sender,
20402042
// rather than failing to decrypt due to lack of keys, so we
20412043
// don't need to keep it on the pending list.
@@ -2200,7 +2202,7 @@ function rustEncryptionInfoToJsEncryptionInfo(
22002202
case RustSdkCryptoJs.ShieldStateCode.SentInClear:
22012203
shieldReason = EventShieldReason.SENT_IN_CLEAR;
22022204
break;
2203-
case RustSdkCryptoJs.ShieldStateCode.PreviouslyVerified:
2205+
case RustSdkCryptoJs.ShieldStateCode.VerificationViolation:
22042206
shieldReason = EventShieldReason.VERIFICATION_VIOLATION;
22052207
break;
22062208
}

yarn.lock

+6-24
Original file line numberDiff line numberDiff line change
@@ -1477,10 +1477,10 @@
14771477
"@jridgewell/resolve-uri" "^3.1.0"
14781478
"@jridgewell/sourcemap-codec" "^1.4.14"
14791479

1480-
"@matrix-org/matrix-sdk-crypto-wasm@^9.0.0":
1481-
version "9.1.0"
1482-
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-9.1.0.tgz#f889653eb4fafaad2a963654d586bd34de62acd5"
1483-
integrity sha512-CtPoNcoRW6ehwxpRQAksG3tR+NJ7k4DV02nMFYTDwQtie1V4R8OTY77BjEIs97NOblhtS26jU8m1lWsOBEz0Og==
1480+
"@matrix-org/matrix-sdk-crypto-wasm@^11.0.0":
1481+
version "11.0.0"
1482+
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-11.0.0.tgz#c49a1a0d1e367d3c00a2144a4ab23caee0b1eec2"
1483+
integrity sha512-a7NUH8Kjc8hwzNCPpkOGXoceFqWJiWvA8OskXeDrKyODJuDz4yKrZ/nvgaVRfQe45Ab5UC1ZXYqaME+ChlJuqg==
14841484

14851485
"@matrix-org/[email protected]":
14861486
version "3.2.15"
@@ -5846,16 +5846,7 @@ string-length@^4.0.1:
58465846
char-regex "^1.0.2"
58475847
strip-ansi "^6.0.0"
58485848

5849-
"string-width-cjs@npm:string-width@^4.2.0":
5850-
version "4.2.3"
5851-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
5852-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
5853-
dependencies:
5854-
emoji-regex "^8.0.0"
5855-
is-fullwidth-code-point "^3.0.0"
5856-
strip-ansi "^6.0.1"
5857-
5858-
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
5849+
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
58595850
version "4.2.3"
58605851
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
58615852
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -6454,16 +6445,7 @@ word-wrap@^1.2.5:
64546445
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34"
64556446
integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==
64566447

6457-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
6458-
version "7.0.0"
6459-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
6460-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
6461-
dependencies:
6462-
ansi-styles "^4.0.0"
6463-
string-width "^4.1.0"
6464-
strip-ansi "^6.0.0"
6465-
6466-
wrap-ansi@^7.0.0:
6448+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
64676449
version "7.0.0"
64686450
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
64696451
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==

0 commit comments

Comments
 (0)