You've already forked matrix-js-sdk
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:
@@ -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 = (
|
||||
this._baseApis._cryptoCallbacks.shouldUpgradeDeviceVerifications
|
||||
);
|
||||
if (Object.keys(users).length > 0 && shouldUpgradeCb) {
|
||||
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(),
|
||||
);
|
||||
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]
|
||||
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");
|
||||
@@ -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}`);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user