Skip to content

Commit

Permalink
Add handle flushing
Browse files Browse the repository at this point in the history
Signed-off-by: Philipp Deppenwiese <[email protected]>
  • Loading branch information
zaolin committed Mar 16, 2023
1 parent 11ffdd1 commit ea4e4eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/tpm-vuln-checker/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (c *checkCmd) Run(ctx *context) error {
if !tss.IsTPM2(socket) {
return fmt.Errorf("no TPM 2.0 found")
}
tss.FlushAllHandles(socket)
tpmInfo, err := tss.ReadTPM2VendorAttributes(socket)
if err != nil {
return err
Expand Down
19 changes: 19 additions & 0 deletions pkg/tss/tpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,22 @@ func NewTPM(emulator bool) (io.ReadWriteCloser, error) {
}
return rwc, nil
}

func FlushAllHandles(tpm io.ReadWriteCloser) error {
vals, _, err := tpm2.GetCapability(tpm, tpm2.CapabilityHandles, 100, uint32(tpm2.HandleTypeHMACSession)<<24)
if err != nil {
return err
}

if len(vals) > 0 {
for _, handle := range vals {
switch t := handle.(type) {
default:

case tpmutil.Handle:
tpm2.FlushContext(tpm, t)
}
}
}
return nil
}

0 comments on commit ea4e4eb

Please sign in to comment.