diff --git a/src/logging/LogItem.js b/src/logging/LogItem.js index 90747964..7324b7d2 100644 --- a/src/logging/LogItem.js +++ b/src/logging/LogItem.js @@ -94,6 +94,7 @@ export class LogItem { log(labelOrValues, logLevel = null) { const item = this.child(labelOrValues, logLevel, null); item._end = item._start; + return item; } set(key, value) { diff --git a/src/matrix/e2ee/DeviceTracker.js b/src/matrix/e2ee/DeviceTracker.js index e230ea7d..0068a1f9 100644 --- a/src/matrix/e2ee/DeviceTracker.js +++ b/src/matrix/e2ee/DeviceTracker.js @@ -264,7 +264,7 @@ export class DeviceTracker { return false; } curve25519Keys.add(curve25519Key); - const isValid = this._hasValidSignature(deviceKeys); + const isValid = this._hasValidSignature(deviceKeys, parentLog); if (!isValid) { parentLog.log({ l: "ignore device with invalid signature", @@ -279,11 +279,11 @@ export class DeviceTracker { return verifiedKeys; } - _hasValidSignature(deviceSection) { + _hasValidSignature(deviceSection, parentLog) { const deviceId = deviceSection["device_id"]; const userId = deviceSection["user_id"]; const ed25519Key = deviceSection?.keys?.[`${SIGNATURE_ALGORITHM}:${deviceId}`]; - return verifyEd25519Signature(this._olmUtil, userId, deviceId, ed25519Key, deviceSection); + return verifyEd25519Signature(this._olmUtil, userId, deviceId, ed25519Key, deviceSection, parentLog); } /** diff --git a/src/matrix/e2ee/common.js b/src/matrix/e2ee/common.js index fa970236..27a541ec 100644 --- a/src/matrix/e2ee/common.js +++ b/src/matrix/e2ee/common.js @@ -35,7 +35,7 @@ export class DecryptionError extends Error { export const SIGNATURE_ALGORITHM = "ed25519"; -export function verifyEd25519Signature(olmUtil, userId, deviceOrKeyId, ed25519Key, value) { +export function verifyEd25519Signature(olmUtil, userId, deviceOrKeyId, ed25519Key, value, log = undefined) { const clone = Object.assign({}, value); delete clone.unsigned; delete clone.signatures; @@ -49,7 +49,11 @@ export function verifyEd25519Signature(olmUtil, userId, deviceOrKeyId, ed25519Ke olmUtil.ed25519_verify(ed25519Key, canonicalJson, signature); return true; } catch (err) { - console.warn("Invalid signature, ignoring.", ed25519Key, canonicalJson, signature, err); + if (log) { + const logItem = log.log({l: "Invalid signature, ignoring.", ed25519Key, canonicalJson, signature}); + logItem.error = err; + logItem.logLevel = log.level.Warn; + } return false; } } diff --git a/src/matrix/e2ee/olm/Encryption.js b/src/matrix/e2ee/olm/Encryption.js index 1b720ae7..652c657c 100644 --- a/src/matrix/e2ee/olm/Encryption.js +++ b/src/matrix/e2ee/olm/Encryption.js @@ -189,10 +189,10 @@ export class Encryption { log.log({l: "failures", servers: Object.keys(claimResponse.failures)}, log.level.Warn); } const userKeyMap = claimResponse?.["one_time_keys"]; - return this._verifyAndCreateOTKTargets(userKeyMap, devicesByUser); + return this._verifyAndCreateOTKTargets(userKeyMap, devicesByUser, log); } - _verifyAndCreateOTKTargets(userKeyMap, devicesByUser) { + _verifyAndCreateOTKTargets(userKeyMap, devicesByUser, log) { const verifiedEncryptionTargets = []; for (const [userId, userSection] of Object.entries(userKeyMap)) { for (const [deviceId, deviceSection] of Object.entries(userSection)) { @@ -202,7 +202,7 @@ export class Encryption { const device = devicesByUser.get(userId)?.get(deviceId); if (device) { const isValidSignature = verifyEd25519Signature( - this._olmUtil, userId, deviceId, device.ed25519Key, keySection); + this._olmUtil, userId, deviceId, device.ed25519Key, keySection, log); if (isValidSignature) { const target = EncryptionTarget.fromOTK(device, keySection.key); verifiedEncryptionTargets.push(target);