diff --git a/coordinator/attestation/vtpm/vtpm.go b/coordinator/attestation/vtpm/vtpm.go index c81bdda5f..7dae63066 100644 --- a/coordinator/attestation/vtpm/vtpm.go +++ b/coordinator/attestation/vtpm/vtpm.go @@ -43,3 +43,31 @@ func (t nopTPM) Write(p []byte) (int, error) { func (t nopTPM) Close() error { return nil } + +type simulatedTPM struct { + openSimulatedTPM io.ReadWriteCloser +} + +// NewSimulatedTPMOpenFunc returns a TPMOpenFunc that opens a simulated TPM. +func NewSimulatedTPMOpenFunc() (TPMOpenFunc, io.Closer) { + tpm, err := OpenSimulatedTPM() + if err != nil { + panic(err) + } + return func() (io.ReadWriteCloser, error) { + return &simulatedTPM{tpm}, nil + }, tpm +} + +func (t *simulatedTPM) Read(p []byte) (int, error) { + return t.openSimulatedTPM.Read(p) +} + +func (t *simulatedTPM) Write(p []byte) (int, error) { + return t.openSimulatedTPM.Write(p) +} + +func (t *simulatedTPM) Close() error { + // never close the underlying simulated TPM to allow calling the TPMOpenFunc again + return nil +} diff --git a/coordinator/cmd/coordinator/main.go b/coordinator/cmd/coordinator/main.go index d7e05b73d..035c342db 100644 --- a/coordinator/cmd/coordinator/main.go +++ b/coordinator/cmd/coordinator/main.go @@ -3,6 +3,7 @@ package main import ( "context" "flag" + "io" "log" "net" "os"