@@ -905,25 +905,27 @@ impl Account {
905905 /// and shared with us.
906906 ///
907907 /// * `fallback_used` - Was the one-time key a fallback key.
908+ ///
909+ /// * `our_device_keys` - Our own `DeviceKeys`, including cross-signing
910+ /// signatures if applicable, for embedding in encrypted messages.
908911 pub fn create_outbound_session_helper (
909912 & self ,
910913 config : SessionConfig ,
911914 identity_key : Curve25519PublicKey ,
912915 one_time_key : Curve25519PublicKey ,
913916 fallback_used : bool ,
917+ our_device_keys : DeviceKeys ,
914918 ) -> Session {
915919 let session = self . inner . create_outbound_session ( config, identity_key, one_time_key) ;
916920
917921 let now = SecondsSinceUnixEpoch :: now ( ) ;
918922 let session_id = session. session_id ( ) ;
919923
920924 Session {
921- user_id : self . static_data . user_id . clone ( ) ,
922- device_id : self . static_data . device_id . clone ( ) ,
923- our_identity_keys : self . static_data . identity_keys . clone ( ) ,
924925 inner : Arc :: new ( Mutex :: new ( session) ) ,
925926 session_id : session_id. into ( ) ,
926927 sender_key : identity_key,
928+ our_device_keys,
927929 created_using_fallback_key : fallback_used,
928930 creation_time : now,
929931 last_use_time : now,
@@ -978,11 +980,15 @@ impl Account {
978980 ///
979981 /// * `key_map` - A map from the algorithm and device ID to the one-time key
980982 /// that the other account created and shared with us.
983+ ///
984+ /// * `our_device_keys` - Our own `DeviceKeys`, including cross-signing
985+ /// signatures if applicable, for embedding in encrypted messages.
981986 #[ allow( clippy:: result_large_err) ]
982987 pub fn create_outbound_session (
983988 & self ,
984989 device : & ReadOnlyDevice ,
985990 key_map : & BTreeMap < OwnedDeviceKeyId , Raw < ruma:: encryption:: OneTimeKey > > ,
991+ our_device_keys : DeviceKeys ,
986992 ) -> Result < Session , SessionCreationError > {
987993 let pre_key_bundle = Self :: find_pre_key_bundle ( device, key_map) ?;
988994
@@ -1012,6 +1018,7 @@ impl Account {
10121018 identity_key,
10131019 one_time_key,
10141020 is_fallback,
1021+ our_device_keys,
10151022 ) )
10161023 }
10171024 }
@@ -1026,11 +1033,15 @@ impl Account {
10261033 ///
10271034 /// * `their_identity_key` - The other account's identity/curve25519 key.
10281035 ///
1036+ /// * `our_device_keys` - Our own `DeviceKeys`, including cross-signing
1037+ /// signatures if applicable, for embedding in encrypted messages.
1038+ ///
10291039 /// * `message` - A pre-key Olm message that was sent to us by the other
10301040 /// account.
10311041 pub fn create_inbound_session (
10321042 & mut self ,
10331043 their_identity_key : Curve25519PublicKey ,
1044+ our_device_keys : DeviceKeys ,
10341045 message : & PreKeyMessage ,
10351046 ) -> Result < InboundCreationResult , SessionCreationError > {
10361047 Span :: current ( ) . record ( "session_id" , debug ( message. session_id ( ) ) ) ;
@@ -1043,12 +1054,10 @@ impl Account {
10431054 debug ! ( session=?result. session, "Decrypted an Olm message from a new Olm session" ) ;
10441055
10451056 let session = Session {
1046- user_id : self . static_data . user_id . clone ( ) ,
1047- device_id : self . static_data . device_id . clone ( ) ,
1048- our_identity_keys : self . static_data . identity_keys . clone ( ) ,
10491057 inner : Arc :: new ( Mutex :: new ( result. session ) ) ,
10501058 session_id : session_id. into ( ) ,
10511059 sender_key : their_identity_key,
1060+ our_device_keys,
10521061 created_using_fallback_key : false ,
10531062 creation_time : now,
10541063 last_use_time : now,
@@ -1072,7 +1081,8 @@ impl Account {
10721081 let one_time_map = other. signed_one_time_keys ( ) ;
10731082 let device = ReadOnlyDevice :: from_account ( other) ;
10741083
1075- let mut our_session = self . create_outbound_session ( & device, & one_time_map) . unwrap ( ) ;
1084+ let mut our_session =
1085+ self . create_outbound_session ( & device, & one_time_map, self . device_keys ( ) ) . unwrap ( ) ;
10761086
10771087 other. mark_keys_as_published ( ) ;
10781088
@@ -1104,8 +1114,13 @@ impl Account {
11041114 } ;
11051115
11061116 let our_device = ReadOnlyDevice :: from_account ( self ) ;
1107- let other_session =
1108- other. create_inbound_session ( our_device. curve25519_key ( ) . unwrap ( ) , & prekey) . unwrap ( ) ;
1117+ let other_session = other
1118+ . create_inbound_session (
1119+ our_device. curve25519_key ( ) . unwrap ( ) ,
1120+ other. device_keys ( ) ,
1121+ & prekey,
1122+ )
1123+ . unwrap ( ) ;
11091124
11101125 ( our_session, other_session. session )
11111126 }
@@ -1290,20 +1305,23 @@ impl Account {
12901305 ) ;
12911306
12921307 return Err ( OlmError :: SessionWedged (
1293- session. user_id . to_owned ( ) ,
1308+ session. our_device_keys . user_id . to_owned ( ) ,
12941309 session. sender_key ( ) ,
12951310 ) ) ;
12961311 }
12971312 }
12981313
1299- // We didn't find a matching session; try to create a new session.
1300- let result = match self . create_inbound_session ( sender_key, prekey_message) {
1301- Ok ( r) => r,
1302- Err ( e) => {
1303- warn ! ( "Failed to create a new Olm session from a pre-key message: {e:?}" ) ;
1304- return Err ( OlmError :: SessionWedged ( sender. to_owned ( ) , sender_key) ) ;
1305- }
1306- } ;
1314+ let device_keys = store. get_own_device ( ) . await ?. as_device_keys ( ) . clone ( ) ;
1315+ let result =
1316+ match self . create_inbound_session ( sender_key, device_keys, prekey_message) {
1317+ Ok ( r) => r,
1318+ Err ( e) => {
1319+ warn ! (
1320+ "Failed to create a new Olm session from a pre-key message: {e:?}"
1321+ ) ;
1322+ return Err ( OlmError :: SessionWedged ( sender. to_owned ( ) , sender_key) ) ;
1323+ }
1324+ } ;
13071325
13081326 // We need to add the new session to the session cache, otherwise
13091327 // we might try to create the same session again.
0 commit comments