mirror of
https://github.com/chatmail/core.git
synced 2026-05-01 20:36:31 +03:00
Do not reset peerstate on encrypted messages
If message does not contain Autocrypt header, but is encrypted, do not change the peerstate.
This commit is contained in:
committed by
link2xt
parent
f657b2950c
commit
42c5bbcda3
38
src/e2ee.rs
38
src/e2ee.rs
@@ -135,41 +135,31 @@ pub async fn try_decrypt(
|
|||||||
.map(|from| from.addr)
|
.map(|from| from.addr)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let mut peerstate = None;
|
// Apply Autocrypt header
|
||||||
let autocryptheader = Aheader::from_headers(context, &from, &mail.headers);
|
let autocryptheader = Aheader::from_headers(context, &from, &mail.headers);
|
||||||
|
let mut peerstate = Peerstate::from_addr(context, &from).await?;
|
||||||
if message_time > 0 {
|
|
||||||
peerstate = Peerstate::from_addr(context, &from).await?;
|
|
||||||
|
|
||||||
if let Some(ref mut peerstate) = peerstate {
|
if let Some(ref mut peerstate) = peerstate {
|
||||||
if let Some(ref header) = autocryptheader {
|
if let Some(ref header) = autocryptheader {
|
||||||
peerstate.apply_header(&header, message_time);
|
peerstate.apply_header(&header, message_time);
|
||||||
peerstate.save_to_db(&context.sql, false).await?;
|
peerstate.save_to_db(&context.sql, false).await?;
|
||||||
} else if message_time > peerstate.last_seen_autocrypt && !contains_report(mail) {
|
|
||||||
peerstate.degrade_encryption(message_time);
|
|
||||||
peerstate.save_to_db(&context.sql, false).await?;
|
|
||||||
}
|
}
|
||||||
} else if let Some(ref header) = autocryptheader {
|
} else if let Some(ref header) = autocryptheader {
|
||||||
let p = Peerstate::from_header(context, header, message_time);
|
let p = Peerstate::from_header(context, header, message_time);
|
||||||
p.save_to_db(&context.sql, true).await?;
|
p.save_to_db(&context.sql, true).await?;
|
||||||
peerstate = Some(p);
|
peerstate = Some(p);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* possibly perform decryption */
|
// Possibly perform decryption
|
||||||
let private_keyring: Keyring<SignedSecretKey> = Keyring::new_self(context).await?;
|
let private_keyring: Keyring<SignedSecretKey> = Keyring::new_self(context).await?;
|
||||||
let mut public_keyring_for_validate: Keyring<SignedPublicKey> = Keyring::new();
|
let mut public_keyring_for_validate: Keyring<SignedPublicKey> = Keyring::new();
|
||||||
let mut signatures = HashSet::default();
|
let mut signatures = HashSet::default();
|
||||||
|
|
||||||
if peerstate.as_ref().map(|p| p.last_seen).unwrap_or_else(|| 0) == 0 {
|
if let Some(ref mut peerstate) = peerstate {
|
||||||
peerstate = Peerstate::from_addr(&context, &from).await?;
|
|
||||||
}
|
|
||||||
if let Some(peerstate) = peerstate {
|
|
||||||
peerstate.handle_fingerprint_change(context).await?;
|
peerstate.handle_fingerprint_change(context).await?;
|
||||||
if let Some(key) = peerstate.public_key {
|
if let Some(key) = &peerstate.public_key {
|
||||||
public_keyring_for_validate.add(key);
|
public_keyring_for_validate.add(key.clone());
|
||||||
} else if let Some(key) = peerstate.gossip_key {
|
} else if let Some(key) = &peerstate.gossip_key {
|
||||||
public_keyring_for_validate.add(key);
|
public_keyring_for_validate.add(key.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,6 +171,18 @@ pub async fn try_decrypt(
|
|||||||
&mut signatures,
|
&mut signatures,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
if let Some(mut peerstate) = peerstate {
|
||||||
|
// If message is not encrypted and it is not a read receipt, degrade encryption.
|
||||||
|
if out_mail.is_none()
|
||||||
|
&& message_time > peerstate.last_seen_autocrypt
|
||||||
|
&& !contains_report(mail)
|
||||||
|
{
|
||||||
|
peerstate.degrade_encryption(message_time);
|
||||||
|
peerstate.save_to_db(&context.sql, false).await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok((out_mail, signatures))
|
Ok((out_mail, signatures))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user