Commit
+38 -9 +/-4 browse
1 | diff --git a/CHANGELOG.md b/CHANGELOG.md |
2 | index 1af2114..cfdb694 100644 |
3 | --- a/CHANGELOG.md |
4 | +++ b/CHANGELOG.md |
5 | @@ -1,3 +1,7 @@ |
6 | + mail-auth 0.3.9 |
7 | + ================================ |
8 | + - Use relaxed parsing for DNS names (#25) |
9 | + |
10 | mail-auth 0.3.8 |
11 | ================================ |
12 | - Made `pct` field accessible. |
13 | diff --git a/Cargo.toml b/Cargo.toml |
14 | index ea5babb..ddb4948 100644 |
15 | --- a/Cargo.toml |
16 | +++ b/Cargo.toml |
17 | @@ -1,7 +1,7 @@ |
18 | [package] |
19 | name = "mail-auth" |
20 | description = "DKIM, ARC, SPF and DMARC library for Rust" |
21 | - version = "0.3.8" |
22 | + version = "0.3.9" |
23 | edition = "2021" |
24 | authors = [ "Stalwart Labs <hello@stalw.art>"] |
25 | license = "Apache-2.0 OR MIT" |
26 | diff --git a/src/common/resolver.rs b/src/common/resolver.rs |
27 | index f711829..bbb6783 100644 |
28 | --- a/src/common/resolver.rs |
29 | +++ b/src/common/resolver.rs |
30 | @@ -19,7 +19,7 @@ use hickory_resolver::{ |
31 | error::{ResolveError, ResolveErrorKind}, |
32 | proto::rr::RecordType, |
33 | system_conf::read_system_conf, |
34 | - AsyncResolver, |
35 | + AsyncResolver, Name, |
36 | }; |
37 | |
38 | use crate::{ |
39 | @@ -104,7 +104,7 @@ impl Resolver { |
40 | let mut result = vec![]; |
41 | for record in self |
42 | .resolver |
43 | - .txt_lookup(key.into_fqdn().as_ref()) |
44 | + .txt_lookup(Name::from_str_relaxed(key.into_fqdn().as_ref())?) |
45 | .await? |
46 | .as_lookup() |
47 | .record_iter() |
48 | @@ -133,7 +133,10 @@ impl Resolver { |
49 | return mock_resolve(key.as_ref()); |
50 | } |
51 | |
52 | - let txt_lookup = self.resolver.txt_lookup(key.as_ref()).await?; |
53 | + let txt_lookup = self |
54 | + .resolver |
55 | + .txt_lookup(Name::from_str_relaxed(key.as_ref())?) |
56 | + .await?; |
57 | let mut result = Err(Error::InvalidRecordType); |
58 | let records = txt_lookup.as_lookup().record_iter().filter_map(|r| { |
59 | let txt_data = r.data()?.as_txt()?.txt_data(); |
60 | @@ -174,7 +177,10 @@ impl Resolver { |
61 | return mock_resolve(key.as_ref()); |
62 | } |
63 | |
64 | - let mx_lookup = self.resolver.mx_lookup(key.as_ref()).await?; |
65 | + let mx_lookup = self |
66 | + .resolver |
67 | + .mx_lookup(Name::from_str_relaxed(key.as_ref())?) |
68 | + .await?; |
69 | let mx_records = mx_lookup.as_lookup().records(); |
70 | let mut records: Vec<MX> = Vec::with_capacity(mx_records.len()); |
71 | for mx_record in mx_records { |
72 | @@ -214,7 +220,10 @@ impl Resolver { |
73 | return mock_resolve(key.as_ref()); |
74 | } |
75 | |
76 | - let ipv4_lookup = self.resolver.ipv4_lookup(key.as_ref()).await?; |
77 | + let ipv4_lookup = self |
78 | + .resolver |
79 | + .ipv4_lookup(Name::from_str_relaxed(key.as_ref())?) |
80 | + .await?; |
81 | let ips: Vec<Ipv4Addr> = ipv4_lookup |
82 | .as_lookup() |
83 | .record_iter() |
84 | @@ -240,7 +249,10 @@ impl Resolver { |
85 | return mock_resolve(key.as_ref()); |
86 | } |
87 | |
88 | - let ipv6_lookup = self.resolver.ipv6_lookup(key.as_ref()).await?; |
89 | + let ipv6_lookup = self |
90 | + .resolver |
91 | + .ipv6_lookup(Name::from_str_relaxed(key.as_ref())?) |
92 | + .await?; |
93 | let ips = ipv6_lookup |
94 | .as_lookup() |
95 | .record_iter() |
96 | @@ -341,7 +353,11 @@ impl Resolver { |
97 | } |
98 | |
99 | let key = key.into_fqdn(); |
100 | - match self.resolver.lookup_ip(key.as_ref()).await { |
101 | + match self |
102 | + .resolver |
103 | + .lookup_ip(Name::from_str_relaxed(key.as_ref())?) |
104 | + .await |
105 | + { |
106 | Ok(result) => Ok(result.as_lookup().record_iter().any(|r| { |
107 | r.data().map_or(false, |d| { |
108 | matches!(d.record_type(), RecordType::A | RecordType::AAAA) |
109 | diff --git a/src/lib.rs b/src/lib.rs |
110 | index d5765ac..966d50e 100644 |
111 | --- a/src/lib.rs |
112 | +++ b/src/lib.rs |
113 | @@ -270,7 +270,10 @@ use arc::Set; |
114 | use common::{crypto::HashAlgorithm, headers::Header, lru::LruCache, verify::DomainKey}; |
115 | use dkim::{Atps, Canonicalization, DomainKeyReport}; |
116 | use dmarc::Dmarc; |
117 | - use hickory_resolver::{proto::op::ResponseCode, TokioAsyncResolver}; |
118 | + use hickory_resolver::{ |
119 | + proto::{error::ProtoError, op::ResponseCode}, |
120 | + TokioAsyncResolver, |
121 | + }; |
122 | use mta_sts::{MtaSts, TlsRpt}; |
123 | use spf::{Macro, Spf}; |
124 | |
125 | @@ -570,6 +573,12 @@ impl From<io::Error> for Error { |
126 | } |
127 | } |
128 | |
129 | + impl From<ProtoError> for Error { |
130 | + fn from(err: ProtoError) -> Self { |
131 | + Error::DnsError(err.to_string()) |
132 | + } |
133 | + } |
134 | + |
135 | #[cfg(feature = "rsa")] |
136 | impl From<rsa::errors::Error> for Error { |
137 | fn from(err: rsa::errors::Error) -> Self { |