setprimarypolicy.sh 935 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. cleanup() {
  4. tpm2 flushcontext session.ctx 2>/dev/null || true
  5. rm -f session.ctx policy.pcr primary.ctx
  6. if [ "${1}" != "no-shutdown" ]; then
  7. shut_down
  8. fi
  9. }
  10. trap cleanup EXIT
  11. start_up
  12. cleanup "no-shutdown"
  13. tpm2 clear
  14. tpm2 changeauth -c e endorsementpassword
  15. tpm2 startauthsession -S session.ctx
  16. tpm2 policypcr -l sha256:0 -L policy.pcr -S session.ctx
  17. tpm2 flushcontext session.ctx
  18. tpm2 setprimarypolicy -C e -L policy.pcr -g sha256 -P endorsementpassword
  19. #
  20. # Try changing the endorsement hierarchy password with the policy
  21. #
  22. tpm2 startauthsession -S session.ctx --policy-session
  23. tpm2 policypcr -l sha256:0 -S session.ctx
  24. tpm2 changeauth -c e -p session:session.ctx newendorsementpassword
  25. tpm2 flushcontext session.ctx
  26. #
  27. # Use the new password to create a primary key
  28. #
  29. tpm2 createprimary -C e -c primary.ctx -P newendorsementpassword
  30. exit 0