Skip to content

Instantly share code, notes, and snippets.

@chrisccoulson
Created July 6, 2022 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisccoulson/c57a3af290ee79f7d12a7cf0b8daa5d3 to your computer and use it in GitHub Desktop.
Save chrisccoulson/c57a3af290ee79f7d12a7cf0b8daa5d3 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os"
"github.com/canonical/go-tpm2"
"github.com/canonical/go-tpm2/linux"
)
func run() error {
tcti, err := linux.OpenDevice("/dev/tpm0")
if err != nil {
return fmt.Errorf("cannot open TPM device: %v", err)
}
tpm := tpm2.NewTPMContext(tcti)
defer tpm.Close()
v, err := tpm.GetCapabilityTPMProperty(tpm2.PropertyLockoutCounter)
if err != nil {
return fmt.Errorf("cannot obtain lockout counter value: %v", err)
}
if v != 0 {
return fmt.Errorf("lockout counter is non-zero (%d)", v)
}
return nil
}
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment