quote.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. alg_primary_obj=sha256
  4. alg_primary_key=rsa
  5. alg_create_obj=0x000B
  6. alg_create_key=hmac
  7. alg_quote=0x0004
  8. alg_quote1=0x000b
  9. file_primary_key_ctx=context.p_"$alg_primary_obj"_"$alg_primary_key"
  10. file_quote_key_pub=opu_"$alg_create_obj"_"$alg_create_key"
  11. file_quote_key_priv=opr_"$alg_create_obj"_"$alg_create_key"
  12. file_quote_key_name=name.load_"$alg_primary_obj"_"$alg_primary_key"-\
  13. "$alg_create_obj"_"$alg_create_key"
  14. file_quote_key_ctx=ctx_load_out_"$alg_primary_obj"_"$alg_primary_key"-\
  15. "$alg_create_obj"_"$alg_create_key"
  16. Handle_ak_quote=0x81010016
  17. Handle_ek_quote=0x81010017
  18. Handle_ak_quote2=0x81010018
  19. ak2_ctx=ak2.ctx
  20. out=out.yaml
  21. toss_out=junk.out
  22. cleanup() {
  23. rm -f $file_primary_key_ctx $file_quote_key_pub $file_quote_key_priv \
  24. $file_quote_key_name $file_quote_key_ ak.pub2 ak.name_2 \
  25. $out $toss_out $ak2_ctx ek.ctx ak.ctx nonce.bin quote.bin quote.sig quote.pcr
  26. tpm2 evictcontrol -Q -Co -c $Handle_ek_quote 2>/dev/null || true
  27. tpm2 evictcontrol -Q -Co -c $Handle_ak_quote 2>/dev/null || true
  28. tpm2 evictcontrol -Q -Co -c $Handle_ak_quote2 2>/dev/null || true
  29. if [ "$1" != "no-shut-down" ]; then
  30. shut_down
  31. fi
  32. }
  33. trap cleanup EXIT
  34. start_up
  35. tpm2 getcap properties-fixed | tr -dc '[[:print:]]\r\n' > $out
  36. maxdigest=$(yaml_get_kv $out "TPM2_PT_MAX_DIGEST" "raw")
  37. if ! [[ "$maxdigest" =~ ^(0x)*[0-9]+$ ]] ; then
  38. echo "error: not a number, got: \"$maxdigest\"" >&2
  39. exit 1
  40. fi
  41. nonce=12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde
  42. nonce=${nonce:0:2*$maxdigest}
  43. cleanup "no-shut-down"
  44. tpm2 clear
  45. tpm2 createprimary -Q -C e -g $alg_primary_obj -G $alg_primary_key \
  46. -c $file_primary_key_ctx
  47. tpm2 create -Q -g $alg_create_obj -G $alg_create_key -u $file_quote_key_pub \
  48. -r $file_quote_key_priv -C $file_primary_key_ctx
  49. tpm2 load -Q -C $file_primary_key_ctx -u $file_quote_key_pub \
  50. -r $file_quote_key_priv -n $file_quote_key_name -c $file_quote_key_ctx
  51. tpm2 quote -c $file_quote_key_ctx -l $alg_quote:16,17,18 -q $nonce \
  52. -m $toss_out -s $toss_out -o $toss_out -g $alg_primary_obj > $out
  53. yaml_verify $out
  54. tpm2 quote -Q -c $file_quote_key_ctx \
  55. -l $alg_quote:16,17,18+$alg_quote1:16,17,18 -q $nonce -m $toss_out \
  56. -s $toss_out -o $toss_out -g $alg_primary_obj
  57. #####handle testing
  58. tpm2 evictcontrol -Q -C o -c $file_quote_key_ctx $Handle_ak_quote
  59. tpm2 quote -Q -c $Handle_ak_quote -l $alg_quote:16,17,18 -q $nonce \
  60. -m $toss_out -s $toss_out -o $toss_out -g $alg_primary_obj
  61. tpm2 quote -Q -c $Handle_ak_quote -l $alg_quote:16,17,18+$alg_quote1:16,17,18 \
  62. -q $nonce -m $toss_out -s $toss_out -o $toss_out -g $alg_primary_obj
  63. #####AK
  64. tpm2 createek -Q -c $Handle_ek_quote -G 0x01
  65. tpm2 createak -Q -C $Handle_ek_quote -c $ak2_ctx -u ak.pub2 -n ak.name_2
  66. tpm2 evictcontrol -Q -C o -c $ak2_ctx $Handle_ak_quote2
  67. tpm2 quote -Q -c $Handle_ak_quote -l $alg_quote:16,17,18 -q $nonce \
  68. -m $toss_out -s $toss_out -o $toss_out -g $alg_primary_obj
  69. # ECC Test
  70. tpm2 createek -G ecc -c ek.ctx
  71. tpm2 createak -C ek.ctx -c ak.ctx -G ecc -g sha256 -s ecdsa
  72. tpm2 getrandom -o nonce.bin 20
  73. tpm2 quote -c ak.ctx -l sha256:15,16,22 -q nonce.bin -m quote.bin -s quote.sig -o quote.pcr -g sha256
  74. exit 0