You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Make olmlib.verifySignature async
This commit is contained in:
@@ -587,7 +587,7 @@ function _updateStoredDeviceKeysForUser(_olmDevice, userId, userStore,
|
|||||||
const unsigned = deviceResult.unsigned || {};
|
const unsigned = deviceResult.unsigned || {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
olmlib.verifySignature(_olmDevice, deviceResult, userId, deviceId, signKey);
|
await olmlib.verifySignature(_olmDevice, deviceResult, userId, deviceId, signKey);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("Unable to verify signature on device " +
|
console.warn("Unable to verify signature on device " +
|
||||||
userId + ":" + deviceId + ":" + e);
|
userId + ":" + deviceId + ":" + e);
|
||||||
|
|||||||
@@ -165,6 +165,7 @@ module.exports.ensureOlmSessionsForDevices = function(
|
|||||||
devicesWithoutSession, oneTimeKeyAlgorithm,
|
devicesWithoutSession, oneTimeKeyAlgorithm,
|
||||||
).then(function(res) {
|
).then(function(res) {
|
||||||
const otk_res = res.one_time_keys || {};
|
const otk_res = res.one_time_keys || {};
|
||||||
|
const promises = [];
|
||||||
for (const userId in devicesByUser) {
|
for (const userId in devicesByUser) {
|
||||||
if (!devicesByUser.hasOwnProperty(userId)) {
|
if (!devicesByUser.hasOwnProperty(userId)) {
|
||||||
continue;
|
continue;
|
||||||
@@ -195,21 +196,23 @@ module.exports.ensureOlmSessionsForDevices = function(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sid = _verifyKeyAndStartSession(
|
promises.push(
|
||||||
olmDevice, oneTimeKey, userId, deviceInfo,
|
_verifyKeyAndStartSession(
|
||||||
|
olmDevice, oneTimeKey, userId, deviceInfo,
|
||||||
|
).then((sid) => {
|
||||||
|
result[userId][deviceId].sessionId = sid;
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
result[userId][deviceId].sessionId = sid;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return Promise.all(promises).return(result);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function _verifyKeyAndStartSession(olmDevice, oneTimeKey, userId, deviceInfo) {
|
||||||
function _verifyKeyAndStartSession(olmDevice, oneTimeKey, userId, deviceInfo) {
|
|
||||||
const deviceId = deviceInfo.deviceId;
|
const deviceId = deviceInfo.deviceId;
|
||||||
try {
|
try {
|
||||||
_verifySignature(
|
await _verifySignature(
|
||||||
olmDevice, oneTimeKey, userId, deviceId,
|
olmDevice, oneTimeKey, userId, deviceId,
|
||||||
deviceInfo.getFingerprint(),
|
deviceInfo.getFingerprint(),
|
||||||
);
|
);
|
||||||
@@ -252,8 +255,11 @@ function _verifyKeyAndStartSession(olmDevice, oneTimeKey, userId, deviceInfo) {
|
|||||||
* @param {string} signingDeviceId ID of the device whose signature should be checked
|
* @param {string} signingDeviceId ID of the device whose signature should be checked
|
||||||
*
|
*
|
||||||
* @param {string} signingKey base64-ed ed25519 public key
|
* @param {string} signingKey base64-ed ed25519 public key
|
||||||
|
*
|
||||||
|
* Returns a promise which resolves (to undefined) if the the signature is good,
|
||||||
|
* or rejects with an Error if it is bad.
|
||||||
*/
|
*/
|
||||||
const _verifySignature = module.exports.verifySignature = function(
|
const _verifySignature = module.exports.verifySignature = async function(
|
||||||
olmDevice, obj, signingUserId, signingDeviceId, signingKey,
|
olmDevice, obj, signingUserId, signingDeviceId, signingKey,
|
||||||
) {
|
) {
|
||||||
const signKeyId = "ed25519:" + signingDeviceId;
|
const signKeyId = "ed25519:" + signingDeviceId;
|
||||||
|
|||||||
Reference in New Issue
Block a user