Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a76b28b
api!: remove reset_encryption() APIs
link2xt Apr 10, 2025
5219c5c
PGP-contacts
link2xt Feb 28, 2025
bd7b4da
remove allow_aeap
link2xt Apr 8, 2025
42f7d1d
TODO: mark as verified
link2xt Apr 8, 2025
0570033
Encrypt all messages to chats with a group ID
link2xt Apr 10, 2025
45832dc
test fixup
link2xt Apr 10, 2025
6954cea
test: test receiving member added
link2xt Apr 10, 2025
752e687
test: make sure adding contact results in a PGP contact if there is g…
link2xt Apr 10, 2025
db10fb5
WIP: to_ids from gossip
link2xt Apr 10, 2025
791c4ff
refactor: use add_or_lookup_contact_id
link2xt Apr 10, 2025
8baa5ab
format
link2xt Apr 10, 2025
cf4899a
Use load_from_db()
link2xt Apr 10, 2025
8ad9368
make chat::chat_tests::test_info_contact_id pass
link2xt Apr 10, 2025
0f3edb9
chat::chat_tests::test_info_contact_id passes
link2xt Apr 10, 2025
378d4ab
test: add sections to chat::chat_tests::test_past_members
link2xt Apr 11, 2025
a739312
simplify peerstate loading
link2xt Apr 11, 2025
ba56b21
format
link2xt Apr 11, 2025
26b2b12
simplify peerstate loading
link2xt Apr 11, 2025
ffd9dbd
MimeFactory.encryption_certificates
link2xt Apr 11, 2025
f0dfe00
rename variable
link2xt Apr 11, 2025
fe4986e
move encryption_certificates generation
link2xt Apr 11, 2025
b79cc5f
Remove pgp_contacts_addr from the migration
link2xt Apr 11, 2025
fa0cf1e
Take OpenPGP certificates from a public key table
link2xt Apr 11, 2025
65d3b4e
Save public key from a vCard
link2xt Apr 11, 2025
b863ca7
Take keys from public_keys table
link2xt Apr 11, 2025
0922147
no peerstate in mimefactory and contact anymore
link2xt Apr 11, 2025
a06fc25
no peerstates in REPL
link2xt Apr 11, 2025
c0f9053
mark as verified
link2xt Apr 12, 2025
53d2adc
no should_encrypt
link2xt Apr 12, 2025
a7e4a37
unused
link2xt Apr 12, 2025
6241543
less peerstate
link2xt Apr 12, 2025
d71f999
process Autocrypt
link2xt Apr 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions deltachat-jsonrpc/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1533,15 +1533,6 @@ impl CommandApi {
Ok(())
}

/// Resets contact encryption.
async fn reset_contact_encryption(&self, account_id: u32, contact_id: u32) -> Result<()> {
let ctx = self.get_context(account_id).await?;
let contact_id = ContactId::new(contact_id);

contact_id.reset_encryption(&ctx).await?;
Ok(())
}

/// Sets display name for existing contact.
async fn change_contact_name(
&self,
Expand Down
17 changes: 0 additions & 17 deletions deltachat-repl/src/cmdline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ use tokio::fs;
/// e.g. bitmask 7 triggers actions defined with bits 1, 2 and 4.
async fn reset_tables(context: &Context, bits: i32) {
println!("Resetting tables ({bits})...");
if 0 != bits & 2 {
context
.sql()
.execute("DELETE FROM acpeerstates;", ())
.await
.unwrap();
println!("(2) Peerstates reset.");
}
if 0 != bits & 4 {
context
.sql()
Expand Down Expand Up @@ -296,15 +288,6 @@ async fn log_contactlist(context: &Context, contacts: &[ContactId]) -> Result<()
verified_str,
if !addr.is_empty() { addr } else { "addr unset" }
);
let peerstate = Peerstate::from_addr(context, addr)
.await
.expect("peerstate error");
if peerstate.is_some() && *contact_id != ContactId::SELF {
line2 = format!(
", prefer-encrypt={}",
peerstate.as_ref().unwrap().prefer_encrypt
);
}

println!("Contact#{}: {}{}", *contact_id, line, line2);
}
Expand Down
4 changes: 0 additions & 4 deletions deltachat-rpc-client/src/deltachat_rpc_client/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ def delete(self) -> None:
"""Delete contact."""
self._rpc.delete_contact(self.account.id, self.id)

def reset_encryption(self) -> None:
"""Reset contact encryption."""
self._rpc.reset_contact_encryption(self.account.id, self.id)

def set_name(self, name: str) -> None:
"""Change the name of this contact."""
self._rpc.change_contact_name(self.account.id, self.id, name)
Expand Down
1 change: 0 additions & 1 deletion deltachat-rpc-client/tests/test_something.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ def test_contact(acfactory) -> None:
assert repr(alice_contact_bob)
alice_contact_bob.block()
alice_contact_bob.unblock()
alice_contact_bob.reset_encryption()
alice_contact_bob.set_name("new name")
alice_contact_bob.get_encryption_info()
snapshot = alice_contact_bob.get_snapshot()
Expand Down
50 changes: 38 additions & 12 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,17 +1334,11 @@ impl ChatId {
{
let contact = Contact::get_by_id(context, *contact_id).await?;
let addr = contact.get_addr();
let peerstate = Peerstate::from_addr(context, addr).await?;

match peerstate
.filter(|peerstate| peerstate.peek_key(false).is_some())
.map(|peerstate| peerstate.prefer_encrypt)
{
Some(EncryptPreference::Mutual) | Some(EncryptPreference::NoPreference) => {
ret_available += &format!("{addr}\n")
}
Some(EncryptPreference::Reset) | None => ret_reset += &format!("{addr}\n"),
};
if contact.is_pgp_contact() {
ret_available += &format!("{addr}\n");
} else {
ret_reset += &format!("{addr}\n");
}
}

let mut ret = String::new();
Expand Down Expand Up @@ -2319,7 +2313,11 @@ impl Chat {
return Ok(None);
}
let contact = Contact::get_by_id(context, contact_id).await?;
r = Some(SyncId::ContactAddr(contact.get_addr().to_string()));
if let Some(fingerprint) = contact.fingerprint() {
r = Some(SyncId::ContactFingerprint(fingerprint.to_string()));
} else {
r = Some(SyncId::ContactAddr(contact.get_addr().to_string()));
}
}
Ok(r)
}
Expand Down Expand Up @@ -4847,7 +4845,12 @@ async fn set_contacts_by_addrs(context: &Context, id: ChatId, addrs: &[String])
/// A cross-device chat id used for synchronisation.
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub(crate) enum SyncId {
// E-mail address of the contact.
ContactAddr(String),

// OpenPGP fingerprint of the contact.
ContactFingerprint(String),

Grpid(String),
/// "Message-ID"-s, from oldest to latest. Used for ad-hoc groups.
Msgids(Vec<String>),
Expand Down Expand Up @@ -4899,6 +4902,29 @@ impl Context {
.await?
.id
}
SyncId::ContactFingerprint(fingerprint) => {
let name = "";
let addr = "";
let (contact_id, _) =
Contact::add_or_lookup_ex(self, name, addr, fingerprint, Origin::Hidden)
.await?;
match action {
SyncAction::Rename(to) => {
contact_id.set_name_ex(self, Nosync, to).await?;
return Ok(());
}
SyncAction::Block => {
return contact::set_blocked(self, Nosync, contact_id, true).await
}
SyncAction::Unblock => {
return contact::set_blocked(self, Nosync, contact_id, false).await
}
_ => (),
}
ChatIdBlocked::get_for_contact(self, contact_id, Blocked::Request)
.await?
.id
}
SyncId::Grpid(grpid) => {
if let SyncAction::CreateBroadcast(name) = action {
create_broadcast_list_ex(self, Nosync, grpid.clone(), name.clone()).await?;
Expand Down
38 changes: 26 additions & 12 deletions src/chat/chat_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async fn test_chat_info() {

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_get_draft_no_draft() {
let t = TestContext::new().await;
let t = TestContext::new_alice().await;
let chat = t.get_self_chat().await;
let draft = chat.id.get_draft(&t).await.unwrap();
assert!(draft.is_none());
Expand All @@ -60,14 +60,14 @@ async fn test_get_draft_special_chat_id() {
async fn test_get_draft_no_chat() {
// This is a weird case, maybe this should be an error but we
// do not get this info from the database currently.
let t = TestContext::new().await;
let t = TestContext::new_alice().await;
let draft = ChatId::new(42).get_draft(&t).await.unwrap();
assert!(draft.is_none());
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_get_draft() {
let t = TestContext::new().await;
let t = TestContext::new_alice().await;
let chat_id = &t.get_self_chat().await.id;
let mut msg = Message::new_text("hello".to_string());

Expand Down Expand Up @@ -325,20 +325,29 @@ async fn test_member_add_remove() -> Result<()> {
create_group_chat(&alice, ProtectionStatus::Unprotected, "Group chat").await?;
let alice_fiona_contact_id = alice.add_or_lookup_contact_id(&fiona).await;
add_contact_to_chat(&alice, alice_chat_id, alice_fiona_contact_id).await?;
alice
let sent = alice
.send_text(alice_chat_id, "Hi! I created a group.")
.await;
let fiona_chat_id = fiona.recv_msg(&sent).await.chat_id;

// Alice adds Bob to the chat.
add_contact_to_chat(&alice, alice_chat_id, alice_bob_contact_id).await?;
let sent = alice.pop_sent_msg().await;
fiona.recv_msg(&sent).await;

// Locally set name "robert" should not leak.
assert!(!sent.payload.contains("robert"));
assert_eq!(
sent.load_from_db().await.get_text(),
"You added member robert."
);
let fiona_contact_ids = get_chat_contacts(&fiona, fiona_chat_id).await?;
assert_eq!(fiona_contact_ids.len(), 3);
for contact_id in fiona_contact_ids {
let contact = Contact::get_by_id(&fiona, contact_id).await?;
assert_ne!(contact.get_name(), "robert");
assert!(contact.is_pgp_contact());
}

// Alice removes Bob from the chat.
remove_contact_from_chat(&alice, alice_chat_id, alice_bob_contact_id).await?;
Expand Down Expand Up @@ -968,7 +977,7 @@ async fn test_delete_device_chat() {

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_device_chat_cannot_sent() {
let t = TestContext::new().await;
let t = TestContext::new_alice().await;
t.update_device_chats().await.unwrap();
let device_chat_id = ChatId::get_for_contact(&t, ContactId::DEVICE)
.await
Expand Down Expand Up @@ -1015,7 +1024,7 @@ async fn chatlist_len(ctx: &Context, listflags: usize) -> usize {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_archive() {
// create two chats
let t = TestContext::new().await;
let t = TestContext::new_alice().await;
let mut msg = Message::new_text("foo".to_string());
let msg_id = add_device_msg(&t, None, Some(&mut msg)).await.unwrap();
let chat_id1 = message::Message::load_from_db(&t, msg_id)
Expand Down Expand Up @@ -1313,7 +1322,7 @@ async fn get_chats_from_chat_list(ctx: &Context, listflags: usize) -> Vec<ChatId

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_pinned() {
let t = TestContext::new().await;
let t = TestContext::new_alice().await;

// create 3 chats, wait 1 second in between to get a reliable order (we order by time)
let mut msg = Message::new_text("foo".to_string());
Expand Down Expand Up @@ -3004,9 +3013,9 @@ async fn test_sync_accept_before_first_msg() -> Result<()> {
assert_eq!(alice1_contacts.len(), 1);
let a1b_contact_id = alice1_contacts[0];
let a1b_contact = Contact::get_by_id(alice1, a1b_contact_id).await?;
assert_eq!(a1b_contact.get_addr(), "bob@example.net");
assert_eq!(a1b_contact.get_addr(), "");
assert_eq!(a1b_contact.origin, Origin::CreateChat);
let a1b_chat = alice1.get_chat(bob).await;
let a1b_chat = alice1.get_pgp_chat(bob).await;
assert_eq!(a1b_chat.blocked, Blocked::Not);
let chats = Chatlist::try_load(alice1, 0, None, None).await?;
assert_eq!(chats.len(), 1);
Expand Down Expand Up @@ -3207,7 +3216,7 @@ async fn test_sync_muted() -> Result<()> {
alice1.create_chat(&bob).await;

assert_eq!(
alice1.get_chat(&bob).await.mute_duration,
alice1.get_pgp_chat(&bob).await.mute_duration,
MuteDuration::NotMuted
);
let mute_durations = [
Expand All @@ -3225,7 +3234,7 @@ async fn test_sync_muted() -> Result<()> {
),
_ => m,
};
assert_eq!(alice1.get_chat(&bob).await.mute_duration, m);
assert_eq!(alice1.get_pgp_chat(&bob).await.mute_duration, m);
}
Ok(())
}
Expand Down Expand Up @@ -3386,7 +3395,7 @@ async fn test_info_contact_id() -> Result<()> {
expected_bob_id: ContactId,
) -> Result<()> {
let sent_msg = alice.pop_sent_msg().await;
let msg = Message::load_from_db(alice, sent_msg.sender_msg_id).await?;
let msg = sent_msg.load_from_db().await;
assert_eq!(msg.get_info_type(), expected_type);
assert_eq!(
msg.get_info_contact_id(alice).await?,
Expand Down Expand Up @@ -3549,19 +3558,24 @@ async fn test_past_members() -> Result<()> {
let fiona = &tcm.fiona().await;
let alice_fiona_contact_id = alice.add_or_lookup_contact_id(fiona).await;

tcm.section("Alice creates a chat.");
let alice_chat_id =
create_group_chat(alice, ProtectionStatus::Unprotected, "Group chat").await?;
add_contact_to_chat(alice, alice_chat_id, alice_fiona_contact_id).await?;
alice
.send_text(alice_chat_id, "Hi! I created a group.")
.await;

tcm.section("Alice removes Fiona from the chat.");
remove_contact_from_chat(alice, alice_chat_id, alice_fiona_contact_id).await?;
assert_eq!(get_past_chat_contacts(alice, alice_chat_id).await?.len(), 1);

tcm.section("Alice adds Bob to the chat.");
let bob = &tcm.bob().await;
let alice_bob_contact_id = alice.add_or_lookup_contact_id(bob).await;
add_contact_to_chat(alice, alice_chat_id, alice_bob_contact_id).await?;

tcm.section("Bob receives a message.");
let add_message = alice.pop_sent_msg().await;
let bob_add_message = bob.recv_msg(&add_message).await;
let bob_chat_id = bob_add_message.chat_id;
Expand Down
4 changes: 2 additions & 2 deletions src/chatlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ mod tests {

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_sort_self_talk_up_on_forward() {
let t = TestContext::new().await;
let t = TestContext::new_alice().await;
t.update_device_chats().await.unwrap();
create_group_chat(&t, ProtectionStatus::Unprotected, "a chat")
.await
Expand Down Expand Up @@ -604,7 +604,7 @@ mod tests {

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_search_special_chat_names() {
let t = TestContext::new().await;
let t = TestContext::new_alice().await;
t.update_device_chats().await.unwrap();

let chats = Chatlist::try_load(&t, 0, Some("t-1234-s"), None)
Expand Down
Loading
Loading