Skip to content

Commit

Permalink
fix(crypto): Fix crash loading older sender data from storage
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalaam committed Dec 17, 2024
1 parent 0ca35d6 commit 385c0ab
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion crates/matrix-sdk-crypto/src/olm/group_sessions/sender_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ enum SenderDataReader {
legacy_session: bool,
},

#[serde(alias = "SenderUnverifiedButPreviouslyVerified")]
VerificationViolation(KnownSenderData),

SenderUnverified(KnownSenderData),
Expand Down Expand Up @@ -286,7 +287,10 @@ mod tests {
use vodozemac::Ed25519PublicKey;

use super::SenderData;
use crate::types::{DeviceKeys, Signatures};
use crate::{
olm::KnownSenderData,
types::{DeviceKeys, Signatures},
};

#[test]
fn serializing_unknown_device_correctly_preserves_owner_check_failed_if_true() {
Expand Down Expand Up @@ -360,6 +364,47 @@ mod tests {
assert_let!(SenderData::SenderVerified { .. } = end);
}

#[test]
fn deserializing_sender_unverified_but_previously_verified_migrates_to_verification_violation()
{
let json = r#"
{
"SenderUnverifiedButPreviouslyVerified":{
"user_id":"@u:s.co",
"master_key":[
150,140,249,139,141,29,63,230,179,14,213,175,176,61,11,255,
26,103,10,51,100,154,183,47,181,117,87,204,33,215,241,92
],
"master_key_verified":true
}
}
"#;

let end: SenderData = serde_json::from_str(json).expect("Failed to parse!");
assert_let!(SenderData::VerificationViolation(KnownSenderData { user_id, .. }) = end);
assert_eq!(user_id, owned_user_id!("@u:s.co"));
}

#[test]
fn deserializing_verification_violation() {
let json = r#"
{
"VerificationViolation":{
"user_id":"@u:s.co",
"master_key":[
150,140,249,139,141,29,63,230,179,14,213,175,176,61,11,255,
26,103,10,51,100,154,183,47,181,117,87,204,33,215,241,92
],
"master_key_verified":true
}
}
"#;

let end: SenderData = serde_json::from_str(json).expect("Failed to parse!");
assert_let!(SenderData::VerificationViolation(KnownSenderData { user_id, .. }) = end);
assert_eq!(user_id, owned_user_id!("@u:s.co"));
}

#[test]
fn equal_sessions_have_same_trust_level() {
let unknown = SenderData::unknown();
Expand Down

0 comments on commit 385c0ab

Please sign in to comment.