Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exclude = [
]
homepage = "https://dns.lookup.dog/"
license = "MIT"
version = "0.2.1-beta"
version = "0.2.2-beta"


[[bin]]
Expand Down Expand Up @@ -60,7 +60,7 @@ log = "0.4"

# Git workflows as well as my sanity will fail without this
[dependencies.openssl-sys]
version = "0.9"
version = "0.9.99"
features = ["vendored"]

# windows default nameserver determination
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ It has colourful output, understands normal command-line argument syntax, suppor
doge example.net MX ...looking up MX records instead
doge example.net MX @1.1.1.1 ...using a specific nameserver instead
doge example.net MX @1.1.1.1 -T ...using TCP rather than UDP
doge exapple.net MX @1.1.1.1 -p 53 ...using a nonstandart port
doge -q example.net -t MX -n 1.1.1.1 -T As above, but using explicit arguments

---
Expand All @@ -39,6 +40,7 @@ It has colourful output, understands normal command-line argument syntax, suppor
-q, --query=HOST Host name or domain name to query
-t, --type=TYPE Type of the DNS record being queried (A, MX, NS...)
-n, --nameserver=ADDR Address of the nameserver to send packets to
-p, --port=PORT Port options for sending queries on nonstandart ports
--class=CLASS Network class of the DNS record being queried (IN, CH, HS)

### Sending options
Expand Down
13 changes: 9 additions & 4 deletions dns-transport/src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,25 @@ use super::{Transport, Error, UdpTransport, TcpTransport};
/// This is the default behaviour for many DNS clients.
pub struct AutoTransport {
addr: String,
custom_port: u16
}

impl AutoTransport {

/// Creates a new automatic transport that connects to the given host.
pub fn new(addr: String) -> Self {
Self { addr }
pub fn new(addr: String, port: Option<u16>) -> Self {
let custom_port: u16 = match port {
Some(port) => port,
None => 53,
};
Self { addr, custom_port }
}
}


impl Transport for AutoTransport {
fn send(&self, request: &Request) -> Result<Response, Error> {
let udp_transport = UdpTransport::new(self.addr.clone());
let udp_transport = UdpTransport::new(self.addr.clone(), Some(self.custom_port.clone()));
let udp_response = udp_transport.send(&request)?;

if ! udp_response.flags.truncated {
Expand All @@ -33,7 +38,7 @@ impl Transport for AutoTransport {

debug!("Truncated flag set, so switching to TCP");

let tcp_transport = TcpTransport::new(self.addr.clone());
let tcp_transport = TcpTransport::new(self.addr.clone(), Some(self.custom_port.clone()));
let tcp_response = tcp_transport.send(&request)?;
Ok(tcp_response)
}
Expand Down
13 changes: 9 additions & 4 deletions dns-transport/src/https.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ use super::tls_stream;
/// encrypted with TLS, using TCP.
pub struct HttpsTransport {
url: String,
custom_port: u16
}

impl HttpsTransport {

/// Creates a new HTTPS transport that connects to the given URL.
pub fn new(url: String) -> Self {
Self { url }
pub fn new(url: String, port: Option<u16>) -> Self {
let custom_port: u16 = match port {
Some(port) => port,
None => 443,
};
Self { url, custom_port }
}
}

Expand All @@ -42,7 +47,7 @@ impl Transport for HttpsTransport {
let (domain, path) = self.split_domain().expect("Invalid HTTPS nameserver");

info!("Opening TLS socket to {:?}", domain);
let mut stream = Self::stream(&domain, 443)?;
let mut stream = Self::stream(&domain, *&self.custom_port)?;

debug!("Connected");

Expand Down Expand Up @@ -123,5 +128,5 @@ impl HttpsTransport {
}

/// The User-Agent header sent with HTTPS requests.
static USER_AGENT: &str = concat!("dog/", env!("CARGO_PKG_VERSION"));
static USER_AGENT: &str = concat!("doge/", env!("CARGO_PKG_VERSION"));

17 changes: 9 additions & 8 deletions dns-transport/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ use super::{Transport, Error};
/// TCP, Implementation Requirements (March 2016)
pub struct TcpTransport {
addr: String,
custom_port: u16
}

impl TcpTransport {

/// Creates a new TCP transport that connects to the given host.
pub fn new(addr: String) -> Self {
Self { addr }
pub fn new(addr: String, port: Option<u16>) -> Self {
let custom_port: u16 = match port {
Some(port) => port,
None => 53,
};
Self { addr, custom_port }
}
}

Expand All @@ -33,12 +38,8 @@ impl Transport for TcpTransport {
fn send(&self, request: &Request) -> Result<Response, Error> {
info!("Opening TCP stream");
let mut stream =
if self.addr.contains(':') {
TcpStream::connect(&*self.addr)?
}
else {
TcpStream::connect((&*self.addr, 53))?
};
TcpStream::connect((&*self.addr, self.custom_port))?;

debug!("Opened");

// The message is prepended with the length when sent over TCP,
Expand Down
25 changes: 11 additions & 14 deletions dns-transport/src/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ use super::tls_stream::TlsStream;
/// encrypted TLS connection.
pub struct TlsTransport {
addr: String,
custom_port: u16
}

impl TlsTransport {

/// Creates a new TLS transport that connects to the given host.
pub fn new(addr: String) -> Self {
Self { addr }
pub fn new(addr: String, port: Option<u16>) -> Self {
let custom_port: u16 = match port {
Some(p) => p,
None => 853,
};
Self { addr, custom_port }
}
}

Expand All @@ -30,22 +35,14 @@ impl Transport for TlsTransport {

#[cfg(feature = "with_tls")]
fn send(&self, request: &Request) -> Result<Response, Error> {
use native_tls::TlsStream;

info!("Opening TLS socket");

let domain = self.sni_domain();
info!("Connecting using domain {:?}", domain);
let mut stream =
if self.addr.contains(':') {
let mut parts = self.addr.split(":");
let domain = parts.nth(0).unwrap();
let port = parts.last().unwrap().parse::<u16>().expect("Invalid port number");

Self::stream(domain, port)?
}
else {
Self::stream(&*self.addr, 853)?
};

// comminicate that the port must EXPLICATLY BE SEPERATE
let mut stream: TlsStream<TcpStream> = Self::stream(&self.addr, *&self.custom_port)?;

debug!("Connected");

Expand Down
17 changes: 9 additions & 8 deletions dns-transport/src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ use super::{Transport, Error};
/// Implementation and Specification (November 1987)
pub struct UdpTransport {
addr: String,
custom_port: u16
}

impl UdpTransport {

/// Creates a new UDP transport that connects to the given host.
pub fn new(addr: String) -> Self {
Self { addr }
pub fn new(addr: String, port: Option<u16>) -> Self {
let custom_port: u16 = match port {
Some(p) => p,
None => 53,
};
// info!("Running on nonstandart port");
Self { addr, custom_port }
}
}

Expand All @@ -30,13 +36,8 @@ impl Transport for UdpTransport {
info!("Opening UDP socket");
// TODO: This will need to be changed for IPv6 support.
let socket = UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0))?;
socket.connect( (&*self.addr, self.custom_port))?;

if self.addr.contains(':') {
socket.connect(&*self.addr)?;
}
else {
socket.connect((&*self.addr, 53))?;
}
debug!("Opened");

let bytes_to_send = request.to_bytes().expect("failed to serialise request");
Expand Down
25 changes: 15 additions & 10 deletions src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,26 @@ pub enum TransportType {
/// UDP is used by default. If the request packet would be too large, send
/// a TCP packet instead; if a UDP _response_ packet is truncated, try
/// again with TCP.
Automatic,
/// Takes an 'Option<u16>' for diffrent ports None uses the protocol default port
Automatic(Option<u16>),

/// Send packets over UDP only.
/// If the request packet is too large or the response packet is
/// truncated, fail with an error.
UDP,
/// Takes an 'Option<u16>' for diffrent ports None uses the protocol default port
UDP(Option<u16>),

/// Send packets over TCP only.
TCP,
/// Takes an 'Option<u16>' for diffrent ports None uses the protocol default port
TCP(Option<u16>),

/// Send encrypted DNS-over-TLS packets.
TLS,
/// Takes an 'Option<u16>' for diffrent ports None uses the protocol default port
TLS(Option<u16>),

/// Send encrypted DNS-over-HTTPS packets.
HTTPS,
/// Takes an 'Option<u16>' for diffrent ports None uses the protocol default port
HTTPS(Option<u16>),
}

impl TransportType {
Expand All @@ -36,11 +41,11 @@ impl TransportType {
/// stringified address for the others.
pub fn make_transport(self, param: String) -> Box<dyn Transport> {
match self {
Self::Automatic => Box::new(AutoTransport::new(param)),
Self::UDP => Box::new(UdpTransport::new(param)),
Self::TCP => Box::new(TcpTransport::new(param)),
Self::TLS => Box::new(TlsTransport::new(param)),
Self::HTTPS => Box::new(HttpsTransport::new(param)),
Self::Automatic(p) => Box::new(AutoTransport::new(param, p)),
Self::UDP(p) => Box::new(UdpTransport::new(param, p)),
Self::TCP(p) => Box::new(TcpTransport::new(param, p)),
Self::TLS(p) => Box::new(TlsTransport::new(param, p)),
Self::HTTPS(p) => Box::new(HttpsTransport::new(param, p)),
}
}
}
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ fn disabled_feature_check(options: &Options) {
use crate::connect::TransportType;

#[cfg(all(not(feature = "with_tls"), not(feature = "with_rustls_tls")))]
if options.requests.inputs.transport_types.contains(&TransportType::TLS) {
eprintln!("dog: Cannot use '--tls': This version of dog has been compiled without TLS support");
if options.requests.inputs.transport_types.contains(&TransportType::TLS(None)) {
eprintln!("doge: Cannot use '--tls': This version of dog has been compiled without TLS support");
exit(exits::OPTIONS_ERROR);
}

#[cfg(all(not(feature = "with_https"), not(feature = "with_rustls_https")))]
if options.requests.inputs.transport_types.contains(&TransportType::HTTPS) {
eprintln!("dog: Cannot use '--https': This version of dog has been compiled without HTTPS support");
if options.requests.inputs.transport_types.contains(&TransportType::HTTPS(None)) {
eprintln!("doge: Cannot use '--https': This version of dog has been compiled without HTTPS support");
exit(exits::OPTIONS_ERROR);
}
}
Expand Down
Loading