Merge pull request #3794 from matrix-org/dbkr/slashverify_checkdevicetrust

Convert /verify to checkDeviceTrust
pull/21833/head
David Baker 2020-01-03 13:08:24 +00:00 committed by GitHub
commit b0ca8f24d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 42 additions and 44 deletions

View File

@ -780,54 +780,52 @@ export const CommandMap = {
const deviceId = matches[2]; const deviceId = matches[2];
const fingerprint = matches[3]; const fingerprint = matches[3];
return success( return success((async () => {
// Promise.resolve to handle transition from static result to promise; can be removed const device = await cli.getStoredDevice(userId, deviceId);
// in future if (!device) {
Promise.resolve(cli.getStoredDevice(userId, deviceId)).then((device) => { throw new Error(_t('Unknown (user, device) pair:') + ` (${userId}, ${deviceId})`);
if (!device) { }
throw new Error(_t('Unknown (user, device) pair:') + ` (${userId}, ${deviceId})`); const deviceTrust = await cli.checkDeviceTrust(userId, deviceId);
}
if (device.isVerified()) { if (deviceTrust.isVerified()) {
if (device.getFingerprint() === fingerprint) { if (device.getFingerprint() === fingerprint) {
throw new Error(_t('Device already verified!')); throw new Error(_t('Device already verified!'));
} else { } else {
throw new Error(_t('WARNING: Device already verified, but keys do NOT MATCH!')); throw new Error(_t('WARNING: Device already verified, but keys do NOT MATCH!'));
}
} }
}
if (device.getFingerprint() !== fingerprint) { if (device.getFingerprint() !== fingerprint) {
const fprint = device.getFingerprint(); const fprint = device.getFingerprint();
throw new Error( throw new Error(
_t('WARNING: KEY VERIFICATION FAILED! The signing key for %(userId)s and device' + _t('WARNING: KEY VERIFICATION FAILED! The signing key for %(userId)s and device' +
' %(deviceId)s is "%(fprint)s" which does not match the provided key ' + ' %(deviceId)s is "%(fprint)s" which does not match the provided key ' +
'"%(fingerprint)s". This could mean your communications are being intercepted!', '"%(fingerprint)s". This could mean your communications are being intercepted!',
{ {
fprint, fprint,
userId, userId,
deviceId, deviceId,
fingerprint, fingerprint,
})); }));
} }
return cli.setDeviceVerified(userId, deviceId, true); await cli.setDeviceVerified(userId, deviceId, true);
}).then(() => {
// Tell the user we verified everything // Tell the user we verified everything
const InfoDialog = sdk.getComponent('dialogs.InfoDialog'); const InfoDialog = sdk.getComponent('dialogs.InfoDialog');
Modal.createTrackedDialog('Slash Commands', 'Verified key', InfoDialog, { Modal.createTrackedDialog('Slash Commands', 'Verified key', InfoDialog, {
title: _t('Verified key'), title: _t('Verified key'),
description: <div> description: <div>
<p> <p>
{ {
_t('The signing key you provided matches the signing key you received ' + _t('The signing key you provided matches the signing key you received ' +
'from %(userId)s\'s device %(deviceId)s. Device marked as verified.', 'from %(userId)s\'s device %(deviceId)s. Device marked as verified.',
{userId, deviceId}) {userId, deviceId})
} }
</p> </p>
</div>, </div>,
}); });
}), })());
);
} }
} }
return reject(this.getUsage()); return reject(this.getUsage());