@@ -311,6 +311,69 @@ pub async fn mark_alice_identity_as_verified_test_helper(alice: &OlmMachine, bob
311
311
. is_verified( ) ) ;
312
312
}
313
313
314
+ /// Test that the verification state is set correctly when the sender of an
315
+ /// event does not match the owner of the device that sent us the session.
316
+ ///
317
+ /// In this test, Bob receives an event from Alice, but the HS admin has
318
+ /// rewritten the `sender` of the event to look like another user.
319
+ #[ async_test]
320
+ async fn test_verification_states_spoofed_sender ( ) {
321
+ let ( alice, bob) = get_machine_pair_with_setup_sessions_test_helper (
322
+ tests:: alice_id ( ) ,
323
+ tests:: user_id ( ) ,
324
+ false ,
325
+ )
326
+ . await ;
327
+
328
+ let room_id = room_id ! ( "!test:example.org" ) ;
329
+ let decryption_settings =
330
+ DecryptionSettings { sender_device_trust_requirement : TrustRequirement :: Untrusted } ;
331
+
332
+ // Alice sends a message to Bob.
333
+ let ( event, _) = encrypt_message ( & alice, room_id, & bob, "Secret message" ) . await ;
334
+ bob. decrypt_room_event ( & event, room_id, & decryption_settings)
335
+ . await
336
+ . expect ( "Bob could not decrypt event" ) ;
337
+ let event_encryption_info = bob. get_room_event_encryption_info ( & event, room_id) . await . unwrap ( ) ;
338
+ assert_matches ! (
339
+ event_encryption_info. verification_state,
340
+ VerificationState :: Unverified ( VerificationLevel :: UnsignedDevice )
341
+ ) ;
342
+
343
+ // Alice now sends a second message to Bob, using the same room key, but the HS
344
+ // admin rewrites the 'sender' to Charlie.
345
+ let encrypted_content = alice
346
+ . encrypt_room_event (
347
+ room_id,
348
+ AnyMessageLikeEventContent :: RoomMessage ( RoomMessageEventContent :: text_plain (
349
+ "spoofed message" ,
350
+ ) ) ,
351
+ )
352
+ . await
353
+ . unwrap ( ) ;
354
+ let event = json ! ( {
355
+ "event_id" : "$xxxxy:example.org" ,
356
+ "origin_server_ts" : MilliSecondsSinceUnixEpoch :: now( ) ,
357
+ "sender" : "@charlie:example.org" , // Note! spoofed sender
358
+ "type" : "m.room.encrypted" ,
359
+ "content" : encrypted_content,
360
+ } ) ;
361
+ let event = json_convert ( & event) . unwrap ( ) ;
362
+
363
+ bob. decrypt_room_event ( & event, room_id, & decryption_settings)
364
+ . await
365
+ . expect ( "Bob could not decrypt spoofed event" ) ;
366
+
367
+ // The verification_state of the event should be `MissingDevice` (since it
368
+ // manifests as a message from Charlie which does not correspond to one of
369
+ // Charlie's devices).
370
+ let event_encryption_info = bob. get_room_event_encryption_info ( & event, room_id) . await . unwrap ( ) ;
371
+ assert_matches ! (
372
+ event_encryption_info. verification_state,
373
+ VerificationState :: Unverified ( VerificationLevel :: None ( DeviceLinkProblem :: MissingDevice ) )
374
+ ) ;
375
+ }
376
+
314
377
#[ async_test]
315
378
async fn test_verification_states_multiple_device ( ) {
316
379
let ( bob, _) = get_prepared_machine_test_helper ( tests:: user_id ( ) , false ) . await ;
0 commit comments