1
0
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:
Richard van der Hoff
2017-07-26 08:04:46 +01:00
parent aff32afefa
commit a2d7b221ee
2 changed files with 15 additions and 9 deletions

View File

@@ -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);

View File

@@ -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;