abrmd_policysecret.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. TPM_RH_OWNER=0x40000001
  4. SEALED_SECRET=SEALED-SECRET
  5. session_ctx=session.ctx
  6. o_policy_digest=policy.digest
  7. primary_ctx=prim.ctx
  8. seal_key_pub=sealing_key.pub
  9. seal_key_priv=sealing_key.priv
  10. seal_key_ctx=sealing_key.ctx
  11. cleanup() {
  12. rm -f $session_ctx $o_policy_digest $primary_ctx $seal_key_pub $seal_key_priv\
  13. $seal_key_ctx qual.dat
  14. tpm2 flushcontext $session_ctx 2>/dev/null || true
  15. tpm2 clear
  16. if [ "${1}" != "no-shutdown" ]; then
  17. shut_down
  18. fi
  19. }
  20. trap cleanup EXIT
  21. start_up
  22. cleanup "no-shutdown"
  23. tpm2 clear
  24. tpm2 changeauth -c o ownerauth
  25. # Create Policy
  26. tpm2 startauthsession -S $session_ctx
  27. tpm2 policysecret -S $session_ctx -c $TPM_RH_OWNER -L $o_policy_digest ownerauth
  28. tpm2 flushcontext $session_ctx
  29. rm $session_ctx
  30. # Create and Load Object
  31. tpm2 createprimary -Q -C o -c $primary_ctx -P ownerauth
  32. tpm2 create -Q -g sha256 -u $seal_key_pub -r $seal_key_priv -C $primary_ctx \
  33. -L $o_policy_digest -i- <<< $SEALED_SECRET
  34. tpm2 load -C $primary_ctx -u $seal_key_pub -r $seal_key_priv -c $seal_key_ctx
  35. # Satisfy policy and unseal data
  36. tpm2 startauthsession --policy-session -S $session_ctx
  37. echo -n "ownerauth" | tpm2 policysecret -S $session_ctx -c $TPM_RH_OWNER \
  38. -L $o_policy_digest file:-
  39. unsealed=`tpm2 unseal -p"session:$session_ctx" -c $seal_key_ctx`
  40. tpm2 flushcontext $session_ctx
  41. rm $session_ctx
  42. test "$unsealed" == "$SEALED_SECRET"
  43. if [ $? != 0 ]; then
  44. echo "Failed policysecret integration test where ref object password was set."
  45. fi
  46. #Test the policy with auth reference object password not set
  47. unsealed=""
  48. tpm2 changeauth -c o -p ownerauth
  49. tpm2 startauthsession --policy-session -S $session_ctx
  50. tpm2 policysecret -S $session_ctx -c $TPM_RH_OWNER -L $o_policy_digest
  51. unsealed=`tpm2 unseal -p"session:$session_ctx" -c $seal_key_ctx`
  52. tpm2 flushcontext $session_ctx
  53. rm $session_ctx
  54. test "$unsealed" == "$SEALED_SECRET"
  55. if [ $? != 0 ]; then
  56. echo "Failed policysecret integration test for passwordless reference object."
  57. fi
  58. #
  59. # Test with policyref or qualification data
  60. #
  61. unsealed=""
  62. tpm2 clear
  63. dd if=/dev/urandom of=qual.dat bs=1 count=32
  64. tpm2 startauthsession -S $session_ctx
  65. tpm2 policysecret -S $session_ctx -c $TPM_RH_OWNER -L $o_policy_digest \
  66. -q qual.dat
  67. tpm2 flushcontext $session_ctx
  68. tpm2 createprimary -Q -C o -c $primary_ctx
  69. tpm2 create -Q -g sha256 -u $seal_key_pub -r $seal_key_priv -C $primary_ctx \
  70. -L $o_policy_digest -i- <<< $SEALED_SECRET
  71. tpm2 load -C $primary_ctx -u $seal_key_pub -r $seal_key_priv -c $seal_key_ctx
  72. tpm2 startauthsession --policy-session -S $session_ctx
  73. tpm2 policysecret -S $session_ctx -c $TPM_RH_OWNER -L $o_policy_digest \
  74. -q qual.dat
  75. unsealed=`tpm2 unseal -p"session:$session_ctx" -c $seal_key_ctx`
  76. tpm2 flushcontext $session_ctx
  77. test "$unsealed" == "$SEALED_SECRET"
  78. if [ $? != 0 ]; then
  79. echo "Failed policysecret integration test for passwordless reference object."
  80. fi
  81. #
  82. # Test with policy auth reference instead of plain password
  83. #
  84. tpm2 startauthsession -S session.ctx
  85. tpm2 policyauthvalue -S session.ctx -L policy.authval
  86. tpm2 flushcontext session.ctx
  87. tpm2 setprimarypolicy -C o -L policy.authval -g sha256
  88. tpm2 startauthsession -S session.ctx --policy-session
  89. tpm2 startauthsession -S policy_session.ctx --policy-session
  90. tpm2 policyauthvalue -S session.ctx
  91. tpm2 policysecret -S policy_session.ctx -c o session:session.ctx
  92. tpm2 flushcontext session.ctx
  93. tpm2 flushcontext policy_session.ctx
  94. exit 0