createek.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. cleanup() {
  4. rm -f ek.pub ek.log ek.template ek.nonce ek.ctx
  5. # Evict persistent handles, we want them to always succeed and never trip
  6. # the onerror trap.
  7. tpm2 evictcontrol -Q -C o -c 0x81010005 2>/dev/null || true
  8. if [ "$1" != "no-shut-down" ]; then
  9. shut_down
  10. fi
  11. }
  12. trap cleanup EXIT
  13. start_up
  14. cleanup "no-shut-down"
  15. tpm2 createek -c 0x81010005 -G rsa -u ek.pub
  16. cleanup "no-shut-down"
  17. tpm2 createek -c - -G rsa -u ek.pub > ek.log
  18. phandle=`yaml_get_kv ek.log "persistent-handle"`
  19. tpm2 evictcontrol -Q -C o -c $phandle
  20. cleanup "no-shut-down"
  21. tpm2 createek -G rsa -u ek.pub -c ek.ctx
  22. cleanup "no-shut-down"
  23. ek_nonce_index=0x01c00003
  24. ek_template_index=0x01c00004
  25. # Define RSA EK template
  26. nbytes=$(wc -c ${abs_srcdir}/test/integration/fixtures/ek-template-default.bin | awk {'print $1'})
  27. tpm2 nvdefine -Q $ek_template_index -C o -s $nbytes \
  28. -a "ownerread|policywrite|ownerwrite"
  29. tpm2 nvwrite -Q $ek_template_index -C o \
  30. -i ${abs_srcdir}/test/integration/fixtures/ek-template-default.bin
  31. # Define RSA EK nonce
  32. echo -n -e '\0' > ek.nonce
  33. tpm2 nvdefine -Q $ek_nonce_index -C o -s 1 \
  34. -a "ownerread|policywrite|ownerwrite"
  35. tpm2 nvwrite -Q $ek_nonce_index -C o -i ek.nonce
  36. tpm2 createek -t -G rsa -u ek.pub -c ek.ctx
  37. cleanup "no-shut-down"
  38. exit 0