fapi-nv-write-read_ecc.sh 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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/myNVwrite
  13. DATA_WRITE_FILE=$TEMP_DIR/nv_write_data.file
  14. DATA_READ_FILE=$TEMP_DIR/nv_read_data.file
  15. EMPTY_FILE=$TEMP_DIR/empty.file
  16. BIG_FILE=$TEMP_DIR/big_file.file
  17. LOG_FILE=$TEMP_DIR/log.file
  18. touch $LOG_FILE
  19. tss2 provision
  20. echo 1234567890123456789 > $DATA_WRITE_FILE
  21. tss2 createnv --path=$NV_PATH --type="noDa" --size=20 --authValue=""
  22. tss2 nvwrite --nvPath=$NV_PATH --data=$DATA_WRITE_FILE
  23. echo "tss2 nvwrite with EMPTY_FILE" # Expected to succeed
  24. tss2 nvwrite --nvPath=$NV_PATH --data=$EMPTY_FILE
  25. echo "tss2 nvwrite with BIG_FILE" # Expected to fail
  26. expect <<EOF
  27. spawn sh -c "tss2 nvwrite --nvPath=$NV_PATH --data=$BIG_FILE 2> $LOG_FILE"
  28. set ret [wait]
  29. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  30. set file [open $LOG_FILE r]
  31. set log [read \$file]
  32. close $file
  33. send_user "[lindex \$log]\n"
  34. exit 1
  35. }
  36. EOF
  37. if [[ "`cat $LOG_FILE`" == $SANITIZER_FILTER ]]; then
  38. echo "Error: AddressSanitizer triggered."
  39. cat $LOG_FILE
  40. exit 1
  41. fi
  42. tss2 nvread --nvPath=$NV_PATH --data=$DATA_READ_FILE --force
  43. if [ `cat $DATA_READ_FILE` != `cat $DATA_WRITE_FILE` ]; then
  44. echo "Test without password: Strings are not equal"
  45. exit 99
  46. fi
  47. tss2 delete --path=$NV_PATH
  48. tss2 createnv --path=$NV_PATH --type="noDa" --size=20 --authValue=$PW
  49. expect <<EOF
  50. # Check if system asks for auth value and provide it
  51. spawn tss2 nvwrite --nvPath=$NV_PATH --data=$DATA_WRITE_FILE
  52. expect {
  53. "Authorize object: " {
  54. } eof {
  55. send_user "The system has not asked for password\n"
  56. exit 1
  57. }
  58. }
  59. send "$PW\r"
  60. set ret [wait]
  61. if {[lindex \$ret 2] || [lindex \$ret 3]} {
  62. send_user "Passing password has failed\n"
  63. exit 1
  64. }
  65. EOF
  66. expect <<EOF
  67. # Try with missing nvPath
  68. spawn tss2 nvread --data=$DATA_READ_FILE --force
  69. set ret [wait]
  70. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  71. Command has not failed as expected\n"
  72. exit 1
  73. }
  74. EOF
  75. expect <<EOF
  76. # Try with missing data
  77. spawn tss2 nvread --nvPath=$NV_PATH --force
  78. set ret [wait]
  79. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  80. Command has not failed as expected\n"
  81. exit 1
  82. }
  83. EOF
  84. expect <<EOF
  85. # Try with multiple stdout (1)
  86. spawn tss2 nvread --nvPath=$NV_PATH --data=- --logData=- --force
  87. set ret [wait]
  88. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  89. Command has not failed as expected\n"
  90. exit 1
  91. }
  92. EOF
  93. expect <<EOF
  94. # Try with multiple stdout (1)
  95. spawn tss2 nvread --nvPath $NV_PATH --data - --logData - --force
  96. set ret [wait]
  97. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  98. Command has not failed as expected\n"
  99. exit 1
  100. }
  101. EOF
  102. expect <<EOF
  103. # Try with missing nvPath
  104. spawn tss2 nvwrite --data=$DATA_WRITE_FILE
  105. set ret [wait]
  106. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  107. Command has not failed as expected\n"
  108. exit 1
  109. }
  110. EOF
  111. expect <<EOF
  112. # Try with missing data
  113. spawn tss2 nvwrite --nvPath=$NV_PATH
  114. set ret [wait]
  115. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  116. Command has not failed as expected\n"
  117. exit 1
  118. }
  119. EOF
  120. tss2 delete --path=$NV_PATH
  121. NODA="noDa"
  122. expect <<EOF
  123. # Try interactive prompt
  124. spawn tss2 createnv --path=$NV_PATH --type=$NODA --size=20
  125. expect "Authorize object Password: "
  126. send "$PW\r"
  127. expect "Authorize object Retype password: "
  128. send "$PW\r"
  129. set ret [wait]
  130. if {[lindex \$ret 2] || [lindex \$ret 3] != 0} {
  131. send_user "Using interactive prompt with password has failed\n"
  132. exit 1
  133. }
  134. EOF
  135. # Try with missing type
  136. tss2 delete --path=$NV_PATH
  137. tss2 createnv --path=$NV_PATH --size=20 --authValue=$PW
  138. # Try with size-0 supported types
  139. tss2 delete --path=$NV_PATH
  140. tss2 createnv --path=$NV_PATH --type="bitfield" --size=0 --authValue=$PW
  141. tss2 delete --path=$NV_PATH
  142. tss2 createnv --path=$NV_PATH --type="pcr" --size=0 --authValue=$PW
  143. tss2 delete --path=$NV_PATH
  144. tss2 createnv --path=$NV_PATH --type="counter" --size=0 --authValue=$PW
  145. tss2 delete --path=$NV_PATH
  146. tss2 createnv --path=$NV_PATH --type="bitfield" --authValue=$PW
  147. tss2 delete --path=$NV_PATH
  148. tss2 createnv --path=$NV_PATH --type="pcr" --authValue=$PW
  149. tss2 delete --path=$NV_PATH
  150. tss2 createnv --path=$NV_PATH --type="counter" --authValue=$PW
  151. tss2 delete --path=$NV_PATH
  152. expect <<EOF
  153. # Try with missing size and no type
  154. spawn tss2 createnv --path=$NV_PATH --authValue=$PW
  155. set ret [wait]
  156. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  157. Command has not failed as expected\n"
  158. exit 1
  159. }
  160. EOF
  161. expect <<EOF
  162. # Try with size=0 and no type
  163. spawn tss2 createnv --path=$NV_PATH --size=0 --authValue=$PW
  164. set ret [wait]
  165. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  166. Command has not failed as expected\n"
  167. exit 1
  168. }
  169. EOF
  170. exit 0