pcrevent.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. #this script is for hash case testing
  3. source helpers.sh
  4. hash_out_file=hash.out
  5. hash_in_file=hash.in
  6. yaml_out_file=pcr_list.yaml
  7. cleanup() {
  8. rm -f $hash_in_file $hash_out_file $yaml_out_file
  9. shut_down
  10. }
  11. trap cleanup EXIT
  12. start_up
  13. echo "T0naX0u123abc" > $hash_in_file
  14. # Run FILE and stdin as FILE
  15. tpm2 pcrevent -Q $hash_in_file
  16. tpm2 pcrevent -Q < $hash_in_file
  17. # Test that fifo stdin works
  18. cat $hash_in_file | tpm2 pcrevent > $hash_out_file
  19. yaml_verify $hash_out_file
  20. # Verify output as expected.
  21. while IFS='' read -r l || [[ -n "$l" ]]; do
  22. alg=`echo -n $l | cut -d\: -f 1-1`
  23. if ! which "$alg"sum >/dev/null 2>&1; then
  24. echo "Ignore checking $alg algorithm due to unavailable \"${alg}sum\" program"
  25. continue
  26. fi
  27. hash=`echo -n $l | awk {'print $2'}`
  28. check=`"$alg"sum $hash_in_file | cut -d' ' -f 1-1`
  29. if [ "$check" != "$hash" ]; then
  30. echo "Hash check failed for alg \"$alg\", got \"$hash\", expected \"$check\""
  31. exit 1
  32. fi
  33. done < $hash_out_file
  34. tpm2 pcrread sha1:9 > $yaml_out_file
  35. old_pcr_value=`yaml_get_kv $yaml_out_file "sha1" "9"`
  36. # Verify that extend works, and test large files
  37. dd if=/dev/urandom of=$hash_in_file count=1 bs=2093 2> /dev/null
  38. tpm2 pcrevent -Q 9 $hash_in_file
  39. tpm2 pcrread sha1:9 > $yaml_out_file
  40. new_pcr_value=`yaml_get_kv $yaml_out_file "sha1" "9"`
  41. if [ "$new_pcr_value" == "$old_pcr_value" ]; then
  42. echo "Expected PCR value to change after pcrevent with index 9."
  43. echo "Got the same hash as before: "$new_pcr_value"".
  44. exit 1;
  45. fi
  46. # verify that specifying -P without -i fails
  47. trap - ERR
  48. cmd="tpm2 pcrevent -Q -P foo $hash_in_file 2> /dev/null"
  49. eval "$cmd"
  50. if [ $? -eq 0 ]; then
  51. echo "Expected $cmd to fail, passed."
  52. exit 1;
  53. fi
  54. exit 0