fapi-pcr-extend-read_ecc.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. NV_PATH=/nv/Owner/myNVwrite
  12. PCR_DIGEST_FILE=$TEMP_DIR/pcr_digest.file
  13. PCR_LOG_FILE_WRITE=$TEMP_DIR/pcr_log_write.file
  14. echo "{\"test\": \"myfile\"}" > $PCR_LOG_FILE_WRITE
  15. PCR_LOG_FILE_READ=$TEMP_DIR/pcr_log_read.file
  16. PCR_EVENT_DATA=$TEMP_DIR/pcr_event_data.file
  17. echo "0,1,2,3,4,5,6,7,8,9" > $PCR_EVENT_DATA
  18. EMPTY_FILE=$TEMP_DIR/empty.file
  19. BIG_FILE=$TEMP_DIR/big_file.file
  20. LOG_FILE=$TEMP_DIR/log.file
  21. touch $LOG_FILE
  22. tss2 provision
  23. tss2 pcrextend --pcr=16 --data=$PCR_EVENT_DATA \
  24. --logData=$PCR_LOG_FILE_WRITE
  25. echo "tss2 pcrextend with EMPTY_FILE data" # Expected to fail
  26. expect <<EOF
  27. spawn sh -c "tss2 pcrextend --pcr=16 --data=$EMPTY_FILE \
  28. --logData=$PCR_LOG_FILE_WRITE 2> $LOG_FILE"
  29. set ret [wait]
  30. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  31. set file [open $LOG_FILE r]
  32. set log [read \$file]
  33. close $file
  34. send_user "[lindex \$log]\n"
  35. exit 1
  36. }
  37. EOF
  38. if [[ "`cat $LOG_FILE`" == $SANITIZER_FILTER ]]; then
  39. echo "Error: AddressSanitizer triggered."
  40. cat $LOG_FILE
  41. exit 1
  42. fi
  43. echo "tss2 pcrextend with BIG_FILE data" # Expected to fail
  44. expect <<EOF
  45. spawn sh -c "tss2 pcrextend --pcr=16 --data=$BIG_FILE \
  46. --logData=$PCR_LOG_FILE_WRITE 2> $LOG_FILE"
  47. set ret [wait]
  48. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  49. set file [open $LOG_FILE r]
  50. set log [read \$file]
  51. close $file
  52. send_user "[lindex \$log]\n"
  53. exit 1
  54. }
  55. EOF
  56. if [[ "`cat $LOG_FILE`" == $SANITIZER_FILTER ]]; then
  57. echo "Error: AddressSanitizer triggered."
  58. cat $LOG_FILE
  59. exit 1
  60. fi
  61. echo "tss2 pcrextend with EMPTY_FILE logData" # Expected to fail
  62. expect <<EOF
  63. spawn sh -c "tss2 pcrextend --pcr=16 --data=$PCR_EVENT_DATA \
  64. --logData=$EMPTY_FILE 2> $LOG_FILE"
  65. set ret [wait]
  66. if {[lindex \$ret 2] || [lindex \$ret 3] != 1 } {
  67. set file [open $LOG_FILE r]
  68. set log [read \$file]
  69. close $file
  70. send_user "[lindex \$log]\n"
  71. exit 1
  72. }
  73. EOF
  74. if [[ "`cat $LOG_FILE`" == $SANITIZER_FILTER ]]; then
  75. echo "Error: AddressSanitizer triggered."
  76. cat $LOG_FILE
  77. exit 1
  78. fi
  79. echo "tss2 pcrextend with BIG_FILE logData" # Expected to fail
  80. expect <<EOF
  81. spawn sh -c "tss2 pcrextend --pcr=16 --data=$PCR_EVENT_DATA \
  82. --logData=$BIG_FILE 2> $LOG_FILE"
  83. set ret [wait]
  84. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  85. set file [open $LOG_FILE r]
  86. set log [read \$file]
  87. close $file
  88. send_user "[lindex \$log]\n"
  89. exit 1
  90. }
  91. EOF
  92. if [[ "`cat $LOG_FILE`" == $SANITIZER_FILTER ]]; then
  93. echo "Error: AddressSanitizer triggered."
  94. cat $LOG_FILE
  95. exit 1
  96. fi
  97. tss2 pcrread --pcrIndex=16 --pcrValue=$PCR_DIGEST_FILE \
  98. --pcrLog=$PCR_LOG_FILE_READ --force
  99. if [ ! -s $PCR_DIGEST_FILE ] || [ ! -s $PCR_LOG_FILE_READ ]; then
  100. echo "At least one returned file is empty"
  101. exit 1
  102. fi
  103. expect <<EOF
  104. # Try with missing pcr
  105. spawn tss2 pcrextend --data=$PCR_EVENT_DATA --logData=$PCR_LOG_FILE_WRITE
  106. set ret [wait]
  107. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  108. Command has not failed as expected\n"
  109. exit 1
  110. }
  111. EOF
  112. expect <<EOF
  113. # Try with missing data
  114. spawn tss2 pcrextend --pcr=16 --logData=$PCR_LOG_FILE_WRITE
  115. set ret [wait]
  116. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  117. Command has not failed as expected\n"
  118. exit 1
  119. }
  120. EOF
  121. expect <<EOF
  122. # Try with wrong pcr
  123. spawn tss2 pcrextend --pcr=abc --data=$PCR_EVENT_DATA \
  124. --logData=$PCR_LOG_FILE_WRITE
  125. set ret [wait]
  126. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  127. Command has not failed as expected\n"
  128. exit 1
  129. }
  130. EOF
  131. expect <<EOF
  132. # Try with multiple stdins
  133. spawn tss2 pcrextend --pcr=16 --data=- --logData=-
  134. set ret [wait]
  135. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  136. Command has not failed as expected\n"
  137. exit 1
  138. }
  139. EOF
  140. # Try with missing logData
  141. tss2 pcrextend --pcr=16 --data=$PCR_EVENT_DATA
  142. expect <<EOF
  143. # Try with missing pcrIndex
  144. spawn tss2 pcrread --pcrValue=$PCR_DIGEST_FILE --pcrLog=$PCR_LOG_FILE_READ --force
  145. set ret [wait]
  146. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  147. Command has not failed as expected\n"
  148. exit 1
  149. }
  150. EOF
  151. # Try with missing pcrValue
  152. tss2 pcrread --pcrIndex=16 --pcrLog=$PCR_LOG_FILE_READ --force
  153. # Try with missing pcrLog
  154. tss2 pcrread --pcrIndex=16 --pcrValue=$PCR_DIGEST_FILE --force
  155. expect <<EOF
  156. # Try with multiple stdins (1)
  157. spawn tss2 pcrread --pcrIndex=16 --pcrValue=- \
  158. --pcrLog=-
  159. set ret [wait]
  160. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  161. Command has not failed as expected\n"
  162. exit 1
  163. }
  164. EOF
  165. expect <<EOF
  166. # Try with wrong pcrIndex
  167. spawn tss2 pcrread --pcrIndex=abc --pcrValue=$PCR_DIGEST_FILE \
  168. --pcrLog=$PCR_LOG_FILE_READ --force
  169. set ret [wait]
  170. if {[lindex \$ret 2] || [lindex \$ret 3] != 1} {
  171. Command has not failed as expected\n"
  172. exit 1
  173. }
  174. EOF
  175. exit 0