From e5ec2f03c2792b8022124dbbc0f661e0f835f673 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Thu, 12 Mar 2020 14:21:46 +0000 Subject: [PATCH 1/2] Convert `trustedLocally` to a bool in all cases This ensure we always have a boolean value, even when device is null. Part of https://github.com/vector-im/riot-web/issues/12693 --- src/crypto/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/index.js b/src/crypto/index.js index fac954266..0af393709 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -842,7 +842,7 @@ Crypto.prototype.checkDeviceTrust = function(userId, deviceId) { * @returns {DeviceTrustLevel} */ Crypto.prototype._checkDeviceInfoTrust = function(userId, device) { - const trustedLocally = device && device.isVerified(); + const trustedLocally = !!(device && device.isVerified()); const userCrossSigning = this._deviceList.getStoredCrossSigningForUser(userId); if (device && userCrossSigning) { From 3b7def880f3118ccc613e8967c6675ec5629ce87 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Thu, 12 Mar 2020 14:47:28 +0000 Subject: [PATCH 2/2] Check key backup trust for the right user ID This corrects the key backup trust computation so that we use the user ID for the device we're checking inside of always using the client's main user ID, which would always resulted in false for other people. Fixes https://github.com/vector-im/riot-web/issues/12693 --- src/crypto/DeviceList.js | 30 +++++++++++++++++++++--------- src/crypto/index.js | 5 ++++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/crypto/DeviceList.js b/src/crypto/DeviceList.js index c31ab9898..6ef8a0dee 100644 --- a/src/crypto/DeviceList.js +++ b/src/crypto/DeviceList.js @@ -379,6 +379,26 @@ export class DeviceList extends EventEmitter { return DeviceInfo.fromStorage(devs[deviceId], deviceId); } + /** + * Get a user ID by one of their device's curve25519 identity key + * + * @param {string} algorithm encryption algorithm + * @param {string} senderKey curve25519 key to match + * + * @return {string} user ID + */ + getUserByIdentityKey(algorithm, senderKey) { + if ( + algorithm !== olmlib.OLM_ALGORITHM && + algorithm !== olmlib.MEGOLM_ALGORITHM + ) { + // we only deal in olm keys + return null; + } + + return this._userByIdentityKey[senderKey]; + } + /** * Find a device by curve25519 identity key * @@ -388,19 +408,11 @@ export class DeviceList extends EventEmitter { * @return {module:crypto/deviceinfo?} */ getDeviceByIdentityKey(algorithm, senderKey) { - const userId = this._userByIdentityKey[senderKey]; + const userId = this.getUserByIdentityKey(algorithm, senderKey); if (!userId) { return null; } - if ( - algorithm !== olmlib.OLM_ALGORITHM && - algorithm !== olmlib.MEGOLM_ALGORITHM - ) { - // we only deal in olm keys - return null; - } - const devices = this._devices[userId]; if (!devices) { return null; diff --git a/src/crypto/index.js b/src/crypto/index.js index 0af393709..3d7d5285b 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -2168,10 +2168,13 @@ Crypto.prototype._backupPendingKeys = async function(limit) { const forwardedCount = (sessionData.forwarding_curve25519_key_chain || []).length; + const userId = this._deviceList.getUserByIdentityKey( + olmlib.MEGOLM_ALGORITHM, session.senderKey, + ); const device = this._deviceList.getDeviceByIdentityKey( olmlib.MEGOLM_ALGORITHM, session.senderKey, ); - const verified = this._checkDeviceInfoTrust(this._userId, device).isVerified(); + const verified = this._checkDeviceInfoTrust(userId, device).isVerified(); data[roomId]['sessions'][session.sessionId] = { first_message_index: firstKnownIndex,