Skip to content

Commit 0a664ac

Browse files
committed
Fix a lingering panic by using a stricter type
The functions `request_ephemeral_peer` and consecutively `new_client` accepted an `IpAddr`, but due to only ever preparing a v4 socket this lead to panic due to an `EAFNOSUPPORT` error if an IPv6 was provided. It would also have made sense to change `new_client` to create either an IPv4 or IPv6 socket depending on the type of the address, but the tuncfg service is currently not accepting IPv6 connections, therefore this was the cleaner change.
1 parent 8b17243 commit 0a664ac

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

talpid-tunnel-config-client/examples/psk-exchange.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// Usage: ./psk-exchange <tuncfg_server_ip> <wireguard_public_key>
55
// e. g. ./psk-exchange 10.64.0.1 NkECLsf+VbZUjve7RVN6sE3NYUcYUmUn8qpFugqbXFk=
66

7-
use std::net::IpAddr;
87
use talpid_types::net::wireguard::{PrivateKey, PublicKey};
98

109
#[tokio::main]
@@ -24,7 +23,7 @@ async fn main() {
2423
let ephemeral_private_key = PrivateKey::new_from_random();
2524

2625
let ephemeral_peer = talpid_tunnel_config_client::request_ephemeral_peer(
27-
IpAddr::V4(tuncfg_server_ip),
26+
tuncfg_server_ip,
2827
public_key, // Parent connection's public key.
2928
ephemeral_private_key.public_key(),
3029
true, // Whether to negotiate a "PQ-safe" PSK.

talpid-tunnel-config-client/src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use proto::PostQuantumRequestV1;
22
use std::fmt;
33
#[cfg(not(target_os = "ios"))]
4-
use std::net::IpAddr;
5-
#[cfg(not(target_os = "ios"))]
64
use std::net::SocketAddr;
5+
#[cfg(not(target_os = "ios"))]
6+
use std::net::{IpAddr, Ipv4Addr};
77
use talpid_types::net::wireguard::{PresharedKey, PublicKey};
88
#[cfg(not(target_os = "ios"))]
99
use tokio::net::TcpSocket;
@@ -189,7 +189,7 @@ pub async fn request_ephemeral_peer_with(
189189
/// Negotiate a short-lived peer with a PQ-safe PSK or with DAITA enabled.
190190
#[cfg(not(target_os = "ios"))]
191191
pub async fn request_ephemeral_peer(
192-
service_address: IpAddr,
192+
service_address: Ipv4Addr,
193193
parent_pubkey: PublicKey,
194194
ephemeral_pubkey: PublicKey,
195195
enable_post_quantum: bool,
@@ -245,8 +245,9 @@ fn xor_assign(dst: &mut [u8; 32], src: &[u8; 32]) {
245245
}
246246

247247
#[cfg(not(target_os = "ios"))]
248-
async fn new_client(addr: IpAddr) -> Result<RelayConfigService, Error> {
248+
async fn new_client(addr: Ipv4Addr) -> Result<RelayConfigService, Error> {
249249
let endpoint = Endpoint::from_static("tcp://0.0.0.0:0");
250+
let addr = IpAddr::V4(addr);
250251

251252
let conn = endpoint
252253
.connect_with_connector(service_fn(move |_| async move {

talpid-wireguard/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ impl WireguardMonitor {
732732
let ephemeral = tokio::time::timeout(
733733
timeout,
734734
talpid_tunnel_config_client::request_ephemeral_peer(
735-
IpAddr::from(config.ipv4_gateway),
735+
config.ipv4_gateway,
736736
config.tunnel.private_key.public_key(),
737737
wg_psk_pubkey,
738738
enable_pq,

0 commit comments

Comments
 (0)