From 952729cb1b17d70a473788b4b33884a82d352491 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 2 Sep 2020 12:32:34 +0100 Subject: [PATCH 1/2] Abort early if cross-signing key not found This helps us print a better error message when the key does not exist. Part of https://github.com/vector-im/element-web/issues/14970 --- src/crypto/CrossSigning.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/crypto/CrossSigning.js b/src/crypto/CrossSigning.js index d3ecaf647..f414788a7 100644 --- a/src/crypto/CrossSigning.js +++ b/src/crypto/CrossSigning.js @@ -202,6 +202,9 @@ export class CrossSigningInfo extends EventEmitter { */ static async getFromSecretStorage(type, secretStorage) { const encodedKey = await secretStorage.get(`m.cross_signing.${type}`); + if (!encodedKey) { + return null; + } return decodeBase64(encodedKey); } From 646c09196607499d959055fe9d830f7532e5b95a Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 2 Sep 2020 12:54:26 +0100 Subject: [PATCH 2/2] Skip self-signing if device already signed When adding a device to your account, both devices attempt to sign each other using the self-signing key, but in reality only the new device needs to be signed. This avoids a case where web would fail verification while attempting to sign the old device because of missing private keys (since they aren't in 4S and it hasn't requested them from the other device yet), even though signing the old device is redundant anyway. Part of https://github.com/vector-im/element-web/issues/14970 --- src/crypto/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/crypto/index.js b/src/crypto/index.js index 0be9716d1..f0254a0b1 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -2122,9 +2122,18 @@ Crypto.prototype.setDeviceVerification = async function( // do cross-signing if (verified && userId === this._userId) { logger.info("Own device " + deviceId + " marked verified: signing"); - const device = await this._crossSigningInfo.signDevice( - userId, DeviceInfo.fromStorage(dev, deviceId), - ); + + // Signing only needed if other device not already signed + let device; + const deviceTrust = this.checkDeviceTrust(userId, deviceId); + if (deviceTrust.isCrossSigningVerified()) { + logger.log(`Own device ${deviceId} already cross-signing verified`); + } else { + device = await this._crossSigningInfo.signDevice( + userId, DeviceInfo.fromStorage(dev, deviceId), + ); + } + if (device) { const upload = async ({shouldEmit}) => { logger.info("Uploading signature for " + deviceId);