Skip to content

Commit 0394761

Browse files
committed
Merge branch 'release-for-crypto-wasm-11'
This brings in the fix for #4424 that we did on a release branch to allow a quick release of crypto-wasm
2 parents 373709f + b18e7d7 commit 0394761

File tree

3 files changed

+175
-21
lines changed

3 files changed

+175
-21
lines changed

crates/matrix-sdk-common/src/deserialized_responses.rs

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ pub enum VerificationLevel {
179179

180180
/// The message was sent by a user identity we have not verified, but the
181181
/// user was previously verified.
182+
#[serde(alias = "PreviouslyVerified")]
182183
VerificationViolation,
183184

184185
/// The message was sent by a device not linked to (signed by) any user
@@ -262,6 +263,7 @@ pub enum ShieldStateCode {
262263
/// An unencrypted event in an encrypted room.
263264
SentInClear,
264265
/// The sender was previously verified but changed their identity.
266+
#[serde(alias = "PreviouslyVerified")]
265267
VerificationViolation,
266268
}
267269

@@ -921,7 +923,7 @@ mod tests {
921923
TimelineEventKind, UnableToDecryptInfo, UnableToDecryptReason, UnsignedDecryptionResult,
922924
UnsignedEventLocation, VerificationState, WithheldCode,
923925
};
924-
use crate::deserialized_responses::{DeviceLinkProblem, VerificationLevel};
926+
use crate::deserialized_responses::{DeviceLinkProblem, ShieldStateCode, VerificationLevel};
925927

926928
fn example_event() -> serde_json::Value {
927929
json!({
@@ -996,6 +998,74 @@ mod tests {
996998
);
997999
}
9981000

1001+
#[test]
1002+
fn test_verification_level_deserializes() {
1003+
// Given a JSON VerificationLevel
1004+
#[derive(Deserialize)]
1005+
struct Container {
1006+
verification_level: VerificationLevel,
1007+
}
1008+
let container = json!({ "verification_level": "VerificationViolation" });
1009+
1010+
// When we deserialize it
1011+
let deserialized: Container = serde_json::from_value(container)
1012+
.expect("We can deserialize the old PreviouslyVerified value");
1013+
1014+
// Then it is populated correctly
1015+
assert_eq!(deserialized.verification_level, VerificationLevel::VerificationViolation);
1016+
}
1017+
1018+
#[test]
1019+
fn test_verification_level_deserializes_from_old_previously_verified_value() {
1020+
// Given a JSON VerificationLevel with the old value PreviouslyVerified
1021+
#[derive(Deserialize)]
1022+
struct Container {
1023+
verification_level: VerificationLevel,
1024+
}
1025+
let container = json!({ "verification_level": "PreviouslyVerified" });
1026+
1027+
// When we deserialize it
1028+
let deserialized: Container = serde_json::from_value(container)
1029+
.expect("We can deserialize the old PreviouslyVerified value");
1030+
1031+
// Then it is migrated to the new value
1032+
assert_eq!(deserialized.verification_level, VerificationLevel::VerificationViolation);
1033+
}
1034+
1035+
#[test]
1036+
fn test_shield_state_code_deserializes() {
1037+
// Given a JSON ShieldStateCode with value VerificationViolation
1038+
#[derive(Deserialize)]
1039+
struct Container {
1040+
shield_state_code: ShieldStateCode,
1041+
}
1042+
let container = json!({ "shield_state_code": "VerificationViolation" });
1043+
1044+
// When we deserialize it
1045+
let deserialized: Container = serde_json::from_value(container)
1046+
.expect("We can deserialize the old PreviouslyVerified value");
1047+
1048+
// Then it is populated correctly
1049+
assert_eq!(deserialized.shield_state_code, ShieldStateCode::VerificationViolation);
1050+
}
1051+
1052+
#[test]
1053+
fn test_shield_state_code_deserializes_from_old_previously_verified_value() {
1054+
// Given a JSON ShieldStateCode with the old value PreviouslyVerified
1055+
#[derive(Deserialize)]
1056+
struct Container {
1057+
shield_state_code: ShieldStateCode,
1058+
}
1059+
let container = json!({ "shield_state_code": "PreviouslyVerified" });
1060+
1061+
// When we deserialize it
1062+
let deserialized: Container = serde_json::from_value(container)
1063+
.expect("We can deserialize the old PreviouslyVerified value");
1064+
1065+
// Then it is migrated to the new value
1066+
assert_eq!(deserialized.shield_state_code, ShieldStateCode::VerificationViolation);
1067+
}
1068+
9991069
#[test]
10001070
fn sync_timeline_event_serialisation() {
10011071
let room_event = SyncTimelineEvent {

crates/matrix-sdk-crypto/src/identities/user.rs

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ enum OwnUserIdentityVerifiedState {
922922
NeverVerified,
923923

924924
/// We previously verified this identity, but it has changed.
925+
#[serde(alias = "PreviouslyVerifiedButNoLonger")]
925926
VerificationViolation,
926927

927928
/// We have verified the current identity.
@@ -1541,26 +1542,10 @@ pub(crate) mod tests {
15411542
/// that we can deserialize boolean values.
15421543
#[test]
15431544
fn test_deserialize_own_user_identity_bool_verified() {
1544-
let mut json = json!({
1545-
"user_id": "@example:localhost",
1546-
"master_key": {
1547-
"user_id":"@example:localhost",
1548-
"usage":["master"],
1549-
"keys":{"ed25519:rJ2TAGkEOP6dX41Ksll6cl8K3J48l8s/59zaXyvl2p0":"rJ2TAGkEOP6dX41Ksll6cl8K3J48l8s/59zaXyvl2p0"},
1550-
},
1551-
"self_signing_key": {
1552-
"user_id":"@example:localhost",
1553-
"usage":["self_signing"],
1554-
"keys":{"ed25519:0C8lCBxrvrv/O7BQfsKnkYogHZX3zAgw3RfJuyiq210":"0C8lCBxrvrv/O7BQfsKnkYogHZX3zAgw3RfJuyiq210"}
1555-
},
1556-
"user_signing_key": {
1557-
"user_id":"@example:localhost",
1558-
"usage":["user_signing"],
1559-
"keys":{"ed25519:DU9z4gBFKFKCk7a13sW9wjT0Iyg7Hqv5f0BPM7DEhPo":"DU9z4gBFKFKCk7a13sW9wjT0Iyg7Hqv5f0BPM7DEhPo"}
1560-
},
1561-
"verified": false
1562-
});
1545+
let mut json = own_user_identity_data();
15631546

1547+
// Set `"verified": false`
1548+
*json.get_mut("verified").unwrap() = false.into();
15641549
let id: OwnUserIdentityData = serde_json::from_value(json.clone()).unwrap();
15651550
assert_eq!(*id.verified.read().unwrap(), OwnUserIdentityVerifiedState::NeverVerified);
15661551

@@ -1570,6 +1555,38 @@ pub(crate) mod tests {
15701555
assert_eq!(*id.verified.read().unwrap(), OwnUserIdentityVerifiedState::Verified);
15711556
}
15721557

1558+
#[test]
1559+
fn test_own_user_identity_verified_state_verification_violation_deserializes() {
1560+
// Given data containing verified: VerificationViolation
1561+
let mut json = own_user_identity_data();
1562+
*json.get_mut("verified").unwrap() = "VerificationViolation".into();
1563+
1564+
// When we deserialize
1565+
let id: OwnUserIdentityData = serde_json::from_value(json.clone()).unwrap();
1566+
1567+
// Then the value is correctly populated
1568+
assert_eq!(
1569+
*id.verified.read().unwrap(),
1570+
OwnUserIdentityVerifiedState::VerificationViolation
1571+
);
1572+
}
1573+
1574+
#[test]
1575+
fn test_own_user_identity_verified_state_previously_verified_deserializes() {
1576+
// Given data containing verified: PreviouslyVerifiedButNoLonger
1577+
let mut json = own_user_identity_data();
1578+
*json.get_mut("verified").unwrap() = "PreviouslyVerifiedButNoLonger".into();
1579+
1580+
// When we deserialize
1581+
let id: OwnUserIdentityData = serde_json::from_value(json.clone()).unwrap();
1582+
1583+
// Then the old value is re-interpreted as VerificationViolation
1584+
assert_eq!(
1585+
*id.verified.read().unwrap(),
1586+
OwnUserIdentityVerifiedState::VerificationViolation
1587+
);
1588+
}
1589+
15731590
#[test]
15741591
fn own_identity_check_signatures() {
15751592
let response = own_key_query();
@@ -1945,4 +1962,26 @@ pub(crate) mod tests {
19451962
assert!(!own_identity.was_previously_verified());
19461963
assert!(!own_identity.has_verification_violation());
19471964
}
1965+
1966+
fn own_user_identity_data() -> Value {
1967+
json!({
1968+
"user_id": "@example:localhost",
1969+
"master_key": {
1970+
"user_id":"@example:localhost",
1971+
"usage":["master"],
1972+
"keys":{"ed25519:rJ2TAGkEOP6dX41Ksll6cl8K3J48l8s/59zaXyvl2p0":"rJ2TAGkEOP6dX41Ksll6cl8K3J48l8s/59zaXyvl2p0"},
1973+
},
1974+
"self_signing_key": {
1975+
"user_id":"@example:localhost",
1976+
"usage":["self_signing"],
1977+
"keys":{"ed25519:0C8lCBxrvrv/O7BQfsKnkYogHZX3zAgw3RfJuyiq210":"0C8lCBxrvrv/O7BQfsKnkYogHZX3zAgw3RfJuyiq210"}
1978+
},
1979+
"user_signing_key": {
1980+
"user_id":"@example:localhost",
1981+
"usage":["user_signing"],
1982+
"keys":{"ed25519:DU9z4gBFKFKCk7a13sW9wjT0Iyg7Hqv5f0BPM7DEhPo":"DU9z4gBFKFKCk7a13sW9wjT0Iyg7Hqv5f0BPM7DEhPo"}
1983+
},
1984+
"verified": false
1985+
})
1986+
}
19481987
}

crates/matrix-sdk-crypto/src/olm/group_sessions/sender_data.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ enum SenderDataReader {
215215
legacy_session: bool,
216216
},
217217

218+
#[serde(alias = "SenderUnverifiedButPreviouslyVerified")]
218219
VerificationViolation(KnownSenderData),
219220

220221
SenderUnverified(KnownSenderData),
@@ -286,7 +287,10 @@ mod tests {
286287
use vodozemac::Ed25519PublicKey;
287288

288289
use super::SenderData;
289-
use crate::types::{DeviceKeys, Signatures};
290+
use crate::{
291+
olm::KnownSenderData,
292+
types::{DeviceKeys, Signatures},
293+
};
290294

291295
#[test]
292296
fn serializing_unknown_device_correctly_preserves_owner_check_failed_if_true() {
@@ -360,6 +364,47 @@ mod tests {
360364
assert_let!(SenderData::SenderVerified { .. } = end);
361365
}
362366

367+
#[test]
368+
fn deserializing_sender_unverified_but_previously_verified_migrates_to_verification_violation()
369+
{
370+
let json = r#"
371+
{
372+
"SenderUnverifiedButPreviouslyVerified":{
373+
"user_id":"@u:s.co",
374+
"master_key":[
375+
150,140,249,139,141,29,63,230,179,14,213,175,176,61,11,255,
376+
26,103,10,51,100,154,183,47,181,117,87,204,33,215,241,92
377+
],
378+
"master_key_verified":true
379+
}
380+
}
381+
"#;
382+
383+
let end: SenderData = serde_json::from_str(json).expect("Failed to parse!");
384+
assert_let!(SenderData::VerificationViolation(KnownSenderData { user_id, .. }) = end);
385+
assert_eq!(user_id, owned_user_id!("@u:s.co"));
386+
}
387+
388+
#[test]
389+
fn deserializing_verification_violation() {
390+
let json = r#"
391+
{
392+
"VerificationViolation":{
393+
"user_id":"@u:s.co",
394+
"master_key":[
395+
150,140,249,139,141,29,63,230,179,14,213,175,176,61,11,255,
396+
26,103,10,51,100,154,183,47,181,117,87,204,33,215,241,92
397+
],
398+
"master_key_verified":true
399+
}
400+
}
401+
"#;
402+
403+
let end: SenderData = serde_json::from_str(json).expect("Failed to parse!");
404+
assert_let!(SenderData::VerificationViolation(KnownSenderData { user_id, .. }) = end);
405+
assert_eq!(user_id, owned_user_id!("@u:s.co"));
406+
}
407+
363408
#[test]
364409
fn equal_sessions_have_same_trust_level() {
365410
let unknown = SenderData::unknown();

0 commit comments

Comments
 (0)