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
Element-R: check persistent room list for encryption config (#4035)
* crypto.spec: make `keyResponder` a local var it is never used between functions, so making it external was confusing * Persist encryption state to the rust room list. * `MatrixClient.shouldEncryptEventForRoom`: fix for rust crypto Previously, we were not bothering to ask the Rust Crypto stack if it thought we should be encrypting for a given room. This adds a new method to `CryptoApi`, wires it up for legacy and Rust crypto, and calls it. * Tests for persistent room list
This commit is contained in:
committed by
GitHub
parent
869576747c
commit
11348f9532
@@ -311,6 +311,16 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, RustCryptoEv
|
||||
return `Rust SDK ${versions.matrix_sdk_crypto} (${versions.git_sha}), Vodozemac ${versions.vodozemac}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link CryptoApi#isEncryptionEnabledInRoom}.
|
||||
*/
|
||||
public async isEncryptionEnabledInRoom(roomId: string): Promise<boolean> {
|
||||
const roomSettings: RustSdkCryptoJs.RoomSettings | undefined = await this.olmMachine.getRoomSettings(
|
||||
new RustSdkCryptoJs.RoomId(roomId),
|
||||
);
|
||||
return Boolean(roomSettings?.algorithm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link CryptoApi#getOwnDeviceKeys}.
|
||||
*/
|
||||
@@ -1285,7 +1295,27 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, RustCryptoEv
|
||||
*/
|
||||
public async onCryptoEvent(room: Room, event: MatrixEvent): Promise<void> {
|
||||
const config = event.getContent();
|
||||
const settings = new RustSdkCryptoJs.RoomSettings();
|
||||
|
||||
if (config.algorithm === "m.megolm.v1.aes-sha2") {
|
||||
settings.algorithm = RustSdkCryptoJs.EncryptionAlgorithm.MegolmV1AesSha2;
|
||||
} else {
|
||||
// Among other situations, this happens if the crypto state event is redacted.
|
||||
this.logger.warn(`Room ${room.roomId}: ignoring crypto event with invalid algorithm ${config.algorithm}`);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
settings.sessionRotationPeriodMs = config.rotation_period_ms;
|
||||
settings.sessionRotationPeriodMessages = config.rotation_period_msgs;
|
||||
await this.olmMachine.setRoomSettings(new RustSdkCryptoJs.RoomId(room.roomId), settings);
|
||||
} catch (e) {
|
||||
this.logger.warn(`Room ${room.roomId}: ignoring crypto event which caused error: ${e}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// If we got this far, the SDK found the event acceptable.
|
||||
// We need to either create or update the active RoomEncryptor.
|
||||
const existingEncryptor = this.roomEncryptors[room.roomId];
|
||||
if (existingEncryptor) {
|
||||
existingEncryptor.onCryptoEvent(config);
|
||||
|
||||
Reference in New Issue
Block a user