From c2fae3bad8dde2d1a855cd2e512c419b9834dfc0 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 3 Jun 2021 19:02:46 -0600 Subject: [PATCH] Fix missed conversion fallout --- spec/unit/crypto/backup.spec.js | 2 +- src/crypto/backup.ts | 46 ++++++++++++++++----------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/spec/unit/crypto/backup.spec.js b/spec/unit/crypto/backup.spec.js index eeee60fae..1bb8a39f8 100644 --- a/spec/unit/crypto/backup.spec.js +++ b/spec/unit/crypto/backup.spec.js @@ -581,7 +581,7 @@ describe("MegolmBackup", function() { const BAD_BACKUP_INFO = Object.assign({}, BACKUP_INFO, { algorithm: "this.algorithm.does.not.exist", }); - client._http.authedRequest = function() { + client.http.authedRequest = function() { return Promise.resolve(KEY_BACKUP_DATA); }; diff --git a/src/crypto/backup.ts b/src/crypto/backup.ts index d513c24aa..39c9006ff 100644 --- a/src/crypto/backup.ts +++ b/src/crypto/backup.ts @@ -84,7 +84,7 @@ export class BackupManager { private backupInfo: BackupInfo | undefined; // The info dict from /room_keys/version public checkedForBackup: boolean; // Have we checked the server for a backup we can use? private sendingBackups: boolean; // Are we currently sending backups? - constructor(private readonly baseApis, public readonly getKey: GetKey) { + constructor(private readonly baseApis: MatrixClient, public readonly getKey: GetKey) { this.checkedForBackup = false; this.sendingBackups = false; } @@ -268,7 +268,7 @@ export class BackupManager { return ret; } - const trustedPubkey = this.baseApis._crypto._sessionStore.getLocalTrustedBackupPubKey(); + const trustedPubkey = this.baseApis.crypto._sessionStore.getLocalTrustedBackupPubKey(); if (backupInfo.auth_data.public_key === trustedPubkey) { logger.info("Backup public key " + trustedPubkey + " is trusted locally"); @@ -288,12 +288,12 @@ export class BackupManager { const sigInfo: SigInfo = { deviceId: keyIdParts[1] }; // first check to see if it's from our cross-signing key - const crossSigningId = this.baseApis._crypto._crossSigningInfo.getId(); + const crossSigningId = this.baseApis.crypto._crossSigningInfo.getId(); if (crossSigningId === sigInfo.deviceId) { sigInfo.crossSigningId = true; try { await verifySignature( - this.baseApis._crypto._olmDevice, + this.baseApis.crypto._olmDevice, backupInfo.auth_data, this.baseApis.getUserId(), sigInfo.deviceId, @@ -313,7 +313,7 @@ export class BackupManager { // Now look for a sig from a device // At some point this can probably go away and we'll just support // it being signed by the cross-signing master key - const device = this.baseApis._crypto._deviceList.getStoredDevice( + const device = this.baseApis.crypto._deviceList.getStoredDevice( this.baseApis.getUserId(), sigInfo.deviceId, ); if (device) { @@ -323,7 +323,7 @@ export class BackupManager { ); try { await verifySignature( - this.baseApis._crypto._olmDevice, + this.baseApis.crypto._olmDevice, backupInfo.auth_data, this.baseApis.getUserId(), device.deviceId, @@ -400,7 +400,7 @@ export class BackupManager { await this.checkKeyBackup(); // Backup version has changed or this backup version // has been deleted - this.baseApis._crypto.emit("crypto.keyBackupFailed", err.data.errcode); + this.baseApis.crypto.emit("crypto.keyBackupFailed", err.data.errcode); throw err; } } @@ -423,13 +423,13 @@ export class BackupManager { * @returns {integer} Number of sessions backed up */ private async backupPendingKeys(limit: number): Promise { - const sessions = await this.baseApis._crypto._cryptoStore.getSessionsNeedingBackup(limit); + const sessions = await this.baseApis.crypto._cryptoStore.getSessionsNeedingBackup(limit); if (!sessions.length) { return 0; } - let remaining = await this.baseApis._crypto._cryptoStore.countSessionsNeedingBackup(); - this.baseApis._crypto.emit("crypto.keyBackupSessionsRemaining", remaining); + let remaining = await this.baseApis.crypto._cryptoStore.countSessionsNeedingBackup(); + this.baseApis.crypto.emit("crypto.keyBackupSessionsRemaining", remaining); const data = {}; for (const session of sessions) { @@ -438,7 +438,7 @@ export class BackupManager { data[roomId] = { sessions: {} }; } - const sessionData = await this.baseApis._crypto._olmDevice.exportInboundGroupSession( + const sessionData = await this.baseApis.crypto._olmDevice.exportInboundGroupSession( session.senderKey, session.sessionId, session.sessionData, ); sessionData.algorithm = MEGOLM_ALGORITHM; @@ -446,13 +446,13 @@ export class BackupManager { const forwardedCount = (sessionData.forwarding_curve25519_key_chain || []).length; - const userId = this.baseApis._crypto._deviceList.getUserByIdentityKey( + const userId = this.baseApis.crypto._deviceList.getUserByIdentityKey( MEGOLM_ALGORITHM, session.senderKey, ); - const device = this.baseApis._crypto._deviceList.getDeviceByIdentityKey( + const device = this.baseApis.crypto._deviceList.getDeviceByIdentityKey( MEGOLM_ALGORITHM, session.senderKey, ); - const verified = this.baseApis._crypto._checkDeviceInfoTrust(userId, device).isVerified(); + const verified = this.baseApis.crypto._checkDeviceInfoTrust(userId, device).isVerified(); data[roomId]['sessions'][session.sessionId] = { first_message_index: sessionData.first_known_index, @@ -467,9 +467,9 @@ export class BackupManager { { rooms: data }, ); - await this.baseApis._crypto._cryptoStore.unmarkSessionsNeedingBackup(sessions); - remaining = await this.baseApis._crypto._cryptoStore.countSessionsNeedingBackup(); - this.baseApis._crypto.emit("crypto.keyBackupSessionsRemaining", remaining); + await this.baseApis.crypto._cryptoStore.unmarkSessionsNeedingBackup(sessions); + remaining = await this.baseApis.crypto._cryptoStore.countSessionsNeedingBackup(); + this.baseApis.crypto.emit("crypto.keyBackupSessionsRemaining", remaining); return sessions.length; } @@ -477,7 +477,7 @@ export class BackupManager { public async backupGroupSession( senderKey: string, sessionId: string, ): Promise { - await this.baseApis._crypto._cryptoStore.markSessionsNeedingBackup([{ + await this.baseApis.crypto._cryptoStore.markSessionsNeedingBackup([{ senderKey: senderKey, sessionId: sessionId, }]); @@ -509,22 +509,22 @@ export class BackupManager { * (which will be equal to the number of sessions in the store). */ public async flagAllGroupSessionsForBackup(): Promise { - await this.baseApis._crypto._cryptoStore.doTxn( + await this.baseApis.crypto._cryptoStore.doTxn( 'readwrite', [ IndexedDBCryptoStore.STORE_INBOUND_GROUP_SESSIONS, IndexedDBCryptoStore.STORE_BACKUP, ], (txn) => { - this.baseApis._crypto._cryptoStore.getAllEndToEndInboundGroupSessions(txn, (session) => { + this.baseApis.crypto._cryptoStore.getAllEndToEndInboundGroupSessions(txn, (session) => { if (session !== null) { - this.baseApis._crypto._cryptoStore.markSessionsNeedingBackup([session], txn); + this.baseApis.crypto._cryptoStore.markSessionsNeedingBackup([session], txn); } }); }, ); - const remaining = await this.baseApis._crypto._cryptoStore.countSessionsNeedingBackup(); + const remaining = await this.baseApis.crypto._cryptoStore.countSessionsNeedingBackup(); this.baseApis.emit("crypto.keyBackupSessionsRemaining", remaining); return remaining; } @@ -534,7 +534,7 @@ export class BackupManager { * @returns {Promise} Resolves to the number of sessions requiring backup */ public countSessionsNeedingBackup(): Promise { - return this.baseApis._crypto._cryptoStore.countSessionsNeedingBackup(); + return this.baseApis.crypto._cryptoStore.countSessionsNeedingBackup(); } }