control/controlclient: stop using wgkey.

Updates #3206

Signed-off-by: David Anderson <danderson@tailscale.com>
pull/3215/head
David Anderson 3 years ago
parent e03fda7ae6
commit 4d38194c21

@ -14,11 +14,11 @@ import (
"tailscale.com/logtail/backoff" "tailscale.com/logtail/backoff"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
"tailscale.com/types/empty" "tailscale.com/types/empty"
"tailscale.com/types/key"
"tailscale.com/types/logger" "tailscale.com/types/logger"
"tailscale.com/types/netmap" "tailscale.com/types/netmap"
"tailscale.com/types/persist" "tailscale.com/types/persist"
"tailscale.com/types/structs" "tailscale.com/types/structs"
"tailscale.com/types/wgkey"
) )
type LoginGoal struct { type LoginGoal struct {
@ -699,9 +699,9 @@ func (c *Auto) Shutdown() {
// NodePublicKey returns the node public key currently in use. This is // NodePublicKey returns the node public key currently in use. This is
// used exclusively in tests. // used exclusively in tests.
func (c *Auto) TestOnlyNodePublicKey() wgkey.Key { func (c *Auto) TestOnlyNodePublicKey() key.NodePublic {
priv := c.direct.GetPersist() priv := c.direct.GetPersist()
return priv.PrivateNodeKey.Public().AsWGKey() return priv.PrivateNodeKey.Public()
} }
func (c *Auto) TestOnlySetAuthKey(authkey string) { func (c *Auto) TestOnlySetAuthKey(authkey string) {

@ -46,7 +46,6 @@ import (
"tailscale.com/types/netmap" "tailscale.com/types/netmap"
"tailscale.com/types/opt" "tailscale.com/types/opt"
"tailscale.com/types/persist" "tailscale.com/types/persist"
"tailscale.com/types/wgkey"
"tailscale.com/util/systemd" "tailscale.com/util/systemd"
"tailscale.com/wgengine/monitor" "tailscale.com/wgengine/monitor"
) )
@ -72,7 +71,7 @@ type Direct struct {
serverKey key.MachinePublic serverKey key.MachinePublic
persist persist.Persist persist persist.Persist
authKey string authKey string
tryingNewKey wgkey.Private tryingNewKey key.NodePrivate
expiry *time.Time expiry *time.Time
// hostinfo is mutated in-place while mu is held. // hostinfo is mutated in-place while mu is held.
hostinfo *tailcfg.Hostinfo // always non-nil hostinfo *tailcfg.Hostinfo // always non-nil
@ -327,27 +326,22 @@ func (c *Direct) doLogin(ctx context.Context, opt loginOpt) (mustRegen bool, new
c.mu.Unlock() c.mu.Unlock()
} }
var oldNodeKey wgkey.Key var oldNodeKey key.NodePublic
switch { switch {
case opt.Logout: case opt.Logout:
tryingNewKey = persist.PrivateNodeKey.AsWGPrivate() tryingNewKey = persist.PrivateNodeKey
case opt.URL != "": case opt.URL != "":
// Nothing. // Nothing.
case regen || persist.PrivateNodeKey.IsZero(): case regen || persist.PrivateNodeKey.IsZero():
c.logf("Generating a new nodekey.") c.logf("Generating a new nodekey.")
persist.OldPrivateNodeKey = persist.PrivateNodeKey persist.OldPrivateNodeKey = persist.PrivateNodeKey
key, err := wgkey.NewPrivate() tryingNewKey = key.NewNode()
if err != nil {
c.logf("login keygen: %v", err)
return regen, opt.URL, err
}
tryingNewKey = key
default: default:
// Try refreshing the current key first // Try refreshing the current key first
tryingNewKey = persist.PrivateNodeKey.AsWGPrivate() tryingNewKey = persist.PrivateNodeKey
} }
if !persist.OldPrivateNodeKey.IsZero() { if !persist.OldPrivateNodeKey.IsZero() {
oldNodeKey = persist.OldPrivateNodeKey.Public().AsWGKey() oldNodeKey = persist.OldPrivateNodeKey.Public()
} }
if tryingNewKey.IsZero() { if tryingNewKey.IsZero() {
@ -363,8 +357,8 @@ func (c *Direct) doLogin(ctx context.Context, opt loginOpt) (mustRegen bool, new
now := time.Now().Round(time.Second) now := time.Now().Round(time.Second)
request := tailcfg.RegisterRequest{ request := tailcfg.RegisterRequest{
Version: 1, Version: 1,
OldNodeKey: tailcfg.NodeKey(oldNodeKey), OldNodeKey: tailcfg.NodeKeyFromNodePublic(oldNodeKey),
NodeKey: tailcfg.NodeKey(tryingNewKey.Public()), NodeKey: tailcfg.NodeKeyFromNodePublic(tryingNewKey.Public()),
Hostinfo: hostinfo, Hostinfo: hostinfo,
Followup: opt.URL, Followup: opt.URL,
Timestamp: &now, Timestamp: &now,
@ -469,7 +463,7 @@ func (c *Direct) doLogin(ctx context.Context, opt loginOpt) (mustRegen bool, new
c.mu.Lock() c.mu.Lock()
if resp.AuthURL == "" { if resp.AuthURL == "" {
// key rotation is complete // key rotation is complete
persist.PrivateNodeKey = key.NodePrivateFromRaw32(mem.B(tryingNewKey[:])) persist.PrivateNodeKey = tryingNewKey
} else { } else {
// save it for the retry-with-URL // save it for the retry-with-URL
c.tryingNewKey = tryingNewKey c.tryingNewKey = tryingNewKey
@ -708,7 +702,7 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, cb func(*netm
} }
}() }()
sess := newMapSession(persist.PrivateNodeKey.AsWGPrivate()) sess := newMapSession(persist.PrivateNodeKey)
sess.logf = c.logf sess.logf = c.logf
sess.vlogf = vlogf sess.vlogf = vlogf
sess.machinePubKey = machinePubKey sess.machinePubKey = machinePubKey

@ -10,13 +10,11 @@ import (
"sort" "sort"
"strconv" "strconv"
"go4.org/mem"
"inet.af/netaddr" "inet.af/netaddr"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
"tailscale.com/types/key" "tailscale.com/types/key"
"tailscale.com/types/logger" "tailscale.com/types/logger"
"tailscale.com/types/netmap" "tailscale.com/types/netmap"
"tailscale.com/types/wgkey"
"tailscale.com/wgengine/filter" "tailscale.com/wgengine/filter"
) )
@ -30,7 +28,7 @@ import (
// one MapRequest). // one MapRequest).
type mapSession struct { type mapSession struct {
// Immutable fields. // Immutable fields.
privateNodeKey wgkey.Private privateNodeKey key.NodePrivate
logf logger.Logf logf logger.Logf
vlogf logger.Logf vlogf logger.Logf
machinePubKey key.MachinePublic machinePubKey key.MachinePublic
@ -52,7 +50,7 @@ type mapSession struct {
netMapBuilding *netmap.NetworkMap netMapBuilding *netmap.NetworkMap
} }
func newMapSession(privateNodeKey wgkey.Private) *mapSession { func newMapSession(privateNodeKey key.NodePrivate) *mapSession {
ms := &mapSession{ ms := &mapSession{
privateNodeKey: privateNodeKey, privateNodeKey: privateNodeKey,
logf: logger.Discard, logf: logger.Discard,
@ -112,8 +110,8 @@ func (ms *mapSession) netmapForResponse(resp *tailcfg.MapResponse) *netmap.Netwo
} }
nm := &netmap.NetworkMap{ nm := &netmap.NetworkMap{
NodeKey: tailcfg.NodeKey(ms.privateNodeKey.Public()), NodeKey: tailcfg.NodeKeyFromNodePublic(ms.privateNodeKey.Public()),
PrivateKey: key.NodePrivateFromRaw32(mem.B(ms.privateNodeKey[:])), PrivateKey: ms.privateNodeKey,
MachineKey: ms.machinePubKey, MachineKey: ms.machinePubKey,
Peers: resp.Peers, Peers: resp.Peers,
UserProfiles: make(map[tailcfg.UserID]tailcfg.UserProfile), UserProfiles: make(map[tailcfg.UserID]tailcfg.UserProfile),

@ -13,8 +13,8 @@ import (
"time" "time"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
"tailscale.com/types/key"
"tailscale.com/types/netmap" "tailscale.com/types/netmap"
"tailscale.com/types/wgkey"
) )
func TestUndeltaPeers(t *testing.T) { func TestUndeltaPeers(t *testing.T) {
@ -170,11 +170,7 @@ func formatNodes(nodes []*tailcfg.Node) string {
} }
func newTestMapSession(t *testing.T) *mapSession { func newTestMapSession(t *testing.T) *mapSession {
k, err := wgkey.NewPrivate() return newMapSession(key.NewNode())
if err != nil {
t.Fatal(err)
}
return newMapSession(k)
} }
func TestNetmapForResponse(t *testing.T) { func TestNetmapForResponse(t *testing.T) {

Loading…
Cancel
Save