don't apply SMTP transparency decoding

This commit is contained in:
André Cruz
2022-07-20 14:41:59 +01:00
parent 04c62ce917
commit 0afece009a
4 changed files with 24 additions and 29 deletions
+20
View File
@@ -0,0 +1,20 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [0.2.0] - 2022-07-20
### Changed
- This library no longer performs the decoding of the SMTP transparency encoding before generating a signature.
## [0.1.5] - 2022-06-28
### Added
- Exposed method in order to be able to provide an existing resolver.
Generated
+1 -1
View File
@@ -69,7 +69,7 @@ checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
[[package]]
name = "cfdkim"
version = "0.1.5"
version = "0.2.0"
dependencies = [
"base64",
"chrono",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "cfdkim"
version = "0.1.5"
version = "0.2.0"
authors = ["Sven Sauleau <sven@cloudflare.com>"]
edition = "2021"
description = "DKIM (RFC6376) implementation"
+2 -27
View File
@@ -1,8 +1,6 @@
use indexmap::set::IndexSet;
use mailparse::MailHeaderMap;
use slog::debug;
use std::io::BufRead;
use std::io::BufReader;
use crate::canonicalization::{
self, canonicalize_body_relaxed, canonicalize_body_simple, canonicalize_header_relaxed,
@@ -17,31 +15,8 @@ pub enum HashAlgo {
}
/// Get the body part of an email
/// De-transparency according to RFC 5321, Section 4.5.2
fn get_body<'a>(email: &'a mailparse::ParsedMail<'a>) -> Result<Vec<u8>, DKIMError> {
let body = bytes::get_all_after(email.raw_bytes, b"\r\n\r\n");
let mut reader = BufReader::new(body);
let mut buffer = Vec::new();
loop {
let mut line = Vec::new();
let byte_read = reader
.read_until(b'\n', &mut line)
.map_err(|_err| DKIMError::MalformedBody)?;
if byte_read == 0 {
break;
}
// Remove leading period
if line[0] == b'.' {
line.remove(0);
}
buffer.append(&mut line);
}
Ok(buffer)
Ok(bytes::get_all_after(email.raw_bytes, b"\r\n\r\n").to_vec())
}
fn hash_sha1<T: AsRef<[u8]>>(data: T) -> Vec<u8> {
@@ -404,7 +379,7 @@ Hello Alice
#[test]
fn test_get_body() {
let email =
mailparse::parse_mail("Subject: A\r\n\r\nContent\n..hi\n..hello..".as_bytes()).unwrap();
mailparse::parse_mail("Subject: A\r\n\r\nContent\n.hi\n.hello..".as_bytes()).unwrap();
assert_eq!(
String::from_utf8_lossy(&get_body(&email).unwrap()),
"Content\n.hi\n.hello..".to_owned()