Skip to content

WIP: PGP contacts #6796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 193 commits into
base: main
Choose a base branch
from
Open

WIP: PGP contacts #6796

wants to merge 193 commits into from

Conversation

link2xt
Copy link
Collaborator

@link2xt link2xt commented Apr 12, 2025

Still missing, not all of this should be fixed before merging but at least CI should pass:

  • Return an error when API user tries to add email contact to encrypted chats.
  • Same for PGP-contacts, they should not be added to unencrypted chats.
  • Fix AEAP tests.
  • Chat-Group-Member-Fpr header.
  • Ignore Chat-Group-ID if the message is not encrypted+signed.
  • Complete Thunderbird tests.
  • Tests for 1:1 chat assignment. If we have multiple PGP-contacts with the same email address, can assign outgoing messages without Autocrypt-Gossip to the most recent one or using In-Reply-To or References. If there are no PGP-contacts, the message can go to email contact or trash. EDIT: we have tests for incomplete message assignment, they pass. This is not comprehensive and does not use Message-IDs and References, but tying chat assignment to contact lookup is complicated.
  • Migration. Started at [WIP] feat: Migration for PGP-contacts #6818
  • Do not list email-contacts in the contact list by default. For email contacts maybe add a flag.
  • SHA-256 fingerprints (API to get SHA2-256 fingerprints for any keys rpgp/rpgp#531, wip: "imprint" fn rpgp/rpgp#541). If we can, we should use SHA-256 fingerprints for v4 keys instead of having SHA-1 fingerprints as the primary key. Invite links with SHA-1 should still be supported. Adding a column can be done later and we will likely need two columns anyway with standard fingerprint and SHA-256 to support openpgp4fpr and invite links, but Chat-Group-Member-Fpr format should be fixed before release.
  • Open issues for Thunderbird: test_prefer_encrypt_mutual_if_encrypted has TODOs for assigning to chat by issuer fingerprint. This should also work if the key is attached and no Autocrypt header is sent. Signed-only messages should probably go to PGP-chat without a padlock. Fixing this is out of scope of this PR. If Thunderbird is configured to send Autocrypt header, chatting should work, this is already tested.

@link2xt link2xt mentioned this pull request Apr 12, 2025
@link2xt link2xt changed the title Link2xt/pgp contacts WIP: PGP contacts Apr 12, 2025
@link2xt link2xt force-pushed the link2xt/pgp-contacts branch 2 times, most recently from 7acd920 to 280e5dd Compare April 13, 2025 05:49
@link2xt link2xt force-pushed the link2xt/pgp-contacts branch from 7e5dab4 to 479879a Compare April 14, 2025 19:13
Copy link
Collaborator

@Hocuri Hocuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just 3 small things I was wondering while skimming over

/// This first creates a contact, but does not import the key,
/// so may create a PGP-contact with a fingerprint
/// but without the key.
pub async fn get_pgp_chat(&self, other: &TestContext) -> Chat {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since PGP chats are the more common type of chat now, I think it would make sense to call this function get_chat() and the other one get_email_chat() or get_unencrypted_chat() or similar. But it's not that important, e.g. if this would mean that a lot of test have to be changed.

@link2xt link2xt force-pushed the link2xt/pgp-contacts branch 2 times, most recently from ebe2a09 to cac8d20 Compare April 16, 2025 16:13
@adbenitez
Copy link
Collaborator

a way to know if a chat is an encrypted chat is missing, currently there is only "isPgpContact" that can be used to mark contacts/1:1 chat but for unencrypted groups/threads of classic email non-pgp contacts there is no API to recognize such chats and also put the "classic email" marker as for classic email contacts

@link2xt link2xt force-pushed the link2xt/pgp-contacts branch 2 times, most recently from 625f8f4 to c87c241 Compare April 21, 2025 21:24
@@ -187,6 +191,7 @@ impl BasicChat {
id: chat_id,
name: chat.name.clone(),
is_protected: chat.is_protected(),
is_encrypted: chat.is_encrypted(context).await?,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds up to 2 additional database calls to loading BasicChat, though I can't think of a good way to avoid it, so maybe it's fine. Or maybe it should only be added to FullChat, idk.

) -> Result<(ContactId, Modifier)> {
Self::add_or_lookup_ex(context, name, addr, "", origin).await
}

/// Lookup a contact and create it if it does not exist yet.
/// The contact is identified by the email-address, a name and an "origin" can be given.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment here should explain how fingerprint & addr parameters relate; the way I understand the code:

/// If `fingerprint` is passed, a PGP-contact with this fingerprint added / looked up.
/// Otherwise, an email-contact with `addr` is added / looked up.
/// A name and an "origin" can be given.

Comment on lines +850 to +858
if !fingerprint.is_empty() {
let fingerprint_self = load_self_public_key(context).await?.dc_fingerprint().hex();
if fingerprint == fingerprint_self {
return Ok((ContactId::SELF, sth_modified));
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading the self fingerprint everytime a contact is looked up, just to check whether it's ContactId::SELF, seems unnecessarily slow to me.

I wonder if we can simplify & speed up things by not using the kepairs table anymore, and instead storing the private and public key in configs. This would mean that it's not possible to have multiple self keys anymore, but I'm not sure there is anyone who is actually making use of the fact that DC theoretically supports using multiple self keys. It would also mean that we have to store the key as base64, not sure about the consequences there. An alternative would be to store the self fingerprint in a OnceCell, since we don't allow changing the primary key anyway.

But we can open an issue for this, and do it in a follow-up PR.

Comment on lines -713 to +801
to_ids: &[ContactId],
past_ids: &[ContactId],
to_ids: &[Option<ContactId>],
past_ids: &[Option<ContactId>],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to put a comment what a None element means.

@link2xt link2xt force-pushed the link2xt/pgp-contacts branch 2 times, most recently from 1cff5d4 to 907628e Compare May 2, 2025 17:13
@link2xt link2xt marked this pull request as ready for review May 2, 2025 17:53
@link2xt link2xt force-pushed the link2xt/pgp-contacts branch from c156eca to ec7c421 Compare May 6, 2025 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants