@@ -1540,6 +1540,14 @@ impl Account {
1540
1540
}
1541
1541
1542
1542
/// Look up the [`Device`] that sent us a successfully-decrypted event.
1543
+ ///
1544
+ /// Also validates the `sender_device_keys` field, if present.
1545
+ ///
1546
+ /// `m.room_key` events are special-cased and return `None`: we look up
1547
+ /// their devices later on.
1548
+ ///
1549
+ /// For other events, we look up the device in the store, and return the
1550
+ /// details.
1543
1551
async fn get_event_sender_device (
1544
1552
store : & Store ,
1545
1553
sender_key : Curve25519PublicKey ,
@@ -1550,13 +1558,15 @@ impl Account {
1550
1558
// valid. The processing of the historic room key bundle depends on this being
1551
1559
// here.
1552
1560
Self :: check_sender_device_keys ( event, sender_key) ?;
1553
- let mut sender_device: Option < Device > = None ;
1554
1561
if let AnyDecryptedOlmEvent :: RoomKey ( _) = event {
1555
1562
// If this event is an `m.room_key` event, defer the check for
1556
1563
// the Ed25519 key of the sender until we decrypt room events.
1557
1564
// This ensures that we receive the room key even if we don't
1558
1565
// have access to the device.
1559
- } else if let AnyDecryptedOlmEvent :: RoomKeyBundle ( _) = event {
1566
+ return Ok ( None ) ;
1567
+ }
1568
+
1569
+ if let AnyDecryptedOlmEvent :: RoomKeyBundle ( _) = event {
1560
1570
// If this is a room key bundle we're requiring the device keys to be part of
1561
1571
// the `AnyDecryptedOlmEvent`. This ensures that we can skip the check for the
1562
1572
// Ed25519 key below since `Self::check_sender_device_keys` already did so.
@@ -1566,22 +1576,24 @@ impl Account {
1566
1576
event. sender_device_keys ( ) . ok_or ( EventError :: MissingSigningKey ) . inspect_err ( |_| {
1567
1577
warn ! ( "The room key bundle was missing the sender device keys in the event" )
1568
1578
} ) ?;
1569
- } else {
1570
- let device = store
1571
- . get_device_from_curve_key ( event. sender ( ) , sender_key)
1572
- . await ?
1573
- . ok_or ( EventError :: MissingSigningKey ) ?;
1579
+ }
1574
1580
1575
- let key = device. ed25519_key ( ) . ok_or ( EventError :: MissingSigningKey ) ?;
1581
+ let device = store
1582
+ . get_device_from_curve_key ( event. sender ( ) , sender_key)
1583
+ . await ?
1584
+ . ok_or ( EventError :: MissingSigningKey ) ?;
1576
1585
1577
- if key != event. keys ( ) . ed25519 {
1578
- return Err (
1579
- EventError :: MismatchedKeys ( key. into ( ) , event. keys ( ) . ed25519 . into ( ) ) . into ( )
1580
- ) ;
1581
- }
1582
- sender_device = Some ( device) ;
1586
+ let key = device. ed25519_key ( ) . ok_or ( EventError :: MissingSigningKey ) ?;
1587
+
1588
+ if key != event. keys ( ) . ed25519 {
1589
+ return Err ( EventError :: MismatchedKeys ( key. into ( ) , event. keys ( ) . ed25519 . into ( ) ) . into ( ) ) ;
1583
1590
}
1584
- Ok ( sender_device)
1591
+
1592
+ // TODO: we may want to consider falling back to the details from
1593
+ // `sender_device_keys` if the device isn't in the store, to make
1594
+ // things work better when the sending device is not (yet) known.
1595
+
1596
+ Ok ( Some ( device) )
1585
1597
}
1586
1598
1587
1599
/// Return true if:
0 commit comments