fapi-nv-write-read-policy-or_ecc.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. set -e
  2. source helpers.sh
  3. start_up
  4. CRYPTO_PROFILE="ECC"
  5. setup_fapi $CRYPTO_PROFILE
  6. function cleanup {
  7. tss2 delete --path=/
  8. shut_down
  9. }
  10. trap cleanup EXIT
  11. PW=abc
  12. NV_PATH=/nv/Owner/myNV
  13. DATA_WRITE_FILE=$TEMP_DIR/nv_write_data.file
  14. DATA_READ_FILE=$TEMP_DIR/nv_read_data.file
  15. POLICY_NV_DATA=$TEMP_DIR/pol_nv_read_write.json
  16. POLICY_NV=/policy/nv_read_write
  17. LOG_FILE=$TEMP_DIR/log.file
  18. touch $LOG_FILE
  19. PW=abc
  20. tss2 provision
  21. echo test > $DATA_WRITE_FILE
  22. tss2 import -i $POLICY_NV_DATA -p $POLICY_NV
  23. tss2 createnv -p $NV_PATH -P $POLICY_NV -s 16 --authValue=$PW
  24. echo "Write with write policy"
  25. expect <<EOF
  26. # Check if system asks for branch selection
  27. spawn sh -c "tss2 nvwrite --nvPath=$NV_PATH --data=$DATA_WRITE_FILE> $LOG_FILE"
  28. expect -re {
  29. "Select a branch.*" {
  30. } eof {
  31. send_user "The system has not asked for branch selection\n"
  32. exit 1
  33. }
  34. }
  35. send "1\r"
  36. set ret [wait]
  37. if {[lindex \$ret 2]} {
  38. send_user "Command failed\n"
  39. exit 1
  40. }
  41. EOF
  42. echo "Read with read policy."
  43. expect <<EOF
  44. spawn sh -c "tss2 nvread --nvPath=$NV_PATH --data=$DATA_READ_FILE> $LOG_FILE"
  45. expect -re {
  46. "Select a branch.*" { }
  47. eof {
  48. send_user "The system has not asked for branch selection\n"
  49. exit 1
  50. }
  51. }
  52. send "2\r"
  53. set ret [wait]
  54. if {[lindex \$ret 2] || [lindex \$ret 3] != 0} {
  55. set file [open $LOG_FILE r]
  56. send_user "Command failed\n"
  57. exit 1
  58. }
  59. EOF
  60. echo "Write with read policy should fail."
  61. expect <<EOF
  62. # Check if system asks for branch selection
  63. spawn sh -c "tss2 nvwrite --nvPath=$NV_PATH --data=$DATA_WRITE_FILE> $LOG_FILE"
  64. expect -re {
  65. "Select a branch.*" {
  66. } eof {
  67. send_user "The system has not asked for branch selection\n"
  68. exit 1
  69. }
  70. }
  71. send "2\r"
  72. set ret [wait]
  73. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  74. send_user "Command failed\n"
  75. exit 1
  76. }
  77. EOF
  78. echo "Read with write policy should fail."
  79. expect <<EOF
  80. spawn sh -c "tss2 nvread --nvPath=$NV_PATH --data=$DATA_READ_FILE> $LOG_FILE"
  81. expect -re {
  82. "Select a branch.*" {
  83. } eof {
  84. send_user "The system has not asked for branch selection\n"
  85. exit 1
  86. }
  87. }
  88. send "1\r"
  89. set ret [wait]
  90. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  91. set file [open $LOG_FILE r]
  92. send_user "Command failed\n"
  93. exit 1
  94. }
  95. EOF
  96. tss2 delete --path=$NV_PATH
  97. if [[ "`cat $LOG_FILE`" == $SANITIZER_FILTER ]]; then
  98. echo "Error: AddressSanitizer triggered."
  99. cat $LOG_FILE
  100. exit 1
  101. fi
  102. exit 0