abrmd_policynv.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. nv_test_index=0x01500001
  4. cleanup() {
  5. tpm2 nvundefine -Q -C o $nv_test_index 2>/dev/null || true
  6. tpm2 flushcontext -t
  7. tpm2 flushcontext -l
  8. tpm2 flushcontext -s
  9. rm -f session.ctx
  10. if [ "$1" != "no-shut-down" ]; then
  11. shut_down
  12. fi
  13. }
  14. # Data written to NV index --> 129 or -127
  15. operandA=0x81
  16. # Data specified in command line options for comparison
  17. operandB=0
  18. evaluate_failing_test_case() {
  19. tpm2 startauthsession -S session.ctx --policy-session
  20. trap - ERR
  21. echo $operandA | xxd -r -p | \
  22. tpm2 policynv -S session.ctx -i- -P nvpass $nv_test_index eq
  23. if [ $? != 1 ];then
  24. echo "FAIL: Expected tpm2 policynv to fail!"
  25. exit 1
  26. fi
  27. trap onerror ERR
  28. tpm2 flushcontext session.ctx
  29. }
  30. evaluate_passing_test_case() {
  31. tpm2 startauthsession -S session.ctx --policy-session
  32. echo $operandB | xxd -r -p | \
  33. tpm2 policynv -S session.ctx -i- -P nvpass $nv_test_index $1
  34. tpm2 flushcontext session.ctx
  35. }
  36. trap cleanup EXIT
  37. start_up
  38. cleanup "no-shut-down"
  39. tpm2 clear
  40. # Perform any comparison operation on an undefined NV index --> Should fail
  41. evaluate_failing_test_case
  42. # Define an NV index
  43. tpm2 nvdefine -C o -p nvpass $nv_test_index -a "authread|authwrite" -s 2
  44. # Perform any comparison operation on an unwritten NV index --> Should fail
  45. evaluate_failing_test_case
  46. # Write data to NV index --> This is operandA
  47. echo $operandA | xxd -r -p | tpm2 nvwrite -P nvpass -i- $nv_test_index
  48. # Perform comparison operation "eq"
  49. operandB=0x81
  50. evaluate_passing_test_case eq
  51. # Perform comparison operation "neq"
  52. operandB=0x80
  53. evaluate_passing_test_case neq
  54. # Perform comparison operation "sgt"
  55. operandB=0x82
  56. evaluate_passing_test_case sgt
  57. # Perform comparison operation "ugt"
  58. operandB=0x80
  59. evaluate_passing_test_case ugt
  60. # Perform comparison operation "slt"
  61. operandB=0x80
  62. evaluate_passing_test_case slt
  63. # Perform comparison operation "ult"
  64. operandB=0x82
  65. evaluate_passing_test_case ult
  66. # Perform comparison operation "sge"
  67. operandB=0x82
  68. evaluate_passing_test_case sge
  69. operandB=0x81
  70. evaluate_passing_test_case sge
  71. # Perform comparison operation "uge"
  72. operandB=0x80
  73. evaluate_passing_test_case uge
  74. operandB=0x81
  75. evaluate_passing_test_case uge
  76. # Perform comparison operation "sle"
  77. operandB=0x80
  78. evaluate_passing_test_case sle
  79. operandB=0x81
  80. evaluate_passing_test_case sle
  81. # Perform comparison operation "ule"
  82. operandB=0x82
  83. evaluate_passing_test_case ule
  84. operandB=0x81
  85. evaluate_passing_test_case ule
  86. # Perform comparison operation "bs"
  87. operandB=0x81
  88. evaluate_passing_test_case bs
  89. # Perform comparison operation "bc"
  90. operandB=0x7E
  91. evaluate_passing_test_case bc
  92. exit 0