testparms.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. cleanup() {
  4. if [ "$1" != "no-shut-down" ]; then
  5. shut_down
  6. fi
  7. }
  8. trap cleanup EXIT
  9. start_up
  10. cleanup "no-shut-down"
  11. aesmodes="$(populate_algs "details['encrypting'] and details['symmetric']")"
  12. hashalgs="$(populate_algs "details['hash'] and not details['method'] \
  13. and not details['signing'] \
  14. and not details['symmetric'] \
  15. and alg is not None")"
  16. eccmethods="$(populate_algs "details['signing'] and not details['hash'] and \"ec\" in alg")"
  17. rsamethods="$(populate_algs "details['signing'] and not details['hash'] and \"rsa\" in alg")"
  18. # Test that common algorithms are supported
  19. for i in "rsa" "xor" "hmac" "ecc" "keyedhash"; do
  20. tpm2 testparms "${i}"
  21. done
  22. # Test that RSA signing schemes are supported
  23. for i in ${rsamethods}; do
  24. echo "tpm2 testparms rsa:${i}"
  25. tpm2 testparms "rsa:${i}"
  26. done
  27. # Test that ECC signing schemes are supported
  28. for i in ${eccmethods}; do
  29. tpm2 testparms "ecc:${i}"
  30. done
  31. # Test that aes modes are supported
  32. for i in ${aesmodes}; do
  33. tpm2 testparms "aes128${i}"
  34. done
  35. # Test that xor on hash algs is supported
  36. for i in ${hashalgs}; do
  37. tpm2 testparms "xor:${i}"
  38. done
  39. # Test that hmac on hash algs is supported
  40. for i in ${hashalgs}; do
  41. tpm2 testparms "hmac:${i}"
  42. done
  43. # Test that null algorithm raise an error (error from software stack)
  44. if ! tpm2 testparms "null" 2>&1 1>/dev/null | \
  45. grep -q "Invalid or unsupported by the tool : null"; then
  46. echo "tpm2 testparms with 'null' algorithm didn't fail"
  47. exit 1
  48. else
  49. true
  50. fi
  51. # Attempt to specify a suite that is not supported (error from TPM)
  52. if tpm2 getcap ecc-curves | grep -q TPM2_ECC_NIST_P521; then
  53. if tpm2 testparms "ecc521:ecdsa:camellia" &>/dev/null; then
  54. echo "tpm2 testparms succeeded while it shouldn't or TPM failed"
  55. exit 1
  56. else
  57. true
  58. fi
  59. fi
  60. exit 0