mirror of
https://github.com/chatmail/core.git
synced 2026-05-14 20:36:30 +03:00
refactor: Don't even parse Autocrypt header for outgoing messages (#5259)
Accordingly, there's no need in `Peerstate` for self addresses (and in the db too).
This commit is contained in:
@@ -12,7 +12,7 @@ use crate::authres::{self, DkimResults};
|
|||||||
use crate::contact::addr_cmp;
|
use crate::contact::addr_cmp;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::headerdef::{HeaderDef, HeaderDefMap};
|
use crate::headerdef::{HeaderDef, HeaderDefMap};
|
||||||
use crate::key::{self, DcKey, Fingerprint, SignedPublicKey, SignedSecretKey};
|
use crate::key::{DcKey, Fingerprint, SignedPublicKey, SignedSecretKey};
|
||||||
use crate::peerstate::Peerstate;
|
use crate::peerstate::Peerstate;
|
||||||
use crate::pgp;
|
use crate::pgp;
|
||||||
|
|
||||||
@@ -69,25 +69,26 @@ pub(crate) async fn prepare_decryption(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let autocrypt_header =
|
let autocrypt_header = if context.is_self_addr(from).await? {
|
||||||
if let Some(autocrypt_header_value) = mail.headers.get_header_value(HeaderDef::Autocrypt) {
|
None
|
||||||
match Aheader::from_str(&autocrypt_header_value) {
|
} else if let Some(aheader_value) = mail.headers.get_header_value(HeaderDef::Autocrypt) {
|
||||||
Ok(header) if addr_cmp(&header.addr, from) => Some(header),
|
match Aheader::from_str(&aheader_value) {
|
||||||
Ok(header) => {
|
Ok(header) if addr_cmp(&header.addr, from) => Some(header),
|
||||||
warn!(
|
Ok(header) => {
|
||||||
context,
|
warn!(
|
||||||
"Autocrypt header address {:?} is not {:?}.", header.addr, from
|
context,
|
||||||
);
|
"Autocrypt header address {:?} is not {:?}.", header.addr, from
|
||||||
None
|
);
|
||||||
}
|
None
|
||||||
Err(err) => {
|
|
||||||
warn!(context, "Failed to parse Autocrypt header: {:#}.", err);
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
Err(err) => {
|
||||||
None
|
warn!(context, "Failed to parse Autocrypt header: {:#}.", err);
|
||||||
};
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
let dkim_results = handle_authres(context, mail, from, message_time).await?;
|
let dkim_results = handle_authres(context, mail, from, message_time).await?;
|
||||||
|
|
||||||
@@ -265,21 +266,16 @@ pub(crate) fn validate_detached_signature<'a, 'b>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns public keyring for `peerstate`.
|
/// Returns public keyring for `peerstate`.
|
||||||
pub(crate) async fn keyring_from_peerstate(
|
pub(crate) fn keyring_from_peerstate(peerstate: Option<&Peerstate>) -> Vec<SignedPublicKey> {
|
||||||
context: &Context,
|
|
||||||
peerstate: Option<&Peerstate>,
|
|
||||||
) -> Result<Vec<SignedPublicKey>> {
|
|
||||||
let mut public_keyring_for_validate = Vec::new();
|
let mut public_keyring_for_validate = Vec::new();
|
||||||
if let Some(peerstate) = peerstate {
|
if let Some(peerstate) = peerstate {
|
||||||
if let Some(key) = &peerstate.public_key {
|
if let Some(key) = &peerstate.public_key {
|
||||||
public_keyring_for_validate.push(key.clone());
|
public_keyring_for_validate.push(key.clone());
|
||||||
} else if let Some(key) = &peerstate.gossip_key {
|
} else if let Some(key) = &peerstate.gossip_key {
|
||||||
public_keyring_for_validate.push(key.clone());
|
public_keyring_for_validate.push(key.clone());
|
||||||
} else if context.is_self_addr(&peerstate.addr).await? {
|
|
||||||
public_keyring_for_validate = key::load_self_public_keyring(context).await?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(public_keyring_for_validate)
|
public_keyring_for_validate
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Applies Autocrypt header to Autocrypt peer state and saves it into the database.
|
/// Applies Autocrypt header to Autocrypt peer state and saves it into the database.
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ use crate::decrypt::{
|
|||||||
use crate::dehtml::dehtml;
|
use crate::dehtml::dehtml;
|
||||||
use crate::events::EventType;
|
use crate::events::EventType;
|
||||||
use crate::headerdef::{HeaderDef, HeaderDefMap};
|
use crate::headerdef::{HeaderDef, HeaderDefMap};
|
||||||
use crate::key::{load_self_secret_keyring, DcKey, Fingerprint, SignedPublicKey};
|
use crate::key::{self, load_self_secret_keyring, DcKey, Fingerprint, SignedPublicKey};
|
||||||
use crate::message::{
|
use crate::message::{
|
||||||
self, set_msg_failed, update_msg_state, Message, MessageState, MsgId, Viewtype,
|
self, set_msg_failed, update_msg_state, Message, MessageState, MsgId, Viewtype,
|
||||||
};
|
};
|
||||||
@@ -304,8 +304,11 @@ impl MimeMessage {
|
|||||||
hop_info += "\n\n";
|
hop_info += "\n\n";
|
||||||
hop_info += &decryption_info.dkim_results.to_string();
|
hop_info += &decryption_info.dkim_results.to_string();
|
||||||
|
|
||||||
let public_keyring =
|
let incoming = !context.is_self_addr(&from.addr).await?;
|
||||||
keyring_from_peerstate(context, decryption_info.peerstate.as_ref()).await?;
|
let public_keyring = match decryption_info.peerstate.is_none() && !incoming {
|
||||||
|
true => key::load_self_public_keyring(context).await?,
|
||||||
|
false => keyring_from_peerstate(decryption_info.peerstate.as_ref()),
|
||||||
|
};
|
||||||
let (mail, mut signatures, encrypted) = match tokio::task::block_in_place(|| {
|
let (mail, mut signatures, encrypted) = match tokio::task::block_in_place(|| {
|
||||||
try_decrypt(&mail, &private_keyring, &public_keyring)
|
try_decrypt(&mail, &private_keyring, &public_keyring)
|
||||||
}) {
|
}) {
|
||||||
@@ -430,7 +433,6 @@ impl MimeMessage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let incoming = !context.is_self_addr(&from.addr).await?;
|
|
||||||
let mut parser = MimeMessage {
|
let mut parser = MimeMessage {
|
||||||
parts: Vec::new(),
|
parts: Vec::new(),
|
||||||
headers,
|
headers,
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ use crate::message::Message;
|
|||||||
use crate::mimeparser::SystemMessage;
|
use crate::mimeparser::SystemMessage;
|
||||||
use crate::sql::Sql;
|
use crate::sql::Sql;
|
||||||
use crate::stock_str;
|
use crate::stock_str;
|
||||||
use crate::tools;
|
|
||||||
|
|
||||||
/// Type of the public key stored inside the peerstate.
|
/// Type of the public key stored inside the peerstate.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -167,7 +166,7 @@ impl Peerstate {
|
|||||||
/// Loads peerstate corresponding to the given address from the database.
|
/// Loads peerstate corresponding to the given address from the database.
|
||||||
pub async fn from_addr(context: &Context, addr: &str) -> Result<Option<Peerstate>> {
|
pub async fn from_addr(context: &Context, addr: &str) -> Result<Option<Peerstate>> {
|
||||||
if context.is_self_addr(addr).await? {
|
if context.is_self_addr(addr).await? {
|
||||||
return Ok(Some(Peerstate::get_self_stub(addr)));
|
return Ok(None);
|
||||||
}
|
}
|
||||||
let query = "SELECT addr, last_seen, last_seen_autocrypt, prefer_encrypted, public_key, \
|
let query = "SELECT addr, last_seen, last_seen_autocrypt, prefer_encrypted, public_key, \
|
||||||
gossip_timestamp, gossip_key, public_key_fingerprint, gossip_key_fingerprint, \
|
gossip_timestamp, gossip_key, public_key_fingerprint, gossip_key_fingerprint, \
|
||||||
@@ -212,7 +211,7 @@ impl Peerstate {
|
|||||||
addr: &str,
|
addr: &str,
|
||||||
) -> Result<Option<Peerstate>> {
|
) -> Result<Option<Peerstate>> {
|
||||||
if context.is_self_addr(addr).await? {
|
if context.is_self_addr(addr).await? {
|
||||||
return Ok(Some(Peerstate::get_self_stub(addr)));
|
return Ok(None);
|
||||||
}
|
}
|
||||||
let query = "SELECT addr, last_seen, last_seen_autocrypt, prefer_encrypted, public_key, \
|
let query = "SELECT addr, last_seen, last_seen_autocrypt, prefer_encrypted, public_key, \
|
||||||
gossip_timestamp, gossip_key, public_key_fingerprint, gossip_key_fingerprint, \
|
gossip_timestamp, gossip_key, public_key_fingerprint, gossip_key_fingerprint, \
|
||||||
@@ -229,34 +228,6 @@ impl Peerstate {
|
|||||||
Self::from_stmt(context, query, (&fp, &addr, &fp)).await
|
Self::from_stmt(context, query, (&fp, &addr, &fp)).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns peerstate stub for self `addr`.
|
|
||||||
///
|
|
||||||
/// Needed for [`crate::decrypt::keyring_from_peerstate()`] which returns a keyring of all our
|
|
||||||
/// pubkeys for such a stub so that we can check if a message is signed by us.
|
|
||||||
fn get_self_stub(addr: &str) -> Self {
|
|
||||||
let now = tools::time();
|
|
||||||
// We can have multiple pubkeys, just make the corresponding fields None.
|
|
||||||
Self {
|
|
||||||
addr: addr.to_string(),
|
|
||||||
last_seen: now,
|
|
||||||
last_seen_autocrypt: now,
|
|
||||||
prefer_encrypt: EncryptPreference::Mutual,
|
|
||||||
public_key: None,
|
|
||||||
public_key_fingerprint: None,
|
|
||||||
gossip_key: None,
|
|
||||||
gossip_key_fingerprint: None,
|
|
||||||
gossip_timestamp: 0,
|
|
||||||
verified_key: None,
|
|
||||||
verified_key_fingerprint: None,
|
|
||||||
verifier: None,
|
|
||||||
secondary_verified_key: None,
|
|
||||||
secondary_verified_key_fingerprint: None,
|
|
||||||
secondary_verifier: None,
|
|
||||||
backward_verified_key_id: None,
|
|
||||||
fingerprint_changed: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn from_stmt(
|
async fn from_stmt(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
query: &str,
|
query: &str,
|
||||||
|
|||||||
Reference in New Issue
Block a user