This commit is contained in:
LiuHanCheng 2022-11-05 16:07:22 +08:00 committed by GitHub
parent bf87b33292
commit 07f92e647c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 47 additions and 35 deletions

View file

@ -3,6 +3,7 @@ package cli
import (
"fmt"
"github.com/juanfont/headscale"
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
@ -10,8 +11,7 @@ import (
)
const (
keyLength = 64
errPreAuthKeyTooShort = Error("key too short, must be 64 hexadecimal characters")
errPreAuthKeyMalformed = Error("key is malformed. expected 64 hex characters with `nodekey` prefix")
)
// Error is used to compare errors as per https://dave.cheney.net/2016/04/07/constant-errors
@ -87,8 +87,8 @@ var createNodeCmd = &cobra.Command{
return
}
if len(machineKey) != keyLength {
err = errPreAuthKeyTooShort
if !headscale.NodePublicKeyRegex.Match([]byte(machineKey)) {
err = errPreAuthKeyMalformed
ErrorOutput(
err,
fmt.Sprintf("Error: %s", err),