abrmd_policycountertimer.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. cleanup() {
  4. rm -f session.ctx prim.ctx key.pub key.priv key.ctx policy.countertimer.minute
  5. if [ "$1" != "no-shut-down" ]; then
  6. shut_down
  7. fi
  8. }
  9. trap cleanup EXIT
  10. start_up
  11. cleanup "no-shut-down"
  12. tpm2 clear
  13. #
  14. # Create a sealing object with a policy that evaluates for first minute after
  15. # TPM restart. NOTE the time is 60000 milliseconds.
  16. #
  17. tpm2 startauthsession -S session.ctx
  18. tpm2 policycountertimer -S session.ctx -L policy.countertimer.minute --ult \
  19. 60000
  20. tpm2 flushcontext session.ctx
  21. tpm2 createprimary -C o -c prim.ctx -Q
  22. echo "SUPERSECRET" | \
  23. tpm2 create -Q -u key.pub -r key.priv -i- -C prim.ctx \
  24. -L policy.countertimer.minute -a "fixedtpm|fixedparent" -c key.ctx
  25. #
  26. # ASSUMING 1 minute hasn't elapsed since clear, Try unseal in the first minute
  27. # -- Should pass
  28. #
  29. tpm2 startauthsession -S session.ctx --policy-session
  30. tpm2 policycountertimer -S session.ctx -L policy.countertimer.minute --ult \
  31. 60000
  32. tpm2 unseal -c key.ctx -p session:session.ctx
  33. tpm2 flushcontext session.ctx
  34. #
  35. # Test if a policycountertimer evaluates with the clock
  36. #
  37. tpm2 clear
  38. tpm2 startauthsession -S session.ctx --policy-session
  39. tpm2 policycountertimer -S session.ctx --ult clock=60000
  40. tpm2 flushcontext session.ctx
  41. #
  42. # Test if a policycountertimer evaluates with the TPM clocks safe flag
  43. # Assuming the safe flag is set since with just started and cleared the TPM
  44. #
  45. tpm2 clear
  46. tpm2 startauthsession -S session.ctx --policy-session
  47. tpm2 policycountertimer -S session.ctx safe
  48. tpm2 flushcontext session.ctx
  49. #
  50. # Test if a policycountertimer evaluates with the TPM reset count
  51. # Assuming the value is zero since we just cleared the TPM
  52. #
  53. tpm2 clear
  54. tpm2 startauthsession -S session.ctx --policy-session
  55. tpm2 policycountertimer -S session.ctx resets=0
  56. tpm2 flushcontext session.ctx
  57. #
  58. # Test if a policycountertimer evaluates with the TPM restart count
  59. # Assuming the value is zero since we just cleared the TPM
  60. #
  61. tpm2 clear
  62. tpm2 startauthsession -S session.ctx --policy-session
  63. tpm2 policycountertimer -S session.ctx restarts=0
  64. tpm2 flushcontext session.ctx
  65. exit 0