create.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. cleanup() {
  4. rm -f key.pub key.priv policy.bin out.pub key.ctx
  5. if [ $(ina "$@" "keep-context") -ne 0 ]; then
  6. rm -f context.out
  7. fi
  8. rm -f key*.ctx out.yaml
  9. if [ $(ina "$@" "no-shut-down") -ne 0 ]; then
  10. shut_down
  11. fi
  12. }
  13. trap cleanup EXIT
  14. start_up
  15. cleanup "no-shut-down"
  16. tpm2 createprimary -Q -C o -g sha1 -G rsa -c context.out
  17. # Keep the algorithm specifiers mixed to test friendly and raw
  18. # values.
  19. for gAlg in `populate_hash_algs`; do
  20. for GAlg in rsa keyedhash ecc aes; do
  21. echo "tpm2 create -Q -C context.out -g $gAlg -G $GAlg -u key.pub \
  22. -r key.priv"
  23. tpm2 create -Q -C context.out -g $gAlg -G $GAlg -u key.pub -r key.priv
  24. cleanup "keep-context" "no-shut-down"
  25. done
  26. done
  27. cleanup "keep-context" "no-shut-down"
  28. policy_orig=f28230c080bbe417141199e36d18978228d8948fc10a6a24921b9eba6bb1d988
  29. echo "$policy_orig" | xxd -r -p > policy.bin
  30. tpm2 create -C context.out -g sha256 -G rsa -L policy.bin -u key.pub \
  31. -r key.priv -a 'sign|fixedtpm|fixedparent|sensitivedataorigin' > out.pub
  32. policy_new=$(yaml_get_kv out.pub "authorization policy")
  33. test "$policy_orig" == "$policy_new"
  34. #
  35. # Test the extended format specifiers
  36. #
  37. # aes128cfb (mandatory for PCClient TPMs)
  38. tpm2 create -Q -C context.out -g sha256 -G aes128cfb -u key.pub -r key.priv
  39. tpm2 load -Q -C context.out -u key.pub -r key.priv -c key1.ctx
  40. tpm2 readpublic -c key1.ctx > out.yaml
  41. keybits=$(yaml_get_kv out.yaml "sym-keybits")
  42. mode=$(yaml_get_kv out.yaml "sym-mode" "value")
  43. test "$keybits" -eq "128"
  44. test "$mode" == "cfb"
  45. # aes256ofb (if supported)
  46. if is_alg_supported aes256ofb; then
  47. mode="$(populate_alg_modes $strongest_aes | head -n1)" # e.g. aes128ecb
  48. tpm2 create -Q -C context.out -g sha256 -G aes256ofb -u key.pub -r key.priv
  49. tpm2 load -Q -C context.out -u key.pub -r key.priv -c key2.ctx
  50. tpm2 readpublic -c key2.ctx > out.yaml
  51. keybits=$(yaml_get_kv out.yaml "sym-keybits")
  52. mode=$(yaml_get_kv out.yaml "sym-mode" "value")
  53. test "$keybits" -eq "256"
  54. test "$mode" == "ofb"
  55. fi
  56. exit 0
  57. #
  58. # Test scheme support
  59. #
  60. for alg in "rsa1024:rsaes" "ecc384:ecdaa4-sha256"; do
  61. if is_alg_supported $alg; then
  62. tpm2 create -Q -C context.out -g sha256 -G "$alg" -u key.pub -r key.priv
  63. fi
  64. done
  65. # Test createloaded support
  66. tpm2 create -C context.out -u key.pub -r key.priv -c key.ctx
  67. tpm2 readpublic -c key.ctx 2>/dev/null
  68. # Test that creation data has the specified outside info
  69. tpm2 createprimary -C o -c prim.ctx -Q
  70. dd if=/dev/urandom of=outside.info bs=1 count=32
  71. tpm2 create -C prim.ctx -u key.pub -r key.priv --creation-data creation.data \
  72. -q outside.info -Q
  73. xxd -p creation.data | tr -d '\n' | grep `xxd -p outside.info | tr -d '\n'`
  74. # Test that selected pcrs digest is present in the creation data
  75. tpm2 pcrread sha256:0 -o pcr_data.bin
  76. tpm2 create -C prim.ctx -u key.pub -r key.priv --creation-data creation.data \
  77. -l sha256:0 -Q
  78. xxd -p creation.data | tr -d '\n' | \
  79. grep `cat pcr_data.bin | openssl dgst -sha256 -binary | xxd -p | tr -d '\n'`
  80. # Test if additional sessions can be specified
  81. tpm2 clear
  82. tpm2 createprimary -C o -c prim.ctx -Q
  83. tpm2 startauthsession -S audit_session.ctx --audit-session
  84. tpm2 startauthsession -S enc_session.ctx --hmac-session -c prim.ctx
  85. tpm2 create -C prim.ctx -u key.pub -r key.priv -p apple \
  86. -S enc_session.ctx \
  87. -S audit_session.ctx
  88. tpm2 flushcontext audit_session.ctx
  89. tpm2 flushcontext enc_session.ctx
  90. exit 0