mirror of
https://github.com/chatmail/core.git
synced 2026-04-21 15:36:30 +03:00
feat: key-contacts
This change introduces a new type of contacts
identified by their public key fingerprint
rather than an e-mail address.
Encrypted chats now stay encrypted
and unencrypted chats stay unencrypted.
For example, 1:1 chats with key-contacts
are encrypted and 1:1 chats with address-contacts
are unencrypted.
Groups that have a group ID are encrypted
and can only contain key-contacts
while groups that don't have a group ID ("adhoc groups")
are unencrypted and can only contain address-contacts.
JSON-RPC API `reset_contact_encryption` is removed.
Python API `Contact.reset_encryption` is removed.
"Group tracking plugin" in legacy Python API was removed because it
relied on parsing email addresses from system messages with regexps.
Co-authored-by: Hocuri <hocuri@gmx.de>
Co-authored-by: iequidoo <dgreshilov@gmail.com>
Co-authored-by: B. Petersen <r10s@b44t.com>
This commit is contained in:
56
src/key.rs
56
src/key.rs
@@ -129,8 +129,11 @@ pub(crate) trait DcKey: Serialize + Deserializable + Clone {
|
||||
fn key_id(&self) -> KeyId;
|
||||
}
|
||||
|
||||
pub(crate) async fn load_self_public_key(context: &Context) -> Result<SignedPublicKey> {
|
||||
let public_key = context
|
||||
/// Attempts to load own public key.
|
||||
///
|
||||
/// Returns `None` if no key is generated yet.
|
||||
pub(crate) async fn load_self_public_key_opt(context: &Context) -> Result<Option<SignedPublicKey>> {
|
||||
let Some(public_key_bytes) = context
|
||||
.sql
|
||||
.query_row_optional(
|
||||
"SELECT public_key
|
||||
@@ -142,9 +145,20 @@ pub(crate) async fn load_self_public_key(context: &Context) -> Result<SignedPubl
|
||||
Ok(bytes)
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
match public_key {
|
||||
Some(bytes) => SignedPublicKey::from_slice(&bytes),
|
||||
.await?
|
||||
else {
|
||||
return Ok(None);
|
||||
};
|
||||
let public_key = SignedPublicKey::from_slice(&public_key_bytes)?;
|
||||
Ok(Some(public_key))
|
||||
}
|
||||
|
||||
/// Loads own public key.
|
||||
///
|
||||
/// If no key is generated yet, generates a new one.
|
||||
pub(crate) async fn load_self_public_key(context: &Context) -> Result<SignedPublicKey> {
|
||||
match load_self_public_key_opt(context).await? {
|
||||
Some(public_key) => Ok(public_key),
|
||||
None => {
|
||||
let keypair = generate_keypair(context).await?;
|
||||
Ok(keypair.public)
|
||||
@@ -171,6 +185,38 @@ pub(crate) async fn load_self_public_keyring(context: &Context) -> Result<Vec<Si
|
||||
Ok(keys)
|
||||
}
|
||||
|
||||
/// Returns own public key fingerprint in (not human-readable) hex representation.
|
||||
/// This is the fingerprint format that is used in the database.
|
||||
///
|
||||
/// If no key is generated yet, generates a new one.
|
||||
///
|
||||
/// For performance reasons, the fingerprint is cached after the first invocation.
|
||||
pub(crate) async fn self_fingerprint(context: &Context) -> Result<&str> {
|
||||
if let Some(fp) = context.self_fingerprint.get() {
|
||||
Ok(fp)
|
||||
} else {
|
||||
let fp = load_self_public_key(context).await?.dc_fingerprint().hex();
|
||||
Ok(context.self_fingerprint.get_or_init(|| fp))
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns own public key fingerprint in (not human-readable) hex representation.
|
||||
/// This is the fingerprint format that is used in the database.
|
||||
///
|
||||
/// Returns `None` if no key is generated yet.
|
||||
///
|
||||
/// For performance reasons, the fingerprint is cached after the first invocation.
|
||||
pub(crate) async fn self_fingerprint_opt(context: &Context) -> Result<Option<&str>> {
|
||||
if let Some(fp) = context.self_fingerprint.get() {
|
||||
Ok(Some(fp))
|
||||
} else if let Some(key) = load_self_public_key_opt(context).await? {
|
||||
let fp = key.dc_fingerprint().hex();
|
||||
Ok(Some(context.self_fingerprint.get_or_init(|| fp)))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn load_self_secret_key(context: &Context) -> Result<SignedSecretKey> {
|
||||
let private_key = context
|
||||
.sql
|
||||
|
||||
Reference in New Issue
Block a user