Skip to content

Commit

Permalink
add tsig rr form resolver to dns message
Browse files Browse the repository at this point in the history
  • Loading branch information
Litr0 committed Aug 6, 2024
1 parent 1096f87 commit aa80f21
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/async_resolver/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::client::client_connection::ConnectionProtocol;
use crate::message::DnsMessage;
use crate::tsig::tsig_algorithm::TsigAlgorithm;
use std::cmp::max;
use std::io::SeekFrom;
use std::option;
use std::{net::{IpAddr,SocketAddr,Ipv4Addr}, time::Duration};

Expand Down Expand Up @@ -278,6 +279,21 @@ impl ResolverConfig {
self.algorithm = algorithm;
}
}

/// add tsig from the resolver to a dns message
///
/// # Examples
/// ```
/// let mut resolver_config = ResolverConfig::default();
/// resolver_config.add_tsig("keyname".to_string(), b"key".to_vec(), Some(TsigAlgorithm::HmacSha256));
/// let message = Message::new();
/// resolver_config.add_tsig_to_message(&message, 300, vec![]);
/// ```
pub fn add_tsig_to_message(&self, message: &mut DnsMessage, fudge: u16, mac_request: Vec<u8>) {
if self.tsig {
message.add_tsig(self.key.clone(), self.algorithm.clone(), fudge, self.key_name.clone(), mac_request);
}
}
}

///Getters
Expand Down
4 changes: 2 additions & 2 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,11 @@ impl DnsMessage {
/// dns_query_message.add_tsig(key, alg_name, fudge, key_name, mac_request);
/// ```
pub fn add_tsig(&mut self, key: Vec<u8>, alg_name: TsigAlgorithm,
fudge: u16, key_name: String, mac_request: Vec<u8>) {
fudge: u16, key_name: Option<String>, mac_request: Vec<u8>) {
let message = self;
let time_signed = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs();
tsig::sign_tsig(message, &key, alg_name,
fudge, time_signed, key_name, mac_request);
fudge, time_signed, key_name.unwrap_or("".to_string()), mac_request);
}

/// Gets the MAC from the TSIG RR.
Expand Down

0 comments on commit aa80f21

Please sign in to comment.