Skip to content

Commit 2c669c7

Browse files
iequidoolink2xt
authored andcommitted
test: Add failing test on outgoing message forgery
If a message is sent from SELF, but signed with a foreign key, it mustn't be considered Autocrypt-encrypted and shown with a padlock. Currently this is broken.
1 parent fb04319 commit 2c669c7

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/receive_imf/tests.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::config::Config;
1212
use crate::constants::{DC_GCL_FOR_FORWARDING, DC_GCL_NO_SPECIALS};
1313
use crate::download::{DownloadState, MIN_DOWNLOAD_LIMIT};
1414
use crate::imap::prefetch_should_download;
15+
use crate::imex::{imex, ImexMode};
1516
use crate::message::{self, Message};
1617
use crate::test_utils::{get_chat_msg, TestContext, TestContextManager};
1718

@@ -4016,6 +4017,37 @@ async fn test_download_later() -> Result<()> {
40164017
Ok(())
40174018
}
40184019

4020+
/// Malice can pretend they have the same address as Alice and sends a message encrypted to Alice's
4021+
/// key but signed with another one. Alice must detect that this message is wrongly signed and not
4022+
/// treat it as Autocrypt-encrypted.
4023+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
4024+
async fn test_outgoing_msg_forgery() -> Result<()> {
4025+
let mut tcm = TestContextManager::new();
4026+
let export_dir = tempfile::tempdir().unwrap();
4027+
let alice = &tcm.alice().await;
4028+
let alice_addr = &alice.get_config(Config::Addr).await?.unwrap();
4029+
imex(alice, ImexMode::ExportSelfKeys, export_dir.path(), None).await?;
4030+
// We need Bob only to encrypt the forged message to Alice's key, actually Bob doesn't
4031+
// participate in the scenario.
4032+
let bob = &TestContext::new().await;
4033+
bob.configure_addr("bob@example.net").await;
4034+
imex(bob, ImexMode::ImportSelfKeys, export_dir.path(), None).await?;
4035+
let malice = &TestContext::new().await;
4036+
malice.configure_addr(alice_addr).await;
4037+
4038+
let malice_chat_id = tcm
4039+
.send_recv_accept(bob, malice, "hi from bob")
4040+
.await
4041+
.chat_id;
4042+
4043+
let sent_msg = malice.send_text(malice_chat_id, "hi from malice").await;
4044+
let msg = alice.recv_msg(&sent_msg).await;
4045+
assert_eq!(msg.state, MessageState::OutDelivered);
4046+
assert!(!msg.get_showpadlock());
4047+
4048+
Ok(())
4049+
}
4050+
40194051
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
40204052
async fn test_create_group_with_big_msg() -> Result<()> {
40214053
let mut tcm = TestContextManager::new();

0 commit comments

Comments
 (0)