1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-01 04:43:29 +03:00

Skip device verif upgrades when callback not present

This skips the upgrade when the upgrade callback is not present (which is
expected as no one sets it currently). This adds logging for around the upgrade
process.
This commit is contained in:
J. Ryan Stinnett
2020-03-09 15:03:00 +00:00
parent 4fdd817ff5
commit 951fff45e6

View File

@@ -672,39 +672,46 @@ Crypto.prototype._afterCrossSigningLocalKeyChange = async function() {
}, },
}); });
// check all users for signatures
// FIXME: do this in batches
const users = {};
for (const [userId, crossSigningInfo]
of Object.entries(this._deviceList._crossSigningInfo)) {
const upgradeInfo = await this._checkForDeviceVerificationUpgrade(
userId, CrossSigningInfo.fromStorage(crossSigningInfo, userId),
);
if (upgradeInfo) {
users[userId] = upgradeInfo;
}
}
const shouldUpgradeCb = ( const shouldUpgradeCb = (
this._baseApis._cryptoCallbacks.shouldUpgradeDeviceVerifications this._baseApis._cryptoCallbacks.shouldUpgradeDeviceVerifications
); );
if (Object.keys(users).length > 0 && shouldUpgradeCb) { if (shouldUpgradeCb) {
try { logger.info("Starting device verification upgrade");
const usersToUpgrade = await shouldUpgradeCb({users: users});
if (usersToUpgrade) { // Check all users for signatures if upgrade callback present
for (const userId of usersToUpgrade) { // FIXME: do this in batches
if (userId in users) { const users = {};
await this._baseApis.setDeviceVerified( for (const [userId, crossSigningInfo]
userId, users[userId].crossSigningInfo.getId(), of Object.entries(this._deviceList._crossSigningInfo)) {
); const upgradeInfo = await this._checkForDeviceVerificationUpgrade(
userId, CrossSigningInfo.fromStorage(crossSigningInfo, userId),
);
if (upgradeInfo) {
users[userId] = upgradeInfo;
}
}
if (Object.keys(users).length > 0) {
logger.info(`Found ${Object.keys(users).length} verif users to upgrade`);
try {
const usersToUpgrade = await shouldUpgradeCb({ users: users });
if (usersToUpgrade) {
for (const userId of usersToUpgrade) {
if (userId in users) {
await this._baseApis.setDeviceVerified(
userId, users[userId].crossSigningInfo.getId(),
);
}
} }
} }
} catch (e) {
logger.log(
"shouldUpgradeDeviceVerifications threw an error: not upgrading", e,
);
} }
} catch (e) {
logger.log(
"shouldUpgradeDeviceVerifications threw an error: not upgrading", e,
);
} }
logger.info("Finished device verification upgrade");
} }
logger.info("Finished cross-signing key change post-processing"); logger.info("Finished cross-signing key change post-processing");
@@ -984,16 +991,21 @@ Crypto.prototype._storeTrustedSelfKeys = async function(keys) {
* @param {string} userId the user ID whose key should be checked * @param {string} userId the user ID whose key should be checked
*/ */
Crypto.prototype._checkDeviceVerifications = async function(userId) { Crypto.prototype._checkDeviceVerifications = async function(userId) {
const shouldUpgradeCb = (
this._baseApis._cryptoCallbacks.shouldUpgradeDeviceVerifications
);
if (!shouldUpgradeCb) {
// Upgrading skipped when callback is not present.
return;
}
logger.info(`Starting device verification upgrade for ${userId}`);
if (this._crossSigningInfo.keys.user_signing) { if (this._crossSigningInfo.keys.user_signing) {
const crossSigningInfo = this._deviceList.getStoredCrossSigningForUser(userId); const crossSigningInfo = this._deviceList.getStoredCrossSigningForUser(userId);
if (crossSigningInfo) { if (crossSigningInfo) {
const upgradeInfo = await this._checkForDeviceVerificationUpgrade( const upgradeInfo = await this._checkForDeviceVerificationUpgrade(
userId, crossSigningInfo, userId, crossSigningInfo,
); );
const shouldUpgradeCb = ( if (upgradeInfo) {
this._baseApis._cryptoCallbacks.shouldUpgradeDeviceVerifications
);
if (upgradeInfo && shouldUpgradeCb) {
const usersToUpgrade = await shouldUpgradeCb({ const usersToUpgrade = await shouldUpgradeCb({
users: { users: {
[userId]: upgradeInfo, [userId]: upgradeInfo,
@@ -1007,6 +1019,7 @@ Crypto.prototype._checkDeviceVerifications = async function(userId) {
} }
} }
} }
logger.info(`Finished device verification upgrade for ${userId}`);
}; };
/** /**