Skip to content

Commit

Permalink
v0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mdecimus committed Dec 18, 2024
1 parent 600b85e commit 1d2c50a
Show file tree
Hide file tree
Showing 13 changed files with 301 additions and 180 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
mail-auth 0.5.1
================================
- Build `AuthenticatedMessage` from `mail-parser::Message`.

mail-auth 0.5.0
================================
- Fix: Use public suffix list for DMARC relaxed alignment verification (#37)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ lru-cache = "0.1.2"
mail-parser = { version = "0.9", features = ["ludicrous_mode", "full_encoding"] }
mail-builder = { version = "0.3", features = ["ludicrous_mode"] }
parking_lot = "0.12.0"
quick-xml = { version = "0.36", optional = true }
quick-xml = { version = "0.37", optional = true }
ring = { version = "0.17", optional = true }
rsa = { version = "0.9.6", optional = true }
rustls-pemfile = { version = "2", optional = true }
Expand Down
65 changes: 35 additions & 30 deletions src/arc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,53 +34,53 @@ pub struct ArcSealer<T: SigningKey<Hasher = Sha256>, State = NeedDomain> {

#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct Signature {
pub(crate) i: u32,
pub(crate) a: Algorithm,
pub(crate) d: String,
pub(crate) s: String,
pub(crate) b: Vec<u8>,
pub(crate) bh: Vec<u8>,
pub(crate) h: Vec<String>,
pub(crate) z: Vec<String>,
pub(crate) l: u64,
pub(crate) x: u64,
pub(crate) t: u64,
pub(crate) ch: Canonicalization,
pub(crate) cb: Canonicalization,
pub i: u32,
pub a: Algorithm,
pub d: String,
pub s: String,
pub b: Vec<u8>,
pub bh: Vec<u8>,
pub h: Vec<String>,
pub z: Vec<String>,
pub l: u64,
pub x: u64,
pub t: u64,
pub ch: Canonicalization,
pub cb: Canonicalization,
}

#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct Seal {
pub(crate) i: u32,
pub(crate) a: Algorithm,
pub(crate) b: Vec<u8>,
pub(crate) d: String,
pub(crate) s: String,
pub(crate) t: u64,
pub(crate) cv: ChainValidation,
pub i: u32,
pub a: Algorithm,
pub b: Vec<u8>,
pub d: String,
pub s: String,
pub t: u64,
pub cv: ChainValidation,
}

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Results {
pub(crate) i: u32,
pub i: u32,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ArcSet<'x> {
pub(crate) signature: Signature,
pub(crate) seal: Seal,
pub(crate) results: &'x AuthenticationResults<'x>,
pub signature: Signature,
pub seal: Seal,
pub results: &'x AuthenticationResults<'x>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Set<'x> {
pub(crate) signature: Header<'x, &'x Signature>,
pub(crate) seal: Header<'x, &'x Seal>,
pub(crate) results: Header<'x, &'x Results>,
pub signature: Header<'x, &'x Signature>,
pub seal: Header<'x, &'x Seal>,
pub results: Header<'x, &'x Results>,
}

#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub(crate) enum ChainValidation {
pub enum ChainValidation {
#[default]
None,
Fail,
Expand Down Expand Up @@ -123,12 +123,17 @@ impl VerifySignature for Seal {
}
}

impl ArcOutput<'_> {
pub(crate) fn with_result(mut self, result: DkimResult) -> Self {
impl<'x> ArcOutput<'x> {
pub fn with_result(mut self, result: DkimResult) -> Self {
self.result = result;
self
}

pub fn with_set(mut self, set: Set<'x>) -> Self {
self.set.push(set);
self
}

pub fn can_be_sealed(&self) -> bool {
self.set.is_empty() || self.set.last().unwrap().seal.header.cv != ChainValidation::Fail
}
Expand Down
9 changes: 8 additions & 1 deletion src/arc/seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl Signature {
mod test {
use std::time::{Duration, Instant};

use mail_parser::decoders::base64::base64_decode;
use mail_parser::{decoders::base64::base64_decode, MessageParser};

use crate::{
arc::ArcSealer,
Expand Down Expand Up @@ -313,6 +313,13 @@ mod test {
pk: impl SigningKey<Hasher = Sha256>,
) -> String {
let message = AuthenticatedMessage::parse(raw_message.as_bytes()).unwrap();
assert_eq!(
message,
AuthenticatedMessage::from_parsed(
&MessageParser::new().parse(raw_message).unwrap(),
true
)
);
let dkim_result = resolver.verify_dkim(&message).await;
let arc_result = resolver.verify_arc(&message).await;
assert!(
Expand Down
9 changes: 9 additions & 0 deletions src/arc/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ mod test {
time::{Duration, Instant},
};

use mail_parser::MessageParser;

use crate::{
common::{parse::TxtRecordParser, verify::DomainKey},
AuthenticatedMessage, DkimResult, Resolver,
Expand All @@ -206,6 +208,13 @@ mod test {
let resolver = new_resolver(dns_records);
let raw_message = raw_message.replace('\n', "\r\n");
let message = AuthenticatedMessage::parse(raw_message.as_bytes()).unwrap();
assert_eq!(
message,
AuthenticatedMessage::from_parsed(
&MessageParser::new().parse(&raw_message).unwrap(),
true
)
);

let arc = resolver.verify_arc(&message).await;
assert_eq!(arc.result(), &DkimResult::Pass);
Expand Down
Loading

0 comments on commit 1d2c50a

Please sign in to comment.