Use stable identifier for m.shared_history

This commit is contained in:
Andy Balaam
2026-04-20 16:33:40 +01:00
committed by Andy Balaam
parent efa28a1ffd
commit 103ff7d3ec
8 changed files with 152 additions and 36 deletions
+3 -2
View File
@@ -8,8 +8,9 @@ All notable changes to this project will be documented in this file.
### Features
- [**breaking**] Change to the stable identifiers for `m.room_key_bundle` and
`m.history_not_shared`. We still support reading the unstable identifiers.
- [**breaking**] Change to the stable identifiers for `m.room_key_bundle`,
`m.history_not_shared` and `m.shared_history`. We still support reading the
unstable identifiers.
([#6467](https://github.com/matrix-org/matrix-rust-sdk/pull/6467))
- Add support for MSC4385.
([#6164](https://github.com/matrix-org/matrix-rust-sdk/pull/6164))
@@ -1223,12 +1223,14 @@ mod tests {
.unwrap()
}
#[async_test]
async fn test_shared_history_from_m_room_key_content() {
let content = json!({
fn key_json(stable: bool) -> serde_json::Value {
let shared_history =
if stable { "m.shared_history" } else { "org.matrix.msc3061.shared_history" };
json!({
"algorithm": "m.megolm.v1.aes-sha2",
"room_id": "!Cuyf34gef24t:localhost",
"org.matrix.msc3061.shared_history": true,
shared_history: true,
"session_id": "ZFD6+OmV7fVCsJ7Gap8UnORH8EnmiAkes8FAvQuCw/I",
"session_key": "AgAAAADNp1EbxXYOGmJtyX4AkD1bvJvAUyPkbIaKxtnGKjv\
SQ3E/4mnuqdM4vsmNzpO1EeWzz1rDkUpYhYE9kP7sJhgLXi\
@@ -1237,7 +1239,12 @@ mod tests {
QrCexmqfFJzkR/BJ5ogJHrPBQL0LgsPyglIbMTLg7qygIaY\
U5Fe2QdKMH7nTZPNIRHh1RaMfHVETAUJBax88EWZBoifk80\
gdHUwHSgMk77vCc2a5KHKLDA",
});
})
}
#[async_test]
async fn test_shared_history_from_m_room_key_content_stable() {
let content = key_json(true);
let sender_key = Curve25519PublicKey::from_bytes([0; 32]);
let signing_key = Ed25519PublicKey::from_slice(&[0; 32]).expect("");
@@ -1267,20 +1274,57 @@ mod tests {
}
#[async_test]
async fn test_shared_history_from_exported_room_key() {
let content = json!({
"algorithm": "m.megolm.v1.aes-sha2",
"room_id": "!room:id",
"sender_key": "FOvlmz18LLI3k/llCpqRoKT90+gFF8YhuL+v1YBXHlw",
"session_id": "/2K+V777vipCxPZ0gpY9qcpz1DYaXwuMRIu0UEP0Wa0",
"session_key": "AQAAAAAclzWVMeWBKH+B/WMowa3rb4ma3jEl6n5W4GCs9ue65CruzD3ihX+85pZ9hsV9Bf6fvhjp76WNRajoJYX0UIt7aosjmu0i+H+07hEQ0zqTKpVoSH0ykJ6stAMhdr6Q4uW5crBmdTTBIsqmoWsNJZKKoE2+ldYrZ1lrFeaJbjBIY/9ivle++74qQsT2dIKWPanKc9Q2Gl8LjESLtFBD9Fmt",
"sender_claimed_keys": {
"ed25519": "F4P7f1Z0RjbiZMgHk1xBCG3KC4/Ng9PmxLJ4hQ13sHA"
},
"forwarding_curve25519_key_chain": [],
"org.matrix.msc3061.shared_history": true
async fn test_shared_history_from_m_room_key_content_unstable() {
let content = key_json(false);
});
let sender_key = Curve25519PublicKey::from_bytes([0; 32]);
let signing_key = Ed25519PublicKey::from_slice(&[0; 32]).expect("");
let mut content: room_key::MegolmV1AesSha2Content = serde_json::from_value(content)
.expect("We should be able to deserialize the m.room_key content");
let session = InboundGroupSession::from_room_key_content(sender_key, signing_key, &content)
.expect(
"We should be able to create an inbound group session from the room key content",
);
assert!(
session.shared_history,
"The shared history flag should be set as it was set in the m.room_key content"
);
content.shared_history = false;
let session = InboundGroupSession::from_room_key_content(sender_key, signing_key, &content)
.expect(
"We should be able to create an inbound group session from the room key content",
);
assert!(
!session.shared_history,
"The shared history flag should not be set as it was not set in the m.room_key content"
);
}
fn exported_key_json(stable: bool) -> serde_json::Value {
let shared_history =
if stable { "m.shared_history" } else { "org.matrix.msc3061.shared_history" };
json!({
"algorithm": "m.megolm.v1.aes-sha2",
"room_id": "!room:id",
"sender_key": "FOvlmz18LLI3k/llCpqRoKT90+gFF8YhuL+v1YBXHlw",
"session_id": "/2K+V777vipCxPZ0gpY9qcpz1DYaXwuMRIu0UEP0Wa0",
"session_key": "AQAAAAAclzWVMeWBKH+B/WMowa3rb4ma3jEl6n5W4GCs9ue65CruzD3ihX+85pZ9hsV9Bf6fvhjp76WNRajoJYX0UIt7aosjmu0i+H+07hEQ0zqTKpVoSH0ykJ6stAMhdr6Q4uW5crBmdTTBIsqmoWsNJZKKoE2+ldYrZ1lrFeaJbjBIY/9ivle++74qQsT2dIKWPanKc9Q2Gl8LjESLtFBD9Fmt",
"sender_claimed_keys": {
"ed25519": "F4P7f1Z0RjbiZMgHk1xBCG3KC4/Ng9PmxLJ4hQ13sHA"
},
"forwarding_curve25519_key_chain": [],
shared_history: true
})
}
#[async_test]
async fn test_shared_history_from_exported_room_key_stable() {
let content = exported_key_json(true);
let mut content: ExportedRoomKey = serde_json::from_value(content)
.expect("We should be able to deserialize the m.room_key content");
@@ -1305,8 +1349,36 @@ mod tests {
}
#[async_test]
async fn test_shared_history_from_backed_up_room_key() {
let content = json!({
async fn test_shared_history_from_exported_room_key_unstable() {
let content = exported_key_json(false);
let mut content: ExportedRoomKey = serde_json::from_value(content)
.expect("We should be able to deserialize the m.room_key content");
let session = InboundGroupSession::from_export(&content).expect(
"We should be able to create an inbound group session from the room key export",
);
assert!(
session.shared_history,
"The shared history flag should be set as it was set in the exported room key"
);
content.shared_history = false;
let session = InboundGroupSession::from_export(&content).expect(
"We should be able to create an inbound group session from the room key export",
);
assert!(
!session.shared_history,
"The shared history flag should not be set as it was not set in the exported room key"
);
}
fn backed_up_room_key(stable: bool) -> serde_json::Value {
let shared_history =
if stable { "m.shared_history" } else { "org.matrix.msc3061.shared_history" };
json!({
"algorithm": "m.megolm.v1.aes-sha2",
"sender_key": "FOvlmz18LLI3k/llCpqRoKT90+gFF8YhuL+v1YBXHlw",
"session_key": "AQAAAAAclzWVMeWBKH+B/WMowa3rb4ma3jEl6n5W4GCs9ue65CruzD3ihX+85pZ9hsV9Bf6fvhjp76WNRajoJYX0UIt7aosjmu0i+H+07hEQ0zqTKpVoSH0ykJ6stAMhdr6Q4uW5crBmdTTBIsqmoWsNJZKKoE2+ldYrZ1lrFeaJbjBIY/9ivle++74qQsT2dIKWPanKc9Q2Gl8LjESLtFBD9Fmt",
@@ -1314,9 +1386,34 @@ mod tests {
"ed25519": "F4P7f1Z0RjbiZMgHk1xBCG3KC4/Ng9PmxLJ4hQ13sHA"
},
"forwarding_curve25519_key_chain": [],
"org.matrix.msc3061.shared_history": true
shared_history: true
})
}
});
#[async_test]
async fn test_shared_history_from_backed_up_room_key_stable() {
let content = backed_up_room_key(true);
let session_id = "/2K+V777vipCxPZ0gpY9qcpz1DYaXwuMRIu0UEP0Wa0";
let room_id = owned_room_id!("!room:id");
let room_key: BackedUpRoomKey = serde_json::from_value(content)
.expect("We should be able to deserialize the backed up room key");
let room_key =
ExportedRoomKey::from_backed_up_room_key(room_id, session_id.to_owned(), room_key);
let session = InboundGroupSession::from_export(&room_key).expect(
"We should be able to create an inbound group session from the room key export",
);
assert!(
session.shared_history,
"The shared history flag should be set as it was set in the backed up room key"
);
}
#[async_test]
async fn test_shared_history_from_backed_up_room_key_unstable() {
let content = backed_up_room_key(false);
let session_id = "/2K+V777vipCxPZ0gpY9qcpz1DYaXwuMRIu0UEP0Wa0";
let room_id = owned_room_id!("!room:id");
@@ -109,7 +109,7 @@ pub struct ExportedRoomKey {
/// defined in [MSC3061].
///
/// [MSC3061]: https://github.com/matrix-org/matrix-spec-proposals/pull/3061
#[serde(default, rename = "org.matrix.msc3061.shared_history")]
#[serde(default, rename = "m.shared_history", alias = "org.matrix.msc3061.shared_history")]
pub shared_history: bool,
}
@@ -196,7 +196,7 @@ pub struct BackedUpRoomKey {
/// defined in [MSC3061].
///
/// [MSC3061]: https://github.com/matrix-org/matrix-spec-proposals/pull/3061
#[serde(default, rename = "org.matrix.msc3061.shared_history")]
#[serde(default, rename = "m.shared_history", alias = "org.matrix.msc3061.shared_history")]
pub shared_history: bool,
}
@@ -721,7 +721,7 @@ mod tests {
"content": {
"algorithm": "m.megolm.v1.aes-sha2",
"room_id": "!Cuyf34gef24t:localhost",
"org.matrix.msc3061.shared_history": true,
"m.shared_history": true,
"session_id": "ZFD6+OmV7fVCsJ7Gap8UnORH8EnmiAkes8FAvQuCw/I",
"session_key": "AgAAAADNp1EbxXYOGmJtyX4AkD1bvJvAUyPkbIaKxtnGKjv\
SQ3E/4mnuqdM4vsmNzpO1EeWzz1rDkUpYhYE9kP7sJhgLXi\
@@ -124,7 +124,7 @@ pub struct MegolmV1AesSha2Content {
/// [MSC3061].
///
/// [MSC3061]: https://github.com/matrix-org/matrix-spec-proposals/pull/3061
#[serde(default, rename = "org.matrix.msc3061.shared_history")]
#[serde(default, rename = "m.shared_history", alias = "org.matrix.msc3061.shared_history")]
pub shared_history: bool,
/// Any other, custom and non-specced fields of the content.
#[serde(flatten)]
@@ -229,14 +229,22 @@ pub(super) mod tests {
use super::RoomKeyEvent;
use crate::types::events::room_key::RoomKeyContent;
pub fn json() -> Value {
pub fn json_stable() -> Value {
json(true)
}
pub fn json_unstable() -> Value {
json(false)
}
pub fn json(stable: bool) -> Value {
json!({
"sender": "@alice:example.org",
"content": {
"m.custom": "something custom",
"algorithm": "m.megolm.v1.aes-sha2",
"room_id": "!Cuyf34gef24t:localhost",
"org.matrix.msc3061.shared_history": false,
if stable { "m.shared_history" } else { "org.matrix.msc3061.shared_history" }: false,
"session_id": "ZFD6+OmV7fVCsJ7Gap8UnORH8EnmiAkes8FAvQuCw/I",
"session_key": "AgAAAADNp1EbxXYOGmJtyX4AkD1bvJvAUyPkbIaKxtnGKjv\
SQ3E/4mnuqdM4vsmNzpO1EeWzz1rDkUpYhYE9kP7sJhgLXi\
@@ -252,8 +260,8 @@ pub(super) mod tests {
}
#[test]
fn deserialization() -> Result<(), serde_json::Error> {
let json = json();
fn deserialization_stable() -> Result<(), serde_json::Error> {
let json = json_stable();
let event: RoomKeyEvent = serde_json::from_value(json.clone())?;
assert_matches!(event.content, RoomKeyContent::MegolmV1AesSha2(_));
@@ -262,4 +270,14 @@ pub(super) mod tests {
Ok(())
}
#[test]
fn deserialization_unstable() -> Result<(), serde_json::Error> {
let json = json_unstable();
let event: RoomKeyEvent = serde_json::from_value(json)?;
assert_matches!(event.content, RoomKeyContent::MegolmV1AesSha2(_));
Ok(())
}
}
@@ -13,7 +13,7 @@ expression: event
},
"content": {
"algorithm": "m.megolm.v1.aes-sha2",
"org.matrix.msc3061.shared_history": false,
"m.shared_history": false,
"room_id": "!Cuyf34gef24t:localhost",
"session_id": "ZFD6+OmV7fVCsJ7Gap8UnORH8EnmiAkes8FAvQuCw/I",
"session_key": "AgAAAADNp1EbxXYOGmJtyX4AkD1bvJvAUyPkbIaKxtnGKjvSQ3E/4mnuqdM4vsmNzpO1EeWzz1rDkUpYhYE9kP7sJhgLXijVv80fMPHfGc49hPdu8A+xnwD4SQiYdFmSWJOIqsxeo/fiHtino//CDQENtcKuEt0I9s0+Kk4YSH310Szse2RQ+vjple31QrCexmqfFJzkR/BJ5ogJHrPBQL0LgsPyglIbMTLg7qygIaYU5Fe2QdKMH7nTZPNIRHh1RaMfHVETAUJBax88EWZBoifk80gdHUwHSgMk77vCc2a5KHKLDA"
@@ -30,7 +30,7 @@ expression: event
},
"content": {
"algorithm": "m.megolm.v1.aes-sha2",
"org.matrix.msc3061.shared_history": false,
"m.shared_history": false,
"room_id": "!Cuyf34gef24t:localhost",
"session_id": "ZFD6+OmV7fVCsJ7Gap8UnORH8EnmiAkes8FAvQuCw/I",
"session_key": "AgAAAADNp1EbxXYOGmJtyX4AkD1bvJvAUyPkbIaKxtnGKjvSQ3E/4mnuqdM4vsmNzpO1EeWzz1rDkUpYhYE9kP7sJhgLXijVv80fMPHfGc49hPdu8A+xnwD4SQiYdFmSWJOIqsxeo/fiHtino//CDQENtcKuEt0I9s0+Kk4YSH310Szse2RQ+vjple31QrCexmqfFJzkR/BJ5ogJHrPBQL0LgsPyglIbMTLg7qygIaYU5Fe2QdKMH7nTZPNIRHh1RaMfHVETAUJBax88EWZBoifk80gdHUwHSgMk77vCc2a5KHKLDA"
@@ -520,7 +520,7 @@ mod tests {
assert_serialization_roundtrip!(
// `m.room_key
crate::types::events::room_key::tests::json => RoomKey,
crate::types::events::room_key::tests::json_stable => RoomKey,
// `m.forwarded_room_key`
forwarded_room_key_event => ForwardedRoomKey,
@@ -570,7 +570,7 @@ mod tests {
assert_serialization_roundtrip!(
// `m.room_key
crate::types::events::room_key::tests::json => RoomKey,
crate::types::events::room_key::tests::json_stable => RoomKey,
// `m.forwarded_room_key`
forwarded_room_key_event => ForwardedRoomKey,