diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-03-23 12:10:47 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-03-23 12:10:47 +0100 |
| commit | b9b2659908d5fe8afcc74f2769a8da7bab243018 (patch) | |
| tree | c8d524cb99cd98d326d78b78ce988395e4fb3e26 /src/wireguard.go | |
| parent | ed6073f2c2c6600063f2e5062937b7a2a1162eb2 (diff) | |
Add wrapping functionality for getting a wireguard config
Diffstat (limited to 'src/wireguard.go')
| -rw-r--r-- | src/wireguard.go | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/wireguard.go b/src/wireguard.go index 9441c51..0d5967c 100644 --- a/src/wireguard.go +++ b/src/wireguard.go @@ -6,13 +6,13 @@ import ( "regexp" ) -func WireguardGenerateKey() (wgtypes.Key, error) { +func wireguardGenerateKey() (wgtypes.Key, error) { key, error := wgtypes.GeneratePrivateKey() return key, error } // FIXME: Instead of doing a regex replace, decide if we should use a parser -func WireguardConfigAddKey(config string, key wgtypes.Key) string { +func wireguardConfigAddKey(config string, key wgtypes.Key) string { interface_section := "[Interface]" interface_section_escaped := regexp.QuoteMeta(interface_section) @@ -24,3 +24,22 @@ func WireguardConfigAddKey(config string, key wgtypes.Key) string { to_replace := fmt.Sprintf("%s\nPrivateKey = %s", interface_section, key.String()) return interface_re.ReplaceAllString(config, to_replace) } + +func (eduvpn *VPNState) WireguardGetConfig() (string, error) { + wireguardKey, wireguardErr := wireguardGenerateKey() + + if wireguardErr != nil { + return "", wireguardErr + } + + wireguardPublicKey := wireguardKey.PublicKey().String() + configWireguard, configErr := eduvpn.APIConnectWireguard(wireguardPublicKey) + + if configErr != nil { + return "", configErr + } + + configWireguardKey := wireguardConfigAddKey(configWireguard, wireguardKey) + + return configWireguardKey, nil +} |
