This reverts commit a760cbe33f.
Signed-off-by: Andrew Lytvynov <awly@tailscale.com>
This commit is contained in:
@@ -26,6 +26,7 @@ type Persist struct {
|
||||
UserProfile tailcfg.UserProfile
|
||||
NetworkLockKey key.NLPrivate
|
||||
NodeID tailcfg.StableNodeID
|
||||
AttestationKey key.HardwareAttestationKey `json:",omitempty"`
|
||||
|
||||
// DisallowedTKAStateIDs stores the tka.State.StateID values which
|
||||
// this node will not operate network lock on. This is used to
|
||||
@@ -84,11 +85,20 @@ func (p *Persist) Equals(p2 *Persist) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
var pub, p2Pub key.HardwareAttestationPublic
|
||||
if p.AttestationKey != nil && !p.AttestationKey.IsZero() {
|
||||
pub = key.HardwareAttestationPublicFromPlatformKey(p.AttestationKey)
|
||||
}
|
||||
if p2.AttestationKey != nil && !p2.AttestationKey.IsZero() {
|
||||
p2Pub = key.HardwareAttestationPublicFromPlatformKey(p2.AttestationKey)
|
||||
}
|
||||
|
||||
return p.PrivateNodeKey.Equal(p2.PrivateNodeKey) &&
|
||||
p.OldPrivateNodeKey.Equal(p2.OldPrivateNodeKey) &&
|
||||
p.UserProfile.Equal(&p2.UserProfile) &&
|
||||
p.NetworkLockKey.Equal(p2.NetworkLockKey) &&
|
||||
p.NodeID == p2.NodeID &&
|
||||
pub.Equal(p2Pub) &&
|
||||
reflect.DeepEqual(nilIfEmpty(p.DisallowedTKAStateIDs), nilIfEmpty(p2.DisallowedTKAStateIDs))
|
||||
}
|
||||
|
||||
@@ -96,12 +106,16 @@ func (p *Persist) Pretty() string {
|
||||
var (
|
||||
ok, nk key.NodePublic
|
||||
)
|
||||
akString := "-"
|
||||
if !p.OldPrivateNodeKey.IsZero() {
|
||||
ok = p.OldPrivateNodeKey.Public()
|
||||
}
|
||||
if !p.PrivateNodeKey.IsZero() {
|
||||
nk = p.PublicNodeKey()
|
||||
}
|
||||
return fmt.Sprintf("Persist{o=%v, n=%v u=%#v}",
|
||||
ok.ShortString(), nk.ShortString(), p.UserProfile.LoginName)
|
||||
if p.AttestationKey != nil && !p.AttestationKey.IsZero() {
|
||||
akString = fmt.Sprintf("%v", p.AttestationKey.Public())
|
||||
}
|
||||
return fmt.Sprintf("Persist{o=%v, n=%v u=%#v ak=%s}",
|
||||
ok.ShortString(), nk.ShortString(), p.UserProfile.LoginName, akString)
|
||||
}
|
||||
|
||||
@@ -19,6 +19,9 @@ func (src *Persist) Clone() *Persist {
|
||||
}
|
||||
dst := new(Persist)
|
||||
*dst = *src
|
||||
if src.AttestationKey != nil {
|
||||
dst.AttestationKey = src.AttestationKey.Clone()
|
||||
}
|
||||
dst.DisallowedTKAStateIDs = append(src.DisallowedTKAStateIDs[:0:0], src.DisallowedTKAStateIDs...)
|
||||
return dst
|
||||
}
|
||||
@@ -31,5 +34,6 @@ var _PersistCloneNeedsRegeneration = Persist(struct {
|
||||
UserProfile tailcfg.UserProfile
|
||||
NetworkLockKey key.NLPrivate
|
||||
NodeID tailcfg.StableNodeID
|
||||
AttestationKey key.HardwareAttestationKey
|
||||
DisallowedTKAStateIDs []string
|
||||
}{})
|
||||
|
||||
@@ -21,7 +21,7 @@ func fieldsOf(t reflect.Type) (fields []string) {
|
||||
}
|
||||
|
||||
func TestPersistEqual(t *testing.T) {
|
||||
persistHandles := []string{"PrivateNodeKey", "OldPrivateNodeKey", "UserProfile", "NetworkLockKey", "NodeID", "DisallowedTKAStateIDs"}
|
||||
persistHandles := []string{"PrivateNodeKey", "OldPrivateNodeKey", "UserProfile", "NetworkLockKey", "NodeID", "AttestationKey", "DisallowedTKAStateIDs"}
|
||||
if have := fieldsOf(reflect.TypeFor[Persist]()); !reflect.DeepEqual(have, persistHandles) {
|
||||
t.Errorf("Persist.Equal check might be out of sync\nfields: %q\nhandled: %q\n",
|
||||
have, persistHandles)
|
||||
|
||||
@@ -89,10 +89,11 @@ func (v *PersistView) UnmarshalJSONFrom(dec *jsontext.Decoder) error {
|
||||
func (v PersistView) PrivateNodeKey() key.NodePrivate { return v.ж.PrivateNodeKey }
|
||||
|
||||
// needed to request key rotation
|
||||
func (v PersistView) OldPrivateNodeKey() key.NodePrivate { return v.ж.OldPrivateNodeKey }
|
||||
func (v PersistView) UserProfile() tailcfg.UserProfile { return v.ж.UserProfile }
|
||||
func (v PersistView) NetworkLockKey() key.NLPrivate { return v.ж.NetworkLockKey }
|
||||
func (v PersistView) NodeID() tailcfg.StableNodeID { return v.ж.NodeID }
|
||||
func (v PersistView) OldPrivateNodeKey() key.NodePrivate { return v.ж.OldPrivateNodeKey }
|
||||
func (v PersistView) UserProfile() tailcfg.UserProfile { return v.ж.UserProfile }
|
||||
func (v PersistView) NetworkLockKey() key.NLPrivate { return v.ж.NetworkLockKey }
|
||||
func (v PersistView) NodeID() tailcfg.StableNodeID { return v.ж.NodeID }
|
||||
func (v PersistView) AttestationKey() tailcfg.StableNodeID { panic("unsupported") }
|
||||
|
||||
// DisallowedTKAStateIDs stores the tka.State.StateID values which
|
||||
// this node will not operate network lock on. This is used to
|
||||
@@ -110,5 +111,6 @@ var _PersistViewNeedsRegeneration = Persist(struct {
|
||||
UserProfile tailcfg.UserProfile
|
||||
NetworkLockKey key.NLPrivate
|
||||
NodeID tailcfg.StableNodeID
|
||||
AttestationKey key.HardwareAttestationKey
|
||||
DisallowedTKAStateIDs []string
|
||||
}{})
|
||||
|
||||
Reference in New Issue
Block a user