DefGuard / wireguard-rs

Rust library providing unified WireGuard interface to native/kernel and userspace implementations
https://github.com/defguard/defguard/
Other
124 stars 11 forks source link

Presharedkey support #11

Closed Ange-Cesari closed 9 months ago

Ange-Cesari commented 9 months ago

Hi,

I couldn't see any code related to the presharedkey for the server (nor the client)

Is it supported ?

If so, would it be possible to provide a example with presharedkey support ?

If it's supported by the library but not implemented yet (macros, public function...), do you think it's possible to provide an example of how to create the presharedkey with dalek and write to the api ?

Thanks, Ange

teon commented 9 months ago

Right now we do not support pre-shared key, but we will put this on the roadmap.

Ange-Cesari commented 9 months ago

Hi @teon

Would it be possible to have a link to that roadmap ? I couldn't find it on github. Is it public ?

Best, Ange

master-hax commented 9 months ago

fwiw i'm using this as a workaround at the moment:

let mut file = NamedTempFile::new()?;
writeln!(file, "{}", preshared_key.to_string());
let path = file.into_temp_path();
println!("wrote psk to file {:#?}", path);

let output = std::process::Command::new("wg")
.args(["set", interface_name, "peer", &peer_public_key.to_string(), "preshared-key", path.to_str().unwrap()])
.output()?;

path.close()?;
Ange-Cesari commented 9 months ago

Hey @master-hax ,

Thank you for the work around. Unfortunately I can't write on the disk and I can't process command from the binary due to security reasons, so I guess I'll have to wait for @wojcik91 to implement it.

Best, Ange

wojcik91 commented 9 months ago

Hi @Ange-Cesari & @master-hax! I did not have time to look into this yet, but from what I know the Peer struct already includes an optional preshared_key field.

Did you try it out?

master-hax commented 9 months ago

Hi @Ange-Cesari & @master-hax! I did not have time to look into this yet, but from what I know the Peer struct already includes an optional preshared_key field.

Did you try it out?

Yes I've tried it out.

The key passed to the struct is persisted and looks like it gets applied when the interface configuration is read back.

However, if we double-check the peer with wg showwe can see that the preshared key is not set.

Ange-Cesari commented 9 months ago

Hey, @wojcik91

I tried too,

It seems it's not a structure issue, it's an interface configuration issue and more like how are applied the different fields

wojcik91 commented 9 months ago

Hi. There was indeed a bug in Linux implementation. Should be resolved now by https://github.com/DefGuard/wireguard-rs/pull/21. I'll make a new patch release shortly.