mirror of
https://github.com/chatmail/relay.git
synced 2026-08-21 07:50:51 +00:00
chore(deps): Upgrade hickory-resolver (#138)
This commit is contained in:
committed by
missytake
parent
8742ead65e
commit
2e80eb651f
@@ -1,4 +1,4 @@
|
||||
use hickory_resolver::{Name, TokioResolver};
|
||||
use hickory_resolver::{TokioResolver, proto::rr::Name};
|
||||
use lru::LruCache;
|
||||
use std::io;
|
||||
use std::num::NonZeroUsize;
|
||||
@@ -84,22 +84,26 @@ impl LookupTxt for CachedResolver {
|
||||
|
||||
log::debug!("Trying to resolve TXT records for {}", name);
|
||||
let txts: Vec<Vec<u8>> = {
|
||||
let lookup = self.dns_resolver.txt_lookup(name.clone()).await?;
|
||||
let lookup = self
|
||||
.dns_resolver
|
||||
.txt_lookup(name.clone())
|
||||
.await
|
||||
.map_err(io::Error::other)?;
|
||||
|
||||
// viadkim would filter out non-DKIM TXT records,
|
||||
// but we filter it here anyway so that we know which one should be cached.
|
||||
lookup
|
||||
.into_iter()
|
||||
.answers()
|
||||
.iter()
|
||||
// We don't check all records, as this can be a DoS attack vector.
|
||||
// In theory, selector domains should only have a single TXT record.
|
||||
// In practice, we check at most 3, just in case of weird configuration.
|
||||
.take(3)
|
||||
.map(|txt| {
|
||||
let rdata_raw = txt.txt_data().concat();
|
||||
let rdata = String::from_utf8_lossy(&rdata_raw);
|
||||
log::trace!("TXT (concat): {:?}", rdata);
|
||||
let rdata = txt.data.to_string();
|
||||
log::trace!("TXT (raw rdata): {:?}", rdata);
|
||||
let normalized = normalize_rdata(&rdata);
|
||||
log::trace!("TXT (normalized): {:?}", normalized);
|
||||
log::trace!("TXT (concatenated and normalized): {:?}", normalized);
|
||||
normalized.into_bytes()
|
||||
})
|
||||
.collect()
|
||||
|
||||
@@ -11,7 +11,7 @@ pub enum Error {
|
||||
#[error(transparent)]
|
||||
Io(#[from] std::io::Error),
|
||||
#[error(transparent)]
|
||||
Resolve(#[from] hickory_resolver::ResolveError),
|
||||
Resolve(#[from] hickory_resolver::net::NetError),
|
||||
#[error("OpenPGP packet header is truncated - can't validate!")]
|
||||
TruncatedHeader,
|
||||
#[error("Unable to send email, Error during {context}, server said: {raw_smtp_answer}")]
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::smtp_server::{Envelope, SmtpHandler};
|
||||
use crate::tls;
|
||||
use crate::utils::{AddressDomain, build_resolver};
|
||||
use async_trait::async_trait;
|
||||
use hickory_resolver::TokioResolver;
|
||||
use hickory_resolver::{TokioResolver, proto::rr::RData};
|
||||
use http_body_util::BodyExt;
|
||||
use hyper::body::Bytes;
|
||||
use hyper_rustls::HttpsConnector;
|
||||
@@ -141,9 +141,14 @@ impl TransportHandler {
|
||||
match dns_resolver.mx_lookup(query).await {
|
||||
Ok(mx_records) => {
|
||||
let mut hosts: Vec<(u16, String)> = Vec::new();
|
||||
for mx in mx_records {
|
||||
for mx_record in mx_records.answers() {
|
||||
let mx = match mx_record.data {
|
||||
RData::MX(ref mx) => mx,
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
// Null MX / RFC7505
|
||||
if mx.exchange().is_root() {
|
||||
if mx.exchange.is_root() {
|
||||
// From RFC7505 section 3:
|
||||
// > A domain that advertises a null MX MUST NOT
|
||||
// > advertise any other MX RR.
|
||||
@@ -154,8 +159,8 @@ impl TransportHandler {
|
||||
);
|
||||
}
|
||||
|
||||
let host = mx.exchange().to_string().trim_end_matches('.').to_string();
|
||||
hosts.push((mx.preference(), host))
|
||||
let host = mx.exchange.to_string().trim_end_matches('.').to_string();
|
||||
hosts.push((mx.preference, host))
|
||||
}
|
||||
hosts.sort();
|
||||
hosts
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use hickory_resolver::TokioResolver;
|
||||
use hickory_resolver::name_server::TokioConnectionProvider;
|
||||
use hickory_resolver::{TokioResolver, proto::dnssec::TrustAnchors};
|
||||
use mailparse::MailAddr;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Extracts the first email address found in SMTP command or email header.
|
||||
///
|
||||
@@ -106,12 +106,10 @@ pub async fn log_eml(reason: &str, data: &[u8]) -> Result<PathBuf, crate::error:
|
||||
|
||||
/// Creates a DNS resolver with DNSSEC enabled and system configuration (resolv.conf).
|
||||
pub fn build_resolver() -> Result<TokioResolver, crate::error::Error> {
|
||||
let dns_resolver = {
|
||||
let mut builder = TokioResolver::builder(TokioConnectionProvider::default())?;
|
||||
let dns_resolver = TokioResolver::builder_tokio()?
|
||||
// https://github.com/hickory-dns/hickory-dns/issues/3519
|
||||
builder.options_mut().validate = true;
|
||||
builder.build()
|
||||
};
|
||||
.with_trust_anchor(Arc::new(TrustAnchors::default()))
|
||||
.build()?;
|
||||
|
||||
assert!(
|
||||
dns_resolver.options().validate,
|
||||
|
||||
Reference in New Issue
Block a user