mirror of https://github.com/tailscale/tailscale/
types/persist: add AttestationKey (#17281)
Extend Persist with AttestationKey to record a hardware-backed attestation key for the node's identity. Add a flag to tailscaled to allow users to control the use of hardware-backed keys to bind node identity to individual machines. Updates tailscale/corp#31269 Change-Id: Idcf40d730a448d85f07f1bebf387f086d4c58be3 Signed-off-by: Patrick O'Doherty <patrick@tailscale.com>pull/17527/head
parent
a2dc517d7d
commit
e45557afc0
@ -0,0 +1,48 @@
|
|||||||
|
// Copyright (c) Tailscale Inc & AUTHORS
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
//go:build !ts_omit_tpm
|
||||||
|
|
||||||
|
package ipnlocal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"tailscale.com/feature"
|
||||||
|
"tailscale.com/types/key"
|
||||||
|
"tailscale.com/types/logger"
|
||||||
|
"tailscale.com/types/persist"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
feature.HookGenerateAttestationKeyIfEmpty.Set(generateAttestationKeyIfEmpty)
|
||||||
|
}
|
||||||
|
|
||||||
|
// generateAttestationKeyIfEmpty generates a new hardware attestation key if
|
||||||
|
// none exists. It returns true if a new key was generated and stored in
|
||||||
|
// p.AttestationKey.
|
||||||
|
func generateAttestationKeyIfEmpty(p *persist.Persist, logf logger.Logf) (bool, error) {
|
||||||
|
// attempt to generate a new hardware attestation key if none exists
|
||||||
|
var ak key.HardwareAttestationKey
|
||||||
|
if p != nil {
|
||||||
|
ak = p.AttestationKey
|
||||||
|
}
|
||||||
|
|
||||||
|
if ak == nil || ak.IsZero() {
|
||||||
|
var err error
|
||||||
|
ak, err = key.NewHardwareAttestationKey()
|
||||||
|
if err != nil {
|
||||||
|
if !errors.Is(err, key.ErrUnsupported) {
|
||||||
|
logf("failed to create hardware attestation key: %v", err)
|
||||||
|
}
|
||||||
|
} else if ak != nil {
|
||||||
|
logf("using new hardware attestation key: %v", ak.Public())
|
||||||
|
if p == nil {
|
||||||
|
p = &persist.Persist{}
|
||||||
|
}
|
||||||
|
p.AttestationKey = ak
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue