createak.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. cleanup() {
  4. rm -f ek.pub ak.pub ak.name ak.name ak.log
  5. # Evict persistent handles, we want them to always succeed and never trip
  6. # the onerror trap.
  7. tpm2 evictcontrol -Q -C o -c 0x8101000b 2>/dev/null || true
  8. tpm2 evictcontrol -Q -C o -c 0x8101000c 2>/dev/null || true
  9. # clear tpm state
  10. tpm2 clear
  11. if [ "$1" != "no-shut-down" ]; then
  12. shut_down
  13. fi
  14. }
  15. trap cleanup EXIT
  16. start_up
  17. cleanup "no-shut-down"
  18. tpm2 createek -Q -c 0x8101000b -G rsa -u ek.pub
  19. tpm2 createak -Q -C 0x8101000b -c ak.ctx -G rsa -g sha256 -s rsassa -u ak.pub \
  20. -n ak.name -q ak.qname
  21. # Validate the qname
  22. tpm2 readpublic -c ak.ctx -q ak.qname2
  23. diff ak.qname ak.qname2
  24. # Find a vacant persistent handle
  25. tpm2 createak -C 0x8101000b -c ak.ctx -G rsa -g sha256 -s rsassa -u ak.pub \
  26. -n ak.name
  27. tpm2 evictcontrol -c ak.ctx > ak.log
  28. phandle=`yaml_get_kv ak.log "persistent-handle"`
  29. tpm2 evictcontrol -Q -C o -c $phandle
  30. # Test tpm2 createak with endorsement password
  31. cleanup "no-shut-down"
  32. tpm2 changeauth -c e endauth
  33. tpm2 createek -Q -P endauth -c 0x8101000b -G rsa -u ek.pub
  34. tpm2 createak -Q -P endauth -C 0x8101000b -c ak.ctx -G rsa -u ak.pub -n ak.name
  35. exit 0