summaryrefslogtreecommitdiff
path: root/src/wireguard.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/wireguard.go')
-rw-r--r--src/wireguard.go23
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
+}