Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfigureDevice erasing peers, but not adding it on windows #146

Open
WebV5 opened this issue Apr 11, 2024 · 2 comments
Open

ConfigureDevice erasing peers, but not adding it on windows #146

WebV5 opened this issue Apr 11, 2024 · 2 comments

Comments

@WebV5
Copy link

WebV5 commented Apr 11, 2024

Hello, got some problems with device configuration via wgctrl
Here is my code:

privateKey, err := wgtypes.ParseKey(data.PrivateKey)
if err != nil {
    i.log.Error(err)
    return err
}
publicKey, err := wgtypes.ParseKey(data.PublicKey)
if err != nil {
    i.log.Error(err)
    return err
}
endpointIpPort, err := netip.ParseAddrPort(data.Endpoint)
if err != nil {
    i.log.Error(err)
    return err
}
endpoint := net.UDPAddrFromAddrPort(endpointIpPort)
if endpoint == nil {
    i.log.Error("endpoint was not provided")
    return errors.New("endpoint was not provided")
}

keepalive := time.Duration(data.KeepaliveInterval) * time.Second
_, allowedIps, _ := net.ParseCIDR("0.0.0.0/1")
i.log.Debugf("setup peer %s", publicKey.String())
peers := make([]wgtypes.PeerConfig, 0)
peers = append(peers, wgtypes.PeerConfig{
    PublicKey:                   publicKey,
    Endpoint:                    endpoint,
    ReplaceAllowedIPs:           true,
    PersistentKeepaliveInterval: &keepalive,
    AllowedIPs:                  []net.IPNet{*allowedIps},
})
config := wgtypes.Config{
    ReplacePeers: true,
    PrivateKey:   &privateKey,
    ListenPort:   &data.ListenPort,
    Peers:        peers,
}
i.log.Debugf("%+v", config)
err = i.client.ConfigureDevice(i.tun.GetInterfaceName(), config)
if err != nil {
    i.log.Error(err)
    return err
}

Some context: i'm using wireguard-go to create userspace network device
and wgctrl to add/delete peers; versions:

[golang.zx2c4.com/wireguard](http://golang.zx2c4.com/wireguard) v0.0.0-20231211153847-12269c276173
[golang.zx2c4.com/wireguard/wgctrl](http://golang.zx2c4.com/wireguard/wgctrl) v0.0.0-20230429144221-925a1e7659e6

System: Windows 10 Enterprise / amd64

Here is sample config structure from debug log:

"{
    PrivateKey:sCf8HRn1x2N1Lq6wrHyGYBs6Ydp/48KF74u6ok7LNlk=
    ListenPort:0xc0001dc040
    FirewallMark:<nil>
    ReplacePeers:true
    Peers:[
        {
            PublicKey:VWpriu6779/kWXjdeKDNwcKP0wgIAtA6/2/rNSmuDyE=
            Remove:false
            UpdateOnly:false
            PresharedKey:<nil>
            Endpoint:????:8030
            PersistentKeepaliveInterval:15s
            ReplaceAllowedIPs:true
            AllowedIPs:[{IP:0.0.0.0 Mask:80000000}]
        }
    ]
}

Peer list is always empty after executing ConfigureDevice

Here is log samples:

time="2024-04-11T15:58:36+03:00" level=trace msg="UAPI: Updating private key"
time="2024-04-11T15:58:36+03:00" level=trace msg="UAPI: Updating listen port"
time="2024-04-11T15:58:36+03:00" level=trace msg="Routine: receive incoming v4 - stopped"
time="2024-04-11T15:58:36+03:00" level=trace msg="Routine: receive incoming v6 - stopped"
time="2024-04-11T15:58:36+03:00" level=trace msg="UDP bind has been updated"
time="2024-04-11T15:58:36+03:00" level=trace msg="UAPI: Removing all peers"
time="2024-04-11T15:58:36+03:00" level=trace msg="Routine: receive incoming v4 - started"
time="2024-04-11T15:58:36+03:00" level=trace msg="peer(AAAA…AAAA) - UAPI: Updating endpoint"
time="2024-04-11T15:58:36+03:00" level=trace msg="Routine: receive incoming v6 - started"
time="2024-04-11T15:58:36+03:00" level=trace msg="peer(AAAA…AAAA) - UAPI: Updating persistent keepalive interval"
time="2024-04-11T15:58:36+03:00" level=trace msg="peer(AAAA…AAAA) - UAPI: Removing all allowedips"
time="2024-04-11T15:58:36+03:00" level=trace msg="peer(AAAA…AAAA) - UAPI: Adding allowedip"

Notice: peer(AAAA…AAAA) after added peer via ConfigureDevice

Facing this problem only on windows, linux/macos tests are successful

@WebV5
Copy link
Author

WebV5 commented Apr 11, 2024

Works perfectly when using wg.exe set command btw

@nikwo
Copy link

nikwo commented Apr 16, 2024

Seems to be your public key is a public part of your private key. It is very weird, but wg silently refuses to add peer to device with his own public key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants