Factor wgkey to types/key

This commit converts all the uses of wgkey to the new key interfaces.

It now has specific  machine, node and discovery keys and we now should
use them correctly.

Please note the new logic which strips a key prefix (in utils.go) that
is now standard inside tailscale.

In theory we could put it in the database, but to preserve backwards
compatibility and not spend a lot of resources on accounting for both,
we just strip them.
This commit is contained in:
Kristoffer Dalby 2021-11-26 23:30:42 +00:00
parent 07418140a2
commit cfd53bc4aa
7 changed files with 184 additions and 143 deletions

View file

@ -11,9 +11,9 @@ import (
v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
"go4.org/mem"
"google.golang.org/grpc/status"
"tailscale.com/tailcfg"
"tailscale.com/types/wgkey"
"tailscale.com/types/key"
)
func init() {
@ -486,11 +486,10 @@ func nodesToPtables(
expiry = machine.Expiry.AsTime()
}
nKey, err := wgkey.ParseHex(machine.NodeKey)
nodeKey, err := key.ParseNodePublicUntyped(mem.S(machine.NodeKey))
if err != nil {
return nil, err
}
nodeKey := tailcfg.NodeKey(nKey)
var online string
if lastSeen.After(