Skip to content

Commit da28586

Browse files
committed
remove PSK in RDV point
1 parent c5133f6 commit da28586

File tree

6 files changed

+8
-33
lines changed

6 files changed

+8
-33
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# wg-turn
22

3-
wg-turn is just a [turn](https://en.wikipedia.org/wiki/Traversal_Using_Relays_around_NAT) daemon for wireguard.If you need more functionality, you can look at [cunīcu](https://cunicu.li/), [netbird](https://netbird.io/), [TailScale](https://tailscale.com/) or other
3+
wg-turn is just a [turn](https://en.wikipedia.org/wiki/Traversal_Using_Relays_around_NAT) daemon for wireguard. If you need more functionality, you can look at [cunīcu](https://cunicu.li/), [netbird](https://netbird.io/), [TailScale](https://tailscale.com/) or other
44

55
wg-turn use the mainline DHT to discover the peers endpoint
66

src/dht.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use tokio::{sync::mpsc, sync::RwLock};
2424

2525
pub struct DHT {
2626
dht4: Arc<MainlineDht>,
27-
dht6: Arc<MainlineDht>, //todo: test IPv6
27+
dht6: Arc<MainlineDht>,
2828
pub_key: Option<PublicKey>,
2929
tasks: RwLock<Vec<Abort<()>>>,
3030
}
@@ -81,16 +81,8 @@ impl DHT {
8181
}
8282
}
8383

84-
pub async fn register(
85-
&mut self,
86-
pub_key: &PublicKey,
87-
psk: &PublicKey,
88-
) -> mpsc::Receiver<SocketAddr> {
89-
let key_array: [u8; 64] = utils::calc_id(
90-
&pub_key.array(),
91-
&self.pub_key.clone().unwrap().array(),
92-
&psk.array(),
93-
);
84+
pub async fn register(&mut self, pub_key: &PublicKey) -> mpsc::Receiver<SocketAddr> {
85+
let key_array = utils::calc_id(&pub_key.array(), &self.pub_key.clone().unwrap().array());
9486
let id = InfoHash::sha1(&key_array);
9587

9688
let (snd1, rcv) = mpsc::channel(1);

src/main.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ use tokio::signal::unix::{signal, SignalKind};
2121
use tokio::task::JoinSet;
2222
use wg::WgDevice;
2323

24-
// #[async_std::main]
2524
#[tokio::main]
2625
async fn main() {
27-
println!("wg-turn v1.0.0");
26+
println!("wg-turn v1.1");
2827
let mut tasks = JoinSet::new();
2928

3029
let mut route = wireguard_uapi::linux::RouteSocket::connect().unwrap();

src/task.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ pub async fn peer_task(mut peer: wg::WgPeer, dht: Arc<RwLock<dht::DHT>>) -> Resu
2929
let mut rx_dht: mpsc::Receiver<SocketAddr>;
3030

3131
let mut w_dht = dht.write().await;
32-
rx_dht = w_dht
33-
.register(&peer.public_key(), &peer.preshared_key())
34-
.await;
32+
rx_dht = w_dht.register(&peer.public_key()).await;
3533
drop(w_dht);
3634

3735
let rx_wg = peer.check_input();

src/utils.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use anyhow::anyhow;
1515
use anyhow::Result;
1616
use base64::prelude::*;
1717
use blake3::Hash;
18-
use concat_arrays::concat_arrays;
1918
use crypto_box::aead::{Aead, AeadCore, OsRng};
2019
use crypto_box::{ChaChaBox, Nonce, SecretKey};
2120
use rand::prelude::*;
@@ -285,21 +284,12 @@ impl fmt::Display for PublicKey {
285284
}
286285
}
287286

288-
pub fn calc_id(pub_key1: &[u8; 32], pub_key2: &[u8; 32], psk: &[u8; 32]) -> [u8; 64] {
289-
// let psk_sha: [u8; 20] = Sha1::digest(psk).into();
290-
// let mut add_array = [0u8; 32];
291-
// for ((add_val, l_val), r_val) in add_array.iter_mut().zip(pub_key1).zip(pub_key2) {
292-
// *add_val = u8::wrapping_add(*l_val, *r_val);
293-
// }
294-
// concat_arrays!(add_array, psk_sha)
295-
296-
let psk_hash = *blake3::hash(psk).as_bytes();
287+
pub fn calc_id(pub_key1: &[u8; 32], pub_key2: &[u8; 32]) -> [u8; 32] {
297288
let pub_key1_hash = *blake3::hash(pub_key1).as_bytes();
298289
let pub_key2_hash = *blake3::hash(pub_key2).as_bytes();
299290
let mut add_array = [0u8; 32];
300291
for ((add_val, l_val), r_val) in add_array.iter_mut().zip(pub_key1_hash).zip(pub_key2_hash) {
301292
*add_val = u8::wrapping_add(l_val, r_val);
302293
}
303-
304-
concat_arrays!(add_array, psk_hash)
294+
add_array
305295
}

src/wg.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1071,10 +1071,6 @@ impl WgPeer {
10711071
return PublicKey::new(self.wg_peer.public_key);
10721072
}
10731073

1074-
pub fn preshared_key(&self) -> PublicKey {
1075-
return PublicKey::new(self.wg_peer.preshared_key);
1076-
}
1077-
10781074
pub async fn clean(&mut self) {
10791075
// println!("WgPeer::clean() for {} with {:?}",self.public_key(), self.inet_endpoint);
10801076
let mut w_test = self.tests.write().await;

0 commit comments

Comments
 (0)