Check for encryption
- collect body of incoming mail. - check if incoming mail is already encrypted - dont touch it if it is. - check if recipients of that mail can encrypt.
This commit is contained in:
+43
-12
@@ -17,16 +17,18 @@ use indymilter::{
|
||||
EomContext,
|
||||
Macros,
|
||||
NegotiateContext,
|
||||
ProtoOpts,
|
||||
ProtoOpts,
|
||||
SocketInfo,
|
||||
Status,
|
||||
Config,
|
||||
Status,
|
||||
Config,
|
||||
ContextActions,
|
||||
};
|
||||
|
||||
use crate::types::husk_context::HuskContext;
|
||||
use crate::config::{HuskConfig, HuskConfigContainer};
|
||||
use crate::mail;
|
||||
use crate::crypto;
|
||||
use crate::types::mail_context::ProtectionPossibility;
|
||||
|
||||
pub struct Daemon { }
|
||||
|
||||
@@ -101,7 +103,7 @@ impl Daemon {
|
||||
log::error!("{}", e);
|
||||
Status::Tempfail
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_mail(cx: &mut Context<HuskContext<'_>>, args: Vec<CString>) -> Status {
|
||||
@@ -110,7 +112,7 @@ impl Daemon {
|
||||
let mut sender: Option<String> = None;
|
||||
|
||||
for arg in args {
|
||||
if let Some(s) = mail::to_email(&arg) {
|
||||
if let Some(s) = mail::to_email(&arg) {
|
||||
sender = Some(s);
|
||||
break;
|
||||
}
|
||||
@@ -133,18 +135,18 @@ impl Daemon {
|
||||
|
||||
let mut rcpt: Option<String> = None;
|
||||
for arg in args {
|
||||
if let Some(s) = mail::to_email(&arg) {
|
||||
if let Some(s) = mail::to_email(&arg) {
|
||||
rcpt = Some(s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if rcpt.is_none() {
|
||||
Status::Tempfail
|
||||
if rcpt.is_none() {
|
||||
Status::Tempfail
|
||||
} else {
|
||||
context.add_recipient(rcpt.unwrap()).unwrap();
|
||||
Status::Continue
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
Status::Tempfail
|
||||
}
|
||||
@@ -153,7 +155,7 @@ impl Daemon {
|
||||
async fn handle_data(cx: &mut Context<HuskContext<'_>>) -> Status {
|
||||
log::debug!("DATA");
|
||||
|
||||
if let Some(ref mut context) = cx.data {
|
||||
if let Some(ref mut _context) = cx.data {
|
||||
// XXX: check for early accepting
|
||||
// if there are no recipients with authenticated certificates
|
||||
// tell the MTA that this milter is done and the mail can be further
|
||||
@@ -176,10 +178,15 @@ impl Daemon {
|
||||
Status::Continue
|
||||
}
|
||||
|
||||
async fn handle_body(_cx: &mut Context<HuskContext<'_>>, chunk: Bytes) -> Status {
|
||||
async fn handle_body(cx: &mut Context<HuskContext<'_>>, chunk: Bytes) -> Status {
|
||||
log::debug!("BODY: chunk with {:?} bytes received", &chunk.len());
|
||||
|
||||
Status::Continue
|
||||
if let Some(ref mut context) = cx.data {
|
||||
context.mail.add_chunk(chunk);
|
||||
Status::Continue
|
||||
} else {
|
||||
Status::Tempfail
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_eom(cx: &mut EomContext<HuskContext<'_>>) -> Status {
|
||||
@@ -188,6 +195,30 @@ impl Daemon {
|
||||
if let Some(ref mut context) = cx.data {
|
||||
log::debug!("Mail from {:?} complete", context.mail.sender);
|
||||
log::debug!("recipients: {:?}", context.mail.recipients);
|
||||
log::debug!("body size: {}", context.mail.body_size);
|
||||
|
||||
let body = context.mail.collect_body();
|
||||
|
||||
// check if mail is already encrypted. If it is, keep it as such.
|
||||
if crypto::is_encrypted(&body) {
|
||||
log::info!("encrypted mail detected");
|
||||
return Status::Accept;
|
||||
}
|
||||
|
||||
|
||||
// possible protection
|
||||
// none -> accept
|
||||
// partial -> accept (later: split)
|
||||
// full -> encrypt
|
||||
// check mailbody
|
||||
// is encrypted -> accept
|
||||
// else -> encrypt
|
||||
|
||||
let protection = ProtectionPossibility::from(&context.mail);
|
||||
|
||||
if protection == ProtectionPossibility::Full {
|
||||
// encrypt
|
||||
}
|
||||
}
|
||||
|
||||
Status::Continue
|
||||
|
||||
Reference in New Issue
Block a user