From 44a69f6a2376a043a04f58aff992004986ef95be Mon Sep 17 00:00:00 2001 From: UnAfraid Date: Sun, 22 Oct 2023 16:31:17 +0300 Subject: [PATCH] Prevent updating server with empty private key --- pkg/server/service.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/server/service.go b/pkg/server/service.go index 203a52d..0d1b9b9 100644 --- a/pkg/server/service.go +++ b/pkg/server/service.go @@ -3,6 +3,7 @@ package server import ( "context" "encoding/json" + "errors" "fmt" "path" "strings" @@ -273,12 +274,14 @@ func processUpdateServer(server *Server, options *UpdateOptions, fieldMask *Upda if fieldMask.PrivateKey { if len(strings.TrimSpace(options.PrivateKey)) == 0 { - key, err := wgtypes.GeneratePrivateKey() - if err != nil { - return fmt.Errorf("failed to generate private key: %w", err) - } - options.PrivateKey = key.String() + return errors.New("private key is required") + } + + key, err := wgtypes.ParseKey(options.PrivateKey) + if err != nil { + return fmt.Errorf("failed to parse private key: %w", err) } + options.PrivateKey = key.String() } if userId != "" {