createpolicy.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. ###this script use for test the implementation tpm2 createpolicy
  4. cleanup() {
  5. rm -f pcr.in policy.out
  6. if [ "$1" != "no-shut-down" ]; then
  7. shut_down
  8. fi
  9. }
  10. trap cleanup EXIT
  11. start_up
  12. declare -A digestlengths=\
  13. ([sha1]=20
  14. [sha256]=32)
  15. declare -A expected_policy_digest=\
  16. ([sha1]=f28230c080bbe417141199e36d18978228d8948fc10a6a24921b9eba6bb1d988
  17. [sha256]=33e36e786c878632494217c3f490e74ca0a3a122a8a4f3c5302500df3b32b3b8)
  18. tpm2 pcrread -V sha1
  19. for halg in ${!digestlengths[@]}
  20. do
  21. cleanup "no-shut-down"
  22. # Create file containing expected PCR value
  23. head -c $((${digestlengths[$halg]} - 1)) /dev/zero > pcr.in
  24. echo -n -e '\x03' >> pcr.in
  25. tpm2 createpolicy --policy-pcr -l $halg:0 -f pcr.in -L policy.out
  26. # Test the policy creation hashes against expected
  27. if [ $(xxd -p policy.out | tr -d '\n' ) != \
  28. "${expected_policy_digest[${halg}]}" ]; then
  29. echo "Failure: Creating Policy Digest with PCR policy for index 0 and \
  30. ${halg} pcr index hash"
  31. echo "Got: $(xxd -p policy.out | tr -d '\n')"
  32. echo "Expected: ${expected_policy_digest[${halg}]}"
  33. exit 1
  34. fi
  35. done
  36. exit 0