upgrade trust-dns to 0.21

main
Hannaeko 2022-04-24 15:40:00 +02:00
parent f1f64665cc
commit c8906c0060
6 changed files with 36 additions and 50 deletions

13
Cargo.lock generated
View File

@ -408,9 +408,9 @@ checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d"
[[package]] [[package]]
name = "enum-as-inner" name = "enum-as-inner"
version = "0.3.4" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "570d109b813e904becc80d8d5da38376818a143348413f7149f1340fe04754d4" checksum = "21cdad81446a7f7dc43f6a77409efeb9733d2fa65553efef6018ef257c959b73"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro2", "proc-macro2",
@ -911,6 +911,7 @@ dependencies = [
"diesel-derive-enum", "diesel-derive-enum",
"diesel_migrations", "diesel_migrations",
"figment", "figment",
"futures-util",
"humantime", "humantime",
"rand", "rand",
"rocket", "rocket",
@ -1791,9 +1792,9 @@ dependencies = [
[[package]] [[package]]
name = "trust-dns-client" name = "trust-dns-client"
version = "0.20.4" version = "0.21.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b4ef9b9bde0559b78a4abb00339143750085f05e5a453efb7b8bef1061f09dc" checksum = "a6d9ba1c6079f6f9b4664e482db1700bd53d2ee77b1c9752c1d7a66c0c8bda99"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"data-encoding", "data-encoding",
@ -1811,9 +1812,9 @@ dependencies = [
[[package]] [[package]]
name = "trust-dns-proto" name = "trust-dns-proto"
version = "0.20.4" version = "0.21.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca94d4e9feb6a181c690c4040d7a24ef34018d8313ac5044a61d21222ae24e31" checksum = "9c31f240f59877c3d4bb3b3ea0ec5a6a0cff07323580ff8c7a605cd7d08b255d"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"cfg-if", "cfg-if",

View File

@ -7,8 +7,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
trust-dns-client = "0.20.1" trust-dns-client = { version = "0.21", features = ["dnssec"] }
trust-dns-proto = "0.20.1" trust-dns-proto = "0.21"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
rocket = { git = "https://github.com/SergioBenitez/Rocket", rev = "6bdd2f8", version = "0.5.0-rc.1", features = ["json"] } rocket = { git = "https://github.com/SergioBenitez/Rocket", rev = "6bdd2f8", version = "0.5.0-rc.1", features = ["json"] }
@ -25,3 +25,5 @@ figment = { version = "0.10.6", features = ["toml", "env"] }
clap = {version = "3", features = ["derive", "cargo"]} clap = {version = "3", features = ["derive", "cargo"]}
argon2 = {version = "0.4", default-features = false, features = ["alloc", "password-hash"] } argon2 = {version = "0.4", default-features = false, features = ["alloc", "password-hash"] }
rand = "0.8" rand = "0.8"
# From trust-dns-client
futures-util = { version = "0.3.5", default-features = false, features = ["std"] }

View File

@ -1,10 +1,11 @@
use std::{future::Future, pin::Pin, task::{Context, Poll}}; use std::{future::Future, pin::Pin, task::{Context, Poll}};
use futures_util::{ready, Stream, StreamExt};
use std::net::SocketAddr; use std::net::SocketAddr;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use tokio::{net::TcpStream as TokioTcpStream, task}; use tokio::{net::TcpStream as TokioTcpStream, task};
use trust_dns_client::{client::AsyncClient, error::ClientError, op::DnsResponse, tcp::TcpClientStream}; use trust_dns_client::{client::AsyncClient, error::ClientError, op::DnsResponse, tcp::TcpClientStream};
use trust_dns_proto::error::ProtoError; use trust_dns_proto::error::{ProtoError, ProtoErrorKind};
use trust_dns_proto::iocompat::AsyncIoTokioAsStd; use trust_dns_proto::iocompat::AsyncIoTokioAsStd;
@ -39,18 +40,24 @@ impl DnsClient {
} }
// Reimplement this type here as ClientReponse in trust-dns crate have private fields // Reimplement this type here as ClientReponse in trust-dns crate have private fields
// https://github.com/bluejekyll/trust-dns/blob/v0.21.2/crates/client/src/client/async_client.rs#L621-L641
pub struct ClientResponse<R>(pub(crate) R) pub struct ClientResponse<R>(pub(crate) R)
where where
R: Future<Output = Result<DnsResponse, ProtoError>> + Send + Unpin + 'static; R: Stream<Item = Result<DnsResponse, ProtoError>> + Send + Unpin + 'static;
impl<R> Future for ClientResponse<R> impl<R> Future for ClientResponse<R>
where where
R: Future<Output = Result<DnsResponse, ProtoError>> + Send + Unpin + 'static, R: Stream<Item = Result<DnsResponse, ProtoError>> + Send + Unpin + 'static,
{ {
type Output = Result<DnsResponse, ClientError>; type Output = Result<DnsResponse, ClientError>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
// This is from the future_utils crate, we simply reuse the reexport from Rocket Poll::Ready(
rocket::futures::FutureExt::poll_unpin(&mut self.0, cx).map_err(ClientError::from) match ready!(self.0.poll_next_unpin(cx)) {
Some(r) => r,
None => Err(ProtoError::from(ProtoErrorKind::Timeout)),
}
.map_err(ClientError::from),
)
} }
} }

View File

@ -86,7 +86,7 @@ impl RecordConnector for DnsConnectorClient {
let answers = response.answers(); let answers = response.answers();
let mut records: Vec<_> = answers.to_vec().into_iter() let mut records: Vec<_> = answers.to_vec().into_iter()
.filter(|record| !matches!(record.rdata(), RData::NULL { .. } | RData::DNSSEC(_))) .filter(|record| record.data().is_some() && !matches!(record.data().unwrap(), RData::NULL { .. } | RData::DNSSEC(_)))
.collect(); .collect();
// AXFR response ends with SOA, we remove it so it is not doubled in the response. // AXFR response ends with SOA, we remove it so it is not doubled in the response.

View File

@ -1,4 +1,3 @@
use std::fmt;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::net::{Ipv6Addr, Ipv4Addr}; use std::net::{Ipv6Addr, Ipv4Addr};
@ -113,17 +112,22 @@ impl From<dns::RData> for RData {
dns::RData::CNAME(target) => RData::CNAME { dns::RData::CNAME(target) => RData::CNAME {
target: SerdeName(target) target: SerdeName(target)
}, },
dns::RData::CAA(caa) => RData::CAA { dns::RData::CAA(caa) => {
let value_str = caa.value().to_string();
RData::CAA {
issuer_critical: caa.issuer_critical(), issuer_critical: caa.issuer_critical(),
value: format!("{}", CAAValue(caa.value())), // Remove first and last char (byte) because string is quoted (") (should be a safe operation)
value: value_str[1..(value_str.len())].into(),
property_tag: caa.tag().as_str().to_string(), property_tag: caa.tag().as_str().to_string(),
}
}, },
dns::RData::MX(mx) => RData::MX { dns::RData::MX(mx) => RData::MX {
preference: mx.preference(), preference: mx.preference(),
mail_exchanger: SerdeName(mx.exchange().clone()) mail_exchanger: SerdeName(mx.exchange().clone())
}, },
dns::RData::NULL(null) => RData::NULL { dns::RData::NULL(null) => RData::NULL {
data: base64::encode(null.anything().map(|data| data.to_vec()).unwrap_or_default()) data: base64::encode(null.anything())
}, },
dns::RData::NS(target) => RData::NS { dns::RData::NS(target) => RData::NS {
target: SerdeName(target) target: SerdeName(target)
@ -251,32 +255,3 @@ impl TryFrom<RData> for dns::RData {
}) })
} }
} }
struct CAAValue<'a>(&'a dns::caa::Value);
// trust_dns Display implementation panics if no parameters (fixed in https://github.com/bluejekyll/trust-dns/pull/1631)
// Implementation based on caa::emit_value
// Also the quotes are strips to render in JSON
impl<'a> fmt::Display for CAAValue<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self.0 {
dns::caa::Value::Issuer(name, parameters) => {
if let Some(name) = name {
write!(f, "{}", name)?;
}
if name.is_none() && parameters.is_empty() {
write!(f, ";")?;
}
for value in parameters {
write!(f, "; {}", value)?;
}
}
dns::caa::Value::Url(url) => write!(f, "{}", url)?,
dns::caa::Value::Unknown(v) => write!(f, "{:?}", v)?,
}
Ok(())
}
}

View File

@ -27,7 +27,8 @@ impl From<dns::Record> for Record {
name: SerdeName(record.name().clone()), name: SerdeName(record.name().clone()),
dns_class: record.dns_class().into(), dns_class: record.dns_class().into(),
ttl: record.ttl(), ttl: record.ttl(),
rdata: record.into_data().into(), // Assume data exists, record with empty data should be filtered by caller
rdata: record.into_data().unwrap().into(),
} }
} }
} }