summaryrefslogtreecommitdiff
path: root/src/wireguard.go
diff options
context:
space:
mode:
authorJeroen Wijenbergh <jeroenwijenbergh@protonmail.com>2022-03-21 14:58:58 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-09-20 20:29:52 +0200
commitfc56f8770923ec1997444a8318a18be0a8397520 (patch)
tree3c6522b9b6e44ca2ad6cd94b074da78eed2c1028 /src/wireguard.go
parentd45f5df4dc5fa9ad8abdc47c940f6baf96fdbe45 (diff)
Wireguard: Add basic support
Diffstat (limited to 'src/wireguard.go')
-rw-r--r--src/wireguard.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/wireguard.go b/src/wireguard.go
new file mode 100644
index 0000000..9441c51
--- /dev/null
+++ b/src/wireguard.go
@@ -0,0 +1,26 @@
+package eduvpn
+
+import (
+ "fmt"
+ "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
+ "regexp"
+)
+
+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 {
+ interface_section := "[Interface]"
+ interface_section_escaped := regexp.QuoteMeta(interface_section)
+
+ // (?m) enables multi line mode
+ // ^ match from beginning of line
+ // $ match till end of line
+ // So it matches [Interface] section exactly
+ interface_re := regexp.MustCompile(fmt.Sprintf("(?m)^%s$", interface_section_escaped))
+ to_replace := fmt.Sprintf("%s\nPrivateKey = %s", interface_section, key.String())
+ return interface_re.ReplaceAllString(config, to_replace)
+}