From a77964afc074c750fc40484c5704242ac527d479 Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Sun, 5 Jan 2025 23:00:11 +0100 Subject: [PATCH] move wg keygen to backend --- backend/service/server.go | 10 + .../src/components/protocols/Wireguard.vue | 11 +- frontend/src/layouts/modals/Endpoint.vue | 97 ++++----- frontend/src/plugins/wgUtil.ts | 188 ------------------ frontend/src/types/endpoints.ts | 2 - 5 files changed, 58 insertions(+), 250 deletions(-) delete mode 100644 frontend/src/plugins/wgUtil.ts diff --git a/backend/service/server.go b/backend/service/server.go index 8ba1459..4778731 100644 --- a/backend/service/server.go +++ b/backend/service/server.go @@ -162,6 +162,8 @@ func (s *ServerService) GenKeypair(keyType string, options string) []string { return s.generateTLSKeyPair(options) case "reality": return s.generateRealityKeyPair() + case "wireguard": + return generateWireGuardKey() } return []string{"Failed to generate keypair"} @@ -192,3 +194,11 @@ func (s *ServerService) generateRealityKeyPair() []string { publicKey := privateKey.PublicKey() return []string{"PrivateKey: " + base64.RawURLEncoding.EncodeToString(privateKey[:]), "PublicKey: " + base64.RawURLEncoding.EncodeToString(publicKey[:])} } + +func generateWireGuardKey() []string { + privateKey, err := wgtypes.GeneratePrivateKey() + if err != nil { + return []string{"Failed to generate wireguard keypair: ", err.Error()} + } + return []string{"PrivateKey: " + privateKey.String(), "PublicKey: " + privateKey.PublicKey().String()} +} diff --git a/frontend/src/components/protocols/Wireguard.vue b/frontend/src/components/protocols/Wireguard.vue index d589474..d338dc5 100644 --- a/frontend/src/components/protocols/Wireguard.vue +++ b/frontend/src/components/protocols/Wireguard.vue @@ -109,10 +109,10 @@