diff --git a/src/crypto/backup.ts b/src/crypto/backup.ts index 505409af2..ae87ce706 100644 --- a/src/crypto/backup.ts +++ b/src/crypto/backup.ts @@ -78,7 +78,7 @@ interface BackupAlgorithmClass { key: string | Uint8Array | null, ): Promise<[Uint8Array, AuthData]>; - checkBackupVersion(info: BackupInfo): void; + checkBackupVersion(info: IKeyBackupInfo): void; } interface BackupAlgorithm { @@ -112,9 +112,9 @@ export class BackupManager { * * Throws an error if a problem is detected. * - * @param {BackupInfo} info the key backup info + * @param {IKeyBackupInfo} info the key backup info */ - public static checkBackupVersion(info: BackupInfo): void { + public static checkBackupVersion(info: IKeyBackupInfo): void { const Algorithm = algorithmsByName[info.algorithm]; if (!Algorithm) { throw new Error("Unknown backup algorithm: " + info.algorithm); @@ -273,7 +273,7 @@ export class BackupManager { /** * Check if the given backup info is trusted. * - * @param {object} backupInfo key backup info dict from /room_keys/version + * @param {IKeyBackupInfo} backupInfo key backup info dict from /room_keys/version * @return {object} { * usable: [bool], // is the backup trusted, true iff there is a sig that is valid & from a trusted device * sigs: [ @@ -619,7 +619,7 @@ export class Curve25519 implements BackupAlgorithm { } } - public static checkBackupVersion(info: BackupInfo): void { + public static checkBackupVersion(info: IKeyBackupInfo): void { if (!info.auth_data.public_key) { throw new Error("Invalid backup data returned"); } @@ -754,7 +754,7 @@ export class Aes256 implements BackupAlgorithm { return [outKey, authData]; } - public static checkBackupVersion(info: BackupInfo): void { + public static checkBackupVersion(info: IKeyBackupInfo): void { if (!info.auth_data.iv || !info.auth_data.mac) { throw new Error("Invalid backup data returned"); } diff --git a/src/crypto/index.ts b/src/crypto/index.ts index 12b05ffac..74f0df5a4 100644 --- a/src/crypto/index.ts +++ b/src/crypto/index.ts @@ -126,6 +126,7 @@ export interface IMegolmSessionData { session_id: string; session_key: string; algorithm: string; + untrusted?: boolean; } /* eslint-enable camelcase */ diff --git a/src/crypto/key_passphrase.ts b/src/crypto/key_passphrase.ts index ca11e7d2f..89aefc803 100644 --- a/src/crypto/key_passphrase.ts +++ b/src/crypto/key_passphrase.ts @@ -15,18 +15,13 @@ limitations under the License. */ import { randomString } from '../randomstring'; +import { IKeyBackupInfo } from "./keybackup"; const DEFAULT_ITERATIONS = 500000; const DEFAULT_BITSIZE = 256; -/* eslint-disable camelcase */ -interface IAuthData { - private_key_salt: string; - private_key_iterations: number; - private_key_bits?: number; -} -/* eslint-enable camelcase */ +type IAuthData = IKeyBackupInfo["auth_data"]; interface IKey { key: Uint8Array; diff --git a/src/crypto/keybackup.ts b/src/crypto/keybackup.ts index 123f18f76..d2cb481fa 100644 --- a/src/crypto/keybackup.ts +++ b/src/crypto/keybackup.ts @@ -35,11 +35,13 @@ export interface IKeyBackupRoomSessions { export interface IKeyBackupInfo { algorithm: string; auth_data: { - public_key: string; - signatures: ISignatures; - private_key_salt: string; - private_key_iterations: number; + public_key?: string; + signatures?: ISignatures; + private_key_salt?: string; + private_key_iterations?: number; private_key_bits?: number; + iv?: string; + mac?: string; }; count?: number; etag?: string;