mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-03 04:59:22 +02:00
* feature: replace RegisterPeer with Login method that does both - registration and login * test: add management login test * feature: add WiretrusteeConfig to the Login response to configure peer global config * feature: add client peer login support * fix: missing parts * chore: update go deps * feature: support Management Service gRPC endpoints [CLIENT] * feature: finalize client sync with management * fix: management store peer key lower case restore * fix: management returns peer ip without a mask * refactor: remove cmd pkg * fix: invalid tun interface name on mac * fix: timeout when calling management client * fix: tests and lint errors * fix: golang-test workflow * fix: client service tests * fix: iface build * feature: detect management scheme on startup * chore: better logs for management * fix: goreleaser * fix: lint errors * fix: signal TLS * fix: direct Wireguard connection * chore: verbose logging on direct connection
73 lines
1.7 KiB
Go
73 lines
1.7 KiB
Go
package internal
|
|
|
|
import (
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/wiretrustee/wiretrustee/iface"
|
|
"github.com/wiretrustee/wiretrustee/util"
|
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
|
"os"
|
|
)
|
|
|
|
const ManagementAddrDefault = "https://app.wiretrustee.com"
|
|
|
|
// Config Configuration type
|
|
type Config struct {
|
|
// Wireguard private key of local peer
|
|
PrivateKey string
|
|
ManagementURL string
|
|
WgIface string
|
|
IFaceBlackList []string
|
|
}
|
|
|
|
//createNewConfig creates a new config generating a new Wireguard key and saving to file
|
|
func createNewConfig(managementURL string, configPath string) (*Config, error) {
|
|
wgKey := generateKey()
|
|
config := &Config{PrivateKey: wgKey, WgIface: iface.WgInterfaceDefault, IFaceBlackList: []string{}}
|
|
if managementURL != "" {
|
|
config.ManagementURL = managementURL
|
|
} else {
|
|
config.ManagementURL = ManagementAddrDefault
|
|
}
|
|
|
|
err := util.WriteJson(configPath, config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return config, nil
|
|
}
|
|
|
|
// GetConfig reads existing config or generates a new one
|
|
func GetConfig(managementURL string, configPath string) (*Config, error) {
|
|
|
|
var config *Config
|
|
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
|
log.Warnf("first run - generating new config %s", configPath)
|
|
config, err = createNewConfig(managementURL, configPath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
} else {
|
|
config = &Config{}
|
|
_, err := util.ReadJson(configPath, config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
if managementURL != "" {
|
|
config.ManagementURL = managementURL
|
|
}
|
|
|
|
return config, nil
|
|
}
|
|
|
|
// generateKey generates a new Wireguard private key
|
|
func generateKey() string {
|
|
key, err := wgtypes.GenerateKey()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return key.String()
|
|
}
|