Skip to content

Commit 6dc5cf8

Browse files
committed
Update matrix-sdk-crypto-wasm to 11.0.0
1 parent 3781b6e commit 6dc5cf8

5 files changed

Lines changed: 68 additions & 42 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ import {
8282
} from "./olm-utils";
8383
import { KeyBackupInfo } from "../../../src/crypto-api";
8484
import { encodeBase64 } from "../../../src/base64";
85+
import { RustCrypto } from "../../../src/rust-crypto/rust-crypto";
86+
import type { IDeviceKeys } from "../../../src/@types/crypto";
8587

8688
// The verification flows use javascript timers to set timeouts. We tell jest to use mock timer implementations
8789
// to ensure that we don't end up with dangling timeouts.
@@ -990,6 +992,31 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st
990992
aliceClient.setGlobalErrorOnUnknownDevices(false);
991993
syncResponder.sendOrQueueSyncResponse(getSyncResponse([BOB_TEST_USER_ID]));
992994
await syncPromise(aliceClient);
995+
const crypto = aliceClient.getCrypto()!;
996+
if (crypto instanceof RustCrypto) {
997+
// Rust crypto requires the sender's device keys before it accepts
998+
// a verification request.
999+
const bobIdentityKeys = JSON.parse(testOlmAccount.identity_keys());
1000+
const bobDeviceKeys: IDeviceKeys = {
1001+
user_id: "@bob:xyz",
1002+
device_id: "BobDevice",
1003+
algorithms: ["m.olm.v1.curve25519-aes-sha2", "m.megolm.v1.aes-sha2"],
1004+
keys: {
1005+
"curve25519:BobDevice": bobIdentityKeys.curve25519,
1006+
"ed25519:BobDevice": bobIdentityKeys.ed25519,
1007+
},
1008+
};
1009+
const signature = testOlmAccount.sign(anotherjson.stringify(bobDeviceKeys));
1010+
bobDeviceKeys.signatures = {
1011+
"@bob:xyz": {
1012+
"ed25519:BobDevice": signature,
1013+
},
1014+
};
1015+
e2eKeyResponder.addDeviceKeys(bobDeviceKeys);
1016+
await crypto.processDeviceLists({ changed: ["@bob:xyz"] });
1017+
crypto.onSyncCompleted({});
1018+
await crypto.getUserDeviceInfo(["@bob:xyz"]);
1019+
}
9931020
});
9941021

9951022
/**

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

Lines changed: 25 additions & 3 deletions
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

Lines changed: 8 additions & 6 deletions
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

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,10 +1468,10 @@
14681468
"@jridgewell/resolve-uri" "^3.1.0"
14691469
"@jridgewell/sourcemap-codec" "^1.4.14"
14701470

1471-
"@matrix-org/matrix-sdk-crypto-wasm@^9.0.0":
1472-
version "9.1.0"
1473-
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-9.1.0.tgz#f889653eb4fafaad2a963654d586bd34de62acd5"
1474-
integrity sha512-CtPoNcoRW6ehwxpRQAksG3tR+NJ7k4DV02nMFYTDwQtie1V4R8OTY77BjEIs97NOblhtS26jU8m1lWsOBEz0Og==
1471+
"@matrix-org/matrix-sdk-crypto-wasm@^11.0.0":
1472+
version "11.0.0"
1473+
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-11.0.0.tgz#c49a1a0d1e367d3c00a2144a4ab23caee0b1eec2"
1474+
integrity sha512-a7NUH8Kjc8hwzNCPpkOGXoceFqWJiWvA8OskXeDrKyODJuDz4yKrZ/nvgaVRfQe45Ab5UC1ZXYqaME+ChlJuqg==
14751475

14761476
"@matrix-org/olm@3.2.15":
14771477
version "3.2.15"
@@ -6002,16 +6002,7 @@ string-length@^4.0.1:
60026002
char-regex "^1.0.2"
60036003
strip-ansi "^6.0.0"
60046004

6005-
"string-width-cjs@npm:string-width@^4.2.0":
6006-
version "4.2.3"
6007-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
6008-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
6009-
dependencies:
6010-
emoji-regex "^8.0.0"
6011-
is-fullwidth-code-point "^3.0.0"
6012-
strip-ansi "^6.0.1"
6013-
6014-
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
6005+
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
60156006
version "4.2.3"
60166007
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
60176008
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -6074,14 +6065,7 @@ stringify-entities@^4.0.0:
60746065
character-entities-html4 "^2.0.0"
60756066
character-entities-legacy "^3.0.0"
60766067

6077-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
6078-
version "6.0.1"
6079-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
6080-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
6081-
dependencies:
6082-
ansi-regex "^5.0.1"
6083-
6084-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
6068+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
60856069
version "6.0.1"
60866070
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
60876071
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -6677,16 +6661,7 @@ word-wrap@^1.2.5:
66776661
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34"
66786662
integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==
66796663

6680-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
6681-
version "7.0.0"
6682-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
6683-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
6684-
dependencies:
6685-
ansi-styles "^4.0.0"
6686-
string-width "^4.1.0"
6687-
strip-ansi "^6.0.0"
6688-
6689-
wrap-ansi@^7.0.0:
6664+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
66906665
version "7.0.0"
66916666
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
66926667
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==

0 commit comments

Comments
 (0)