From 0d80c0e3feaac00129ebbfec3056f69a304c1470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 10 Nov 2022 18:40:14 +0100 Subject: [PATCH] chore(crypto): Improve the log for the one-time key signature error --- crates/matrix-sdk-crypto/src/error.rs | 16 +++++++++++++--- crates/matrix-sdk-crypto/src/olm/account.rs | 12 ++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/crates/matrix-sdk-crypto/src/error.rs b/crates/matrix-sdk-crypto/src/error.rs index 483d19961..d08e94144 100644 --- a/crates/matrix-sdk-crypto/src/error.rs +++ b/crates/matrix-sdk-crypto/src/error.rs @@ -18,7 +18,7 @@ use thiserror::Error; use vodozemac::{Curve25519PublicKey, Ed25519PublicKey}; use super::store::CryptoStoreError; -use crate::olm::SessionExportError; +use crate::{olm::SessionExportError, types::SignedKey}; pub type OlmResult = Result; pub type MegolmResult = Result; @@ -229,8 +229,18 @@ pub enum SessionCreationError { OneTimeKeyUnknown(OwnedUserId, OwnedDeviceId), /// Failed to verify the one-time key signatures. - #[error("Failed to verify the one-time key signatures for {0} {1}: {2:?}")] - InvalidSignature(OwnedUserId, OwnedDeviceId, SignatureError), + #[error( + "Failed to verify the signature of a one-time key, key: {one_time_key:?}, \ + signing_key: {signing_key:?}: {error:?}" + )] + InvalidSignature { + /// The one-time key that failed the signature verification. + one_time_key: SignedKey, + /// The key that was used to verify the signature. + signing_key: Option, + /// The exact error describing why the signature verification failed. + error: SignatureError, + }, /// The user's device is missing a curve25519 key. #[error( diff --git a/crates/matrix-sdk-crypto/src/olm/account.rs b/crates/matrix-sdk-crypto/src/olm/account.rs index 1de7f31cb..129de8aad 100644 --- a/crates/matrix-sdk-crypto/src/olm/account.rs +++ b/crates/matrix-sdk-crypto/src/olm/account.rs @@ -1036,12 +1036,12 @@ impl ReadOnlyAccount { Err(e) => return Err(SessionCreationError::InvalidJson(e)), }; - device.verify_one_time_key(&one_time_key).map_err(|e| { - SessionCreationError::InvalidSignature( - device.user_id().to_owned(), - device.device_id().into(), - e, - ) + device.verify_one_time_key(&one_time_key).map_err(|error| { + SessionCreationError::InvalidSignature { + signing_key: device.ed25519_key(), + one_time_key: one_time_key.clone(), + error, + } })?; let identity_key = device.curve25519_key().ok_or_else(|| {