changeauth.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. cleanup() {
  4. rm key.ctx key.pub key.priv primary.ctx
  5. shut_down
  6. }
  7. trap cleanup EXIT
  8. start_up
  9. ownerPasswd=abc123
  10. endorsePasswd=abc123
  11. lockPasswd=abc123
  12. new_ownerPasswd=newpswd
  13. new_endorsePasswd=newpswd
  14. new_lockPasswd=newpswd
  15. tpm2 clear
  16. tpm2 changeauth -c o $ownerPasswd
  17. tpm2 changeauth -c e $endorsePasswd
  18. tpm2 changeauth -c l $lockPasswd
  19. tpm2 changeauth -c o -p $ownerPasswd $new_ownerPasswd
  20. tpm2 changeauth -c e -p $endorsePasswd $new_endorsePasswd
  21. tpm2 changeauth -c l -p $lockPasswd $new_lockPasswd
  22. tpm2 clear $new_lockPasswd
  23. tpm2 changeauth -c o $ownerPasswd
  24. tpm2 changeauth -c e $endorsePasswd
  25. tpm2 changeauth -c l $lockPasswd
  26. tpm2 clear $lockPasswd
  27. # Test changing an objects auth
  28. tpm2 createprimary -Q -C o -c primary.ctx
  29. tpm2 create -Q -C primary.ctx -p foo -u key.pub -r key.priv
  30. tpm2 load -Q -C primary.ctx -u key.pub -r key.priv -c key.ctx
  31. tpm2 changeauth -C primary.ctx -p foo -c key.ctx -r new.priv bar
  32. # Test changing an NV index auth
  33. tpm2 startauthsession -S session.ctx
  34. tpm2 policycommandcode -S session.ctx -L policy.nvchange TPM2_CC_NV_ChangeAuth
  35. tpm2 flushcontext session.ctx
  36. NVIndex=0x1500015
  37. tpm2 nvdefine $NVIndex -C o -s 32 -a "authread|authwrite" -L policy.nvchange
  38. tpm2 startauthsession --policy-session -S session.ctx
  39. tpm2 policycommandcode -S session.ctx -L policy.nvchange TPM2_CC_NV_ChangeAuth
  40. tpm2 changeauth -p session:session.ctx -c $NVIndex newindexauth
  41. exit 0