makecredential.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. handle_ek=0x81010007
  4. ak_ctx=ak.ctx
  5. ek_alg=rsa
  6. ak_alg=rsa
  7. digestAlg=sha256
  8. signAlg=rsassa
  9. file_input_data=secret.data
  10. output_ek_pub=ek_pub.out
  11. output_ak_pub=ak_pub.out
  12. output_ak_pub_name=ak_name_pub.out
  13. output_mkcredential=mkcredential.out
  14. cleanup() {
  15. rm -f $output_ek_pub $output_ak_pub $output_ak_pub_name \
  16. $output_mkcredential $file_input_data output_ak grep.txt $ak_ctx
  17. tpm2 evictcontrol -Q -Co -c $handle_ek 2>/dev/null || true
  18. if [ "$1" != "no-shut-down" ]; then
  19. shut_down
  20. fi
  21. }
  22. trap cleanup EXIT
  23. start_up
  24. cleanup "no-shut-down"
  25. echo "12345678" > $file_input_data
  26. tpm2 createek -Q -c $handle_ek -G $ek_alg -u $output_ek_pub
  27. tpm2 createak -Q -C $handle_ek -c $ak_ctx -G $ak_alg -g $digestAlg -s $signAlg \
  28. -u $output_ak_pub -n $output_ak_pub_name
  29. # Use -c in xxd so there is no line wrapping
  30. file_size=`ls -l $output_ak_pub_name | awk {'print $5'}`
  31. Loadkeyname=`cat $output_ak_pub_name | xxd -p -c $file_size`
  32. tpm2 makecredential -Q -u $output_ek_pub -s $file_input_data -n $Loadkeyname \
  33. -o $output_mkcredential
  34. # use no tpm backend
  35. tpm2 makecredential -T none -Q -u $output_ek_pub -s $file_input_data \
  36. -n $Loadkeyname -o $output_mkcredential
  37. # use no tpm backend and EK in PEM format
  38. tpm2 readpublic -c $handle_ek -o ek.pem -f pem -Q
  39. tpm2 makecredential -T none -Q -u ek.pem -G rsa -s $file_input_data \
  40. -n $Loadkeyname -o $output_mkcredential
  41. exit 0