Skip to content

Commit 25ed92f

Browse files
committed
crypto: Move device_keys to DecryptedOlmV1Event as per MSC4147
1 parent 9aa2774 commit 25ed92f

File tree

7 files changed

+33
-18
lines changed

7 files changed

+33
-18
lines changed

crates/matrix-sdk-crypto/src/gossiping/machine.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,7 @@ mod tests {
14781478
alice_id(),
14791479
alice_id(),
14801480
alice_device.ed25519_key().unwrap(),
1481+
None,
14811482
content,
14821483
);
14831484

@@ -1525,6 +1526,7 @@ mod tests {
15251526
alice_id(),
15261527
alice_id(),
15271528
alice_device.ed25519_key().unwrap(),
1529+
None,
15281530
content,
15291531
);
15301532

@@ -1543,6 +1545,7 @@ mod tests {
15431545
alice_id(),
15441546
alice_id(),
15451547
alice_device.ed25519_key().unwrap(),
1548+
None,
15461549
content,
15471550
);
15481551

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,6 @@ impl OutboundGroupSession {
531531
self.room_id().to_owned(),
532532
self.session_id().to_owned(),
533533
session_key,
534-
None,
535534
)
536535
.into(),
537536
)

crates/matrix-sdk-crypto/src/olm/session.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,12 @@ mod tests {
293293
use vodozemac::olm::{OlmMessage, SessionConfig};
294294

295295
use crate::{
296-
identities::ReadOnlyDevice, olm::Account,
297-
types::events::room::encrypted::ToDeviceEncryptedEventContent,
296+
identities::ReadOnlyDevice,
297+
olm::Account,
298+
types::events::{
299+
dummy::DummyEventContent, olm_v1::DecryptedOlmV1Event,
300+
room::encrypted::ToDeviceEncryptedEventContent,
301+
},
298302
};
299303

300304
#[async_test]
@@ -348,11 +352,18 @@ mod tests {
348352
)
349353
.unwrap();
350354

351-
// Also ensure that the encrypted payload has the device keys.
355+
// Also ensure that the encrypted payload has the device keys under the unstable
356+
// prefix
352357
let plaintext: Value = serde_json::from_str(&bob_session_result.plaintext).unwrap();
353358
assert_eq!(
354359
plaintext["org.matrix.msc4147.device_keys"]["user_id"].as_str(),
355360
Some("@alice:localhost")
356361
);
362+
363+
// And the serialized object matches the format as specified in
364+
// DecryptedOlmV1Event
365+
let event: DecryptedOlmV1Event<DummyEventContent> =
366+
serde_json::from_str(&bob_session_result.plaintext).unwrap();
367+
assert_eq!(event.device_keys.unwrap(), alice.device_keys());
357368
}
358369
}

crates/matrix-sdk-crypto/src/store/integration_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ macro_rules! cryptostore_integration_tests {
905905
recipient_keys: OlmV1Keys {
906906
ed25519: account.identity_keys().ed25519,
907907
},
908+
device_keys: None,
908909
content: SecretSendContent::new(id.to_owned(), secret.to_owned()),
909910
};
910911

crates/matrix-sdk-crypto/src/types/events/olm_v1.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use super::{
3030
secret_send::SecretSendContent,
3131
EventType,
3232
};
33-
use crate::types::{deserialize_ed25519_key, events::from_str, serialize_ed25519_key};
33+
use crate::types::{deserialize_ed25519_key, events::from_str, serialize_ed25519_key, DeviceKeys};
3434

3535
/// An `m.dummy` event that was decrypted using the
3636
/// `m.olm.v1.curve25519-aes-sha2` algorithm
@@ -164,18 +164,28 @@ where
164164
pub keys: OlmV1Keys,
165165
/// The recipient's signing keys of the encrypted event.
166166
pub recipient_keys: OlmV1Keys,
167+
/// The device keys if supplied as per MSC4147
168+
#[serde(rename = "org.matrix.msc4147.device_keys")]
169+
pub device_keys: Option<DeviceKeys>,
167170
/// The type of the event.
168171
pub content: C,
169172
}
170173

171174
impl<C: EventType + Debug + Sized + Serialize> DecryptedOlmV1Event<C> {
172175
#[cfg(test)]
173-
pub fn new(sender: &UserId, recipient: &UserId, key: Ed25519PublicKey, content: C) -> Self {
176+
pub fn new(
177+
sender: &UserId,
178+
recipient: &UserId,
179+
key: Ed25519PublicKey,
180+
device_keys: Option<DeviceKeys>,
181+
content: C,
182+
) -> Self {
174183
Self {
175184
sender: sender.to_owned(),
176185
recipient: recipient.to_owned(),
177186
keys: OlmV1Keys { ed25519: key },
178187
recipient_keys: OlmV1Keys { ed25519: key },
188+
device_keys,
179189
content,
180190
}
181191
}

crates/matrix-sdk-crypto/src/types/events/room/encrypted.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,6 @@ pub(crate) mod tests {
431431
"device_id": "DEWRCMENGS",
432432
"session_id": "ZFD6+OmV7fVCsJ7Gap8UnORH8EnmiAkes8FAvQuCw/I",
433433
"sender_key": "WJ6Ce7U67a6jqkHYHd8o0+5H4bqdi9hInZdk0+swuXs",
434-
"device_keys": null,
435434
"ciphertext":
436435
"AwgAEiBQs2LgBD2CcB+RLH2bsgp9VadFUJhBXOtCmcJuttBDOeDNjL21d9\
437436
z0AcVSfQFAh9huh4or7sWuNrHcvu9/sMbweTgc0UtdA5xFLheubHouXy4a\

crates/matrix-sdk-crypto/src/types/events/room_key.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use serde_json::{value::to_raw_value, Value};
2222
use vodozemac::megolm::SessionKey;
2323

2424
use super::{EventType, ToDeviceEvent};
25-
use crate::types::{DeviceKeys, EventEncryptionAlgorithm};
25+
use crate::types::EventEncryptionAlgorithm;
2626

2727
/// The `m.room_key` to-device event.
2828
pub type RoomKeyEvent = ToDeviceEvent<RoomKeyContent>;
@@ -113,22 +113,15 @@ pub struct MegolmV1AesSha2Content {
113113
///
114114
/// [`InboundGroupSession`]: vodozemac::megolm::InboundGroupSession
115115
pub session_key: SessionKey,
116-
/// The device keys if supplied as per MSC4147
117-
pub device_keys: Option<DeviceKeys>,
118116
/// Any other, custom and non-specced fields of the content.
119117
#[serde(flatten)]
120118
other: BTreeMap<String, Value>,
121119
}
122120

123121
impl MegolmV1AesSha2Content {
124122
/// Create a new `m.megolm.v1.aes-sha2` `m.room_key` content.
125-
pub fn new(
126-
room_id: OwnedRoomId,
127-
session_id: String,
128-
session_key: SessionKey,
129-
device_keys: Option<DeviceKeys>,
130-
) -> Self {
131-
Self { room_id, session_id, session_key, device_keys, other: Default::default() }
123+
pub fn new(room_id: OwnedRoomId, session_id: String, session_key: SessionKey) -> Self {
124+
Self { room_id, session_id, session_key, other: Default::default() }
132125
}
133126
}
134127

@@ -232,7 +225,6 @@ pub(super) mod tests {
232225
QrCexmqfFJzkR/BJ5ogJHrPBQL0LgsPyglIbMTLg7qygIaY\
233226
U5Fe2QdKMH7nTZPNIRHh1RaMfHVETAUJBax88EWZBoifk80\
234227
gdHUwHSgMk77vCc2a5KHKLDA",
235-
"device_keys": null
236228
},
237229
"type": "m.room_key",
238230
"m.custom.top": "something custom in the top",

0 commit comments

Comments
 (0)