fapi-nv-write-read-policy-or2.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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_PWD_NV_DATA=$TEMP_DIR/pol_pwd_nv_read_write.json
  16. POLICY_PWD_NV=/policy/pwd_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_PWD_NV_DATA -p $POLICY_PWD_NV
  23. tss2 createnv -p $NV_PATH -P $POLICY_PWD_NV -s 16 --authValue=$PW
  24. echo "Write without password but policy write."
  25. expect <<EOF
  26. spawn sh -c "tss2 nvwrite --nvPath=$NV_PATH --data=$DATA_WRITE_FILE> $LOG_FILE"
  27. set timout 0
  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 "2\r"
  36. expect -re {
  37. "Your choi.*" { }
  38. eof {
  39. send_user "The system did not comment selection\n"
  40. exit 1
  41. }
  42. }
  43. expect -re {
  44. "Select.*" { }
  45. eof {
  46. send_user "The system has not asked for password\n"
  47. exit 1
  48. }
  49. }
  50. send "1\r"
  51. set ret [wait]
  52. if {[lindex \$ret 2] || [lindex \$ret 3] != 0} {
  53. send_user "Using interactive prompt has failed\n"
  54. exit 1
  55. }
  56. EOF
  57. echo "Write with password policy"
  58. expect <<EOF
  59. spawn sh -c "tss2 nvwrite --nvPath=$NV_PATH --data=$DATA_WRITE_FILE> $LOG_FILE"
  60. set timout 0
  61. expect -re {
  62. "Select a branch.*" { }
  63. eof {
  64. send_user "The system has not asked for branch selection\n"
  65. exit 1
  66. }
  67. }
  68. send "1\r"
  69. expect -re {
  70. "Your choi.*" { }
  71. eof {
  72. send_user "The system did not comment selection\n"
  73. exit 1
  74. }
  75. }
  76. expect -re {
  77. "Authorize.*" { }
  78. eof {
  79. send_user "The system has not asked for password\n"
  80. exit 1
  81. }
  82. }
  83. send "$PW\r"
  84. set ret [wait]
  85. if {[lindex \$ret 2] || [lindex \$ret 3] != 0} {
  86. send_user "Using interactive prompt has failed\n"
  87. exit 1
  88. }
  89. EOF
  90. echo "Read with password policy"
  91. expect <<EOF
  92. spawn sh -c "tss2 nvread --nvPath=$NV_PATH --data=$DATA_READ_FILE > $LOG_FILE"
  93. set timout 0
  94. expect -re {
  95. "Select a branch.*" { }
  96. eof {
  97. send_user "The system has not asked for branch selection\n"
  98. exit 1
  99. }
  100. }
  101. send "1\r"
  102. expect -re {
  103. "Your choi.*" { }
  104. eof {
  105. send_user "The system did not comment selection\n"
  106. exit 1
  107. }
  108. }
  109. expect -re {
  110. "Authorize.*" { }
  111. eof {
  112. send_user "The system has not asked for password\n"
  113. exit 1
  114. }
  115. }
  116. send "$PW\r"
  117. set ret [wait]
  118. if {[lindex \$ret 2] || [lindex \$ret 3] != 0} {
  119. send_user "Using interactive prompt has failed\n"
  120. exit 1
  121. }
  122. EOF
  123. echo "Write with wrong password should fail"
  124. expect <<EOF
  125. # Check if system asks for branch selection
  126. spawn sh -c "tss2 nvwrite --nvPath=$NV_PATH --data=$DATA_WRITE_FILE> $LOG_FILE"
  127. set timout 0
  128. expect -re {
  129. "Select a branch.*" { }
  130. eof {
  131. send_user "The system has not asked for branch selection\n"
  132. exit 1
  133. }
  134. }
  135. send "1\r"
  136. expect -re {
  137. "Your choi.*" { }
  138. eof {
  139. send_user "The system did not comment selection\n"
  140. exit 1
  141. }
  142. }
  143. expect -re {
  144. "Authorize.*" { }
  145. eof {
  146. send_user "The system has not asked for password\n"
  147. exit 1
  148. }
  149. }
  150. send "XXXXX\r"
  151. set ret [wait]
  152. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  153. send_user "Using interactive prompt has failed\n"
  154. exit 1
  155. }
  156. EOF
  157. tss2 delete --path=$NV_PATH
  158. if [[ "`cat $LOG_FILE`" == $SANITIZER_FILTER ]]; then
  159. echo "Error: AddressSanitizer triggered."
  160. cat $LOG_FILE
  161. exit 1
  162. fi
  163. exit 0