You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-29 16:43:09 +03:00
Merge pull request #3202 from matrix-org/rav/element-r/encryption_fixes
Fixes to event encryption in the Rust Crypto implementation
This commit is contained in:
@@ -54,7 +54,12 @@ export class KeyClaimManager {
|
|||||||
// The Rust-SDK requires that we only have one getMissingSessions process in flight at once. This little dance
|
// The Rust-SDK requires that we only have one getMissingSessions process in flight at once. This little dance
|
||||||
// ensures that, by only having one call to ensureSessionsForUsersInner active at once (and making them
|
// ensures that, by only having one call to ensureSessionsForUsersInner active at once (and making them
|
||||||
// queue up in order).
|
// queue up in order).
|
||||||
const prom = this.currentClaimPromise.finally(() => this.ensureSessionsForUsersInner(userList));
|
const prom = this.currentClaimPromise
|
||||||
|
.catch(() => {
|
||||||
|
// any errors in the previous claim will have been reported already, so there is nothing to do here.
|
||||||
|
// we just throw away the error and start anew.
|
||||||
|
})
|
||||||
|
.then(() => this.ensureSessionsForUsersInner(userList));
|
||||||
this.currentClaimPromise = prom;
|
this.currentClaimPromise = prom;
|
||||||
return prom;
|
return prom;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import { Room } from "../models/room";
|
|||||||
import { logger, PrefixedLogger } from "../logger";
|
import { logger, PrefixedLogger } from "../logger";
|
||||||
import { KeyClaimManager } from "./KeyClaimManager";
|
import { KeyClaimManager } from "./KeyClaimManager";
|
||||||
import { RoomMember } from "../models/room-member";
|
import { RoomMember } from "../models/room-member";
|
||||||
|
import { OutgoingRequestProcessor } from "./OutgoingRequestProcessor";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RoomEncryptor: responsible for encrypting messages to a given room
|
* RoomEncryptor: responsible for encrypting messages to a given room
|
||||||
@@ -38,6 +39,7 @@ export class RoomEncryptor {
|
|||||||
public constructor(
|
public constructor(
|
||||||
private readonly olmMachine: OlmMachine,
|
private readonly olmMachine: OlmMachine,
|
||||||
private readonly keyClaimManager: KeyClaimManager,
|
private readonly keyClaimManager: KeyClaimManager,
|
||||||
|
private readonly outgoingRequestProcessor: OutgoingRequestProcessor,
|
||||||
private readonly room: Room,
|
private readonly room: Room,
|
||||||
private encryptionSettings: IContent,
|
private encryptionSettings: IContent,
|
||||||
) {
|
) {
|
||||||
@@ -97,10 +99,21 @@ export class RoomEncryptor {
|
|||||||
const userList = members.map((u) => new UserId(u.userId));
|
const userList = members.map((u) => new UserId(u.userId));
|
||||||
await this.keyClaimManager.ensureSessionsForUsers(userList);
|
await this.keyClaimManager.ensureSessionsForUsers(userList);
|
||||||
|
|
||||||
|
this.prefixedLogger.debug("Sessions for users are ready; now sharing room key");
|
||||||
|
|
||||||
const rustEncryptionSettings = new EncryptionSettings();
|
const rustEncryptionSettings = new EncryptionSettings();
|
||||||
/* FIXME historyVisibility, rotation, etc */
|
/* FIXME historyVisibility, rotation, etc */
|
||||||
|
|
||||||
await this.olmMachine.shareRoomKey(new RoomId(this.room.roomId), userList, rustEncryptionSettings);
|
const shareMessages = await this.olmMachine.shareRoomKey(
|
||||||
|
new RoomId(this.room.roomId),
|
||||||
|
userList,
|
||||||
|
rustEncryptionSettings,
|
||||||
|
);
|
||||||
|
if (shareMessages) {
|
||||||
|
for (const m of shareMessages) {
|
||||||
|
await this.outgoingRequestProcessor.makeOutgoingRequest(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -204,7 +204,13 @@ export class RustCrypto implements CryptoBackend {
|
|||||||
if (existingEncryptor) {
|
if (existingEncryptor) {
|
||||||
existingEncryptor.onCryptoEvent(config);
|
existingEncryptor.onCryptoEvent(config);
|
||||||
} else {
|
} else {
|
||||||
this.roomEncryptors[room.roomId] = new RoomEncryptor(this.olmMachine, this.keyClaimManager, room, config);
|
this.roomEncryptors[room.roomId] = new RoomEncryptor(
|
||||||
|
this.olmMachine,
|
||||||
|
this.keyClaimManager,
|
||||||
|
this.outgoingRequestProcessor,
|
||||||
|
room,
|
||||||
|
config,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// start tracking devices for any users already known to be in this room.
|
// start tracking devices for any users already known to be in this room.
|
||||||
|
|||||||
Reference in New Issue
Block a user