Skip to content

Commit

Permalink
Prevent updating server with empty private key
Browse files Browse the repository at this point in the history
  • Loading branch information
UnAfraid committed Oct 22, 2023
1 parent 046ccfa commit 44a69f6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"context"
"encoding/json"
"errors"
"fmt"
"path"
"strings"
Expand Down Expand Up @@ -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 != "" {
Expand Down

0 comments on commit 44a69f6

Please sign in to comment.