From 8d3d48e000f1aea1e349ad3f3f209d29248024d7 Mon Sep 17 00:00:00 2001 From: Charlotte Brandhorst-Satzkorn Date: Thu, 4 May 2023 17:34:44 -0700 Subject: [PATCH] ipn/ipnlocal: add NodeKey func to return the public node NodeKey This change introduces a NodeKey func on localbackend that returns the public node key. Updates tailscale/corp#9967 Signed-off-by: Charlotte Brandhorst-Satzkorn --- ipn/ipnlocal/local.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 15202b0fd..8c8f342e1 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -3627,6 +3627,19 @@ func (b *LocalBackend) hasNodeKey() bool { return p.Valid() && p.Persist().Valid() && !p.Persist().PrivateNodeKey().IsZero() } +// NodeKey returns the public node key. +func (b *LocalBackend) NodeKey() key.NodePublic { + b.mu.Lock() + defer b.mu.Unlock() + + p := b.pm.CurrentPrefs() + if !p.Valid() || !p.Persist().Valid() || p.Persist().PrivateNodeKey().IsZero() { + return key.NodePublic{} + } + + return p.Persist().PublicNodeKey() +} + // nextState returns the state the backend seems to be in, based on // its internal state. func (b *LocalBackend) nextState() ipn.State {