Some fixes from link2xt's review

This commit is contained in:
Hocuri
2022-10-16 14:52:16 +02:00
parent ba323609fa
commit f358bdbff1
7 changed files with 23 additions and 13 deletions

View File

@@ -469,7 +469,7 @@ Authentication-Results: box.hispanilandia.net; spf=pass smtp.mailfrom=adbenitez@
async fn test_realworld_authentication_results() -> Result<()> { async fn test_realworld_authentication_results() -> Result<()> {
let mut test_failed = false; let mut test_failed = false;
let dir = tools::read_dir("test-data/message/dkimchecks-2022-09-28/") let dir = tools::read_dir("test-data/message/dkimchecks-2022-09-28/".as_ref())
.await .await
.unwrap(); .unwrap();
let mut bytes = Vec::new(); let mut bytes = Vec::new();
@@ -504,7 +504,7 @@ Authentication-Results: box.hispanilandia.net; spf=pass smtp.mailfrom=adbenitez@
} }
// Simulate receiving all emails once, so that we have the correct authserv-ids // Simulate receiving all emails once, so that we have the correct authserv-ids
let mut dir = tools::read_dir(entry.path()).await.unwrap(); let mut dir = tools::read_dir(&entry.path()).await.unwrap();
// The ordering in which the emails are received can matter; // The ordering in which the emails are received can matter;
// the test _should_ pass for every ordering. // the test _should_ pass for every ordering.

View File

@@ -188,7 +188,7 @@ pub enum Config {
/// Space-separated list of all the authserv-ids which we believe /// Space-separated list of all the authserv-ids which we believe
/// may be the one of our email server. /// may be the one of our email server.
/// ///
/// See `crate::authres_handling::update_authservid_candidates`. /// See `crate::authres::update_authservid_candidates`.
AuthservidCandidates, AuthservidCandidates,
} }

View File

@@ -7,8 +7,8 @@ use mailparse::ParsedMail;
use mailparse::SingleInfo; use mailparse::SingleInfo;
use crate::aheader::Aheader; use crate::aheader::Aheader;
use crate::authres_handling; use crate::authres;
use crate::authres_handling::handle_authres; use crate::authres::handle_authres;
use crate::contact::addr_cmp; use crate::contact::addr_cmp;
use crate::context::Context; use crate::context::Context;
use crate::key::{DcKey, Fingerprint, SignedPublicKey, SignedSecretKey}; use crate::key::{DcKey, Fingerprint, SignedPublicKey, SignedSecretKey};
@@ -105,7 +105,7 @@ pub struct DecryptionInfo {
/// means out-of-order message arrival, We don't modify the /// means out-of-order message arrival, We don't modify the
/// peerstate in this case. /// peerstate in this case.
pub message_time: i64, pub message_time: i64,
pub(crate) dkim_results: authres_handling::DkimResults, pub(crate) dkim_results: authres::DkimResults,
} }
/// Returns a reference to the encrypted payload of a ["Mixed /// Returns a reference to the encrypted payload of a ["Mixed
@@ -273,6 +273,9 @@ fn keyring_from_peerstate(peerstate: &Option<Peerstate>) -> Keyring<SignedPublic
/// If we already know this fingerprint from another contact's peerstate, return that /// If we already know this fingerprint from another contact's peerstate, return that
/// peerstate in order to make AEAP work, but don't save it into the db yet. /// peerstate in order to make AEAP work, but don't save it into the db yet.
/// ///
/// The param `allow_change` is used to prevent the autocrypt key from being changed
/// if we suspect that the message may be forged and have a spoofed sender identity.
///
/// Returns updated peerstate. /// Returns updated peerstate.
pub(crate) async fn get_autocrypt_peerstate( pub(crate) async fn get_autocrypt_peerstate(
context: &Context, context: &Context,
@@ -299,9 +302,16 @@ pub(crate) async fn get_autocrypt_peerstate(
.await?; .await?;
if let Some(ref mut peerstate) = peerstate { if let Some(ref mut peerstate) = peerstate {
if addr_cmp(&peerstate.addr, from) && allow_change { if addr_cmp(&peerstate.addr, from) {
if allow_change {
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 {
info!(
context,
"Refusing to update existing peerstate of {}", &peerstate.addr
);
}
} }
// If `peerstate.addr` and `from` differ, this means that // If `peerstate.addr` and `from` differ, this means that
// someone is using the same key but a different addr, probably // someone is using the same key but a different addr, probably

View File

@@ -65,6 +65,7 @@ pub enum HeaderDef {
Received, Received,
/// A header that includes the results of the DKIM, SPF and DMARC checks. /// A header that includes the results of the DKIM, SPF and DMARC checks.
/// See https://datatracker.ietf.org/doc/html/rfc8601
AuthenticationResults, AuthenticationResults,
_TestHeader, _TestHeader,

View File

@@ -93,7 +93,7 @@ mod update_helper;
pub mod webxdc; pub mod webxdc;
#[macro_use] #[macro_use]
mod dehtml; mod dehtml;
mod authres_handling; mod authres;
mod color; mod color;
pub mod html; pub mod html;
pub mod plaintext; pub mod plaintext;

View File

@@ -597,7 +597,6 @@ CREATE INDEX smtp_messageid ON imap(rfc724_mid);
.await?; .await?;
} }
if dbversion < 92 { if dbversion < 92 {
info!(context, "[migration] v92");
sql.execute_migration( sql.execute_migration(
"CREATE TABLE sending_domains(domain TEXT PRIMARY KEY, dkim_works INTEGER DEFAULT 0);", "CREATE TABLE sending_domains(domain TEXT PRIMARY KEY, dkim_works INTEGER DEFAULT 0);",
92, 92,

View File

@@ -495,8 +495,8 @@ pub fn open_file_std<P: AsRef<std::path::Path>>(
} }
} }
pub async fn read_dir(path: impl AsRef<Path>) -> Result<Vec<fs::DirEntry>> { pub async fn read_dir(path: &Path) -> Result<Vec<fs::DirEntry>> {
let res = tokio_stream::wrappers::ReadDirStream::new(fs::read_dir(path.as_ref()).await?) let res = tokio_stream::wrappers::ReadDirStream::new(fs::read_dir(path).await?)
.try_collect() .try_collect()
.await?; .await?;
Ok(res) Ok(res)