mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-27 20:19:31 +00:00
feature/tpm: don't log to stderr in tests
Fixes #17336 Change-Id: I7d2be4e8acf59116c57ce26049a6a5baa8f32436 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
1803226945
commit
9b997c8f2f
@@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/google/go-tpm/tpm2/transport"
|
"github.com/google/go-tpm/tpm2/transport"
|
||||||
"golang.org/x/crypto/nacl/secretbox"
|
"golang.org/x/crypto/nacl/secretbox"
|
||||||
"tailscale.com/atomicfile"
|
"tailscale.com/atomicfile"
|
||||||
|
"tailscale.com/envknob"
|
||||||
"tailscale.com/feature"
|
"tailscale.com/feature"
|
||||||
"tailscale.com/hostinfo"
|
"tailscale.com/hostinfo"
|
||||||
"tailscale.com/ipn"
|
"tailscale.com/ipn"
|
||||||
@@ -31,6 +32,7 @@ import (
|
|||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
"tailscale.com/types/key"
|
"tailscale.com/types/key"
|
||||||
"tailscale.com/types/logger"
|
"tailscale.com/types/logger"
|
||||||
|
"tailscale.com/util/testenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
var infoOnce = sync.OnceValue(info)
|
var infoOnce = sync.OnceValue(info)
|
||||||
@@ -49,13 +51,20 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var verboseTPM = envknob.RegisterBool("TS_DEBUG_TPM")
|
||||||
|
|
||||||
func info() *tailcfg.TPMInfo {
|
func info() *tailcfg.TPMInfo {
|
||||||
|
logf := logger.Discard
|
||||||
|
if !testenv.InTest() || verboseTPM() {
|
||||||
|
logf = log.New(log.Default().Writer(), "TPM: ", 0).Printf
|
||||||
|
}
|
||||||
|
|
||||||
tpm, err := open()
|
tpm, err := open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("TPM: error opening: %v", err)
|
logf("error opening: %v", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
log.Printf("TPM: successfully opened")
|
logf("successfully opened")
|
||||||
defer tpm.Close()
|
defer tpm.Close()
|
||||||
|
|
||||||
info := new(tailcfg.TPMInfo)
|
info := new(tailcfg.TPMInfo)
|
||||||
@@ -84,12 +93,12 @@ func info() *tailcfg.TPMInfo {
|
|||||||
PropertyCount: 1,
|
PropertyCount: 1,
|
||||||
}.Execute(tpm)
|
}.Execute(tpm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("TPM: GetCapability %v: %v", cap.prop, err)
|
logf("GetCapability %v: %v", cap.prop, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
props, err := resp.CapabilityData.Data.TPMProperties()
|
props, err := resp.CapabilityData.Data.TPMProperties()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("TPM: GetCapability %v: %v", cap.prop, err)
|
logf("GetCapability %v: %v", cap.prop, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(props.TPMProperty) == 0 {
|
if len(props.TPMProperty) == 0 {
|
||||||
@@ -97,6 +106,7 @@ func info() *tailcfg.TPMInfo {
|
|||||||
}
|
}
|
||||||
cap.apply(info, props.TPMProperty[0].Value)
|
cap.apply(info, props.TPMProperty[0].Value)
|
||||||
}
|
}
|
||||||
|
logf("successfully read all properties")
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user