wiresock / WireSockUI

GUI to use Wiresock VPN Client in application mode
https://www.wiresock.net/
205 stars 11 forks source link

PresharedKey is required by default when calling wgb_create_tunnel(...) #68

Open nomi-san opened 1 week ago

nomi-san commented 1 week ago

I see the struct WgbPeer says preshared_key is optional, but setting it as empty value when calling wgb_create_tunnel(...) will produce read access violation. Calling wgb_create_tunnel_from_file_w(...) with empty PresharedKey should be fine, I'm sure the function will parse the config first and set this value as empty when the key is missing.

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public struct WgbPeer
    {
        [MarshalAs(UnmanagedType.LPStr)] public string public_key; // required
        [MarshalAs(UnmanagedType.LPStr)] public string preshared_key; // optional
        [MarshalAs(UnmanagedType.LPStr)] public string allowed_ips; // required
        [MarshalAs(UnmanagedType.LPStr)] public string endpoint; // required
        public uint persistent_keep_alive; // optional
    }

In summary, the field preshared_key must be specified a real key, so when my peer server does not use PresharedKey, they could not decrypt packets.

wiresock commented 1 week ago

Have you tried passing null instead of an empty string?

nomi-san commented 1 week ago

Yeah, both null and empty string will produce this read access violation. Tested on both v1.4.5.1 and v1.2.37.1 wgbooster.

Fatal error. System.AccessViolationException: Attempted to read or write protected memory.
This is often an indication that other memory is corrupt.
wiresock commented 6 days ago

Yes, you are right, this is the bug in wgbooster.dll. It will be fixed in the next update. Thanks for reporting this.