Skip to content

Commit adba94c

Browse files
committed
fix: ClientTLSConnection now uses ip for getting ServerName
1 parent 1b4a444 commit adba94c

File tree

1 file changed

+3
-30
lines changed

1 file changed

+3
-30
lines changed

src/client/tls_connection.rs

+3-30
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use tokio::time::timeout;
1919
use tokio_rustls::rustls::ClientConfig;
2020
use tokio_rustls::TlsConnector;
2121
use std::sync::Arc;
22-
22+
use tokio::task;
2323

2424
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
2525
pub struct ClientTLSConnection {
@@ -67,12 +67,8 @@ impl ClientSecurity for ClientTLSConnection {
6767
.with_root_certificates(roots)
6868
.with_no_client_auth();
6969

70-
// Resolve the server's IP address to a domain name
71-
let server_name_res = Self::resolve_hostname(self.get_server_addr()).await;
72-
let server_name = match server_name_res {
73-
Ok(server_name_str) => ServerName::try_from(server_name_str).expect("invalid DNS name"),
74-
Err(_) => return Err(ClientError::FormatError("Unable to resolve the IP address to a valid domain.")),
75-
};
70+
let server_name_str = self.get_server_addr().to_string();
71+
let server_name = ServerName::try_from(server_name_str).expect("invalid DNS name");
7672

7773
// Create a TLS connector with the configured certificates
7874
let connector = TlsConnector::from(Arc::new(config));
@@ -129,29 +125,6 @@ impl ClientTLSConnection {
129125
pub fn get_timeout(&self)-> Duration {
130126
return self.timeout.clone();
131127
}
132-
133-
/// Resolves the IP to a domain name or returns an error if it cannot be resolved.
134-
async fn resolve_hostname(ip: IpAddr) -> Result<String, String> {
135-
let socket_addr = format!("{}:843", ip); // Use port 443 (HTTPS) or the appropriate one
136-
match lookup_host(socket_addr).await {
137-
Ok(mut addrs) => {
138-
// If the IP is resolved, return the domain name
139-
if let Some(SocketAddr::V4(addr)) = addrs.next() {
140-
return Ok(addr.ip().to_string());
141-
}
142-
}
143-
Err(_) => {
144-
// If resolution fails, return an error
145-
return Err("Could not resolve the IP to a domain name.".to_string());
146-
}
147-
}
148-
149-
// If no domain is found, return an error
150-
Err("Unable to resolve the IP address to a valid domain.".to_string())
151-
}
152-
153-
154-
155128
}
156129

157130
//Setters

0 commit comments

Comments
 (0)