Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a TSIG client. #373

Merged
merged 91 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
ce2c35a
Add support for (a) indicating to downstream Service impls that a cer…
ximon18 Aug 6, 2024
5f1a647
Remove fn accidentally included from the xfr branch but not intended …
ximon18 Aug 6, 2024
b5e33a7
Remove fn accidentally included from the xfr branch but not intended …
ximon18 Aug 6, 2024
6701131
Remove changes accidentally included from the xfr branch but not inte…
ximon18 Aug 6, 2024
a0e1a1d
Remove changes accidentally included from the xfr branch but not inte…
ximon18 Aug 6, 2024
a5fcce5
Update Service RustDocs now that implementing a service impicitly via…
ximon18 Aug 7, 2024
53017f5
Cargo fmt.
ximon18 Aug 7, 2024
40eea81
Show more ways to impl Service on a struct.
ximon18 Aug 7, 2024
0a289e9
More Service RustDoc improvements.
ximon18 Aug 7, 2024
37c35e9
Minor RustDoc fixes.
ximon18 Aug 7, 2024
ace9498
More RustDoc about request metadata and response byte reservation.
ximon18 Aug 7, 2024
cb87682
Reorder field setting order to match struct field order.
ximon18 Aug 8, 2024
6e7a754
Remove EDNS fixes that are also dealt with by separate work in branch…
ximon18 Aug 8, 2024
ef0bfd2
Clippy.
ximon18 Aug 8, 2024
c2e9e9a
Support streaming responses with the stream client.
ximon18 Aug 8, 2024
d8c8b14
Support adding to a message generated by a client before sending it s…
ximon18 Aug 8, 2024
1376041
Fix compilation error caused by the recent streaming support commit.
ximon18 Aug 8, 2024
1447bfc
Cargo fmt.
ximon18 Aug 8, 2024
5e36a5c
Stelline server testing changes:
ximon18 Aug 8, 2024
6aacae9
Add net::client::tsig.
ximon18 Aug 8, 2024
67f0f33
Remove the added Clone derive on tsig::Key, use Arc in the example in…
ximon18 Aug 8, 2024
6e72597
More coding standards compliance.
ximon18 Aug 8, 2024
46cd1bd
Client transport support for AXFR and IXFR.
Philip-NLnetLabs Aug 20, 2024
461c342
Fmt
Philip-NLnetLabs Aug 20, 2024
911365e
A bit of cleanup.
Philip-NLnetLabs Aug 21, 2024
767fac4
Clippy
Philip-NLnetLabs Aug 21, 2024
aa294fb
Review feedback: SERVFAIL if question cannot be built when preparing …
ximon18 Aug 27, 2024
119e7a2
Merge branch 'service-request-metadata-and-byte-reservation-net-clien…
ximon18 Aug 29, 2024
787799e
Merge branch 'stelline-server-testing-changes' into tsig-client.
ximon18 Aug 30, 2024
26b87cc
Merge branch 'service-request-metadata-and-byte-reservation-net-clien…
ximon18 Aug 29, 2024
dc7b039
Revert local change made for testing.
ximon18 Sep 2, 2024
1d7c952
Import used type.
ximon18 Sep 2, 2024
bf79aba
Remove outdated comment.
ximon18 Sep 2, 2024
326207d
Remove commented out code.
ximon18 Sep 2, 2024
0bea63d
Merge branch 'stelline-server-testing-changes' into tsig-client
ximon18 Sep 2, 2024
649836a
Review feedback: Respond with SERVFAIL with whatever questions we wer…
ximon18 Sep 2, 2024
80752e8
Simplify comment.
ximon18 Sep 2, 2024
f8c58a1
Minor RustDoc improvement.
ximon18 Sep 2, 2024
9aa5795
Minor RustDoc improvement.
ximon18 Sep 2, 2024
efe4972
Remove Unpin constraint on Service RequestOctets generic type.
ximon18 Sep 2, 2024
9f44750
Clippy.
ximon18 Sep 2, 2024
b06d978
Merge branch 'service-request-metadata-and-byte-reservation' into ser…
ximon18 Sep 2, 2024
6be66f7
Merge branch 'service-request-metadata-and-byte-reservation-net-clien…
ximon18 Sep 2, 2024
ab63edd
Merge branch 'stelline-server-testing-changes' into tsig-client
ximon18 Sep 2, 2024
7c26d76
Add RustDoc for the multiple response support.
ximon18 Sep 2, 2024
88d7087
Remove outdated comment.
ximon18 Sep 2, 2024
18da3ee
Replace incorrect conversion (as it will return Error::FormError for …
ximon18 Sep 2, 2024
b99e6f7
Remove errant whitespace in RustDoc comments.
ximon18 Sep 2, 2024
024b1d1
Undo reformatting of imports in otherwise untouched files.
ximon18 Sep 2, 2024
0d2a488
Undo reformatting in otherwise untouched file.
ximon18 Sep 2, 2024
d6d5794
Undo reformatting in otherwise untouched file.
ximon18 Sep 2, 2024
ab633ef
Merge branch 'service-request-metadata-and-byte-reservation-net-clien…
ximon18 Sep 2, 2024
8018663
Remove outdated comment.
ximon18 Sep 2, 2024
88b5c75
More TSIG client RustDoc.
ximon18 Sep 2, 2024
ca3cccf
Minor code simplification.
ximon18 Sep 2, 2024
119ab45
Fix example.
Philip-NLnetLabs Sep 3, 2024
6adac7a
Rename Message::is_stream to Message::is_xfr. Remove is_stream from
Philip-NLnetLabs Sep 3, 2024
c2b57c1
Merge branch 'main' into service-request-metadata-and-byte-reservatio…
ximon18 Sep 3, 2024
2caa383
Merge branch 'stelline-server-testing-changes' into tsig-client
ximon18 Sep 3, 2024
5d424e7
Remove is_streaming() fn as it has been removed in upstream branches.
ximon18 Sep 3, 2024
b957161
Cherry pick the Stelline server testing README from the `xfr` branch.
ximon18 Sep 3, 2024
41f0992
Merge branch 'main' into service-request-metadata-and-byte-reservatio…
ximon18 Sep 4, 2024
29f7bcb
Merge branch 'service-request-metadata-and-byte-reservation-net-clien…
ximon18 Sep 4, 2024
b4861af
Merge branch 'stelline-server-testing-changes' into tsig-client
ximon18 Sep 4, 2024
1bc196a
Docs
Philip-NLnetLabs Sep 4, 2024
e98bfa4
Cleanup.
Philip-NLnetLabs Sep 4, 2024
0b89d1e
Remove comment abou TcpKeepalive.
Philip-NLnetLabs Sep 4, 2024
523fe1d
Docs
Philip-NLnetLabs Sep 4, 2024
dc7e3c2
Docs
Philip-NLnetLabs Sep 4, 2024
33b5089
Update src/net/client/request.rs
Philip-NLnetLabs Sep 4, 2024
f02f773
Use unreachable! instead of panic!
Philip-NLnetLabs Sep 4, 2024
bf781f8
Merge branch 'service-request-metadata-and-byte-reservation-net-clien…
ximon18 Sep 4, 2024
3c3c19d
Merge branch 'stelline-server-testing-changes' into tsig-client
ximon18 Sep 4, 2024
c1de8ac
Remove left behind trace statement.
ximon18 Sep 4, 2024
e1357c6
Merge branch 'main' into stelline-server-testing-changes
ximon18 Sep 4, 2024
b93422c
Merge branch 'stelline-server-testing-changes' into tsig-client
ximon18 Sep 4, 2024
e99f021
Merge branch 'main' into stelline-server-testing-changes
ximon18 Sep 9, 2024
aeb3c80
Merge branch 'stelline-server-testing-changes' into tsig-client
ximon18 Sep 9, 2024
2f4e464
Merge branch 'main' into tsig-client
ximon18 Sep 9, 2024
76c2b43
- Merge TsigClient and TsigClientMulti.
ximon18 Sep 10, 2024
ebe0d2f
Remove left behind trace logging.
ximon18 Sep 10, 2024
b309a13
Remove AuthenticatedRequestMessageMulti, it isn't needed.
ximon18 Sep 10, 2024
6886079
Fold RequestMulti into Request and RequestStateMulti into RequestStat…
ximon18 Sep 10, 2024
aec32d4
Cargo fmt.
ximon18 Sep 10, 2024
a033102
Small simplification.
ximon18 Sep 10, 2024
ea5dfda
Review feedback: Key should not be optional.
ximon18 Sep 10, 2024
c8c577a
- More RustDocs.
ximon18 Sep 11, 2024
386b2df
Explain on TSIG failure in client-transport that this is probably exp…
ximon18 Sep 11, 2024
67bb521
Add TSIG client tests.
ximon18 Sep 11, 2024
008574b
Add docs for validator_test.
Philip-NLnetLabs Sep 11, 2024
22d8c62
Resolve cargo doc issues.
ximon18 Sep 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 101 additions & 9 deletions examples/client-transports.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
use domain::base::MessageBuilder;
/// Using the `domain::net::client` module for sending a query.
use std::net::{IpAddr, SocketAddr};
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;
use std::vec::Vec;

use domain::base::MessageBuilder;
use domain::base::Name;
use domain::base::Rtype;
use domain::net::client::cache;
Expand All @@ -12,9 +18,16 @@ use domain::net::client::request::{
RequestMessage, RequestMessageMulti, SendRequest,
};
use domain::net::client::stream;
use std::net::{IpAddr, SocketAddr};
use std::str::FromStr;
use std::time::Duration;

#[cfg(feature = "tsig")]
use domain::net::client::request::SendRequestMulti;
#[cfg(feature = "tsig")]
use domain::net::client::tsig::{
self, AuthenticatedRequestMessage, AuthenticatedRequestMessageMulti,
};
#[cfg(feature = "tsig")]
use domain::tsig::{Algorithm, Key, KeyName};

use tokio::net::TcpStream;
use tokio::time::timeout;
use tokio_rustls::rustls::{ClientConfig, RootCertStore};
Expand Down Expand Up @@ -224,7 +237,7 @@ async fn main() {
let reply = request.get_response().await;
println!("Dgram reply: {reply:?}");

// Create a single TCP transport connection. This is usefull for a
// Create a single TCP transport connection. This is useful for a
// single request or a small burst of requests.
let tcp_conn = match TcpStream::connect(server_addr).await {
Ok(conn) => conn,
Expand All @@ -244,13 +257,44 @@ async fn main() {
});

// Send a request message.
let mut request = tcp.send_request(req);
let mut request = SendRequest::send_request(&tcp, req.clone());

// Get the reply
let reply = request.get_response().await;
println!("TCP reply: {reply:?}");

drop(tcp);

#[cfg(feature = "tsig")]
{
let tcp_conn = TcpStream::connect(server_addr).await.unwrap();
let (tcp, transport) = stream::Connection::<
AuthenticatedRequestMessage<
RequestMessage<Vec<u8>>,
Arc<domain::tsig::Key>,
>,
AuthenticatedRequestMessageMulti<
RequestMessageMulti<Vec<u8>>,
Arc<domain::tsig::Key>,
>,
>::new(tcp_conn);
tokio::spawn(async move {
transport.run().await;
println!("single TSIG TCP run terminated");
});

let mut msg = MessageBuilder::new_vec();
msg.header_mut().set_rd(true);
msg.header_mut().set_ad(true);
let mut msg = msg.question();
msg.push((Name::vec_from_str("example.com").unwrap(), Rtype::AXFR))
.unwrap();
let req = RequestMessageMulti::new(msg).unwrap();

do_tsig(tcp.clone(), req).await;

drop(tcp);
}
}

#[cfg(feature = "unstable-validator")]
Expand All @@ -273,9 +317,10 @@ where
let ta =
domain::validator::anchor::TrustAnchors::from_reader(anchor_file)
.unwrap();
let vc = std::sync::Arc::new(
domain::validator::context::ValidationContext::new(ta, conn.clone()),
);
let vc = Arc::new(domain::validator::context::ValidationContext::new(
ta,
conn.clone(),
));
let val_conn = domain::net::client::validator::Connection::new(conn, vc);

// Send a query message.
Expand All @@ -286,3 +331,50 @@ where
let reply = request.get_response().await;
println!("Validator reply: {:?}", reply);
}

#[cfg(feature = "tsig")]
async fn do_tsig<Octs, SR>(conn: SR, req: RequestMessageMulti<Octs>)
where
Octs: AsRef<[u8]>
+ Send
+ Sync
+ std::fmt::Debug
+ domain::dep::octseq::Octets
+ 'static,
SR: SendRequestMulti<
tsig::AuthenticatedRequestMessageMulti<
RequestMessageMulti<Octs>,
Arc<Key>,
>,
> + Send
+ Sync
+ 'static,
{
// Create a signing key.
let key_name = KeyName::from_str("demo-key").unwrap();
let secret = domain::utils::base64::decode::<Vec<u8>>(
"zlCZbVJPIhobIs1gJNQfrsS3xCxxsR9pMUrGwG8OgG8=",
)
.unwrap();
let key = Arc::new(
Key::new(Algorithm::Sha256, &secret, key_name, None, None).unwrap(),
);

// Create a signing transport. This assumes that the server being
// connected to is configured with a key with the same name, algorithm and
// secret and to allow that key to be used for the request we are making.
let tsig_conn = tsig::Connection::new(Some(key), conn);

// Send a query message.
let mut request = tsig_conn.send_request(req);

// Get the reply
loop {
println!("Waiting for signed reply");
let reply = request.get_response().await.unwrap();
println!("Signed reply: {:?}", reply);
if reply.is_none() {
break;
}
}
}
8 changes: 8 additions & 0 deletions src/net/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
//! as upstream transports.
//! * [cache] This is a simple message cache provided as a pass through
//! transport. The cache works with any of the other transports.
#![cfg_attr(feature = "tsig", doc = "* [tsig]:")]
#![cfg_attr(not(feature = "tsig",), doc = "* tsig:")]
//! This is a TSIG request signer and response verifier provided as a
//! pass through transport. The tsig transport works with any upstream
//! transports so long as they don't modify the message once signed nor
//! modify the response before it can be verified.
#![cfg_attr(feature = "unstable-validator", doc = "* [validator]:")]
#![cfg_attr(not(feature = "unstable-validator",), doc = "* validator:")]
//! This is a DNSSEC validator provided as a pass through transport.
Expand Down Expand Up @@ -221,6 +227,8 @@ pub mod protocol;
pub mod redundant;
pub mod request;
pub mod stream;
#[cfg(feature = "tsig")]
pub mod tsig;
#[cfg(feature = "unstable-validator")]
pub mod validator;
pub mod validator_test;
6 changes: 3 additions & 3 deletions src/net/client/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ impl fmt::Display for Error {
Error::Dgram(err) => fmt::Display::fmt(err, f),

#[cfg(feature = "unstable-server-transport")]
Error::ZoneWrite => write!(f, "zone write error"),
Error::ZoneWrite => write!(f, "error writing to zone"),

#[cfg(feature = "tsig")]
Error::Authentication(err) => fmt::Display::fmt(err, f),
Expand Down Expand Up @@ -806,10 +806,10 @@ impl error::Error for Error {
Error::ZoneWrite => None,

#[cfg(feature = "tsig")]
Error::Authentication(err) => Some(err),
Error::Authentication(e) => Some(e),

#[cfg(feature = "unstable-validator")]
Error::Validation(err) => Some(err),
Error::Validation(e) => Some(e),
}
}
}
Loading