summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2024-07-23 13:09:20 +0200
committerLinus Färnstrand <linus@mullvad.net>2024-07-23 13:09:20 +0200
commit64def56e534c4836900e583a7ab10680a352c88a (patch)
treedc072b00c4634bd264b02ba833b109296f9152e5
parenta16537e12bf71d96c32f20effdbb727c6b910355 (diff)
parent9d9eb6c49351c8b64898cca1eb26c2197fb7dabd (diff)
downloadmullvadvpn-64def56e534c4836900e583a7ab10680a352c88a.tar.xz
mullvadvpn-64def56e534c4836900e583a7ab10680a352c88a.zip
Merge remote-tracking branch 'maxzpsk-exchange-example'
-rw-r--r--talpid-tunnel-config-client/examples/psk-exchange.rs30
1 files changed, 18 insertions, 12 deletions
diff --git a/talpid-tunnel-config-client/examples/psk-exchange.rs b/talpid-tunnel-config-client/examples/psk-exchange.rs
index e7b34ab851..bbf1e71fc7 100644
--- a/talpid-tunnel-config-client/examples/psk-exchange.rs
+++ b/talpid-tunnel-config-client/examples/psk-exchange.rs
@@ -1,33 +1,39 @@
//! Example client implementing the quantum resistant tunnel PSK exchange.
//! Useful to test this crate's implementation.
+// Usage: ./psk-exchange <tuncfg_server_ip> <wireguard_public_key>
+// e. g. ./psk-exchange 10.64.0.1 NkECLsf+VbZUjve7RVN6sE3NYUcYUmUn8qpFugqbXFk=
+
use std::net::IpAddr;
use talpid_types::net::wireguard::{PrivateKey, PublicKey};
#[tokio::main]
async fn main() {
let mut args = std::env::args().skip(1);
- let tuncfg_server_ip: IpAddr = args
+ let tuncfg_server_ip = args
.next()
.expect("Give tuncfg server IP as first argument")
.parse()
- .expect("tuncfg ip argument not a valid IP");
- let pubkey_string = args
+ .expect("tuncfg IP argument not a valid IPv4");
+ let public_key_string = args
.next()
.expect("Give WireGuard public key as second argument");
- let pubkey = PublicKey::from_base64(pubkey_string.trim()).expect("Invalid public key");
- let private_key = PrivateKey::new_from_random();
+ let public_key = PublicKey::from_base64(&public_key_string).expect("Invalid public key");
+ // The ephemeral peer requires an ephemeral public WireGuard key,
+ // which can also be provided by other means.
+ let ephemeral_private_key = PrivateKey::new_from_random();
let ephemeral_peer = talpid_tunnel_config_client::request_ephemeral_peer(
- tuncfg_server_ip,
- pubkey,
- private_key.public_key(),
- true,
- false,
+ IpAddr::V4(tuncfg_server_ip),
+ public_key, // Parent connection's public key.
+ ephemeral_private_key.public_key(),
+ true, // Whether to negotiate a "PQ-safe" PSK.
+ false, // Whether to use DAITA (Does not work with Linux kernel WireGuard.)
)
.await
.unwrap();
- println!("private key: {private_key:?}");
- println!("psk: {:?}", ephemeral_peer.psk);
+ println!("Private key: {ephemeral_private_key}");
+ // Use fmt::Debug since Serialize is not implemented for PresharedKey.
+ println!("PSK: {:?}", ephemeral_peer.psk.unwrap());
}