You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-23 17:02:25 +03:00
Bump matrix-sdk-crypto-wasm to 5.0.0 (#4216)
Slightly more involved than normal because it requires us to pass a backup version into OlmMachine.importBackedUpRoomKeys. On the other hand we can now re-enable the test that was disabled in #4214 due to matrix-org/matrix-rust-sdk#3447 Fixes: element-hq/element-web#27165
This commit is contained in:
committed by
GitHub
parent
36196ea422
commit
b19817bb73
@@ -53,7 +53,7 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.12.5",
|
"@babel/runtime": "^7.12.5",
|
||||||
"@matrix-org/matrix-sdk-crypto-wasm": "^4.9.0",
|
"@matrix-org/matrix-sdk-crypto-wasm": "^5.0.0",
|
||||||
"another-json": "^0.2.0",
|
"another-json": "^0.2.0",
|
||||||
"bs58": "^5.0.0",
|
"bs58": "^5.0.0",
|
||||||
"content-type": "^1.0.4",
|
"content-type": "^1.0.4",
|
||||||
|
|||||||
@@ -1415,19 +1415,19 @@ describe("RustCrypto", () => {
|
|||||||
expect(await keyBackupStatusPromise).toBe(true);
|
expect(await keyBackupStatusPromise).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
// XXX: disabled until https://github.com/matrix-org/matrix-rust-sdk/issues/3447 is fixed
|
it("does not back up keys that came from backup", async () => {
|
||||||
it.skip("does not back up keys that came from backup", async () => {
|
|
||||||
const rustCrypto = await makeTestRustCrypto();
|
const rustCrypto = await makeTestRustCrypto();
|
||||||
const olmMachine: OlmMachine = rustCrypto["olmMachine"];
|
const olmMachine: OlmMachine = rustCrypto["olmMachine"];
|
||||||
|
|
||||||
|
const backupVersion = testData.SIGNED_BACKUP_DATA.version!;
|
||||||
await olmMachine.enableBackupV1(
|
await olmMachine.enableBackupV1(
|
||||||
(testData.SIGNED_BACKUP_DATA.auth_data as Curve25519AuthData).public_key,
|
(testData.SIGNED_BACKUP_DATA.auth_data as Curve25519AuthData).public_key,
|
||||||
testData.SIGNED_BACKUP_DATA.version!,
|
backupVersion,
|
||||||
);
|
);
|
||||||
|
|
||||||
// we import two keys: one "from backup", and one "from export"
|
// we import two keys: one "from backup", and one "from export"
|
||||||
const [backedUpRoomKey, exportedRoomKey] = testData.MEGOLM_SESSION_DATA_ARRAY;
|
const [backedUpRoomKey, exportedRoomKey] = testData.MEGOLM_SESSION_DATA_ARRAY;
|
||||||
await rustCrypto.importBackedUpRoomKeys([backedUpRoomKey]);
|
await rustCrypto.importBackedUpRoomKeys([backedUpRoomKey], backupVersion);
|
||||||
await rustCrypto.importRoomKeys([exportedRoomKey]);
|
await rustCrypto.importRoomKeys([exportedRoomKey]);
|
||||||
|
|
||||||
// we ask for the keys that should be backed up
|
// we ask for the keys that should be backed up
|
||||||
@@ -1462,16 +1462,17 @@ describe("RustCrypto", () => {
|
|||||||
const rustCrypto = await makeTestRustCrypto();
|
const rustCrypto = await makeTestRustCrypto();
|
||||||
const olmMachine: OlmMachine = rustCrypto["olmMachine"];
|
const olmMachine: OlmMachine = rustCrypto["olmMachine"];
|
||||||
|
|
||||||
|
const backupVersion = testData.SIGNED_BACKUP_DATA.version!;
|
||||||
await olmMachine.enableBackupV1(
|
await olmMachine.enableBackupV1(
|
||||||
(testData.SIGNED_BACKUP_DATA.auth_data as Curve25519AuthData).public_key,
|
(testData.SIGNED_BACKUP_DATA.auth_data as Curve25519AuthData).public_key,
|
||||||
testData.SIGNED_BACKUP_DATA.version!,
|
backupVersion,
|
||||||
);
|
);
|
||||||
|
|
||||||
const backup = Array.from(testData.MEGOLM_SESSION_DATA_ARRAY);
|
const backup = Array.from(testData.MEGOLM_SESSION_DATA_ARRAY);
|
||||||
// in addition to correct keys, we restore an invalid key
|
// in addition to correct keys, we restore an invalid key
|
||||||
backup.push({ room_id: "!roomid", session_id: "sessionid" } as IMegolmSessionData);
|
backup.push({ room_id: "!roomid", session_id: "sessionid" } as IMegolmSessionData);
|
||||||
const progressCallback = jest.fn();
|
const progressCallback = jest.fn();
|
||||||
await rustCrypto.importBackedUpRoomKeys(backup, { progressCallback });
|
await rustCrypto.importBackedUpRoomKeys(backup, backupVersion, { progressCallback });
|
||||||
expect(progressCallback).toHaveBeenCalledWith({
|
expect(progressCallback).toHaveBeenCalledWith({
|
||||||
total: 3,
|
total: 3,
|
||||||
successes: 0,
|
successes: 0,
|
||||||
|
|||||||
@@ -3863,12 +3863,13 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
if (!backupInfo.version) {
|
if (!backupInfo.version) {
|
||||||
throw new Error("Backup version must be defined");
|
throw new Error("Backup version must be defined");
|
||||||
}
|
}
|
||||||
|
const backupVersion = backupInfo.version!;
|
||||||
|
|
||||||
let totalKeyCount = 0;
|
let totalKeyCount = 0;
|
||||||
let totalFailures = 0;
|
let totalFailures = 0;
|
||||||
let totalImported = 0;
|
let totalImported = 0;
|
||||||
|
|
||||||
const path = this.makeKeyBackupPath(targetRoomId, targetSessionId, backupInfo.version);
|
const path = this.makeKeyBackupPath(targetRoomId, targetSessionId, backupVersion);
|
||||||
|
|
||||||
const backupDecryptor = await this.cryptoBackend.getBackupDecryptor(backupInfo, privKey);
|
const backupDecryptor = await this.cryptoBackend.getBackupDecryptor(backupInfo, privKey);
|
||||||
|
|
||||||
@@ -3882,7 +3883,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
// Cache the key, if possible.
|
// Cache the key, if possible.
|
||||||
// This is async.
|
// This is async.
|
||||||
this.cryptoBackend
|
this.cryptoBackend
|
||||||
.storeSessionBackupPrivateKey(privKey, backupInfo.version)
|
.storeSessionBackupPrivateKey(privKey, backupVersion)
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
this.logger.warn("Error caching session backup key:", e);
|
this.logger.warn("Error caching session backup key:", e);
|
||||||
})
|
})
|
||||||
@@ -3922,7 +3923,8 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
async (chunk) => {
|
async (chunk) => {
|
||||||
// We have a chunk of decrypted keys: import them
|
// We have a chunk of decrypted keys: import them
|
||||||
try {
|
try {
|
||||||
await this.cryptoBackend!.importBackedUpRoomKeys(chunk, {
|
const backupVersion = backupInfo.version!;
|
||||||
|
await this.cryptoBackend!.importBackedUpRoomKeys(chunk, backupVersion, {
|
||||||
untrusted,
|
untrusted,
|
||||||
});
|
});
|
||||||
totalImported += chunk.length;
|
totalImported += chunk.length;
|
||||||
@@ -3952,7 +3954,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
for (const k of keys) {
|
for (const k of keys) {
|
||||||
k.room_id = targetRoomId!;
|
k.room_id = targetRoomId!;
|
||||||
}
|
}
|
||||||
await this.cryptoBackend.importBackedUpRoomKeys(keys, {
|
await this.cryptoBackend.importBackedUpRoomKeys(keys, backupVersion, {
|
||||||
progressCallback,
|
progressCallback,
|
||||||
untrusted,
|
untrusted,
|
||||||
});
|
});
|
||||||
@@ -3966,7 +3968,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
key.room_id = targetRoomId!;
|
key.room_id = targetRoomId!;
|
||||||
key.session_id = targetSessionId!;
|
key.session_id = targetSessionId!;
|
||||||
|
|
||||||
await this.cryptoBackend.importBackedUpRoomKeys([key], {
|
await this.cryptoBackend.importBackedUpRoomKeys([key], backupVersion, {
|
||||||
progressCallback,
|
progressCallback,
|
||||||
untrusted,
|
untrusted,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -113,10 +113,11 @@ export interface CryptoBackend extends SyncCryptoCallbacks, CryptoApi {
|
|||||||
* Import a list of room keys restored from backup
|
* Import a list of room keys restored from backup
|
||||||
*
|
*
|
||||||
* @param keys - a list of session export objects
|
* @param keys - a list of session export objects
|
||||||
|
* @param backupVersion - the version of the backup these keys came from.
|
||||||
* @param opts - options object
|
* @param opts - options object
|
||||||
* @returns a promise which resolves once the keys have been imported
|
* @returns a promise which resolves once the keys have been imported
|
||||||
*/
|
*/
|
||||||
importBackedUpRoomKeys(keys: IMegolmSessionData[], opts?: ImportRoomKeysOpts): Promise<void>;
|
importBackedUpRoomKeys(keys: IMegolmSessionData[], backupVersion: string, opts?: ImportRoomKeysOpts): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The methods which crypto implementations should expose to the Sync api
|
/** The methods which crypto implementations should expose to the Sync api
|
||||||
|
|||||||
@@ -1888,7 +1888,11 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
|
|||||||
/**
|
/**
|
||||||
* Implementation of {@link CryptoBackend#importBackedUpRoomKeys}.
|
* Implementation of {@link CryptoBackend#importBackedUpRoomKeys}.
|
||||||
*/
|
*/
|
||||||
public importBackedUpRoomKeys(keys: IMegolmSessionData[], opts: ImportRoomKeysOpts = {}): Promise<void> {
|
public importBackedUpRoomKeys(
|
||||||
|
keys: IMegolmSessionData[],
|
||||||
|
backupVersion: string,
|
||||||
|
opts: ImportRoomKeysOpts = {},
|
||||||
|
): Promise<void> {
|
||||||
opts.source = "backup";
|
opts.source = "backup";
|
||||||
return this.importRoomKeys(keys, opts);
|
return this.importRoomKeys(keys, opts);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,10 +57,14 @@ class KeyDownloadRateLimitError extends Error {
|
|||||||
/** Details of a megolm session whose key we are trying to fetch. */
|
/** Details of a megolm session whose key we are trying to fetch. */
|
||||||
type SessionInfo = { roomId: string; megolmSessionId: string };
|
type SessionInfo = { roomId: string; megolmSessionId: string };
|
||||||
|
|
||||||
/** Holds the current backup decryptor and version that should be used. */
|
/** Holds the current backup decryptor and version that should be used.
|
||||||
|
*
|
||||||
|
* This is intended to be used as an immutable object (a new instance should be created if the configuration changes),
|
||||||
|
* and some of the logic relies on that, so the properties are marked as `readonly`.
|
||||||
|
*/
|
||||||
type Configuration = {
|
type Configuration = {
|
||||||
backupVersion: string;
|
readonly backupVersion: string;
|
||||||
decryptor: BackupDecryptor;
|
readonly decryptor: BackupDecryptor;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -392,7 +396,7 @@ export class PerSessionKeyBackupDownloader {
|
|||||||
for (const k of keys) {
|
for (const k of keys) {
|
||||||
k.room_id = sessionInfo.roomId;
|
k.room_id = sessionInfo.roomId;
|
||||||
}
|
}
|
||||||
await this.backupManager.importBackedUpRoomKeys(keys);
|
await this.backupManager.importBackedUpRoomKeys(keys, configuration.backupVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -239,7 +239,11 @@ export class RustBackupManager extends TypedEventEmitter<RustBackupCryptoEvents,
|
|||||||
/**
|
/**
|
||||||
* Implementation of {@link CryptoBackend#importBackedUpRoomKeys}.
|
* Implementation of {@link CryptoBackend#importBackedUpRoomKeys}.
|
||||||
*/
|
*/
|
||||||
public async importBackedUpRoomKeys(keys: IMegolmSessionData[], opts?: ImportRoomKeysOpts): Promise<void> {
|
public async importBackedUpRoomKeys(
|
||||||
|
keys: IMegolmSessionData[],
|
||||||
|
backupVersion: string,
|
||||||
|
opts?: ImportRoomKeysOpts,
|
||||||
|
): Promise<void> {
|
||||||
const keysByRoom: Map<RustSdkCryptoJs.RoomId, Map<string, IMegolmSessionData>> = new Map();
|
const keysByRoom: Map<RustSdkCryptoJs.RoomId, Map<string, IMegolmSessionData>> = new Map();
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
const roomId = new RustSdkCryptoJs.RoomId(key.room_id);
|
const roomId = new RustSdkCryptoJs.RoomId(key.room_id);
|
||||||
@@ -259,6 +263,7 @@ export class RustBackupManager extends TypedEventEmitter<RustBackupCryptoEvents,
|
|||||||
};
|
};
|
||||||
opts?.progressCallback?.(importOpt);
|
opts?.progressCallback?.(importOpt);
|
||||||
},
|
},
|
||||||
|
backupVersion,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1217,8 +1217,12 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, RustCryptoEv
|
|||||||
/**
|
/**
|
||||||
* Implementation of {@link CryptoBackend#importBackedUpRoomKeys}.
|
* Implementation of {@link CryptoBackend#importBackedUpRoomKeys}.
|
||||||
*/
|
*/
|
||||||
public async importBackedUpRoomKeys(keys: IMegolmSessionData[], opts?: ImportRoomKeysOpts): Promise<void> {
|
public async importBackedUpRoomKeys(
|
||||||
return await this.backupManager.importBackedUpRoomKeys(keys, opts);
|
keys: IMegolmSessionData[],
|
||||||
|
backupVersion: string,
|
||||||
|
opts?: ImportRoomKeysOpts,
|
||||||
|
): Promise<void> {
|
||||||
|
return await this.backupManager.importBackedUpRoomKeys(keys, backupVersion, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1772,10 +1772,10 @@
|
|||||||
"@jridgewell/resolve-uri" "^3.1.0"
|
"@jridgewell/resolve-uri" "^3.1.0"
|
||||||
"@jridgewell/sourcemap-codec" "^1.4.14"
|
"@jridgewell/sourcemap-codec" "^1.4.14"
|
||||||
|
|
||||||
"@matrix-org/matrix-sdk-crypto-wasm@^4.9.0":
|
"@matrix-org/matrix-sdk-crypto-wasm@^5.0.0":
|
||||||
version "4.10.0"
|
version "5.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-4.10.0.tgz#324211b9bad3d2aa640800f62ba9478ce2845097"
|
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-5.0.0.tgz#f45a7bccaad218c05bcf9e7c8ca783c9d9a07af4"
|
||||||
integrity sha512-zOqKVAYPfzs6Hav/Km9F5xWwoQ0bxDuoUU0/121m03Fg2VnfcHk43TjKImZolFc7IlgXwVGoda9Pp9Z/eTVKJA==
|
integrity sha512-37ASjCKSTU5ycGfkP+LUXG4Ok6OAf6vE+1qU6uwWhe6FwadCS3vVWzJYd/3d9BQFwsx4GhFTIAXrW4iLG85rmQ==
|
||||||
|
|
||||||
"@matrix-org/olm@3.2.15":
|
"@matrix-org/olm@3.2.15":
|
||||||
version "3.2.15"
|
version "3.2.15"
|
||||||
|
|||||||
Reference in New Issue
Block a user