commandaudit.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. cleanup() {
  4. rm -f \
  5. prim.ctx signing_key.ctx signing_key.pub signing_key.priv \
  6. att.data att.sig
  7. if [ "${1}" != "no-shutdown" ]; then
  8. shut_down
  9. fi
  10. }
  11. trap cleanup EXIT
  12. start_up
  13. cleanup "no-shutdown"
  14. tpm2 clear
  15. #
  16. # Audit counter should be zero at reset
  17. #
  18. AUDIT_COUNTER_ZERO=0x0
  19. tpm2 getcap properties-variable | \
  20. grep TPM2_PT_AUDIT_COUNTER_1 | awk -F " " '{print $2}' | \
  21. grep $AUDIT_COUNTER_ZERO
  22. #
  23. # Audit counter increments when setting up the audit digest algorithm
  24. # other than the default. In simulator the default is sha512.
  25. #
  26. tpm2 setcommandauditstatus -g sha256
  27. AUDIT_COUNTER_ONE=0x1
  28. tpm2 getcap properties-variable | \
  29. grep TPM2_PT_AUDIT_COUNTER_1 | awk -F " " '{print $2}' | \
  30. grep $AUDIT_COUNTER_ONE
  31. tpm2 createprimary -C o -c prim.ctx
  32. tpm2 create -C prim.ctx -c signing_key.ctx -u signing_key.pub -r signing_key.priv
  33. #
  34. # Check TPM2_CC_SetCommandAuditStatus is included by default
  35. #
  36. tpm2 getcommandauditdigest -g sha256 -f plain -m att.data -s att.sig \
  37. -c signing_key.ctx
  38. TPM2_CC_SetCommandAuditStatus=00000140
  39. diff -B \
  40. <( echo $TPM2_CC_SetCommandAuditStatus | xxd -r -p | \
  41. openssl dgst -sha256 -binary ) \
  42. <( tail -c 32 att.data )
  43. #
  44. # Check if TPM2_CC_GetRandom is added to the setlist
  45. #
  46. tpm2 setcommandauditstatus TPM2_CC_GetRandom
  47. tpm2 getcommandauditdigest -g sha256 -f plain -m att.data -s att.sig \
  48. -c signing_key.ctx
  49. TPM2_CC_GetRandom=0000017B
  50. diff -B \
  51. <( echo $TPM2_CC_SetCommandAuditStatus$TPM2_CC_GetRandom | \
  52. xxd -r -p | openssl dgst -sha256 -binary ) \
  53. <( tail -c 32 att.data )
  54. #
  55. # Check TPM2_CC_GetRandom is removed from the audit list
  56. #
  57. tpm2 setcommandauditstatus --clear-list TPM2_CC_GetRandom
  58. tpm2 getcommandauditdigest -g sha256 -f plain -m att.data -s att.sig \
  59. -c signing_key.ctx
  60. diff -B \
  61. <( echo $TPM2_CC_SetCommandAuditStatus | xxd -r -p | \
  62. openssl dgst -sha256 -binary ) \
  63. <( tail -c 32 att.data )
  64. exit 0