diff --git a/src/receive_imf/tests.rs b/src/receive_imf/tests.rs index 7b08c704a..6f814e2cb 100644 --- a/src/receive_imf/tests.rs +++ b/src/receive_imf/tests.rs @@ -12,6 +12,7 @@ use crate::config::Config; use crate::constants::{DC_GCL_FOR_FORWARDING, DC_GCL_NO_SPECIALS}; use crate::download::{DownloadState, MIN_DOWNLOAD_LIMIT}; use crate::imap::prefetch_should_download; +use crate::imex::{imex, ImexMode}; use crate::message::{self, Message}; use crate::test_utils::{get_chat_msg, TestContext, TestContextManager}; @@ -4016,6 +4017,37 @@ async fn test_download_later() -> Result<()> { Ok(()) } +/// Malice can pretend they have the same address as Alice and sends a message encrypted to Alice's +/// key but signed with another one. Alice must detect that this message is wrongly signed and not +/// treat it as Autocrypt-encrypted. +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_outgoing_msg_forgery() -> Result<()> { + let mut tcm = TestContextManager::new(); + let export_dir = tempfile::tempdir().unwrap(); + let alice = &tcm.alice().await; + let alice_addr = &alice.get_config(Config::Addr).await?.unwrap(); + imex(alice, ImexMode::ExportSelfKeys, export_dir.path(), None).await?; + // We need Bob only to encrypt the forged message to Alice's key, actually Bob doesn't + // participate in the scenario. + let bob = &TestContext::new().await; + bob.configure_addr("bob@example.net").await; + imex(bob, ImexMode::ImportSelfKeys, export_dir.path(), None).await?; + let malice = &TestContext::new().await; + malice.configure_addr(alice_addr).await; + + let malice_chat_id = tcm + .send_recv_accept(bob, malice, "hi from bob") + .await + .chat_id; + + let sent_msg = malice.send_text(malice_chat_id, "hi from malice").await; + let msg = alice.recv_msg(&sent_msg).await; + assert_eq!(msg.state, MessageState::OutDelivered); + assert!(!msg.get_showpadlock()); + + Ok(()) +} + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_create_group_with_big_msg() -> Result<()> { let mut tcm = TestContextManager::new();