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,7 +672,13 @@ Crypto.prototype._afterCrossSigningLocalKeyChange = async function() {
},
});
// check all users for signatures
const shouldUpgradeCb = (
this._baseApis._cryptoCallbacks.shouldUpgradeDeviceVerifications
);
if (shouldUpgradeCb) {
logger.info("Starting device verification upgrade");
// Check all users for signatures if upgrade callback present
// FIXME: do this in batches
const users = {};
for (const [userId, crossSigningInfo]
@@ -685,10 +691,8 @@ Crypto.prototype._afterCrossSigningLocalKeyChange = async function() {
}
}
const shouldUpgradeCb = (
this._baseApis._cryptoCallbacks.shouldUpgradeDeviceVerifications
);
if (Object.keys(users).length > 0 && shouldUpgradeCb) {
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) {
@@ -707,6 +711,9 @@ Crypto.prototype._afterCrossSigningLocalKeyChange = async function() {
}
}
logger.info("Finished device verification upgrade");
}
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
*/
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) {
const crossSigningInfo = this._deviceList.getStoredCrossSigningForUser(userId);
if (crossSigningInfo) {
const upgradeInfo = await this._checkForDeviceVerificationUpgrade(
userId, crossSigningInfo,
);
const shouldUpgradeCb = (
this._baseApis._cryptoCallbacks.shouldUpgradeDeviceVerifications
);
if (upgradeInfo && shouldUpgradeCb) {
if (upgradeInfo) {
const usersToUpgrade = await shouldUpgradeCb({
users: {
[userId]: upgradeInfo,
@@ -1007,6 +1019,7 @@ Crypto.prototype._checkDeviceVerifications = async function(userId) {
}
}
}
logger.info(`Finished device verification upgrade for ${userId}`);
};
/**